Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfLocationDataTest.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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertFalse;
17 import static org.junit.Assert.assertTrue;
18
19 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23
24 /**
25 * Collection of tests for the {@link CtfLocationData}
26 *
27 * @author alexmont
28 */
29 public class CtfLocationDataTest {
30
31 private CtfLocationData fixture;
32
33 /**
34 * Launch the test.
35 *
36 * @param args
37 * the command line arguments
38 */
39 public static void main(String[] args) {
40 new org.junit.runner.JUnitCore().run(CtfLocationDataTest.class);
41 }
42
43 /**
44 * Perform pre-test initialization.
45 */
46 @Before
47 public void setUp() {
48 fixture = new CtfLocationData(1, 0);
49 }
50
51 /**
52 * Perform post-test clean-up.
53 */
54 @After
55 public void tearDown() {
56 // Add additional tear down code here
57 }
58
59
60 /**
61 * Test for the .getTimestamp() and .getIndex() methods
62 */
63 @Test
64 public void testGetters() {
65 long timestamp = fixture.getTimestamp();
66 long index = fixture.getIndex();
67
68 assertEquals(1, timestamp);
69 assertEquals(0, index);
70 }
71
72 /**
73 * Test for the .hashCode() method
74 */
75 @Test
76 public void testHashCode() {
77 int code = fixture.hashCode();
78 assertEquals(962, code);
79 }
80
81 /**
82 * Test for the .equals() method
83 */
84 @Test
85 public void testEquals() {
86 CtfLocationData same = new CtfLocationData(1, 0);
87 CtfLocationData diff1 = new CtfLocationData(100, 0);
88 CtfLocationData diff2 = new CtfLocationData(1, 10);
89
90 assertTrue(fixture.equals(same));
91 assertFalse(fixture.equals(diff1));
92 assertFalse(fixture.equals(diff2));
93 }
94
95 /**
96 * Test for the .compareTo() method
97 */
98 @Test
99 public void testCompareTo() {
100 CtfLocationData same = new CtfLocationData(1, 0);
101 CtfLocationData smaller = new CtfLocationData(0, 0);
102 CtfLocationData bigger1 = new CtfLocationData(1000, 500);
103 CtfLocationData bigger2 = new CtfLocationData(1, 1);
104
105 assertEquals(0, same.compareTo(fixture));
106 assertEquals(-1, smaller.compareTo(fixture));
107 assertEquals(1, bigger1.compareTo(fixture));
108 assertEquals(1, bigger2.compareTo(fixture));
109 }
110
111 /**
112 * Test for the .toString() method
113 */
114 @Test
115 public void testToString() {
116 String expected = "Element [1/0]"; //$NON-NLS-1$
117 assertEquals(expected, fixture.toString());
118 }
119 }
This page took 0.034007 seconds and 6 git commands to generate.