tmf: Clean up the ctfAdaptor unit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfTimestampTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012 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 generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
22 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp.TimestampType;
23 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
24 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
28
29 /**
30 * The class <code>CtfTmfTimestampTest</code> contains tests for the class
31 * <code>{@link CtfTmfTimestamp}</code>.
32 *
33 * @author ematkho
34 * @version 1.0
35 */
36 public class CtfTmfTimestampTest {
37
38 private CtfTmfTimestamp fixture;
39
40 /**
41 * Launch the test.
42 *
43 * @param args the command line arguments
44 */
45 public static void main(String[] args) {
46 new org.junit.runner.JUnitCore().run(CtfTmfTimestampTest.class);
47 }
48
49 /**
50 * Perform pre-test initialization.
51 */
52 @Before
53 public void setUp() {
54 fixture = new CtfTmfTimestamp(1L);
55 fixture.setType(CtfTmfTimestamp.TimestampType.DAY);
56 }
57
58 /**
59 * Perform post-test clean-up.
60 */
61 @After
62 public void tearDown() {
63 // Add additional tear down code here
64 }
65
66
67 /**
68 * Run the CtfTmfTimestamp(long) constructor test.
69 */
70 @Test
71 public void testCtfTmfTimestamp() {
72 long timestamp = 1L;
73
74 CtfTmfTimestamp result = new CtfTmfTimestamp(timestamp);
75 result.setType(TimestampType.NANOS);
76
77 assertNotNull(result);
78 assertEquals("1 ns", result.toString()); //$NON-NLS-1$
79 assertEquals(0, result.getPrecision());
80 assertEquals(-9, result.getScale());
81 assertEquals(1L, result.getValue());
82 }
83
84
85 /**
86 * Run the boolean equals(Object) method test with another identical object.
87 */
88 @Test
89 public void testEquals_same() {
90 CtfTmfTimestamp obj = new CtfTmfTimestamp(1L);
91 obj.setType(CtfTmfTimestamp.TimestampType.DAY);
92
93 boolean result = fixture.equals(obj);
94 assertTrue(result);
95 }
96
97 /**
98 * Run the boolean equals(Object) method test, with an empty object.
99 */
100 @Test
101 public void testEquals_empty() {
102 Object obj = new Object();
103
104 boolean result = fixture.equals(obj);
105 assertFalse(result);
106 }
107
108 /**
109 * Run the ITmfTimestamp getDelta(ITmfTimestamp) method test.
110 */
111 @Test
112 public void testGetDelta() {
113 ITmfTimestamp ts = new TmfTimestamp();
114 ITmfTimestamp result = fixture.getDelta(ts);
115
116 assertNotNull(result);
117 assertEquals(0, result.getPrecision());
118 assertEquals(-9, result.getScale());
119 assertEquals(1L, result.getValue());
120 }
121
122 /**
123 * Run the CtfTmfTimestamp.TimestampType getType() method test.
124 */
125 @Test
126 public void testGetType() {
127 CtfTmfTimestamp.TimestampType result = fixture.getType();
128
129 assertNotNull(result);
130 assertEquals("DAY", result.name()); //$NON-NLS-1$
131 assertEquals("DAY", result.toString()); //$NON-NLS-1$
132 assertEquals(1, result.ordinal());
133 }
134
135 /**
136 * Run the int hashCode() method test.
137 */
138 @Test
139 public void testHashCode() {
140 int result = fixture.hashCode();
141 assertEquals(1012115, result);
142 }
143
144 /**
145 * Run the int hashCode() method test.
146 */
147 @Test
148 public void testHashCode_nullType() {
149 fixture.setType(null);
150 int result = fixture.hashCode();
151 assertEquals(944663, result);
152 }
153
154 /**
155 * Run the void setType(TimestampType) method test.
156 */
157 @Test
158 public void testSetType() {
159 CtfTmfTimestamp.TimestampType value = CtfTmfTimestamp.TimestampType.DAY;
160 fixture.setType(value);
161 }
162
163 /**
164 * Run the String toString() method test.
165 */
166 @Test
167 public void testToString_ns() {
168 fixture.setType(CtfTmfTimestamp.TimestampType.NANOS);
169 String result = fixture.toString();
170 assertEquals("1 ns", result); //$NON-NLS-1$
171 }
172
173 /**
174 * Run the String toString() method test.
175 */
176 @Test
177 public void testToString_s() {
178 fixture.setType(CtfTmfTimestamp.TimestampType.SECONDS);
179 String result = fixture.toString();
180 assertEquals("1.0E-9 s", result); //$NON-NLS-1$
181 }
182
183 /**
184 * Run the String toString() method test.
185 */
186 @Test
187 public void testToString_day() {
188 String result = fixture.toString();
189 assertEquals("19:00:00.000000001", result); //$NON-NLS-1$
190 }
191
192 /**
193 * Run the String toString() method test.
194 */
195 @Test
196 public void testToString_full() {
197 fixture.setType(CtfTmfTimestamp.TimestampType.FULL_DATE);
198 String result = fixture.toString();
199 assertEquals("1969-12-31 19:00:00.000000001", result); //$NON-NLS-1$
200 }
201 }
This page took 0.038083 seconds and 6 git commands to generate.