Commit | Line | Data |
---|---|---|
4bd7f2db AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 Ericsson | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Matthew Khouzam - Initial API and implementation | |
10 | *******************************************************************************/ | |
11 | ||
866e5b51 FC |
12 | package org.eclipse.linuxtools.ctf.core.tests.trace; |
13 | ||
14 | import static org.junit.Assert.assertEquals; | |
15 | import static org.junit.Assert.assertNotNull; | |
16 | ||
17 | import java.util.UUID; | |
18 | ||
19 | import org.eclipse.linuxtools.ctf.core.trace.Utils; | |
20 | import org.junit.After; | |
21 | import org.junit.Before; | |
22 | import org.junit.Test; | |
23 | ||
24 | /** | |
25 | * The class <code>UtilsTest</code> contains tests for the class | |
c9fe9175 AM |
26 | * {@link Utils}. |
27 | * | |
866e5b51 FC |
28 | * @author ematkho |
29 | * @version $Revision: 1.0 $ | |
30 | */ | |
31 | public class UtilsTest { | |
32 | ||
33 | /** | |
34 | * Launch the test. | |
c9fe9175 | 35 | * |
866e5b51 FC |
36 | * @param args |
37 | * the command line arguments | |
38 | */ | |
39 | public static void main(String[] args) { | |
40 | new org.junit.runner.JUnitCore().run(UtilsTest.class); | |
41 | } | |
42 | ||
43 | /** | |
44 | * Perform pre-test initialization. | |
45 | */ | |
46 | @Before | |
47 | public void setUp() { | |
48 | // add additional set up code here | |
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 | * Run the Utils() constructor test. | |
61 | */ | |
62 | @Test | |
63 | public void testUtils() { | |
64 | Utils result = new Utils(); | |
65 | assertNotNull(result); | |
66 | } | |
67 | ||
68 | /** | |
69 | * Run the UUID makeUUID(byte[]) method test. | |
70 | */ | |
71 | @Test | |
72 | public void testMakeUUID() { | |
73 | int byteSize = 32; | |
74 | byte[] bytes = new byte[byteSize]; | |
75 | for (int i = 0; i < byteSize; i++) { | |
76 | bytes[i] = (byte) (i); | |
77 | } | |
78 | ||
79 | UUID result = Utils.makeUUID(bytes); | |
80 | assertNotNull(result); | |
81 | } | |
82 | ||
83 | /** | |
84 | * Run the UUID makeUUID(byte[]) method test. | |
85 | */ | |
86 | @Test | |
87 | public void testMakeUUID_2() { | |
88 | byte[] bytes = new byte[] { (byte) 1, (byte) 1, (byte) 0, (byte) 0, | |
89 | (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 1, (byte) 1, | |
90 | (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 }; | |
91 | ||
92 | UUID result = Utils.makeUUID(bytes); | |
93 | ||
94 | assertNotNull(result); | |
95 | assertEquals(72339069014638592L, result.getLeastSignificantBits()); | |
96 | assertEquals(72339069014638592L, result.getMostSignificantBits()); | |
4a9c1f07 | 97 | assertEquals("01010000-0000-0000-0101-000000000000", result.toString()); |
866e5b51 FC |
98 | assertEquals(0, result.variant()); |
99 | assertEquals(0, result.version()); | |
100 | } | |
101 | ||
102 | /** | |
103 | * Run the UUID makeUUID(byte[]) method test. | |
104 | */ | |
105 | @Test | |
106 | public void testMakeUUID_3() { | |
107 | byte[] bytes = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, | |
108 | (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, | |
109 | (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 }; | |
110 | ||
111 | UUID result = Utils.makeUUID(bytes); | |
112 | ||
113 | assertNotNull(result); | |
114 | assertEquals(0L, result.getLeastSignificantBits()); | |
115 | assertEquals(0L, result.getMostSignificantBits()); | |
4a9c1f07 | 116 | assertEquals("00000000-0000-0000-0000-000000000000", result.toString()); |
866e5b51 FC |
117 | assertEquals(0, result.variant()); |
118 | assertEquals(0, result.version()); | |
119 | } | |
120 | ||
121 | /** | |
122 | * Run the int unsignedCompare(long,long) method test. | |
123 | */ | |
124 | @Test | |
125 | public void testUnsignedCompare() { | |
126 | long a = 1L; | |
127 | long b = 1L; | |
128 | ||
129 | int result = Utils.unsignedCompare(a, b); | |
130 | assertEquals(0, result); | |
131 | } | |
132 | } |