| 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.assertNotNull; |
| 15 | import static org.junit.Assert.assertTrue; |
| 16 | |
| 17 | import java.io.File; |
| 18 | import java.io.FilenameFilter; |
| 19 | import java.util.Set; |
| 20 | |
| 21 | import org.eclipse.jdt.annotation.NonNull; |
| 22 | import org.eclipse.tracecompass.ctf.core.CTFException; |
| 23 | import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration; |
| 24 | import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration; |
| 25 | import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTraceUtils; |
| 26 | import org.eclipse.tracecompass.ctf.core.trace.CTFStream; |
| 27 | import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInput; |
| 28 | import org.eclipse.tracecompass.ctf.core.trace.CTFTrace; |
| 29 | import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration; |
| 30 | import org.eclipse.tracecompass.internal.ctf.core.event.metadata.exceptions.ParseException; |
| 31 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
| 32 | import org.junit.Before; |
| 33 | import org.junit.Test; |
| 34 | |
| 35 | /** |
| 36 | * The class <code>StreamTest</code> contains tests for the class |
| 37 | * <code>{@link CTFStream}</code>. |
| 38 | * |
| 39 | * @author ematkho |
| 40 | * @version $Revision: 1.0 $ |
| 41 | */ |
| 42 | @SuppressWarnings("javadoc") |
| 43 | public class CTFStreamTest { |
| 44 | |
| 45 | private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL; |
| 46 | |
| 47 | private CTFStream fixture; |
| 48 | |
| 49 | private CTFStreamInput fInput; |
| 50 | |
| 51 | /** |
| 52 | * Perform pre-test initialization. |
| 53 | * |
| 54 | * @throws CTFException |
| 55 | */ |
| 56 | @Before |
| 57 | public void setUp() throws CTFException { |
| 58 | fixture = new CTFStream(CtfTestTraceUtils.getTrace(testTrace)); |
| 59 | fixture.setEventContext(new StructDeclaration(1L)); |
| 60 | fixture.setPacketContext(new StructDeclaration(1L)); |
| 61 | fixture.setEventHeader(new StructDeclaration(1L)); |
| 62 | fixture.setId(1L); |
| 63 | fInput = new CTFStreamInput(new CTFStream(CtfTestTraceUtils.getTrace(testTrace)), createFile()); |
| 64 | fixture.addInput(fInput); |
| 65 | } |
| 66 | |
| 67 | private static @NonNull File createFile() throws CTFException { |
| 68 | File path = new File(CtfTestTraceUtils.getTrace(testTrace).getPath()); |
| 69 | final File[] listFiles = path.listFiles(new FilenameFilter() { |
| 70 | @Override |
| 71 | public boolean accept(File dir, String name) { |
| 72 | if (name.contains("hann")) { |
| 73 | return true; |
| 74 | } |
| 75 | return false; |
| 76 | } |
| 77 | }); |
| 78 | assertNotNull(listFiles); |
| 79 | final File returnFile = listFiles[0]; |
| 80 | assertNotNull(returnFile); |
| 81 | return returnFile; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Run the Stream(CTFTrace) constructor test. |
| 86 | * |
| 87 | * @throws CTFException |
| 88 | */ |
| 89 | @Test |
| 90 | public void testStream() throws CTFException { |
| 91 | CTFTrace trace = CtfTestTraceUtils.getTrace(testTrace); |
| 92 | CTFStream result = new CTFStream(trace); |
| 93 | assertNotNull(result); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Run the void addEvent(EventDeclaration) method test with the basic event. |
| 98 | * |
| 99 | * @throws ParseException |
| 100 | */ |
| 101 | @Test |
| 102 | public void testAddEvent_base() throws ParseException { |
| 103 | EventDeclaration event = new EventDeclaration(); |
| 104 | fixture.addEvent(event); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Run the boolean eventContextIsSet() method test. |
| 109 | */ |
| 110 | @Test |
| 111 | public void testEventContextIsSet() { |
| 112 | assertTrue(fixture.isEventContextSet()); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Run the boolean eventContextIsSet() method test. |
| 117 | */ |
| 118 | @Test |
| 119 | public void testToString() { |
| 120 | assertNotNull(fixture.toString()); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Run the boolean eventHeaderIsSet() method test. |
| 125 | */ |
| 126 | @Test |
| 127 | public void testEventHeaderIsSet() { |
| 128 | assertTrue(fixture.isEventHeaderSet()); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Run the StructDeclaration getEventContextDecl() method test. |
| 133 | */ |
| 134 | @Test |
| 135 | public void testGetEventContextDecl() { |
| 136 | assertNotNull(fixture.getEventContextDecl()); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Run the StructDeclaration getEventHeaderDecl() method test. |
| 141 | */ |
| 142 | @Test |
| 143 | public void testGetEventHeaderDecl() { |
| 144 | IDeclaration eventHeaderDecl = fixture.getEventHeaderDeclaration(); |
| 145 | assertNotNull(eventHeaderDecl); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Run the HashMap<Long, EventDeclaration> getEvents() method test. |
| 150 | */ |
| 151 | @Test |
| 152 | public void testGetEvents() { |
| 153 | assertNotNull(fixture.getEventDeclarations()); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Run the Long getId() method test. |
| 158 | */ |
| 159 | @Test |
| 160 | public void testGetId() { |
| 161 | Long result = fixture.getId(); |
| 162 | assertNotNull(result); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Run the StructDeclaration getPacketContextDecl() method test. |
| 167 | */ |
| 168 | @Test |
| 169 | public void testGetPacketContextDecl() { |
| 170 | StructDeclaration result = fixture.getPacketContextDecl(); |
| 171 | assertNotNull(result); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Run the Set<StreamInput> getStreamInputs() method test. |
| 176 | */ |
| 177 | @Test |
| 178 | public void testGetStreamInputs() { |
| 179 | Set<CTFStreamInput> result = fixture.getStreamInputs(); |
| 180 | assertNotNull(result); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Run the CTFTrace getTrace() method test. |
| 185 | */ |
| 186 | @Test |
| 187 | public void testGetTrace() { |
| 188 | CTFTrace result = fixture.getTrace(); |
| 189 | assertNotNull(result); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Run the boolean idIsSet() method test. |
| 194 | */ |
| 195 | @Test |
| 196 | public void testIdIsSet() { |
| 197 | boolean result = fixture.isIdSet(); |
| 198 | assertTrue(result); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Run the boolean packetContextIsSet() method test. |
| 203 | */ |
| 204 | @Test |
| 205 | public void testPacketContextIsSet() { |
| 206 | boolean result = fixture.isPacketContextSet(); |
| 207 | assertTrue(result); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Run the void setEventContext(StructDeclaration) method test. |
| 212 | */ |
| 213 | @Test |
| 214 | public void testSetEventContext() { |
| 215 | StructDeclaration eventContext = new StructDeclaration(1L); |
| 216 | fixture.setEventContext(eventContext); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Run the void setEventHeader(StructDeclaration) method test. |
| 221 | */ |
| 222 | @Test |
| 223 | public void testSetEventHeader() { |
| 224 | StructDeclaration eventHeader = new StructDeclaration(1L); |
| 225 | fixture.setEventHeader(eventHeader); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Run the void setId(long) method test. |
| 230 | */ |
| 231 | @Test |
| 232 | public void testSetId() { |
| 233 | long id = 1L; |
| 234 | fixture.setId(id); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Run the void setPacketContext(StructDeclaration) method test. |
| 239 | */ |
| 240 | @Test |
| 241 | public void testSetPacketContext() { |
| 242 | StructDeclaration packetContext = new StructDeclaration(1L); |
| 243 | fixture.setPacketContext(packetContext); |
| 244 | } |
| 245 | } |