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