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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
17 import java
.nio
.ByteOrder
;
19 import org
.eclipse
.linuxtools
.ctf
.core
.event
.io
.BitBuffer
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDefinitionScope
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDefinition
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
25 import org
.junit
.Before
;
26 import org
.junit
.Test
;
29 * The class <code>IntegerDefinitionTest</code> contains tests for the class
30 * <code>{@link IntegerDefinition}</code>.
33 * @version $Revision: 1.0 $
35 public class IntegerDefinitionTest
{
37 private IntegerDefinition fixture
;
38 String name
= "testInt";
39 String clockName
= "clock";
42 * Perform pre-test initialization.
46 IntegerDeclaration id
= new IntegerDeclaration(1, false, 1, ByteOrder
.BIG_ENDIAN
, Encoding
.NONE
, clockName
, 8);
47 fixture
= id
.createDefinition(null, name
);
51 * Run the IntegerDefinition(IntegerDeclaration,DefinitionScope,String)
55 public void testIntegerDefinition() {
56 IntegerDeclaration declaration
= new IntegerDeclaration(1, false, 1,
57 ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, null, 8);
58 IDefinitionScope definitionScope
= null;
59 String fieldName
= "";
61 IntegerDefinition result
= new IntegerDefinition(declaration
,
62 definitionScope
, fieldName
);
63 assertNotNull(result
);
67 * Run the IntegerDeclaration getDeclaration() method test.
70 public void testGetDeclaration() {
73 IntegerDeclaration result
= fixture
.getDeclaration();
74 assertNotNull(result
);
78 * Run the long getValue() method test.
81 public void testGetValue() {
84 long result
= fixture
.getValue();
85 assertEquals(1L, result
);
89 * Run the void read(BitBuffer) method test.
90 * @throws CTFReaderException error
93 public void testRead() throws CTFReaderException
{
95 BitBuffer input
= new BitBuffer(java
.nio
.ByteBuffer
.allocateDirect(128));
101 * Run the String toString() method test.
104 public void testToString() {
105 fixture
.setValue(1L);
107 String result
= fixture
.toString();
108 assertNotNull(result
);
112 * Run the IntegerDefinition formatNumber(Long, int, boolean) method test
113 * for unsigned values.
116 public void testFormatNumber_unsignedLong() {
118 long unsignedLongValue
= -64;
119 String result
= IntegerDefinition
.formatNumber(unsignedLongValue
, 10, false);
120 // -64 + 2^64 = 18446744073709551552
121 assertEquals("18446744073709551552", result
);
123 unsignedLongValue
= -131940199973272L;
124 result
= IntegerDefinition
.formatNumber(unsignedLongValue
, 10, false);
125 // -131940199973272l + 2^64 = 18446612133509578344
126 assertEquals("18446612133509578344", result
);
128 unsignedLongValue
= 123456789L;
129 result
= IntegerDefinition
.formatNumber(unsignedLongValue
, 10, false);
130 assertEquals("123456789", result
);
134 * Run the IntegerDefinition formatNumber(Long, int, boolean) method test
138 public void testFormatNumber_signedLong() {
139 long signedValue
= -64L;
140 String result
= IntegerDefinition
.formatNumber(signedValue
, 10, true);
141 assertEquals("-64", result
);
143 signedValue
= -131940199973272L;
144 result
= IntegerDefinition
.formatNumber(signedValue
, 10, true);
145 assertEquals("-131940199973272", result
);
147 signedValue
= 123456789L;
148 result
= IntegerDefinition
.formatNumber(signedValue
, 10, true);
149 assertEquals("123456789", result
);