ctf: Allow the test traces to be used by other plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / StreamInputTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.trace;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertNull;
7 import static org.junit.Assert.assertTrue;
8 import static org.junit.Assume.assumeTrue;
9
10 import java.io.File;
11 import java.io.IOException;
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.shared.CtfTestTraces;
16 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
17 import org.eclipse.linuxtools.ctf.core.trace.Stream;
18 import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
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>.
26 *
27 * @author ematkho
28 * @version $Revision: 1.0 $
29 */
30 @SuppressWarnings("javadoc")
31 public class StreamInputTest {
32
33 private static final int TRACE_INDEX = 0;
34
35 private StreamInput fixture;
36
37 /**
38 * Launch the test.
39 *
40 * @param args
41 * the command line arguments
42 */
43 public static void main(String[] args) {
44 new org.junit.runner.JUnitCore().run(StreamInputTest.class);
45 }
46
47 /**
48 * Perform pre-test initialization.
49 *
50 * @throws CTFReaderException
51 */
52 @Before
53 public void setUp() throws CTFReaderException {
54 assumeTrue(CtfTestTraces.tracesExist());
55 fixture = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
56 (FileChannel) null, createFile());
57 fixture.setTimestampEnd(1L);
58 }
59
60 /**
61 * Perform post-test clean-up.
62 */
63 @After
64 public void tearDown() {
65 // Add additional tear down code here
66 }
67
68 private static File createFile() {
69 return new File("Tests/traces/trace20m/channel_0"); //$NON-NLS-1$
70 }
71
72 /**
73 * Run the StreamInput(Stream,FileChannel,File) constructor test.
74 */
75 @Test
76 public void testStreamInput() {
77 assertNotNull(fixture);
78 }
79
80 /**
81 * Run the FileChannel getFileChannel() method test.
82 *
83 * @throws IOException
84 */
85 @Test
86 public void testGetFileChannel() throws IOException {
87 FileChannel result = fixture.getFileChannel();
88 assertNull(result);
89 if (result != null) {
90 result.close();
91 }
92 }
93
94 /**
95 * Run the String getFilename() method test.
96 */
97 @Test
98 public void testGetFilename() {
99 String result = fixture.getFilename();
100 assertNotNull(result);
101 }
102
103 /**
104 * Run the String getPath() method test.
105 */
106 @Test
107 public void testGetPath() {
108 String result = fixture.getPath();
109 assertNotNull(result);
110 }
111
112 /**
113 * Run the Stream getStream() method test.
114 */
115 @Test
116 public void testGetStream() {
117 Stream result = fixture.getStream();
118 assertNotNull(result);
119 }
120
121 /**
122 * Run the long getTimestampEnd() method test.
123 */
124 @Test
125 public void testGetTimestampEnd() {
126 long result = fixture.getTimestampEnd();
127 assertTrue(0L < result);
128 }
129
130 /**
131 * Run the Definition lookupDefinition(String) method test.
132 */
133 @Test
134 public void testLookupDefinition() {
135 Definition result = fixture.lookupDefinition("id"); //$NON-NLS-1$
136 assertNull(result);
137 }
138
139 /**
140 * Run the void setTimestampEnd(long) method test.
141 */
142 @Test
143 public void testSetTimestampEnd() {
144 fixture.setTimestampEnd(1L);
145 assertEquals(fixture.getTimestampEnd(), 1L);
146 }
147
148 StreamInput s1;
149 StreamInput s2;
150
151
152 @Test
153 public void testEquals1() throws CTFReaderException{
154 s1 = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
155 (FileChannel) null, createFile());
156 assertFalse(s1.equals(null));
157 }
158
159 @Test
160 public void testEquals2() throws CTFReaderException{
161 s1 = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
162 (FileChannel) null, createFile());
163 assertFalse(s1.equals(new Long(23L)));
164
165 }
166 @Test
167 public void testEquals3() throws CTFReaderException{
168 s1 = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
169 (FileChannel) null, createFile());
170 assertEquals(s1,s1);
171
172 }
173 @Test
174 public void testEquals4() throws CTFReaderException{
175 s1 = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
176 (FileChannel) null, createFile());
177 s2 = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
178 (FileChannel) null, createFile());
179 assertEquals(s1,s2);
180 }
181 }
This page took 0.033648 seconds and 5 git commands to generate.