| 1 | package org.eclipse.linuxtools.ctf.core.tests.trace; |
| 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.assertNotNull; |
| 5 | |
| 6 | import java.nio.channels.FileChannel; |
| 7 | import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; |
| 8 | import org.eclipse.linuxtools.ctf.core.event.EventDefinition; |
| 9 | import org.eclipse.linuxtools.ctf.core.tests.TestParams; |
| 10 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
| 11 | import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; |
| 12 | import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; |
| 13 | import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput; |
| 14 | import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderComparator; |
| 15 | import org.junit.*; |
| 16 | |
| 17 | /** |
| 18 | * The class <code>StreamInputReaderComparatorTest</code> contains tests for the |
| 19 | * class <code>{@link StreamInputReaderComparator}</code>. |
| 20 | * |
| 21 | * @author ematkho |
| 22 | * @version $Revision: 1.0 $ |
| 23 | */ |
| 24 | public class StreamInputReaderComparatorTest { |
| 25 | |
| 26 | private StreamInputReaderComparator fixture; |
| 27 | |
| 28 | /** |
| 29 | * Launch the test. |
| 30 | * |
| 31 | * @param args |
| 32 | * the command line arguments |
| 33 | */ |
| 34 | public static void main(String[] args) { |
| 35 | new org.junit.runner.JUnitCore().run(StreamInputReaderComparatorTest.class); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Perform pre-test initialization. |
| 40 | */ |
| 41 | @Before |
| 42 | public void setUp() { |
| 43 | fixture = new StreamInputReaderComparator(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Perform post-test clean-up. |
| 48 | */ |
| 49 | @After |
| 50 | public void tearDown() { |
| 51 | // Add additional tear down code here |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Run the StreamInputReaderComparator() constructor test. |
| 56 | */ |
| 57 | @Test |
| 58 | public void testStreamInputReaderComparator() { |
| 59 | assertNotNull(fixture); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Run the int compare(StreamInputReader,StreamInputReader) method test. |
| 64 | * |
| 65 | * @throws CTFReaderException |
| 66 | */ |
| 67 | @Test |
| 68 | public void testCompare() throws CTFReaderException { |
| 69 | StreamInputReader sir1, sir2; |
| 70 | EventDefinition ed1, ed2; |
| 71 | |
| 72 | sir1 = new StreamInputReader(new StreamInput(new Stream( |
| 73 | TestParams.createTrace()), (FileChannel) null, |
| 74 | TestParams.getEmptyFile())); |
| 75 | ed1 = new EventDefinition(new EventDeclaration(), |
| 76 | new StreamInputReader(new StreamInput(new Stream( |
| 77 | TestParams.createTrace()), (FileChannel) null, |
| 78 | TestParams.getEmptyFile()))); |
| 79 | ed1.timestamp = 1L; |
| 80 | sir1.setCurrentEvent(ed1); |
| 81 | |
| 82 | sir2 = new StreamInputReader(new StreamInput(new Stream( |
| 83 | TestParams.createTrace()), (FileChannel) null, |
| 84 | TestParams.getEmptyFile())); |
| 85 | ed2 = new EventDefinition(new EventDeclaration(), |
| 86 | new StreamInputReader(new StreamInput(new Stream( |
| 87 | TestParams.createTrace()), (FileChannel) null, |
| 88 | TestParams.getEmptyFile()))); |
| 89 | |
| 90 | ed2.timestamp = 1L; |
| 91 | sir2.setCurrentEvent(ed2); |
| 92 | |
| 93 | int result = fixture.compare(sir1, sir2); |
| 94 | assertEquals(0, result); |
| 95 | } |
| 96 | } |