Commit | Line | Data |
---|---|---|
4bd7f2db AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 Ericsson | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Matthew Khouzam - Initial API and implementation | |
10 | *******************************************************************************/ | |
11 | ||
866e5b51 FC |
12 | package org.eclipse.linuxtools.ctf.core.tests.trace; |
13 | ||
4dd0eaed MK |
14 | import static org.junit.Assert.assertEquals; |
15 | import static org.junit.Assert.assertFalse; | |
866e5b51 FC |
16 | import static org.junit.Assert.assertNotNull; |
17 | import static org.junit.Assert.assertNull; | |
18 | import static org.junit.Assert.assertTrue; | |
e5acb357 | 19 | import static org.junit.Assume.assumeTrue; |
866e5b51 FC |
20 | |
21 | import java.io.File; | |
22 | import java.nio.channels.FileChannel; | |
23 | ||
24 | import org.eclipse.linuxtools.ctf.core.event.types.Definition; | |
9ac63b5b | 25 | import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace; |
13be1a8f | 26 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
486efb2e AM |
27 | import org.eclipse.linuxtools.ctf.core.trace.Stream; |
28 | import org.eclipse.linuxtools.ctf.core.trace.StreamInput; | |
866e5b51 FC |
29 | import org.junit.Before; |
30 | import org.junit.Test; | |
31 | ||
32 | /** | |
33 | * The class <code>StreamInputTest</code> contains tests for the class | |
34 | * <code>{@link StreamInput}</code>. | |
4dd0eaed | 35 | * |
866e5b51 FC |
36 | * @author ematkho |
37 | * @version $Revision: 1.0 $ | |
38 | */ | |
be6df2d8 | 39 | @SuppressWarnings("javadoc") |
866e5b51 FC |
40 | public class StreamInputTest { |
41 | ||
9ac63b5b | 42 | private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL; |
32bf80d2 | 43 | |
866e5b51 FC |
44 | private StreamInput fixture; |
45 | ||
866e5b51 FC |
46 | /** |
47 | * Perform pre-test initialization. | |
4dd0eaed MK |
48 | * |
49 | * @throws CTFReaderException | |
866e5b51 FC |
50 | */ |
51 | @Before | |
13be1a8f | 52 | public void setUp() throws CTFReaderException { |
9ac63b5b AM |
53 | assumeTrue(testTrace.exists()); |
54 | fixture = new StreamInput(new Stream(testTrace.getTrace()), | |
866e5b51 FC |
55 | (FileChannel) null, createFile()); |
56 | fixture.setTimestampEnd(1L); | |
57 | } | |
58 | ||
866e5b51 | 59 | private static File createFile() { |
4a9c1f07 | 60 | return new File("Tests/traces/trace20m/channel_0"); |
866e5b51 FC |
61 | } |
62 | ||
63 | /** | |
64 | * Run the StreamInput(Stream,FileChannel,File) constructor test. | |
65 | */ | |
66 | @Test | |
67 | public void testStreamInput() { | |
68 | assertNotNull(fixture); | |
69 | } | |
70 | ||
71 | /** | |
72 | * Run the FileChannel getFileChannel() method test. | |
73 | */ | |
74 | @Test | |
178dc307 | 75 | public void testGetFileChannel() { |
866e5b51 FC |
76 | FileChannel result = fixture.getFileChannel(); |
77 | assertNull(result); | |
78 | } | |
79 | ||
80 | /** | |
81 | * Run the String getFilename() method test. | |
82 | */ | |
83 | @Test | |
84 | public void testGetFilename() { | |
85 | String result = fixture.getFilename(); | |
86 | assertNotNull(result); | |
87 | } | |
88 | ||
866e5b51 FC |
89 | /** |
90 | * Run the String getPath() method test. | |
91 | */ | |
92 | @Test | |
93 | public void testGetPath() { | |
94 | String result = fixture.getPath(); | |
95 | assertNotNull(result); | |
96 | } | |
97 | ||
98 | /** | |
99 | * Run the Stream getStream() method test. | |
100 | */ | |
101 | @Test | |
102 | public void testGetStream() { | |
103 | Stream result = fixture.getStream(); | |
104 | assertNotNull(result); | |
105 | } | |
106 | ||
107 | /** | |
108 | * Run the long getTimestampEnd() method test. | |
109 | */ | |
110 | @Test | |
111 | public void testGetTimestampEnd() { | |
112 | long result = fixture.getTimestampEnd(); | |
113 | assertTrue(0L < result); | |
114 | } | |
115 | ||
116 | /** | |
117 | * Run the Definition lookupDefinition(String) method test. | |
118 | */ | |
119 | @Test | |
120 | public void testLookupDefinition() { | |
4a9c1f07 | 121 | Definition result = fixture.lookupDefinition("id"); |
866e5b51 FC |
122 | assertNull(result); |
123 | } | |
124 | ||
125 | /** | |
126 | * Run the void setTimestampEnd(long) method test. | |
127 | */ | |
128 | @Test | |
129 | public void testSetTimestampEnd() { | |
130 | fixture.setTimestampEnd(1L); | |
4dd0eaed MK |
131 | assertEquals(fixture.getTimestampEnd(), 1L); |
132 | } | |
133 | ||
134 | StreamInput s1; | |
135 | StreamInput s2; | |
136 | ||
137 | ||
138 | @Test | |
139 | public void testEquals1() throws CTFReaderException{ | |
9ac63b5b | 140 | s1 = new StreamInput(new Stream(testTrace.getTrace()), |
4dd0eaed MK |
141 | (FileChannel) null, createFile()); |
142 | assertFalse(s1.equals(null)); | |
143 | } | |
144 | ||
145 | @Test | |
146 | public void testEquals2() throws CTFReaderException{ | |
9ac63b5b | 147 | s1 = new StreamInput(new Stream(testTrace.getTrace()), |
4dd0eaed MK |
148 | (FileChannel) null, createFile()); |
149 | assertFalse(s1.equals(new Long(23L))); | |
150 | ||
151 | } | |
152 | @Test | |
153 | public void testEquals3() throws CTFReaderException{ | |
9ac63b5b | 154 | s1 = new StreamInput(new Stream(testTrace.getTrace()), |
4dd0eaed MK |
155 | (FileChannel) null, createFile()); |
156 | assertEquals(s1,s1); | |
157 | ||
158 | } | |
159 | @Test | |
160 | public void testEquals4() throws CTFReaderException{ | |
9ac63b5b | 161 | s1 = new StreamInput(new Stream(testTrace.getTrace()), |
4dd0eaed | 162 | (FileChannel) null, createFile()); |
9ac63b5b | 163 | s2 = new StreamInput(new Stream(testTrace.getTrace()), |
4dd0eaed MK |
164 | (FileChannel) null, createFile()); |
165 | assertEquals(s1,s2); | |
166 | } | |
866e5b51 | 167 | } |