ctf: Clean up unit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / StreamInputTest.java
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
12 package org.eclipse.linuxtools.ctf.core.tests.trace;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertFalse;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertNull;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assume.assumeTrue;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.channels.FileChannel;
24
25 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
26 import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTraces;
27 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
28 import org.eclipse.linuxtools.ctf.core.trace.Stream;
29 import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 /**
34 * The class <code>StreamInputTest</code> contains tests for the class
35 * <code>{@link StreamInput}</code>.
36 *
37 * @author ematkho
38 * @version $Revision: 1.0 $
39 */
40 @SuppressWarnings("javadoc")
41 public class StreamInputTest {
42
43 private static final int TRACE_INDEX = 0;
44
45 private StreamInput fixture;
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 private static File createFile() {
61 return new File("Tests/traces/trace20m/channel_0");
62 }
63
64 /**
65 * Run the StreamInput(Stream,FileChannel,File) constructor test.
66 */
67 @Test
68 public void testStreamInput() {
69 assertNotNull(fixture);
70 }
71
72 /**
73 * Run the FileChannel getFileChannel() method test.
74 *
75 * @throws IOException
76 */
77 @Test
78 public void testGetFileChannel() throws IOException {
79 FileChannel result = fixture.getFileChannel();
80 assertNull(result);
81 if (result != null) {
82 result.close();
83 }
84 }
85
86 /**
87 * Run the String getFilename() method test.
88 */
89 @Test
90 public void testGetFilename() {
91 String result = fixture.getFilename();
92 assertNotNull(result);
93 }
94
95 /**
96 * Run the String getPath() method test.
97 */
98 @Test
99 public void testGetPath() {
100 String result = fixture.getPath();
101 assertNotNull(result);
102 }
103
104 /**
105 * Run the Stream getStream() method test.
106 */
107 @Test
108 public void testGetStream() {
109 Stream result = fixture.getStream();
110 assertNotNull(result);
111 }
112
113 /**
114 * Run the long getTimestampEnd() method test.
115 */
116 @Test
117 public void testGetTimestampEnd() {
118 long result = fixture.getTimestampEnd();
119 assertTrue(0L < result);
120 }
121
122 /**
123 * Run the Definition lookupDefinition(String) method test.
124 */
125 @Test
126 public void testLookupDefinition() {
127 Definition result = fixture.lookupDefinition("id");
128 assertNull(result);
129 }
130
131 /**
132 * Run the void setTimestampEnd(long) method test.
133 */
134 @Test
135 public void testSetTimestampEnd() {
136 fixture.setTimestampEnd(1L);
137 assertEquals(fixture.getTimestampEnd(), 1L);
138 }
139
140 StreamInput s1;
141 StreamInput s2;
142
143
144 @Test
145 public void testEquals1() throws CTFReaderException{
146 s1 = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
147 (FileChannel) null, createFile());
148 assertFalse(s1.equals(null));
149 }
150
151 @Test
152 public void testEquals2() throws CTFReaderException{
153 s1 = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
154 (FileChannel) null, createFile());
155 assertFalse(s1.equals(new Long(23L)));
156
157 }
158 @Test
159 public void testEquals3() throws CTFReaderException{
160 s1 = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
161 (FileChannel) null, createFile());
162 assertEquals(s1,s1);
163
164 }
165 @Test
166 public void testEquals4() throws CTFReaderException{
167 s1 = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
168 (FileChannel) null, createFile());
169 s2 = new StreamInput(new Stream(CtfTestTraces.getTestTrace(TRACE_INDEX)),
170 (FileChannel) null, createFile());
171 assertEquals(s1,s2);
172 }
173 }
This page took 0.034783 seconds and 5 git commands to generate.