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