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 | ||
19e45ccc MK |
16 | import static org.junit.Assert.assertEquals; |
17 | import static org.junit.Assert.assertNotNull; | |
18 | ||
81c8e6f7 | 19 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation; |
132a02b0 | 20 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData; |
81c8e6f7 MK |
21 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
22 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
19e45ccc MK |
23 | import org.junit.After; |
24 | import org.junit.Before; | |
25 | import org.junit.Test; | |
81c8e6f7 MK |
26 | |
27 | /** | |
95bf10e7 AM |
28 | * The class <code>CtfLocationTest</code> contains tests for the class |
29 | * <code>{@link CtfLocation}</code>. | |
81c8e6f7 | 30 | * |
81c8e6f7 | 31 | * @author ematkho |
95bf10e7 | 32 | * @version 1.0 |
81c8e6f7 MK |
33 | */ |
34 | public class CtfLocationTest { | |
95bf10e7 AM |
35 | |
36 | private CtfLocation fixture; | |
37 | ||
81c8e6f7 | 38 | /** |
95bf10e7 | 39 | * Launch the test. |
81c8e6f7 | 40 | * |
95bf10e7 AM |
41 | * @param args |
42 | * the command line arguments | |
43 | */ | |
44 | public static void main(String[] args) { | |
45 | new org.junit.runner.JUnitCore().run(CtfLocationTest.class); | |
46 | } | |
47 | ||
48 | /** | |
49 | * Perform pre-test initialization. | |
50 | */ | |
51 | @Before | |
52 | public void setUp() { | |
132a02b0 | 53 | fixture = new CtfLocation(new CtfLocationData(1, 0)); |
95bf10e7 AM |
54 | } |
55 | ||
56 | /** | |
57 | * Perform post-test clean-up. | |
58 | */ | |
59 | @After | |
60 | public void tearDown() { | |
61 | // Add additional tear down code here | |
62 | } | |
63 | ||
64 | ||
65 | /** | |
66 | * Run the CtfLocation(Long) constructor test. | |
81c8e6f7 MK |
67 | */ |
68 | @Test | |
95bf10e7 | 69 | public void testCtfLocation_long() { |
132a02b0 | 70 | CtfLocationData location = new CtfLocationData(1, 0); |
81c8e6f7 MK |
71 | CtfLocation result = new CtfLocation(location); |
72 | ||
81c8e6f7 | 73 | assertNotNull(result); |
5976d44a | 74 | assertEquals(Long.valueOf(1), (Long)result.getLocationInfo().getTimestamp()); |
81c8e6f7 MK |
75 | } |
76 | ||
77 | /** | |
78 | * Run the CtfLocation(ITmfTimestamp) constructor test. | |
81c8e6f7 MK |
79 | */ |
80 | @Test | |
95bf10e7 | 81 | public void testCtfLocation_timestamp() { |
81c8e6f7 | 82 | ITmfTimestamp timestamp = new TmfTimestamp(); |
81c8e6f7 MK |
83 | CtfLocation result = new CtfLocation(timestamp); |
84 | ||
81c8e6f7 | 85 | assertNotNull(result); |
5976d44a | 86 | assertEquals(new Long(0L), (Long)result.getLocationInfo().getTimestamp()); |
81c8e6f7 MK |
87 | } |
88 | ||
89 | /** | |
90 | * Run the CtfLocation clone() method test. | |
81c8e6f7 MK |
91 | */ |
92 | @Test | |
95bf10e7 | 93 | public void testClone() { |
81c8e6f7 MK |
94 | CtfLocation result = fixture.clone(); |
95 | ||
81c8e6f7 | 96 | assertNotNull(result); |
5976d44a | 97 | assertEquals(Long.valueOf(1), (Long)result.getLocationInfo().getTimestamp()); |
81c8e6f7 MK |
98 | } |
99 | ||
100 | /** | |
101 | * Run the Long getLocation() method test. | |
81c8e6f7 MK |
102 | */ |
103 | @Test | |
95bf10e7 | 104 | public void testGetLocation() { |
5976d44a | 105 | CtfLocationData location = fixture.getLocationInfo(); |
132a02b0 | 106 | Long result = location.getTimestamp(); |
81c8e6f7 | 107 | assertNotNull(result); |
19e45ccc | 108 | assertEquals("1", result.toString()); //$NON-NLS-1$ |
81c8e6f7 MK |
109 | assertEquals((byte) 1, result.byteValue()); |
110 | assertEquals((short) 1, result.shortValue()); | |
111 | assertEquals(1, result.intValue()); | |
112 | assertEquals(1L, result.longValue()); | |
113 | assertEquals(1.0f, result.floatValue(), 1.0f); | |
114 | assertEquals(1.0, result.doubleValue(), 1.0); | |
115 | } | |
116 | ||
117 | /** | |
118 | * Run the void setLocation(Long) method test. | |
81c8e6f7 MK |
119 | */ |
120 | @Test | |
95bf10e7 | 121 | public void testSetLocation() { |
132a02b0 | 122 | CtfLocationData location = new CtfLocationData(1337, 7331); |
d62bb185 | 123 | fixture = new CtfLocation(location); |
19e45ccc MK |
124 | } |
125 | ||
81c8e6f7 | 126 | /** |
95bf10e7 | 127 | * Test the toString() method with a valid location. |
81c8e6f7 | 128 | */ |
95bf10e7 AM |
129 | @Test |
130 | public void testToString_valid(){ | |
132a02b0 MK |
131 | CtfLocation fixture2 = new CtfLocation(new CtfLocationData(1337, 7331)); |
132 | assertEquals("CtfLocation: Element [1337/7331]",fixture2.toString()); //$NON-NLS-1$ | |
81c8e6f7 MK |
133 | } |
134 | ||
135 | /** | |
95bf10e7 | 136 | * Test the toString() method with an invalid location. |
81c8e6f7 | 137 | */ |
95bf10e7 AM |
138 | @Test |
139 | public void testToString_invalid(){ | |
132a02b0 | 140 | CtfLocation fixture2 = new CtfLocation(new CtfLocationData(-1, -1)); |
95bf10e7 | 141 | assertEquals("CtfLocation: INVALID",fixture2.toString()); //$NON-NLS-1$ |
81c8e6f7 | 142 | } |
95bf10e7 | 143 | } |