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 | ||
9 | import org.eclipse.linuxtools.ctf.core.event.EventDefinition; | |
10 | import org.eclipse.linuxtools.ctf.core.event.types.Definition; | |
11 | import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; | |
12 | import org.eclipse.linuxtools.ctf.core.tests.TestParams; | |
13 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; | |
14 | import org.eclipse.linuxtools.ctf.core.trace.Stream; | |
15 | import org.eclipse.linuxtools.ctf.core.trace.StreamInput; | |
16 | import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndexEntry; | |
17 | import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketReader; | |
18 | import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; | |
19 | import org.junit.*; | |
20 | ||
21 | /** | |
22 | * The class <code>StreamInputPacketReaderTest</code> contains tests for the | |
23 | * class <code>{@link StreamInputPacketReader}</code>. | |
24 | * | |
25 | * @author ematkho | |
26 | * @version $Revision: 1.0 $ | |
27 | */ | |
28 | public class StreamInputPacketReaderTest { | |
29 | ||
30 | private StreamInputPacketReader fixture; | |
31 | ||
32 | /** | |
33 | * Launch the test. | |
34 | * | |
35 | * @param args | |
36 | * the command line arguments | |
37 | */ | |
38 | public static void main(String[] args) { | |
39 | new org.junit.runner.JUnitCore().run(StreamInputPacketReaderTest.class); | |
40 | } | |
41 | ||
42 | /** | |
43 | * Perform pre-test initialization. | |
13be1a8f AM |
44 | * |
45 | * @throws CTFReaderException | |
866e5b51 FC |
46 | */ |
47 | @Before | |
13be1a8f | 48 | public void setUp() throws CTFReaderException { |
866e5b51 FC |
49 | // FIXME The test is broken here. "FileChannel" can't be null because we |
50 | // need it further in. Heck this whole thing shouldn't be public in the | |
51 | // first place, perhaps fixing that is the best way to go. | |
52 | fixture = new StreamInputPacketReader(new StreamInputReader( | |
53 | new StreamInput(new Stream(TestParams.createTrace()), | |
54 | (FileChannel) null, TestParams.getEmptyFile()))); | |
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 | ||
65 | /** | |
66 | * Run the StreamInputPacketReader(StreamInputReader) constructor test. | |
13be1a8f AM |
67 | * |
68 | * @throws CTFReaderException | |
866e5b51 FC |
69 | */ |
70 | @Test | |
13be1a8f | 71 | public void testStreamInputPacketReader() throws CTFReaderException { |
866e5b51 FC |
72 | StreamInputReader streamInputReader; |
73 | StreamInputPacketReader result; | |
74 | ||
75 | streamInputReader = new StreamInputReader(new StreamInput(new Stream( | |
76 | TestParams.createTrace()), (FileChannel) null, | |
77 | TestParams.getEmptyFile())); | |
78 | ||
79 | result = new StreamInputPacketReader(streamInputReader); | |
80 | ||
81 | assertNotNull(result); | |
82 | } | |
83 | ||
84 | /** | |
85 | * Run the int getCPU() method test. | |
86 | */ | |
87 | @Test | |
88 | public void testGetCPU() { | |
89 | int result = fixture.getCPU(); | |
90 | assertEquals(0, result); | |
91 | } | |
92 | ||
93 | /** | |
94 | * Run the StreamInputPacketIndexEntry getCurrentPacket() method test. | |
95 | */ | |
96 | @Test | |
97 | public void testGetCurrentPacket() { | |
98 | StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(1L); | |
99 | fixture.setCurrentPacket(sipie); | |
100 | StreamInputPacketIndexEntry result = fixture.getCurrentPacket(); | |
101 | assertNotNull(result); | |
102 | } | |
103 | ||
104 | /** | |
105 | * Run the String getPath() method test. | |
106 | */ | |
107 | @Test | |
108 | public void testGetPath() { | |
109 | String result = fixture.getPath(); | |
110 | assertNotNull(result); | |
111 | } | |
112 | ||
113 | /** | |
114 | * Run the StructDefinition getStreamPacketContextDef() method test. | |
115 | */ | |
116 | @Test | |
117 | public void testGetStreamPacketContextDef() { | |
118 | fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); | |
119 | StructDefinition result = fixture.getStreamPacketContextDef(); | |
120 | assertNotNull(result); | |
121 | } | |
122 | ||
123 | /** | |
124 | * Run the boolean hasMoreEvents() method test. | |
125 | */ | |
126 | @Test | |
127 | public void testHasMoreEvents() { | |
128 | fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); | |
129 | boolean result = fixture.hasMoreEvents(); | |
130 | assertTrue(result); | |
131 | } | |
132 | ||
133 | /** | |
134 | * Run the Definition lookupDefinition(String) method test. | |
135 | */ | |
136 | @Test | |
137 | public void testLookupDefinition() { | |
138 | fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); | |
139 | String lookupPath = ""; //$NON-NLS-1$ | |
140 | Definition result = fixture.lookupDefinition(lookupPath); | |
141 | assertNotNull(result); | |
142 | } | |
143 | ||
144 | /** | |
145 | * Run the EventDefinition readNextEvent() method test. | |
146 | * | |
147 | * @throws CTFReaderException | |
148 | */ | |
149 | @Test | |
150 | public void testReadNextEvent() throws CTFReaderException { | |
151 | fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); | |
152 | EventDefinition result = fixture.readNextEvent(); | |
153 | assertNotNull(result); | |
154 | } | |
155 | ||
156 | /** | |
157 | * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test. | |
158 | */ | |
159 | @Test | |
160 | public void testSetCurrentPacket() { | |
161 | fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); | |
162 | StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry( | |
163 | 1L); | |
164 | currentPacket.packetSizeBits = 1; | |
165 | fixture.setCurrentPacket(currentPacket); | |
166 | } | |
167 | ||
168 | /** | |
169 | * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test. | |
170 | */ | |
171 | @Test | |
172 | public void testSetCurrentPacket_2() throws Exception { | |
173 | fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); | |
174 | StreamInputPacketIndexEntry currentPacket = null; | |
175 | fixture.setCurrentPacket(currentPacket); | |
176 | ||
177 | } | |
178 | ||
179 | /** | |
180 | * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test. | |
181 | */ | |
182 | @Test | |
183 | public void testSetCurrentPacket_3() { | |
184 | fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L)); | |
185 | StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry( | |
186 | 1L); | |
187 | currentPacket.timestampBegin = 1L; | |
188 | currentPacket.packetSizeBits = 1; | |
189 | ||
190 | fixture.setCurrentPacket(currentPacket); | |
191 | } | |
192 | } |