Commit | Line | Data |
---|---|---|
866e5b51 FC |
1 | package org.eclipse.linuxtools.ctf.core.tests.trace; |
2 | ||
3 | import static org.junit.Assert.assertEquals; | |
4 | import static org.junit.Assert.assertNotNull; | |
5 | import static org.junit.Assert.assertTrue; | |
6 | ||
7 | import java.nio.channels.FileChannel; | |
8 | import java.util.Set; | |
9 | ||
10 | import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; | |
11 | import org.eclipse.linuxtools.ctf.core.event.EventDefinition; | |
12 | import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; | |
13 | import org.eclipse.linuxtools.ctf.core.tests.TestParams; | |
14 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; | |
15 | import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; | |
866e5b51 | 16 | import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; |
ce2388e0 FC |
17 | import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; |
18 | import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; | |
866e5b51 FC |
19 | import org.junit.After; |
20 | import org.junit.Before; | |
21 | import org.junit.Test; | |
22 | ||
23 | /** | |
24 | * The class <code>StreamInputReaderTest</code> contains tests for the class | |
25 | * <code>{@link StreamInputReader}</code>. | |
ce2388e0 | 26 | * |
866e5b51 FC |
27 | * @author ematkho |
28 | * @version $Revision: 1.0 $ | |
29 | */ | |
30 | public class StreamInputReaderTest { | |
31 | ||
32 | private StreamInputReader fixture; | |
33 | ||
34 | /** | |
35 | * Launch the test. | |
ce2388e0 | 36 | * |
866e5b51 FC |
37 | * @param args |
38 | * the command line arguments | |
39 | */ | |
40 | public static void main(String[] args) { | |
41 | new org.junit.runner.JUnitCore().run(StreamInputReaderTest.class); | |
42 | } | |
43 | ||
44 | /** | |
45 | * Perform pre-test initialization. | |
ce2388e0 FC |
46 | * |
47 | * @throws CTFReaderException | |
866e5b51 FC |
48 | */ |
49 | @Before | |
13be1a8f AM |
50 | public void setUp() throws CTFReaderException { |
51 | fixture = getStreamInputReader(); | |
866e5b51 FC |
52 | fixture.setName(1); |
53 | fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(), | |
13be1a8f | 54 | getStreamInputReader())); |
866e5b51 FC |
55 | } |
56 | ||
57 | /** | |
58 | * Perform post-test clean-up. | |
59 | */ | |
60 | @After | |
61 | public void tearDown() { | |
62 | // Add additional tear down code here | |
63 | } | |
64 | ||
13be1a8f | 65 | private static StreamInputReader getStreamInputReader() throws CTFReaderException { |
866e5b51 FC |
66 | CTFTrace trace = TestParams.createTrace(); |
67 | Stream s = trace.getStream((long) 0); | |
68 | Set<StreamInput> streamInput = s.getStreamInputs(); | |
69 | StreamInputReader retVal = null; | |
70 | for (StreamInput si : streamInput) { | |
71 | /* | |
72 | * For the tests, we'll use the stream input corresponding to the | |
73 | * CPU 0 | |
74 | */ | |
75 | if (si.getFilename().endsWith("0_0")) { //$NON-NLS-1$ | |
76 | retVal = new StreamInputReader(si); | |
77 | break; | |
78 | } | |
79 | } | |
80 | return retVal; | |
81 | } | |
82 | ||
83 | /** | |
84 | * Run the StreamInputReader(StreamInput) constructor test, with a valid | |
85 | * trace. | |
86 | */ | |
87 | @Test | |
88 | public void testStreamInputReader_valid() { | |
89 | assertNotNull(fixture); | |
90 | } | |
91 | ||
92 | /** | |
93 | * Run the StreamInputReader(StreamInput) constructor test, with an invalid | |
94 | * trace. | |
ce2388e0 | 95 | * |
866e5b51 FC |
96 | * @throws CTFReaderException |
97 | */ | |
98 | @Test(expected = CTFReaderException.class) | |
99 | public void testStreamInputReader_invalid() throws CTFReaderException { | |
100 | StreamInput streamInput = new StreamInput( | |
101 | new Stream(new CTFTrace("")), (FileChannel) null, TestParams.getEmptyFile()); //$NON-NLS-1$ | |
102 | ||
103 | StreamInputReader result = new StreamInputReader(streamInput); | |
104 | assertNotNull(result); | |
105 | } | |
106 | ||
107 | /** | |
108 | * Run the int getCPU() method test. | |
109 | */ | |
110 | @Test | |
111 | public void testGetCPU() { | |
112 | int result = fixture.getCPU(); | |
113 | assertEquals(0, result); | |
114 | } | |
115 | ||
116 | /** | |
117 | * Run the EventDefinition getCurrentEvent() method test. | |
118 | */ | |
119 | @Test | |
120 | public void testGetCurrentEvent() { | |
121 | EventDefinition result = fixture.getCurrentEvent(); | |
122 | assertNotNull(result); | |
123 | } | |
124 | ||
125 | /** | |
126 | * Run the StructDefinition getCurrentPacketContext() method test. | |
127 | */ | |
128 | @Test | |
129 | public void testGetCurrentPacketContext() { | |
130 | StructDefinition result = fixture.getCurrentPacketContext(); | |
131 | assertNotNull(result); | |
132 | } | |
133 | ||
134 | /** | |
135 | * Run the int getName() method test. | |
136 | */ | |
137 | @Test | |
138 | public void testGetName() { | |
139 | int result = fixture.getName(); | |
140 | assertEquals(1, result); | |
141 | } | |
142 | ||
866e5b51 FC |
143 | /** |
144 | * Run the void goToLastEvent() method test. | |
ce2388e0 | 145 | * |
866e5b51 FC |
146 | * @throws CTFReaderException |
147 | */ | |
148 | @Test | |
149 | public void testGoToLastEvent() throws CTFReaderException { | |
150 | fixture.goToLastEvent(); | |
151 | } | |
152 | ||
153 | /** | |
154 | * Run the boolean readNextEvent() method test. | |
155 | */ | |
156 | @Test | |
157 | public void testReadNextEvent() { | |
158 | boolean result = fixture.readNextEvent(); | |
159 | assertTrue(result); | |
160 | } | |
161 | ||
162 | /** | |
163 | * Run the void seek(long) method test. Seek by direct timestamp | |
164 | */ | |
165 | @Test | |
166 | public void testSeek_timestamp() { | |
167 | long timestamp = 1L; | |
168 | fixture.seek(timestamp); | |
169 | } | |
170 | ||
171 | /** | |
172 | * Run the seek test. Seek by passing an EventDefinition to which we've | |
173 | * given the timestamp we want. | |
ce2388e0 FC |
174 | * |
175 | * @throws CTFReaderException | |
866e5b51 FC |
176 | */ |
177 | @Test | |
13be1a8f | 178 | public void testSeek_eventDefinition() throws CTFReaderException { |
866e5b51 | 179 | EventDefinition eventDefinition = new EventDefinition( |
13be1a8f | 180 | new EventDeclaration(), getStreamInputReader()); |
866e5b51 FC |
181 | eventDefinition.timestamp = 1L; |
182 | fixture.setCurrentEvent(eventDefinition); | |
183 | } | |
184 | } |