+/*******************************************************************************
+ * Copyright (c) 2013 Ericsson
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
package org.eclipse.linuxtools.ctf.core.tests.types;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
-import java.nio.channels.FileChannel;
-
-import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.tests.TestParams;
+import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
-import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
-import org.junit.After;
+import org.eclipse.linuxtools.ctf.core.trace.CTFStream;
+import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
import org.junit.Before;
import org.junit.Test;
* @author ematkho
* @version $Revision: 1.0 $
*/
+@SuppressWarnings("javadoc")
public class EventDeclarationTest {
- private EventDeclaration fixture;
+ private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
- /**
- * Launch the test.
- *
- * @param args
- * the command line arguments
- */
- public static void main(String[] args) {
- new org.junit.runner.JUnitCore().run(EventDeclarationTest.class);
- }
+ private EventDeclaration fixture;
/**
* Perform pre-test initialization.
*/
@Before
public void setUp() throws CTFReaderException {
+ assumeTrue(testTrace.exists());
fixture = new EventDeclaration();
fixture.setContext(new StructDeclaration(1L));
fixture.setId(1L);
fixture.setFields(new StructDeclaration(1L));
- fixture.setStream(new Stream(TestParams.createTrace()));
- fixture.setName(""); //$NON-NLS-1$
- }
-
- /**
- * Perform post-test clean-up.
- */
- @After
- public void tearDown() {
- // Add additional tear down code here
+ fixture.setStream(new CTFStream(testTrace.getTrace()));
+ fixture.setName("");
}
/**
assertFalse(result);
}
- /**
- * Run the EventDefinition createDefinition(StreamInputReader) method test.
- *
- * @throws CTFReaderException
- */
- @Test
- public void testCreateDefinition() throws CTFReaderException {
- StreamInputReader streamInputReader = new StreamInputReader(
- new StreamInput(new Stream(TestParams.createTrace()),
- (FileChannel) null, TestParams.getTraceFile()));
-
- EventDefinition result = fixture.createDefinition(streamInputReader);
- assertNotNull(result);
- }
-
/**
* Run the boolean equals(Object) method test.
*
obj.setContext(new StructDeclaration(1L));
obj.setId(1L);
obj.setFields(new StructDeclaration(1L));
- obj.setStream(new Stream(TestParams.createTrace()));
- obj.setName(""); //$NON-NLS-1$
+ obj.setStream(new CTFStream(testTrace.getTrace()));
+ obj.setName("");
assertTrue(fixture.equals(fixture));
boolean result = fixture.equals(obj);
obj.setContext(new StructDeclaration(1L));
obj.setId(1L);
obj.setFields(new StructDeclaration(1L));
- obj.setName(""); //$NON-NLS-1$
+ obj.setName("");
boolean result = fixture.equals(obj);
assertFalse(result);
*/
@Test
public void testGetId() {
- Long result = fixture.getId();
- assertNotNull(result);
+ assertEquals(1,fixture.id());
}
/**
*/
@Test
public void testGetStream() {
- Stream result = fixture.getStream();
+ CTFStream result = fixture.getStream();
assertNotNull(result);
}
*/
@Test
public void testHashCode_null() {
- fixture.setStream((Stream) null);
+ fixture.setStream((CTFStream) null);
fixture.setName((String) null);
int result = fixture.hashCode();
*/
@Test
public void testStreamIsSet_null() {
- fixture.setStream((Stream) null);
+ fixture.setStream((CTFStream) null);
boolean result = fixture.streamIsSet();
assertEquals(false, result);
*/
@Test
public void testEventDefinition() throws CTFReaderException {
- CTFTrace trace = TestParams.createTrace();
- CTFTraceReader tr = new CTFTraceReader(trace);
- tr.advance();
- EventDefinition ed = new EventDefinition(null, null);
- ed = tr.getCurrentEventDef();
- assertNotNull(ed);
- assertNotNull(ed.getPath());
- assertNotNull(ed.getDeclaration());
- assertNotNull(ed.getFields());
- assertNull(ed.getContext());
- assertNotNull(ed.getPacketContext());
- assertNotNull(ed.getCPU());
- assertNotNull(ed.getPacketContext());
- assertNotNull(ed.getStreamInputReader());
- assertNull(ed.lookupDefinition("context")); //$NON-NLS-1$
- assertNotNull(ed.lookupDefinition("fields")); //$NON-NLS-1$
- assertNull(ed.lookupDefinition("other")); //$NON-NLS-1$
- assertNotNull(ed.toString());
- ed.setContext( ed.getFields());
- assertNotNull(ed.toString());
+ try (CTFTrace trace = testTrace.getTrace();) {
+ EventDefinition ed = null;
+ try (CTFTraceReader tr = new CTFTraceReader(trace);) {
+ tr.advance();
+ ed = tr.getCurrentEventDef();
+ }
+
+ assertNotNull(ed);
+ assertNotNull(ed.getScopePath());
+ assertNotNull(ed.getDeclaration());
+ assertNotNull(ed.getFields());
+ assertNull(ed.getContext());
+ assertNotNull(ed.getPacketContext());
+ assertNotNull(ed.getCPU());
+ assertNotNull(ed.getStreamInputReader());
+ assertNull(ed.lookupDefinition("context"));
+ assertNotNull(ed.lookupDefinition("fields"));
+ assertNull(ed.lookupDefinition("other"));
+ assertNotNull(ed.toString());
+ }
+ }
+
+ EventDeclaration e1;
+ EventDeclaration e2;
+
+ @Test
+ public void testEquals1(){
+ e1 = new EventDeclaration();
+ assertFalse(e1.equals(null));
+ }
+
+ @Test
+ public void testEquals2(){
+ e1 = EventDeclaration.getLostEventDeclaration();
+ assertFalse(e1.equals(new Long(23L)));
+ }
+
+ @Test
+ public void testEquals3(){
+ e1 = EventDeclaration.getLostEventDeclaration();
+ assertEquals(e1,e1);
+ }
+
+ @Test
+ public void testEquals4(){
+ e1 = EventDeclaration.getLostEventDeclaration();
+ e2 = EventDeclaration.getLostEventDeclaration();
+ assertEquals(e1,e2);
+ }
+
+ @Test
+ public void testEquals5(){
+ e1 = EventDeclaration.getLostEventDeclaration();
+ e2 = new EventDeclaration();
+ assertFalse(e1.equals(e2));
}
}