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