rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / UtilsTest.java
CommitLineData
4bd7f2db 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2013, 2014 Ericsson
4bd7f2db
AM
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
f357bcd4 12package org.eclipse.tracecompass.ctf.core.tests.trace;
866e5b51
FC
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16
17import java.util.UUID;
18
1b638236 19import org.eclipse.tracecompass.internal.ctf.core.trace.Utils;
866e5b51
FC
20import org.junit.Test;
21
22/**
23 * The class <code>UtilsTest</code> contains tests for the class
c9fe9175
AM
24 * {@link Utils}.
25 *
866e5b51
FC
26 * @author ematkho
27 * @version $Revision: 1.0 $
28 */
29public class UtilsTest {
30
866e5b51
FC
31 /**
32 * Run the UUID makeUUID(byte[]) method test.
33 */
34 @Test
35 public void testMakeUUID() {
36 int byteSize = 32;
37 byte[] bytes = new byte[byteSize];
38 for (int i = 0; i < byteSize; i++) {
39 bytes[i] = (byte) (i);
40 }
41
42 UUID result = Utils.makeUUID(bytes);
43 assertNotNull(result);
44 }
45
46 /**
47 * Run the UUID makeUUID(byte[]) method test.
48 */
49 @Test
50 public void testMakeUUID_2() {
51 byte[] bytes = new byte[] { (byte) 1, (byte) 1, (byte) 0, (byte) 0,
52 (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 1, (byte) 1,
53 (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
54
55 UUID result = Utils.makeUUID(bytes);
56
57 assertNotNull(result);
58 assertEquals(72339069014638592L, result.getLeastSignificantBits());
59 assertEquals(72339069014638592L, result.getMostSignificantBits());
4a9c1f07 60 assertEquals("01010000-0000-0000-0101-000000000000", result.toString());
866e5b51
FC
61 assertEquals(0, result.variant());
62 assertEquals(0, result.version());
63 }
64
65 /**
66 * Run the UUID makeUUID(byte[]) method test.
67 */
68 @Test
69 public void testMakeUUID_3() {
70 byte[] bytes = new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0,
71 (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
72 (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
73
74 UUID result = Utils.makeUUID(bytes);
75
76 assertNotNull(result);
77 assertEquals(0L, result.getLeastSignificantBits());
78 assertEquals(0L, result.getMostSignificantBits());
4a9c1f07 79 assertEquals("00000000-0000-0000-0000-000000000000", result.toString());
866e5b51
FC
80 assertEquals(0, result.variant());
81 assertEquals(0, result.version());
82 }
83
84 /**
85 * Run the int unsignedCompare(long,long) method test.
86 */
87 @Test
88 public void testUnsignedCompare() {
89 long a = 1L;
90 long b = 1L;
1c8799d5 91 int result;
866e5b51 92
1c8799d5 93 result = Utils.unsignedCompare(a, b);
866e5b51 94 assertEquals(0, result);
1c8799d5
EB
95
96 result = Utils.unsignedCompare(0L, 1L);
97 assertEquals(-1, result);
98 result = Utils.unsignedCompare(0xFFFFFFFFL, 0x100000000L);
99 assertEquals(-1, result);
100 result = Utils.unsignedCompare(-4L, -1L);
101 assertEquals(-1, result);
102 result = Utils.unsignedCompare(-0x80000000L, -1L);
103 assertEquals(-1, result);
104 result = Utils.unsignedCompare(0x7FFFFFFFFFFFFFFEL, 0x7FFFFFFFFFFFFFFFL);
105 assertEquals(-1, result);
106
107 result = Utils.unsignedCompare(1L, 0L);
108 assertEquals(1, result);
109 result = Utils.unsignedCompare(0x100000000L, 0xFFFFFFFFL);
110 assertEquals(1, result);
111 result = Utils.unsignedCompare(-1L, -4L);
112 assertEquals(1, result);
113 result = Utils.unsignedCompare(-1L, -0x80000000L);
114 assertEquals(1, result);
115 result = Utils.unsignedCompare(0x7FFFFFFFFFFFFFFFL, 0x7FFFFFFFFFFFFFFEL);
116 assertEquals(1, result);
866e5b51
FC
117 }
118}
This page took 0.067099 seconds and 5 git commands to generate.