1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
6 import java
.nio
.ByteOrder
;
8 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
10 import org
.junit
.After
;
11 import org
.junit
.Before
;
12 import org
.junit
.Test
;
15 * The class <code>IntegerDeclarationTest</code> contains tests for the class
16 * <code>{@link IntegerDeclaration}</code>.
19 * @version $Revision: 1.0 $
21 public class IntegerDeclarationTest
{
23 private IntegerDeclaration fixture
;
29 * the command line arguments
31 public static void main(String
[] args
) {
32 new org
.junit
.runner
.JUnitCore().run(IntegerDeclarationTest
.class);
36 * Perform pre-test initialization.
40 fixture
= new IntegerDeclaration(1, true, 1, ByteOrder
.BIG_ENDIAN
,
41 Encoding
.ASCII
, null, 32);
45 * Perform post-test clean-up.
48 public void tearDown() {
49 // Add additional tear down code here
53 * Run the IntegerDeclaration(int,boolean,int,ByteOrder,Encoding)
57 public void testIntegerDeclaration() {
59 boolean signed
= true;
61 ByteOrder byteOrder
= ByteOrder
.BIG_ENDIAN
;
62 Encoding encoding
= Encoding
.ASCII
;
64 IntegerDeclaration result
= new IntegerDeclaration(len
, signed
, base
,
65 byteOrder
, encoding
, null, 16);
67 assertNotNull(result
);
68 assertEquals(1, result
.getBase());
69 assertEquals(false, result
.isCharacter());
70 String outputValue
= "[declaration] integer["; //$NON-NLS-1$
71 assertEquals(outputValue
,
72 result
.toString().substring(0, outputValue
.length()));
73 assertEquals(1, result
.getLength());
74 assertEquals(true, result
.isSigned());
78 * Run the int getBase() method test.
81 public void testGetBase() {
82 int result
= fixture
.getBase();
83 assertEquals(1, result
);
87 * Run the ByteOrder getByteOrder() method test.
90 public void testGetByteOrder() {
91 ByteOrder result
= fixture
.getByteOrder();
92 assertNotNull(result
);
93 assertEquals("BIG_ENDIAN", result
.toString()); //$NON-NLS-1$
97 * Run the Encoding getEncoding() method test.
100 public void testGetEncoding() {
101 Encoding result
= fixture
.getEncoding();
102 assertNotNull(result
);
103 assertEquals("ASCII", result
.name()); //$NON-NLS-1$
104 assertEquals("ASCII", result
.toString()); //$NON-NLS-1$
105 assertEquals(1, result
.ordinal());
109 * Run the int getLength() method test.
112 public void testGetLength() {
113 int result
= fixture
.getLength();
114 assertEquals(1, result
);
118 * Run the boolean isCharacter() method test.
121 public void testIsCharacter() {
122 boolean result
= fixture
.isCharacter();
123 assertEquals(false, result
);
127 * Run the boolean isCharacter() method test.
130 public void testIsCharacter_8bytes() {
131 IntegerDeclaration fixture8
= new IntegerDeclaration(8, true, 1,
132 ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, null, 8);
134 boolean result
= fixture8
.isCharacter();
135 assertEquals(true, result
);
139 * Run the boolean isSigned() method test.
142 public void testIsSigned_signed() {
143 boolean result
= fixture
.isSigned();
144 assertEquals(true, result
);
148 * Run the boolean isSigned() method test.
151 public void testIsSigned_unsigned() {
152 IntegerDeclaration fixture_unsigned
= new IntegerDeclaration(1, false,
153 1, ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, null, 8);
155 boolean result
= fixture_unsigned
.isSigned();
156 assertEquals(false, result
);
161 * Run the String toString() method test.
164 public void testToString() {
165 String result
= fixture
.toString();
166 String trunc
= result
.substring(0, 22);
167 assertEquals("[declaration] integer[", trunc
); //$NON-NLS-1$