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; | |
e5acb357 | 8 | import static org.junit.Assume.assumeTrue; |
866e5b51 FC |
9 | |
10 | import java.io.File; | |
79cb3749 | 11 | import java.io.IOException; |
866e5b51 FC |
12 | import java.nio.channels.FileChannel; |
13 | ||
14 | import org.eclipse.linuxtools.ctf.core.event.types.Definition; | |
15 | import org.eclipse.linuxtools.ctf.core.tests.TestParams; | |
13be1a8f | 16 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
486efb2e AM |
17 | import org.eclipse.linuxtools.ctf.core.trace.Stream; |
18 | import org.eclipse.linuxtools.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>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 { |
e5acb357 | 52 | assumeTrue(TestParams.tracesExist()); |
866e5b51 FC |
53 | fixture = new StreamInput(new Stream(TestParams.createTrace()), |
54 | (FileChannel) null, createFile()); | |
55 | fixture.setTimestampEnd(1L); | |
56 | } | |
57 | ||
58 | /** | |
59 | * Perform post-test clean-up. | |
60 | */ | |
61 | @After | |
62 | public void tearDown() { | |
63 | // Add additional tear down code here | |
64 | } | |
65 | ||
66 | private static File createFile() { | |
67 | return new File("Tests/traces/trace20m/channel_0"); //$NON-NLS-1$ | |
68 | } | |
69 | ||
70 | /** | |
71 | * Run the StreamInput(Stream,FileChannel,File) constructor test. | |
72 | */ | |
73 | @Test | |
74 | public void testStreamInput() { | |
75 | assertNotNull(fixture); | |
76 | } | |
77 | ||
78 | /** | |
79 | * Run the FileChannel getFileChannel() method test. | |
4dd0eaed MK |
80 | * |
81 | * @throws IOException | |
866e5b51 FC |
82 | */ |
83 | @Test | |
79cb3749 | 84 | public void testGetFileChannel() throws IOException { |
866e5b51 FC |
85 | FileChannel result = fixture.getFileChannel(); |
86 | assertNull(result); | |
79cb3749 AM |
87 | if (result != null) { |
88 | result.close(); | |
89 | } | |
866e5b51 FC |
90 | } |
91 | ||
92 | /** | |
93 | * Run the String getFilename() method test. | |
94 | */ | |
95 | @Test | |
96 | public void testGetFilename() { | |
97 | String result = fixture.getFilename(); | |
98 | assertNotNull(result); | |
99 | } | |
100 | ||
866e5b51 FC |
101 | /** |
102 | * Run the String getPath() method test. | |
103 | */ | |
104 | @Test | |
105 | public void testGetPath() { | |
106 | String result = fixture.getPath(); | |
107 | assertNotNull(result); | |
108 | } | |
109 | ||
110 | /** | |
111 | * Run the Stream getStream() method test. | |
112 | */ | |
113 | @Test | |
114 | public void testGetStream() { | |
115 | Stream result = fixture.getStream(); | |
116 | assertNotNull(result); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Run the long getTimestampEnd() method test. | |
121 | */ | |
122 | @Test | |
123 | public void testGetTimestampEnd() { | |
124 | long result = fixture.getTimestampEnd(); | |
125 | assertTrue(0L < result); | |
126 | } | |
127 | ||
128 | /** | |
129 | * Run the Definition lookupDefinition(String) method test. | |
130 | */ | |
131 | @Test | |
132 | public void testLookupDefinition() { | |
133 | Definition result = fixture.lookupDefinition("id"); //$NON-NLS-1$ | |
134 | assertNull(result); | |
135 | } | |
136 | ||
137 | /** | |
138 | * Run the void setTimestampEnd(long) method test. | |
139 | */ | |
140 | @Test | |
141 | public void testSetTimestampEnd() { | |
142 | fixture.setTimestampEnd(1L); | |
4dd0eaed MK |
143 | assertEquals(fixture.getTimestampEnd(), 1L); |
144 | } | |
145 | ||
146 | StreamInput s1; | |
147 | StreamInput s2; | |
148 | ||
149 | ||
150 | @Test | |
151 | public void testEquals1() throws CTFReaderException{ | |
152 | s1 = new StreamInput(new Stream(TestParams.createTrace()), | |
153 | (FileChannel) null, createFile()); | |
154 | assertFalse(s1.equals(null)); | |
155 | } | |
156 | ||
157 | @Test | |
158 | public void testEquals2() throws CTFReaderException{ | |
159 | s1 = new StreamInput(new Stream(TestParams.createTrace()), | |
160 | (FileChannel) null, createFile()); | |
161 | assertFalse(s1.equals(new Long(23L))); | |
162 | ||
163 | } | |
164 | @Test | |
165 | public void testEquals3() throws CTFReaderException{ | |
166 | s1 = new StreamInput(new Stream(TestParams.createTrace()), | |
167 | (FileChannel) null, createFile()); | |
168 | assertEquals(s1,s1); | |
169 | ||
170 | } | |
171 | @Test | |
172 | public void testEquals4() throws CTFReaderException{ | |
173 | s1 = new StreamInput(new Stream(TestParams.createTrace()), | |
174 | (FileChannel) null, createFile()); | |
175 | s2 = new StreamInput(new Stream(TestParams.createTrace()), | |
176 | (FileChannel) null, createFile()); | |
177 | assertEquals(s1,s2); | |
178 | } | |
866e5b51 | 179 | } |