Commit | Line | Data |
---|---|---|
132a02b0 | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2012, 2013 Ericsson |
132a02b0 MK |
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 | ||
f5df94f8 | 19 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationInfo; |
132a02b0 MK |
20 | import org.junit.Before; |
21 | import org.junit.Test; | |
22 | ||
23 | /** | |
f5df94f8 | 24 | * Collection of tests for the {@link CtfLocationInfo} |
132a02b0 MK |
25 | * |
26 | * @author alexmont | |
27 | */ | |
28 | public class CtfLocationDataTest { | |
29 | ||
f5df94f8 | 30 | private CtfLocationInfo fixture; |
132a02b0 | 31 | |
132a02b0 MK |
32 | /** |
33 | * Perform pre-test initialization. | |
34 | */ | |
35 | @Before | |
36 | public void setUp() { | |
f5df94f8 | 37 | fixture = new CtfLocationInfo(1, 0); |
132a02b0 MK |
38 | } |
39 | ||
132a02b0 MK |
40 | /** |
41 | * Test for the .getTimestamp() and .getIndex() methods | |
42 | */ | |
43 | @Test | |
44 | public void testGetters() { | |
45 | long timestamp = fixture.getTimestamp(); | |
46 | long index = fixture.getIndex(); | |
47 | ||
48 | assertEquals(1, timestamp); | |
49 | assertEquals(0, index); | |
50 | } | |
51 | ||
52 | /** | |
53 | * Test for the .hashCode() method | |
54 | */ | |
55 | @Test | |
56 | public void testHashCode() { | |
57 | int code = fixture.hashCode(); | |
58 | assertEquals(962, code); | |
59 | } | |
60 | ||
61 | /** | |
62 | * Test for the .equals() method | |
63 | */ | |
64 | @Test | |
65 | public void testEquals() { | |
f5df94f8 AM |
66 | CtfLocationInfo same = new CtfLocationInfo(1, 0); |
67 | CtfLocationInfo diff1 = new CtfLocationInfo(100, 0); | |
68 | CtfLocationInfo diff2 = new CtfLocationInfo(1, 10); | |
132a02b0 MK |
69 | |
70 | assertTrue(fixture.equals(same)); | |
71 | assertFalse(fixture.equals(diff1)); | |
72 | assertFalse(fixture.equals(diff2)); | |
73 | } | |
74 | ||
75 | /** | |
76 | * Test for the .compareTo() method | |
77 | */ | |
78 | @Test | |
79 | public void testCompareTo() { | |
f5df94f8 AM |
80 | CtfLocationInfo same = new CtfLocationInfo(1, 0); |
81 | CtfLocationInfo smaller = new CtfLocationInfo(0, 0); | |
82 | CtfLocationInfo bigger1 = new CtfLocationInfo(1000, 500); | |
83 | CtfLocationInfo bigger2 = new CtfLocationInfo(1, 1); | |
132a02b0 MK |
84 | |
85 | assertEquals(0, same.compareTo(fixture)); | |
86 | assertEquals(-1, smaller.compareTo(fixture)); | |
87 | assertEquals(1, bigger1.compareTo(fixture)); | |
88 | assertEquals(1, bigger2.compareTo(fixture)); | |
89 | } | |
90 | ||
91 | /** | |
92 | * Test for the .toString() method | |
93 | */ | |
94 | @Test | |
95 | public void testToString() { | |
96 | String expected = "Element [1/0]"; //$NON-NLS-1$ | |
97 | assertEquals(expected, fixture.toString()); | |
98 | } | |
99 | } |