Commit | Line | Data |
---|---|---|
4bd7f2db AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 Ericsson | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Matthew Khouzam - Initial API and implementation | |
10 | *******************************************************************************/ | |
11 | ||
866e5b51 FC |
12 | package org.eclipse.linuxtools.ctf.core.tests.trace; |
13 | ||
14 | import static org.junit.Assert.assertNotNull; | |
15 | import static org.junit.Assert.assertTrue; | |
e5acb357 | 16 | import static org.junit.Assume.assumeTrue; |
866e5b51 | 17 | |
9ac63b5b | 18 | import java.io.File; |
8e15b929 | 19 | import java.io.FilenameFilter; |
0594c61c | 20 | import java.util.Map; |
866e5b51 FC |
21 | import java.util.Set; |
22 | ||
8e964be1 | 23 | import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; |
866e5b51 | 24 | import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; |
9ac63b5b | 25 | import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace; |
13be1a8f | 26 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
866e5b51 | 27 | import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; |
d84419e1 AM |
28 | import org.eclipse.linuxtools.ctf.core.trace.CTFStream; |
29 | import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInput; | |
8e964be1 | 30 | import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration; |
ce2388e0 | 31 | import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; |
866e5b51 FC |
32 | import org.junit.Before; |
33 | import org.junit.Test; | |
34 | ||
35 | /** | |
36 | * The class <code>StreamTest</code> contains tests for the class | |
d84419e1 | 37 | * <code>{@link CTFStream}</code>. |
e291b8c8 | 38 | * |
866e5b51 FC |
39 | * @author ematkho |
40 | * @version $Revision: 1.0 $ | |
41 | */ | |
be6df2d8 | 42 | @SuppressWarnings("javadoc") |
d84419e1 | 43 | public class CTFStreamTest { |
866e5b51 | 44 | |
9ac63b5b | 45 | private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL; |
32bf80d2 | 46 | |
d84419e1 | 47 | private CTFStream fixture; |
866e5b51 | 48 | |
866e5b51 FC |
49 | /** |
50 | * Perform pre-test initialization. | |
788ddcbc MK |
51 | * |
52 | * @throws CTFReaderException | |
866e5b51 FC |
53 | */ |
54 | @Before | |
13be1a8f | 55 | public void setUp() throws CTFReaderException { |
9ac63b5b | 56 | assumeTrue(testTrace.exists()); |
d84419e1 | 57 | fixture = new CTFStream(testTrace.getTrace()); |
866e5b51 FC |
58 | fixture.setEventContext(new StructDeclaration(1L)); |
59 | fixture.setPacketContext(new StructDeclaration(1L)); | |
60 | fixture.setEventHeader(new StructDeclaration(1L)); | |
61 | fixture.setId(1L); | |
d84419e1 | 62 | fixture.addInput(new CTFStreamInput(new CTFStream(testTrace.getTrace()), createFile())); |
8e15b929 MK |
63 | } |
64 | ||
65 | private static File createFile() { | |
66 | File path = new File(testTrace.getPath()); | |
67 | return path.listFiles(new FilenameFilter() { | |
68 | @Override | |
69 | public boolean accept(File dir, String name) { | |
70 | if (name.contains("hann")) { | |
71 | return true; | |
72 | } | |
73 | return false; | |
74 | } | |
75 | })[0]; | |
866e5b51 FC |
76 | } |
77 | ||
866e5b51 FC |
78 | /** |
79 | * Run the Stream(CTFTrace) constructor test. | |
788ddcbc MK |
80 | * |
81 | * @throws CTFReaderException | |
866e5b51 FC |
82 | */ |
83 | @Test | |
13be1a8f | 84 | public void testStream() throws CTFReaderException { |
9ac63b5b | 85 | CTFTrace trace = testTrace.getTrace(); |
d84419e1 | 86 | CTFStream result = new CTFStream(trace); |
866e5b51 FC |
87 | assertNotNull(result); |
88 | } | |
89 | ||
90 | /** | |
8e15b929 MK |
91 | * Run the void addEvent(EventDeclaration) method test with the basic event. |
92 | * | |
e291b8c8 | 93 | * @throws ParseException |
866e5b51 FC |
94 | */ |
95 | @Test | |
96 | public void testAddEvent_base() throws ParseException { | |
97 | EventDeclaration event = new EventDeclaration(); | |
98 | fixture.addEvent(event); | |
99 | } | |
100 | ||
866e5b51 FC |
101 | /** |
102 | * Run the boolean eventContextIsSet() method test. | |
103 | */ | |
104 | @Test | |
105 | public void testEventContextIsSet() { | |
9ac2eb62 | 106 | assertTrue(fixture.isEventContextSet()); |
866e5b51 | 107 | } |
8e15b929 | 108 | |
e291b8c8 MK |
109 | /** |
110 | * Run the boolean eventContextIsSet() method test. | |
111 | */ | |
112 | @Test | |
113 | public void testToString() { | |
114 | assertNotNull(fixture.toString()); | |
115 | } | |
866e5b51 FC |
116 | |
117 | /** | |
118 | * Run the boolean eventHeaderIsSet() method test. | |
119 | */ | |
120 | @Test | |
121 | public void testEventHeaderIsSet() { | |
9ac2eb62 | 122 | assertTrue(fixture.isEventHeaderSet()); |
866e5b51 FC |
123 | } |
124 | ||
125 | /** | |
126 | * Run the StructDeclaration getEventContextDecl() method test. | |
127 | */ | |
128 | @Test | |
129 | public void testGetEventContextDecl() { | |
130 | assertNotNull(fixture.getEventContextDecl()); | |
131 | } | |
132 | ||
133 | /** | |
134 | * Run the StructDeclaration getEventHeaderDecl() method test. | |
135 | */ | |
136 | @Test | |
137 | public void testGetEventHeaderDecl() { | |
138 | assertNotNull(fixture.getEventHeaderDecl()); | |
139 | } | |
140 | ||
141 | /** | |
142 | * Run the HashMap<Long, EventDeclaration> getEvents() method test. | |
143 | */ | |
144 | @Test | |
145 | public void testGetEvents() { | |
0594c61c | 146 | Map<Long, IEventDeclaration> result = fixture.getEvents(); |
866e5b51 FC |
147 | assertNotNull(result); |
148 | } | |
149 | ||
150 | /** | |
151 | * Run the Long getId() method test. | |
152 | */ | |
153 | @Test | |
154 | public void testGetId() { | |
155 | Long result = fixture.getId(); | |
156 | assertNotNull(result); | |
157 | } | |
158 | ||
159 | /** | |
160 | * Run the StructDeclaration getPacketContextDecl() method test. | |
161 | */ | |
162 | @Test | |
163 | public void testGetPacketContextDecl() { | |
164 | StructDeclaration result = fixture.getPacketContextDecl(); | |
165 | assertNotNull(result); | |
166 | } | |
167 | ||
168 | /** | |
169 | * Run the Set<StreamInput> getStreamInputs() method test. | |
170 | */ | |
171 | @Test | |
172 | public void testGetStreamInputs() { | |
d84419e1 | 173 | Set<CTFStreamInput> result = fixture.getStreamInputs(); |
866e5b51 FC |
174 | assertNotNull(result); |
175 | } | |
176 | ||
177 | /** | |
178 | * Run the CTFTrace getTrace() method test. | |
179 | */ | |
180 | @Test | |
181 | public void testGetTrace() { | |
05ce5fef AM |
182 | try (CTFTrace result = fixture.getTrace();) { |
183 | assertNotNull(result); | |
184 | } | |
866e5b51 FC |
185 | } |
186 | ||
187 | /** | |
188 | * Run the boolean idIsSet() method test. | |
189 | */ | |
190 | @Test | |
191 | public void testIdIsSet() { | |
9ac2eb62 | 192 | boolean result = fixture.isIdSet(); |
866e5b51 FC |
193 | assertTrue(result); |
194 | } | |
195 | ||
196 | /** | |
197 | * Run the boolean packetContextIsSet() method test. | |
198 | */ | |
199 | @Test | |
200 | public void testPacketContextIsSet() { | |
9ac2eb62 | 201 | boolean result = fixture.isPacketContextSet(); |
866e5b51 FC |
202 | assertTrue(result); |
203 | } | |
204 | ||
866e5b51 FC |
205 | /** |
206 | * Run the void setEventContext(StructDeclaration) method test. | |
207 | */ | |
208 | @Test | |
209 | public void testSetEventContext() { | |
210 | StructDeclaration eventContext = new StructDeclaration(1L); | |
211 | fixture.setEventContext(eventContext); | |
212 | } | |
213 | ||
214 | /** | |
215 | * Run the void setEventHeader(StructDeclaration) method test. | |
216 | */ | |
217 | @Test | |
218 | public void testSetEventHeader() { | |
219 | StructDeclaration eventHeader = new StructDeclaration(1L); | |
220 | fixture.setEventHeader(eventHeader); | |
221 | } | |
222 | ||
223 | /** | |
224 | * Run the void setId(long) method test. | |
225 | */ | |
226 | @Test | |
227 | public void testSetId() { | |
228 | long id = 1L; | |
229 | fixture.setId(id); | |
230 | } | |
231 | ||
232 | /** | |
233 | * Run the void setPacketContext(StructDeclaration) method test. | |
234 | */ | |
235 | @Test | |
236 | public void testSetPacketContext() { | |
237 | StructDeclaration packetContext = new StructDeclaration(1L); | |
238 | fixture.setPacketContext(packetContext); | |
239 | } | |
05ce5fef | 240 | } |