rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / CTFStreamInputTest.java
CommitLineData
4bd7f2db 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2013, 2014 Ericsson
4bd7f2db
AM
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
f357bcd4 12package org.eclipse.tracecompass.ctf.core.tests.trace;
866e5b51 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;
8e15b929 22import java.io.FilenameFilter;
866e5b51 23
b3151232 24import org.eclipse.jdt.annotation.NonNull;
680f9173 25import org.eclipse.tracecompass.ctf.core.CTFException;
f357bcd4
AM
26import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
27import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace;
f357bcd4
AM
28import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
29import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInput;
866e5b51
FC
30import org.junit.Before;
31import org.junit.Test;
32
33/**
34 * The class <code>StreamInputTest</code> contains tests for the class
d84419e1 35 * <code>{@link CTFStreamInput}</code>.
4dd0eaed 36 *
866e5b51
FC
37 * @author ematkho
38 * @version $Revision: 1.0 $
39 */
be6df2d8 40@SuppressWarnings("javadoc")
d84419e1 41public class CTFStreamInputTest {
866e5b51 42
9ac63b5b 43 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
32bf80d2 44
d84419e1 45 private CTFStreamInput fixture;
866e5b51 46
866e5b51
FC
47 /**
48 * Perform pre-test initialization.
4dd0eaed 49 *
680f9173 50 * @throws CTFException
866e5b51
FC
51 */
52 @Before
680f9173 53 public void setUp() throws CTFException {
9ac63b5b 54 assumeTrue(testTrace.exists());
d84419e1 55 fixture = new CTFStreamInput(new CTFStream(testTrace.getTrace()), createFile());
866e5b51
FC
56 fixture.setTimestampEnd(1L);
57 }
58
b3151232 59 @NonNull
866e5b51 60 private static File createFile() {
8e15b929 61 File path = new File(testTrace.getPath());
b3151232 62 final File[] listFiles = path.listFiles(new FilenameFilter() {
8e15b929
MK
63 @Override
64 public boolean accept(File dir, String name) {
65 if (name.contains("hann")) {
66 return true;
67 }
68 return false;
69 }
b3151232
MK
70 });
71 assertNotNull(listFiles);
72 final File returnFile = listFiles[0];
73 assertNotNull(returnFile);
74 return returnFile;
866e5b51
FC
75 }
76
77 /**
78 * Run the StreamInput(Stream,FileChannel,File) constructor test.
79 */
80 @Test
81 public void testStreamInput() {
82 assertNotNull(fixture);
83 }
84
866e5b51
FC
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
866e5b51
FC
94 /**
95 * Run the String getPath() method test.
96 */
97 @Test
98 public void testGetPath() {
fbe6fa6f 99 String result = fixture.getScopePath().getPath();
866e5b51
FC
100 assertNotNull(result);
101 }
102
103 /**
104 * Run the Stream getStream() method test.
105 */
106 @Test
107 public void testGetStream() {
d84419e1 108 CTFStream result = fixture.getStream();
866e5b51
FC
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() {
cc98c947 126 IDefinition result = fixture.lookupDefinition("id");
866e5b51
FC
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);
4dd0eaed
MK
136 assertEquals(fixture.getTimestampEnd(), 1L);
137 }
138
d84419e1
AM
139 CTFStreamInput s1;
140 CTFStreamInput s2;
4dd0eaed 141
4dd0eaed 142 @Test
680f9173 143 public void testEquals1() throws CTFException {
d84419e1 144 s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
8e15b929 145 createFile());
4dd0eaed
MK
146 assertFalse(s1.equals(null));
147 }
148
149 @Test
680f9173 150 public void testEquals2() throws CTFException {
d84419e1 151 s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
8e15b929 152 createFile());
4dd0eaed
MK
153 assertFalse(s1.equals(new Long(23L)));
154
155 }
8e15b929 156
4dd0eaed 157 @Test
680f9173 158 public void testEquals3() throws CTFException {
d84419e1 159 s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
8e15b929
MK
160 createFile());
161 assertEquals(s1, s1);
4dd0eaed
MK
162
163 }
8e15b929 164
4dd0eaed 165 @Test
680f9173 166 public void testEquals4() throws CTFException {
d84419e1 167 s1 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
8e15b929 168 createFile());
d84419e1 169 s2 = new CTFStreamInput(new CTFStream(testTrace.getTrace()),
8e15b929
MK
170 createFile());
171 assertEquals(s1, s2);
4dd0eaed 172 }
866e5b51 173}
This page took 0.088077 seconds and 5 git commands to generate.