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