Commit | Line | Data |
---|---|---|
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 | 12 | package org.eclipse.tracecompass.ctf.core.tests.trace; |
866e5b51 | 13 | |
4dd0eaed MK |
14 | import static org.junit.Assert.assertEquals; |
15 | import static org.junit.Assert.assertFalse; | |
866e5b51 FC |
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; | |
8e15b929 | 21 | import java.io.FilenameFilter; |
866e5b51 | 22 | |
b3151232 | 23 | import org.eclipse.jdt.annotation.NonNull; |
680f9173 | 24 | import org.eclipse.tracecompass.ctf.core.CTFException; |
f357bcd4 | 25 | import org.eclipse.tracecompass.ctf.core.event.types.IDefinition; |
c4d57ac1 | 26 | import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTraceUtils; |
f357bcd4 AM |
27 | import org.eclipse.tracecompass.ctf.core.trace.CTFStream; |
28 | import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInput; | |
c4d57ac1 | 29 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
866e5b51 FC |
30 | import org.junit.Before; |
31 | import 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 | 41 | public 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 { |
c4d57ac1 | 54 | fixture = new CTFStreamInput(new CTFStream(CtfTestTraceUtils.getTrace(testTrace)), createFile()); |
866e5b51 FC |
55 | fixture.setTimestampEnd(1L); |
56 | } | |
57 | ||
c4d57ac1 AM |
58 | private static @NonNull File createFile() throws CTFException { |
59 | File path = new File(CtfTestTraceUtils.getTrace(testTrace).getPath()); | |
b3151232 | 60 | final File[] listFiles = path.listFiles(new FilenameFilter() { |
8e15b929 MK |
61 | @Override |
62 | public boolean accept(File dir, String name) { | |
63 | if (name.contains("hann")) { | |
64 | return true; | |
65 | } | |
66 | return false; | |
67 | } | |
b3151232 MK |
68 | }); |
69 | assertNotNull(listFiles); | |
70 | final File returnFile = listFiles[0]; | |
71 | assertNotNull(returnFile); | |
72 | return returnFile; | |
866e5b51 FC |
73 | } |
74 | ||
75 | /** | |
76 | * Run the StreamInput(Stream,FileChannel,File) constructor test. | |
77 | */ | |
78 | @Test | |
79 | public void testStreamInput() { | |
80 | assertNotNull(fixture); | |
81 | } | |
82 | ||
866e5b51 FC |
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 | ||
866e5b51 FC |
92 | /** |
93 | * Run the String getPath() method test. | |
94 | */ | |
95 | @Test | |
96 | public void testGetPath() { | |
fbe6fa6f | 97 | String result = fixture.getScopePath().getPath(); |
866e5b51 FC |
98 | assertNotNull(result); |
99 | } | |
100 | ||
101 | /** | |
102 | * Run the Stream getStream() method test. | |
103 | */ | |
104 | @Test | |
105 | public void testGetStream() { | |
d84419e1 | 106 | CTFStream result = fixture.getStream(); |
866e5b51 FC |
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() { | |
cc98c947 | 124 | IDefinition result = fixture.lookupDefinition("id"); |
866e5b51 FC |
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); | |
4dd0eaed MK |
134 | assertEquals(fixture.getTimestampEnd(), 1L); |
135 | } | |
136 | ||
d84419e1 AM |
137 | CTFStreamInput s1; |
138 | CTFStreamInput s2; | |
4dd0eaed | 139 | |
4dd0eaed | 140 | @Test |
680f9173 | 141 | public void testEquals1() throws CTFException { |
c4d57ac1 | 142 | s1 = new CTFStreamInput(new CTFStream(CtfTestTraceUtils.getTrace(testTrace)), |
8e15b929 | 143 | createFile()); |
4dd0eaed MK |
144 | assertFalse(s1.equals(null)); |
145 | } | |
146 | ||
147 | @Test | |
680f9173 | 148 | public void testEquals2() throws CTFException { |
c4d57ac1 | 149 | s1 = new CTFStreamInput(new CTFStream(CtfTestTraceUtils.getTrace(testTrace)), |
8e15b929 | 150 | createFile()); |
4dd0eaed MK |
151 | assertFalse(s1.equals(new Long(23L))); |
152 | ||
153 | } | |
8e15b929 | 154 | |
4dd0eaed | 155 | @Test |
680f9173 | 156 | public void testEquals3() throws CTFException { |
c4d57ac1 | 157 | s1 = new CTFStreamInput(new CTFStream(CtfTestTraceUtils.getTrace(testTrace)), |
8e15b929 MK |
158 | createFile()); |
159 | assertEquals(s1, s1); | |
4dd0eaed MK |
160 | |
161 | } | |
8e15b929 | 162 | |
4dd0eaed | 163 | @Test |
680f9173 | 164 | public void testEquals4() throws CTFException { |
c4d57ac1 | 165 | s1 = new CTFStreamInput(new CTFStream(CtfTestTraceUtils.getTrace(testTrace)), |
8e15b929 | 166 | createFile()); |
c4d57ac1 | 167 | s2 = new CTFStreamInput(new CTFStream(CtfTestTraceUtils.getTrace(testTrace)), |
8e15b929 MK |
168 | createFile()); |
169 | assertEquals(s1, s2); | |
4dd0eaed | 170 | } |
866e5b51 | 171 | } |