package org.eclipse.linuxtools.ctf.core.tests.trace;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Perform pre-test initialization.
- * @throws CTFReaderException
+ * @throws CTFReaderException
*/
@Before
public void setUp() throws CTFReaderException {
/**
* Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
* trace.
- * @throws CTFReaderException
+ * @throws CTFReaderException
*/
@Test
public void testOpen_existing() throws CTFReaderException {
*
* Both trace reader are different objects, so they shouldn't "equals" each
* other.
- * @throws CTFReaderException
+ * @throws CTFReaderException
*/
@Test
public void testEquals() throws CTFReaderException {
@Test
public void testGoToLastEvent() throws CTFReaderException {
fixture.goToLastEvent();
- long ts1 = fixture.getCurrentEventDef().timestamp;
+ long ts1 = getTimestamp();
long ts2 = fixture.getEndTime();
- assertTrue(ts1 == ts2);
+ // the end time can be later than the last event.
+ assertTrue(ts1 <= ts2);
}
/**
boolean result = fixture.seek(timestamp);
assertTrue(result);
}
+
+
+ /**
+ * Run the boolean seek(long) method test.
+ * @throws CTFReaderException
+ */
+ @Test
+ public void testSeekIndex() throws CTFReaderException {
+ long rank = 30000L;
+ long first, second = 0, third , fourth;
+ /*
+ * we need to read the trace before seeking
+ */
+ first = getTimestamp();
+ for( int i = 0 ; i < 60000; i++ )
+ {
+ if( i == rank) {
+ second = getTimestamp();
+ }
+ fixture.advance();
+ }
+ boolean result= fixture.seekIndex(0);
+ third = getTimestamp();
+ boolean result2 = fixture.seekIndex(rank);
+ fourth = getTimestamp();
+ assertTrue(result);
+ assertTrue(result2);
+ assertEquals( first , third);
+ assertEquals( second , fourth);
+ }
+
+ /**
+ * @return
+ */
+ private long getTimestamp() {
+ return fixture.getCurrentEventDef().timestamp;
+ }
}