ctf: rename CTFReaderException to CTFException
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / CTFStreamInputTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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.tracecompass.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.FilenameFilter;
23
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.eclipse.tracecompass.ctf.core.CTFException;
26 import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
27 import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace;
28 import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
29 import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInput;
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 CTFStreamInput}</code>.
36 *
37 * @author ematkho
38 * @version $Revision: 1.0 $
39 */
40 @SuppressWarnings("javadoc")
41 public class CTFStreamInputTest {
42
43 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
44
45 private CTFStreamInput fixture;
46
47 /**
48 * Perform pre-test initialization.
49 *
50 * @throws CTFException
51 */
52 @Before
53 public void setUp() throws CTFException {
54 assumeTrue(testTrace.exists());
55 fixture = new CTFStreamInput(new CTFStream(testTrace.getTrace()), createFile());
56 fixture.setTimestampEnd(1L);
57 }
58
59 @NonNull
60 private static File createFile() {
61 File path = new File(testTrace.getPath());
62 final File[] listFiles = path.listFiles(new FilenameFilter() {
63 @Override
64 public boolean accept(File dir, String name) {
65 if (name.contains("hann")) {
66 return true;
67 }
68 return false;
69 }
70 });
71 assertNotNull(listFiles);
72 final File returnFile = listFiles[0];
73 assertNotNull(returnFile);
74 return returnFile;
75 }
76
77 /**
78 * Run the StreamInput(Stream,FileChannel,File) constructor test.
79 */
80 @Test
81 public void testStreamInput() {
82 assertNotNull(fixture);
83 }
84
85 /**
86 * Run the String getFilename() method test.
87 */
88 @Test
89 public void testGetFilename() {
90 String result = fixture.getFilename();
91 assertNotNull(result);
92 }
93
94 /**
95 * Run the String getPath() method test.
96 */
97 @Test
98 public void testGetPath() {
99 String result = fixture.getScopePath().getPath();
100 assertNotNull(result);
101 }
102
103 /**
104 * Run the Stream getStream() method test.
105 */
106 @Test
107 public void testGetStream() {
108 CTFStream result = fixture.getStream();
109 assertNotNull(result);
110 }
111
112 /**
113 * Run the long getTimestampEnd() method test.
114 */
115 @Test
116 public void testGetTimestampEnd() {
117 long result = fixture.getTimestampEnd();
118 assertTrue(0L < result);
119 }
120
121 /**
122 * Run the Definition lookupDefinition(String) method test.
123 */
124 @Test
125 public void testLookupDefinition() {
126 IDefinition result = fixture.lookupDefinition("id");
127 assertNull(result);
128 }
129
130 /**
131 * Run the void setTimestampEnd(long) method test.
132 */
133 @Test
134 public void testSetTimestampEnd() {
135 fixture.setTimestampEnd(1L);
136 assertEquals(fixture.getTimestampEnd(), 1L);
137 }
138
139 CTFStreamInput s1;
140 CTFStreamInput s2;
141
142 @Test
143 public void testEquals1() throws CTFException {
144 s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
145 createFile());
146 assertFalse(s1.equals(null));
147 }
148
149 @Test
150 public void testEquals2() throws CTFException {
151 s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
152 createFile());
153 assertFalse(s1.equals(new Long(23L)));
154
155 }
156
157 @Test
158 public void testEquals3() throws CTFException {
159 s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
160 createFile());
161 assertEquals(s1, s1);
162
163 }
164
165 @Test
166 public void testEquals4() throws CTFException {
167 s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
168 createFile());
169 s2 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
170 createFile());
171 assertEquals(s1, s2);
172 }
173 }
This page took 0.037353 seconds and 5 git commands to generate.