Revert "tmf: Make TmfTimePreferences completely static"
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / event / TmfTimestampDeltaTest.java
CommitLineData
a9ee1687 1/*******************************************************************************
6e1886bc 2 * Copyright (c) 2012, 2013 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
14package org.eclipse.linuxtools.tmf.core.tests.event;
15
6e1886bc
AM
16import static org.junit.Assert.assertEquals;
17import static org.junit.Assert.assertTrue;
a9ee1687 18
3bd46eef
AM
19import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
20import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
21import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampDelta;
22import org.eclipse.linuxtools.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);
38 private final ITmfTimestamp ts3 = new TmfTimestampDelta(12345, 2, 5);
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());
49 assertEquals("getPrecision", 0, ts0.getPrecision());
50 }
51
6e1886bc 52 @Test
a9ee1687
BH
53 public void testValueConstructor() {
54 assertEquals("getValue", 12345, ts1.getValue());
55 assertEquals("getscale", 0, ts1.getScale());
56 assertEquals("getPrecision", 0, ts1.getPrecision());
57 }
58
6e1886bc 59 @Test
a9ee1687
BH
60 public void testValueScaleConstructor() {
61 assertEquals("getValue", 12345, ts2.getValue());
62 assertEquals("getscale", -1, ts2.getScale());
63 assertEquals("getPrecision", 0, ts2.getPrecision());
64 }
65
6e1886bc 66 @Test
a9ee1687
BH
67 public void testFullConstructor() {
68 assertEquals("getValue", 12345, ts3.getValue());
69 assertEquals("getscale", 2, ts3.getScale());
70 assertEquals("getPrecision", 5, ts3.getPrecision());
71
72 assertEquals("getValue", -12345, ts4.getValue());
73 assertEquals("getscale", -5, ts4.getScale());
74 assertEquals("getPrecision", 0, ts4.getPrecision());
75 }
76
6e1886bc 77 @Test
a9ee1687
BH
78 public void testCopyConstructor() {
79 final ITmfTimestamp ts = new TmfTimestamp(12345, 2, 5);
80 final ITmfTimestamp copy = new TmfTimestamp(ts);
81
82 assertEquals("getValue", ts.getValue(), copy.getValue());
83 assertEquals("getscale", ts.getScale(), copy.getScale());
84 assertEquals("getPrecision", ts.getPrecision(), copy.getPrecision());
85
86 assertEquals("getValue", 12345, copy.getValue());
87 assertEquals("getscale", 2, copy.getScale());
88 assertEquals("getPrecision", 5, copy.getPrecision());
89 }
90
032ecd45 91 @Test(expected=IllegalArgumentException.class)
a9ee1687 92 public void testCopyNullConstructor() {
032ecd45 93 new TmfTimestamp((TmfTimestamp) null);
a9ee1687
BH
94 }
95
96 // ------------------------------------------------------------------------
97 // normalize
98 // ------------------------------------------------------------------------
6e1886bc
AM
99
100 @Test
101 public void testNormalizeOffset() {
102 ITmfTimestamp ts = ts0.normalize(12345, 0);
103 assertTrue("instance", ts instanceof TmfTimestampDelta);
104 assertEquals("getValue", 12345, ts.getValue());
105 assertEquals("getscale", 0, ts.getScale());
106 assertEquals("getPrecision", 0, ts.getPrecision());
107 }
a9ee1687
BH
108
109 // ------------------------------------------------------------------------
110 // toString
111 // ------------------------------------------------------------------------
112
6e1886bc 113 @Test
a9ee1687
BH
114 public void testToStringDefault() {
115 assertEquals("toString", "000.000 000 000", ts0.toString());
116 assertEquals("toString", "12345.000 000 000", ts1.toString());
117 assertEquals("toString", "1234.500 000 000", ts2.toString());
118 assertEquals("toString", "1234500.000 000 000", ts3.toString());
119 assertEquals("toString", "-000.123 450 000", ts4.toString());
120 }
121
6e1886bc
AM
122 @Test
123 public void testToStringFormat() {
124 TmfTimestampFormat format = new TmfTimestampFormat("HH:mm:ss.SSS CCC NNN");
125 assertEquals("toString", "00:00:00.000 000 000", ts0.toString(format));
126 assertEquals("toString", "03:25:45.000 000 000", ts1.toString(format));
127 assertEquals("toString", "00:20:34.500 000 000", ts2.toString(format));
128 assertEquals("toString", "06:55:00.000 000 000", ts3.toString(format));
129 assertEquals("toString", "-00:00:00.123 450 000", ts4.toString(format));
130 }
a9ee1687 131}
This page took 0.044026 seconds and 5 git commands to generate.