Commit | Line | Data |
---|---|---|
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 | ||
14 | package org.eclipse.linuxtools.tmf.core.tests.event; | |
15 | ||
6e1886bc AM |
16 | import static org.junit.Assert.assertEquals; |
17 | import static org.junit.Assert.assertTrue; | |
18 | import static org.junit.Assert.fail; | |
a9ee1687 | 19 | |
3bd46eef AM |
20 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
21 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
22 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampDelta; | |
23 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat; | |
6e1886bc | 24 | import org.junit.Test; |
a9ee1687 BH |
25 | |
26 | /** | |
27 | * Test suite for the TmfTimestampDelta class. | |
28 | */ | |
6e1886bc AM |
29 | @SuppressWarnings({"nls", "javadoc"}) |
30 | public class TmfTimestampDeltaTest { | |
a9ee1687 BH |
31 | |
32 | // ------------------------------------------------------------------------ | |
33 | // Variables | |
34 | // ------------------------------------------------------------------------ | |
35 | ||
36 | private final ITmfTimestamp ts0 = new TmfTimestampDelta(); | |
37 | private final ITmfTimestamp ts1 = new TmfTimestampDelta(12345, 0); | |
38 | private final ITmfTimestamp ts2 = new TmfTimestampDelta(12345, -1); | |
39 | private final ITmfTimestamp ts3 = new TmfTimestampDelta(12345, 2, 5); | |
40 | private final ITmfTimestamp ts4 = new TmfTimestampDelta(-12345, -5); | |
41 | ||
a9ee1687 BH |
42 | // ------------------------------------------------------------------------ |
43 | // Constructors | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
6e1886bc | 46 | @Test |
a9ee1687 BH |
47 | public void testDefaultConstructor() { |
48 | assertEquals("getValue", 0, ts0.getValue()); | |
49 | assertEquals("getscale", 0, ts0.getScale()); | |
50 | assertEquals("getPrecision", 0, ts0.getPrecision()); | |
51 | } | |
52 | ||
6e1886bc | 53 | @Test |
a9ee1687 BH |
54 | public void testValueConstructor() { |
55 | assertEquals("getValue", 12345, ts1.getValue()); | |
56 | assertEquals("getscale", 0, ts1.getScale()); | |
57 | assertEquals("getPrecision", 0, ts1.getPrecision()); | |
58 | } | |
59 | ||
6e1886bc | 60 | @Test |
a9ee1687 BH |
61 | public void testValueScaleConstructor() { |
62 | assertEquals("getValue", 12345, ts2.getValue()); | |
63 | assertEquals("getscale", -1, ts2.getScale()); | |
64 | assertEquals("getPrecision", 0, ts2.getPrecision()); | |
65 | } | |
66 | ||
6e1886bc | 67 | @Test |
a9ee1687 BH |
68 | public void testFullConstructor() { |
69 | assertEquals("getValue", 12345, ts3.getValue()); | |
70 | assertEquals("getscale", 2, ts3.getScale()); | |
71 | assertEquals("getPrecision", 5, ts3.getPrecision()); | |
72 | ||
73 | assertEquals("getValue", -12345, ts4.getValue()); | |
74 | assertEquals("getscale", -5, ts4.getScale()); | |
75 | assertEquals("getPrecision", 0, ts4.getPrecision()); | |
76 | } | |
77 | ||
6e1886bc | 78 | @Test |
a9ee1687 BH |
79 | public void testCopyConstructor() { |
80 | final ITmfTimestamp ts = new TmfTimestamp(12345, 2, 5); | |
81 | final ITmfTimestamp copy = new TmfTimestamp(ts); | |
82 | ||
83 | assertEquals("getValue", ts.getValue(), copy.getValue()); | |
84 | assertEquals("getscale", ts.getScale(), copy.getScale()); | |
85 | assertEquals("getPrecision", ts.getPrecision(), copy.getPrecision()); | |
86 | ||
87 | assertEquals("getValue", 12345, copy.getValue()); | |
88 | assertEquals("getscale", 2, copy.getScale()); | |
89 | assertEquals("getPrecision", 5, copy.getPrecision()); | |
90 | } | |
91 | ||
6e1886bc | 92 | @Test |
a9ee1687 BH |
93 | public void testCopyNullConstructor() { |
94 | try { | |
95 | new TmfTimestamp(null); | |
96 | fail("TmfIntervalTimestamp: null argument"); | |
97 | } catch (final IllegalArgumentException e) { | |
98 | } | |
99 | } | |
100 | ||
101 | // ------------------------------------------------------------------------ | |
102 | // normalize | |
103 | // ------------------------------------------------------------------------ | |
6e1886bc AM |
104 | |
105 | @Test | |
106 | public void testNormalizeOffset() { | |
107 | ITmfTimestamp ts = ts0.normalize(12345, 0); | |
108 | assertTrue("instance", ts instanceof TmfTimestampDelta); | |
109 | assertEquals("getValue", 12345, ts.getValue()); | |
110 | assertEquals("getscale", 0, ts.getScale()); | |
111 | assertEquals("getPrecision", 0, ts.getPrecision()); | |
112 | } | |
a9ee1687 BH |
113 | |
114 | // ------------------------------------------------------------------------ | |
115 | // toString | |
116 | // ------------------------------------------------------------------------ | |
117 | ||
6e1886bc | 118 | @Test |
a9ee1687 BH |
119 | public void testToStringDefault() { |
120 | assertEquals("toString", "000.000 000 000", ts0.toString()); | |
121 | assertEquals("toString", "12345.000 000 000", ts1.toString()); | |
122 | assertEquals("toString", "1234.500 000 000", ts2.toString()); | |
123 | assertEquals("toString", "1234500.000 000 000", ts3.toString()); | |
124 | assertEquals("toString", "-000.123 450 000", ts4.toString()); | |
125 | } | |
126 | ||
6e1886bc AM |
127 | @Test |
128 | public void testToStringFormat() { | |
129 | TmfTimestampFormat format = new TmfTimestampFormat("HH:mm:ss.SSS CCC NNN"); | |
130 | assertEquals("toString", "00:00:00.000 000 000", ts0.toString(format)); | |
131 | assertEquals("toString", "03:25:45.000 000 000", ts1.toString(format)); | |
132 | assertEquals("toString", "00:20:34.500 000 000", ts2.toString(format)); | |
133 | assertEquals("toString", "06:55:00.000 000 000", ts3.toString(format)); | |
134 | assertEquals("toString", "-00:00:00.123 450 000", ts4.toString(format)); | |
135 | } | |
a9ee1687 | 136 | } |