Commit | Line | Data |
---|---|---|
866e5b51 FC |
1 | package org.eclipse.linuxtools.ctf.core.tests.trace; |
2 | ||
4dd0eaed MK |
3 | import static org.junit.Assert.assertEquals; |
4 | import static org.junit.Assert.assertFalse; | |
866e5b51 FC |
5 | import static org.junit.Assert.assertNotNull; |
6 | import static org.junit.Assert.assertNull; | |
7 | import static org.junit.Assert.assertTrue; | |
8 | ||
9 | import java.io.File; | |
79cb3749 | 10 | import java.io.IOException; |
866e5b51 FC |
11 | import java.nio.channels.FileChannel; |
12 | ||
13 | import org.eclipse.linuxtools.ctf.core.event.types.Definition; | |
14 | import org.eclipse.linuxtools.ctf.core.tests.TestParams; | |
13be1a8f | 15 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
ce2388e0 FC |
16 | import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; |
17 | import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; | |
18 | import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex; | |
866e5b51 FC |
19 | import org.junit.After; |
20 | import org.junit.Before; | |
21 | import org.junit.Test; | |
22 | ||
23 | /** | |
24 | * The class <code>StreamInputTest</code> contains tests for the class | |
25 | * <code>{@link StreamInput}</code>. | |
4dd0eaed | 26 | * |
866e5b51 FC |
27 | * @author ematkho |
28 | * @version $Revision: 1.0 $ | |
29 | */ | |
be6df2d8 | 30 | @SuppressWarnings("javadoc") |
866e5b51 FC |
31 | public class StreamInputTest { |
32 | ||
33 | private StreamInput fixture; | |
34 | ||
35 | /** | |
36 | * Launch the test. | |
4dd0eaed | 37 | * |
866e5b51 FC |
38 | * @param args |
39 | * the command line arguments | |
40 | */ | |
41 | public static void main(String[] args) { | |
42 | new org.junit.runner.JUnitCore().run(StreamInputTest.class); | |
43 | } | |
44 | ||
45 | /** | |
46 | * Perform pre-test initialization. | |
4dd0eaed MK |
47 | * |
48 | * @throws CTFReaderException | |
866e5b51 FC |
49 | */ |
50 | @Before | |
13be1a8f | 51 | public void setUp() throws CTFReaderException { |
866e5b51 FC |
52 | fixture = new StreamInput(new Stream(TestParams.createTrace()), |
53 | (FileChannel) null, createFile()); | |
54 | fixture.setTimestampEnd(1L); | |
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 | private static File createFile() { | |
66 | return new File("Tests/traces/trace20m/channel_0"); //$NON-NLS-1$ | |
67 | } | |
68 | ||
69 | /** | |
70 | * Run the StreamInput(Stream,FileChannel,File) constructor test. | |
71 | */ | |
72 | @Test | |
73 | public void testStreamInput() { | |
74 | assertNotNull(fixture); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Run the FileChannel getFileChannel() method test. | |
4dd0eaed MK |
79 | * |
80 | * @throws IOException | |
866e5b51 FC |
81 | */ |
82 | @Test | |
79cb3749 | 83 | public void testGetFileChannel() throws IOException { |
866e5b51 FC |
84 | FileChannel result = fixture.getFileChannel(); |
85 | assertNull(result); | |
79cb3749 AM |
86 | if (result != null) { |
87 | result.close(); | |
88 | } | |
866e5b51 FC |
89 | } |
90 | ||
91 | /** | |
92 | * Run the String getFilename() method test. | |
93 | */ | |
94 | @Test | |
95 | public void testGetFilename() { | |
96 | String result = fixture.getFilename(); | |
97 | assertNotNull(result); | |
98 | } | |
99 | ||
100 | /** | |
101 | * Run the StreamInputPacketIndex getIndex() method test. | |
102 | */ | |
103 | @Test | |
104 | public void testGetIndex() { | |
105 | StreamInputPacketIndex result = fixture.getIndex(); | |
106 | assertNotNull(result); | |
107 | } | |
108 | ||
109 | /** | |
110 | * Run the String getPath() method test. | |
111 | */ | |
112 | @Test | |
113 | public void testGetPath() { | |
114 | String result = fixture.getPath(); | |
115 | assertNotNull(result); | |
116 | } | |
117 | ||
118 | /** | |
119 | * Run the Stream getStream() method test. | |
120 | */ | |
121 | @Test | |
122 | public void testGetStream() { | |
123 | Stream result = fixture.getStream(); | |
124 | assertNotNull(result); | |
125 | } | |
126 | ||
127 | /** | |
128 | * Run the long getTimestampEnd() method test. | |
129 | */ | |
130 | @Test | |
131 | public void testGetTimestampEnd() { | |
132 | long result = fixture.getTimestampEnd(); | |
133 | assertTrue(0L < result); | |
134 | } | |
135 | ||
136 | /** | |
137 | * Run the Definition lookupDefinition(String) method test. | |
138 | */ | |
139 | @Test | |
140 | public void testLookupDefinition() { | |
141 | Definition result = fixture.lookupDefinition("id"); //$NON-NLS-1$ | |
142 | assertNull(result); | |
143 | } | |
144 | ||
145 | /** | |
146 | * Run the void setTimestampEnd(long) method test. | |
147 | */ | |
148 | @Test | |
149 | public void testSetTimestampEnd() { | |
150 | fixture.setTimestampEnd(1L); | |
4dd0eaed MK |
151 | assertEquals(fixture.getTimestampEnd(), 1L); |
152 | } | |
153 | ||
154 | StreamInput s1; | |
155 | StreamInput s2; | |
156 | ||
157 | ||
158 | @Test | |
159 | public void testEquals1() throws CTFReaderException{ | |
160 | s1 = new StreamInput(new Stream(TestParams.createTrace()), | |
161 | (FileChannel) null, createFile()); | |
162 | assertFalse(s1.equals(null)); | |
163 | } | |
164 | ||
165 | @Test | |
166 | public void testEquals2() throws CTFReaderException{ | |
167 | s1 = new StreamInput(new Stream(TestParams.createTrace()), | |
168 | (FileChannel) null, createFile()); | |
169 | assertFalse(s1.equals(new Long(23L))); | |
170 | ||
171 | } | |
172 | @Test | |
173 | public void testEquals3() throws CTFReaderException{ | |
174 | s1 = new StreamInput(new Stream(TestParams.createTrace()), | |
175 | (FileChannel) null, createFile()); | |
176 | assertEquals(s1,s1); | |
177 | ||
178 | } | |
179 | @Test | |
180 | public void testEquals4() throws CTFReaderException{ | |
181 | s1 = new StreamInput(new Stream(TestParams.createTrace()), | |
182 | (FileChannel) null, createFile()); | |
183 | s2 = new StreamInput(new Stream(TestParams.createTrace()), | |
184 | (FileChannel) null, createFile()); | |
185 | assertEquals(s1,s2); | |
186 | } | |
866e5b51 | 187 | } |