tmf.core: Introduce TmfTimestamp factory methods
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / event / TmfTimestampDeltaTest.java
CommitLineData
a9ee1687 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2012, 2014 Ericsson
a9ee1687
BH
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 * Bernd Hufmann - Initial API and implementation
6e1886bc 11 * Alexandre Montplaisir - Port to JUnit4
a9ee1687
BH
12 *******************************************************************************/
13
2bdf0193 14package org.eclipse.tracecompass.tmf.core.tests.event;
a9ee1687 15
6e1886bc
AM
16import static org.junit.Assert.assertEquals;
17import static org.junit.Assert.assertTrue;
a9ee1687 18
2bdf0193
AM
19import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
20import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
21import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampDelta;
22import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
6e1886bc 23import org.junit.Test;
a9ee1687
BH
24
25/**
26 * Test suite for the TmfTimestampDelta class.
27 */
cad06250 28@SuppressWarnings("javadoc")
6e1886bc 29public class TmfTimestampDeltaTest {
a9ee1687
BH
30
31 // ------------------------------------------------------------------------
32 // Variables
33 // ------------------------------------------------------------------------
34
35 private final ITmfTimestamp ts0 = new TmfTimestampDelta();
36 private final ITmfTimestamp ts1 = new TmfTimestampDelta(12345, 0);
37 private final ITmfTimestamp ts2 = new TmfTimestampDelta(12345, -1);
065cc19b 38 private final ITmfTimestamp ts3 = new TmfTimestampDelta(12345, 2);
a9ee1687
BH
39 private final ITmfTimestamp ts4 = new TmfTimestampDelta(-12345, -5);
40
a9ee1687
BH
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44
6e1886bc 45 @Test
a9ee1687
BH
46 public void testDefaultConstructor() {
47 assertEquals("getValue", 0, ts0.getValue());
48 assertEquals("getscale", 0, ts0.getScale());
a9ee1687
BH
49 }
50
6e1886bc 51 @Test
a9ee1687
BH
52 public void testValueConstructor() {
53 assertEquals("getValue", 12345, ts1.getValue());
54 assertEquals("getscale", 0, ts1.getScale());
a9ee1687
BH
55 }
56
6e1886bc 57 @Test
a9ee1687
BH
58 public void testValueScaleConstructor() {
59 assertEquals("getValue", 12345, ts2.getValue());
60 assertEquals("getscale", -1, ts2.getScale());
a9ee1687
BH
61 }
62
6e1886bc 63 @Test
a9ee1687
BH
64 public void testFullConstructor() {
65 assertEquals("getValue", 12345, ts3.getValue());
66 assertEquals("getscale", 2, ts3.getScale());
a9ee1687
BH
67
68 assertEquals("getValue", -12345, ts4.getValue());
69 assertEquals("getscale", -5, ts4.getScale());
a9ee1687
BH
70 }
71
6e1886bc 72 @Test
a9ee1687 73 public void testCopyConstructor() {
b2c971ec
MK
74 final ITmfTimestamp ts = TmfTimestamp.create(12345, 2);
75 final ITmfTimestamp copy = TmfTimestamp.create(12345, 2);
a9ee1687
BH
76
77 assertEquals("getValue", ts.getValue(), copy.getValue());
78 assertEquals("getscale", ts.getScale(), copy.getScale());
a9ee1687
BH
79
80 assertEquals("getValue", 12345, copy.getValue());
81 assertEquals("getscale", 2, copy.getScale());
a9ee1687
BH
82 }
83
a9ee1687
BH
84 // ------------------------------------------------------------------------
85 // normalize
86 // ------------------------------------------------------------------------
6e1886bc
AM
87
88 @Test
89 public void testNormalizeOffset() {
90 ITmfTimestamp ts = ts0.normalize(12345, 0);
91 assertTrue("instance", ts instanceof TmfTimestampDelta);
92 assertEquals("getValue", 12345, ts.getValue());
93 assertEquals("getscale", 0, ts.getScale());
6e1886bc 94 }
a9ee1687
BH
95
96 // ------------------------------------------------------------------------
97 // toString
98 // ------------------------------------------------------------------------
99
6e1886bc 100 @Test
a9ee1687
BH
101 public void testToStringDefault() {
102 assertEquals("toString", "000.000 000 000", ts0.toString());
103 assertEquals("toString", "12345.000 000 000", ts1.toString());
104 assertEquals("toString", "1234.500 000 000", ts2.toString());
105 assertEquals("toString", "1234500.000 000 000", ts3.toString());
106 assertEquals("toString", "-000.123 450 000", ts4.toString());
107 }
108
6e1886bc
AM
109 @Test
110 public void testToStringFormat() {
111 TmfTimestampFormat format = new TmfTimestampFormat("HH:mm:ss.SSS CCC NNN");
112 assertEquals("toString", "00:00:00.000 000 000", ts0.toString(format));
113 assertEquals("toString", "03:25:45.000 000 000", ts1.toString(format));
114 assertEquals("toString", "00:20:34.500 000 000", ts2.toString(format));
115 assertEquals("toString", "06:55:00.000 000 000", ts3.toString(format));
116 assertEquals("toString", "-00:00:00.123 450 000", ts4.toString(format));
117 }
a9ee1687 118}
This page took 0.1078 seconds and 5 git commands to generate.