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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.types
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
17 import java
.nio
.ByteBuffer
;
18 import java
.nio
.ByteOrder
;
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
;
31 * The class <code>IntegerDefinitionTest</code> contains tests for the class
32 * <code>{@link IntegerDefinition}</code>.
35 * @version $Revision: 1.0 $
37 public class IntegerDefinitionTest
{
39 private IntegerDefinition fixture
;
40 @NonNull private static final String NAME
= "testInt";
41 @NonNull private static final String clockName
= "clock";
44 * Perform pre-test initialization.
46 * @throws CTFException
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);
56 BitBuffer bb
= new BitBuffer(byb
);
57 fixture
= id
.createDefinition(null, NAME
, bb
);
61 * Run the IntegerDefinition(IntegerDeclaration,DefinitionScope,String)
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
= "";
71 IntegerDefinition result
= new IntegerDefinition(declaration
,
72 definitionScope
, fieldName
, 1);
73 assertNotNull(result
);
77 * Run the IntegerDeclaration getDeclaration() method test.
80 public void testGetDeclaration() {
81 IntegerDeclaration result
= fixture
.getDeclaration();
82 assertNotNull(result
);
86 * Run the long getValue() method test.
89 public void testGetValue() {
90 long result
= fixture
.getValue();
91 assertEquals(0L, result
);
95 * Run the String toString() method test.
98 public void testToString() {
99 String result
= fixture
.toString();
100 assertEquals("0", result
);
104 * Run the IntegerDefinition formatNumber(Long, int, boolean) method test
105 * for unsigned values.
108 public void testFormatNumber_unsignedLong() {
110 long unsignedLongValue
= -64;
111 String result
= IntegerDefinition
.formatNumber(unsignedLongValue
, 10, false);
112 // -64 + 2^64 = 18446744073709551552
113 assertEquals("18446744073709551552", result
);
115 unsignedLongValue
= -131940199973272L;
116 result
= IntegerDefinition
.formatNumber(unsignedLongValue
, 10, false);
117 // -131940199973272l + 2^64 = 18446612133509578344
118 assertEquals("18446612133509578344", result
);
120 unsignedLongValue
= 123456789L;
121 result
= IntegerDefinition
.formatNumber(unsignedLongValue
, 10, false);
122 assertEquals("123456789", result
);
126 * Run the IntegerDefinition formatNumber(Long, int, boolean) method test
130 public void testFormatNumber_signedLong() {
131 long signedValue
= -64L;
132 String result
= IntegerDefinition
.formatNumber(signedValue
, 10, true);
133 assertEquals("-64", result
);
135 signedValue
= -131940199973272L;
136 result
= IntegerDefinition
.formatNumber(signedValue
, 10, true);
137 assertEquals("-131940199973272", result
);
139 signedValue
= 123456789L;
140 result
= IntegerDefinition
.formatNumber(signedValue
, 10, true);
141 assertEquals("123456789", result
);