tmf.core: Introduce TmfTimestamp factory methods
[deliverable/tracecompass.git] / btf / org.eclipse.tracecompass.btf.core.tests / src / org / eclipse / tracecompass / btf / core / tests / trace / BtfTraceTest.java
CommitLineData
ff71e543
MK
1/*******************************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
7ce90559 12package org.eclipse.tracecompass.btf.core.tests.trace;
ff71e543 13
b2c971ec
MK
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16import static org.junit.Assert.assertTrue;
ff71e543 17
ff71e543
MK
18import java.util.Map;
19
7ce90559
AM
20import org.eclipse.tracecompass.btf.core.tests.utils.BtfTestTrace;
21import org.eclipse.tracecompass.btf.core.trace.BtfTrace;
2bdf0193
AM
22import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
23import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
24import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
ff71e543
MK
25import org.junit.After;
26import org.junit.Before;
27import org.junit.Test;
28
29/**
30 * Best trace format test cases
31 *
32 * @author Matthew Khouzam
33 */
34public class BtfTraceTest {
35
36 private static final long START_TIME = 1392809960000000000L;
37
38 private BtfTrace fixture;
39
40 /**
41 * Does the trace exist?
42 */
43 @Before
44 public void setup() {
45 fixture = BtfTestTrace.BTF_TEST.getTrace();
46 assertNotNull(fixture);
47 }
48
49 /**
50 * Cleanup
51 */
52 @After
53 public void cleanup() {
d9aa847c 54 fixture.dispose();
ff71e543
MK
55 }
56
57 /**
58 * Tests validation
59 */
60 @Test
61 public void testValidate(){
62 TraceValidationStatus status = (TraceValidationStatus) fixture.validate(null, fixture.getPath());
63 assertNotNull(status);
64 assertTrue(status.isOK());
65 assertEquals(100, status.getConfidence());
66
67 }
68
69 /**
70 * Seek the first event
71 */
72 @Test
73 public void testSeek1stEvent() {
74 ITmfContext ctx = fixture.seekEvent(0);
75 assertNotNull(ctx);
76 assertEquals(0, ctx.getRank());
77 assertEquals(499L, ctx.getLocation().getLocationInfo());
78 }
79
80 /**
81 * Read the first event
82 */
83 @Test
84 public void testRead1stEvent() {
85 ITmfContext ctx = fixture.seekEvent(0);
86 ITmfEvent event = fixture.getNext(ctx);
87 assertNotNull(event);
88 assertEquals(START_TIME, event.getTimestamp().getValue());
89 }
90
91 /**
92 * Read the tenth event
93 */
94 @Test
95 public void testRead10thEvent1() {
96 ITmfContext ctx = fixture.seekEvent(10);
97 ITmfEvent event = fixture.getNext(ctx);
98 assertNotNull(event);
99 assertEquals(START_TIME, event.getTimestamp().getValue());
100 }
101
102 /**
103 * Read the tenth event without seeking
104 */
105 @Test
106 public void testRead10thEvent2() {
107 ITmfContext ctx = fixture.seekEvent(0);
108 ITmfEvent event = null;
109 for (int i = 0; i < 10; i++) {
110 event = fixture.getNext(ctx);
111 }
112 assertNotNull(event);
113 assertEquals(START_TIME, event.getTimestamp().getValue());
114 }
115
116 /**
117 * Read the trace properties
118 */
119 @Test
120 public void testReadProperties() {
234838b2 121 Map<String, String> data = fixture.getProperties();
ff71e543
MK
122 assertNotNull(data);
123 assertEquals("ns", data.get("#timeScale"));
124 assertEquals("2.1.0", data.get("#version"));
125 }
126
127 /**
128 * Read two contexts
129 */
130 @Test
131 public void testTwoContexts() {
132 ITmfContext ctx0 = fixture.seekEvent(0);
133 ITmfContext ctx1 = fixture.seekEvent(10);
134 ITmfEvent event = null;
135 for (int i = 0; i < 11; i++) {
136 event = fixture.getNext(ctx0);
137 }
138 ITmfEvent event1 = fixture.getNext(ctx1);
139 assertNotNull(event);
140 assertNotNull(event1);
141 assertEquals(event, event1);
142 }
143}
This page took 0.055656 seconds and 5 git commands to generate.