rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / types / IntegerDefinitionTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
12 package org.eclipse.tracecompass.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16
17 import java.nio.ByteBuffer;
18 import java.nio.ByteOrder;
19
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.eclipse.tracecompass.ctf.core.CTFException;
22 import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
23 import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
24 import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
25 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
26 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
27 import org.junit.Before;
28 import org.junit.Test;
29
30 /**
31 * The class <code>IntegerDefinitionTest</code> contains tests for the class
32 * <code>{@link IntegerDefinition}</code>.
33 *
34 * @author ematkho
35 * @version $Revision: 1.0 $
36 */
37 public class IntegerDefinitionTest {
38
39 private IntegerDefinition fixture;
40 @NonNull private static final String NAME = "testInt";
41 @NonNull private static final String clockName = "clock";
42
43 /**
44 * Perform pre-test initialization.
45 *
46 * @throws CTFException
47 * won't happen
48 */
49 @Before
50 public void setUp() throws CTFException {
51 IntegerDeclaration id = IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
52 ByteBuffer byb = ByteBuffer.allocate(128);
53 byb.mark();
54 byb.putInt(1);
55 byb.reset();
56 BitBuffer bb = new BitBuffer(byb);
57 fixture = id.createDefinition(null, NAME, bb);
58 }
59
60 /**
61 * Run the IntegerDefinition(IntegerDeclaration,DefinitionScope,String)
62 * constructor test.
63 */
64 @Test
65 public void testIntegerDefinition() {
66 IntegerDeclaration declaration = IntegerDeclaration.createDeclaration(1, false, 1,
67 ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8);
68 IDefinitionScope definitionScope = null;
69 String fieldName = "";
70
71 IntegerDefinition result = new IntegerDefinition(declaration,
72 definitionScope, fieldName, 1);
73 assertNotNull(result);
74 }
75
76 /**
77 * Run the IntegerDeclaration getDeclaration() method test.
78 */
79 @Test
80 public void testGetDeclaration() {
81 IntegerDeclaration result = fixture.getDeclaration();
82 assertNotNull(result);
83 }
84
85 /**
86 * Run the long getValue() method test.
87 */
88 @Test
89 public void testGetValue() {
90 long result = fixture.getValue();
91 assertEquals(0L, result);
92 }
93
94 /**
95 * Run the String toString() method test.
96 */
97 @Test
98 public void testToString() {
99 String result = fixture.toString();
100 assertEquals("0", result);
101 }
102
103 /**
104 * Run the IntegerDefinition formatNumber(Long, int, boolean) method test
105 * for unsigned values.
106 */
107 @Test
108 public void testFormatNumber_unsignedLong() {
109
110 long unsignedLongValue = -64;
111 String result = IntegerDefinition.formatNumber(unsignedLongValue, 10, false);
112 // -64 + 2^64 = 18446744073709551552
113 assertEquals("18446744073709551552", result);
114
115 unsignedLongValue = -131940199973272L;
116 result = IntegerDefinition.formatNumber(unsignedLongValue, 10, false);
117 // -131940199973272l + 2^64 = 18446612133509578344
118 assertEquals("18446612133509578344", result);
119
120 unsignedLongValue = 123456789L;
121 result = IntegerDefinition.formatNumber(unsignedLongValue, 10, false);
122 assertEquals("123456789", result);
123 }
124
125 /**
126 * Run the IntegerDefinition formatNumber(Long, int, boolean) method test
127 * for signed values.
128 */
129 @Test
130 public void testFormatNumber_signedLong() {
131 long signedValue = -64L;
132 String result = IntegerDefinition.formatNumber(signedValue, 10, true);
133 assertEquals("-64", result);
134
135 signedValue = -131940199973272L;
136 result = IntegerDefinition.formatNumber(signedValue, 10, true);
137 assertEquals("-131940199973272", result);
138
139 signedValue = 123456789L;
140 result = IntegerDefinition.formatNumber(signedValue, 10, true);
141 assertEquals("123456789", result);
142 }
143 }
This page took 0.037968 seconds and 5 git commands to generate.