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; |
486efb2e AM |
28 | import org.eclipse.linuxtools.ctf.core.trace.Stream; |
29 | import org.eclipse.linuxtools.ctf.core.trace.StreamInput; | |
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 | |
37 | * <code>{@link Stream}</code>. | |
e291b8c8 | 38 | * |
866e5b51 FC |
39 | * @author ematkho |
40 | * @version $Revision: 1.0 $ | |
41 | */ | |
be6df2d8 | 42 | @SuppressWarnings("javadoc") |
866e5b51 FC |
43 | public class StreamTest { |
44 | ||
9ac63b5b | 45 | private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL; |
32bf80d2 | 46 | |
866e5b51 FC |
47 | private Stream fixture; |
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 AM |
56 | assumeTrue(testTrace.exists()); |
57 | fixture = new Stream(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); | |
8e15b929 MK |
62 | fixture.addInput(new StreamInput(new Stream(testTrace.getTrace()), createFile())); |
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(); |
866e5b51 FC |
86 | Stream result = new Stream(trace); |
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() { | |
173 | Set<StreamInput> result = fixture.getStreamInputs(); | |
174 | assertNotNull(result); | |
175 | } | |
176 | ||
177 | /** | |
178 | * Run the CTFTrace getTrace() method test. | |
179 | */ | |
180 | @Test | |
181 | public void testGetTrace() { | |
182 | CTFTrace result = fixture.getTrace(); | |
183 | assertNotNull(result); | |
184 | } | |
185 | ||
186 | /** | |
187 | * Run the boolean idIsSet() method test. | |
188 | */ | |
189 | @Test | |
190 | public void testIdIsSet() { | |
9ac2eb62 | 191 | boolean result = fixture.isIdSet(); |
866e5b51 FC |
192 | assertTrue(result); |
193 | } | |
194 | ||
195 | /** | |
196 | * Run the boolean packetContextIsSet() method test. | |
197 | */ | |
198 | @Test | |
199 | public void testPacketContextIsSet() { | |
9ac2eb62 | 200 | boolean result = fixture.isPacketContextSet(); |
866e5b51 FC |
201 | assertTrue(result); |
202 | } | |
203 | ||
866e5b51 FC |
204 | /** |
205 | * Run the void setEventContext(StructDeclaration) method test. | |
206 | */ | |
207 | @Test | |
208 | public void testSetEventContext() { | |
209 | StructDeclaration eventContext = new StructDeclaration(1L); | |
210 | fixture.setEventContext(eventContext); | |
211 | } | |
212 | ||
213 | /** | |
214 | * Run the void setEventHeader(StructDeclaration) method test. | |
215 | */ | |
216 | @Test | |
217 | public void testSetEventHeader() { | |
218 | StructDeclaration eventHeader = new StructDeclaration(1L); | |
219 | fixture.setEventHeader(eventHeader); | |
220 | } | |
221 | ||
222 | /** | |
223 | * Run the void setId(long) method test. | |
224 | */ | |
225 | @Test | |
226 | public void testSetId() { | |
227 | long id = 1L; | |
228 | fixture.setId(id); | |
229 | } | |
230 | ||
231 | /** | |
232 | * Run the void setPacketContext(StructDeclaration) method test. | |
233 | */ | |
234 | @Test | |
235 | public void testSetPacketContext() { | |
236 | StructDeclaration packetContext = new StructDeclaration(1L); | |
237 | fixture.setPacketContext(packetContext); | |
238 | } | |
239 | } |