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