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