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
.types
.Encoding
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
21 import org
.junit
.Before
;
22 import org
.junit
.Test
;
25 * The class <code>IntegerDeclarationTest</code> contains tests for the class
26 * <code>{@link IntegerDeclaration}</code>.
29 * @version $Revision: 1.0 $
31 public class IntegerDeclarationTest
{
33 private IntegerDeclaration fixture
;
36 * Perform pre-test initialization.
40 fixture
= new IntegerDeclaration(1, true, 1, ByteOrder
.BIG_ENDIAN
,
41 Encoding
.ASCII
, null, 32);
45 * Run the IntegerDeclaration(int,boolean,int,ByteOrder,Encoding)
49 public void testIntegerDeclaration() {
51 boolean signed
= true;
53 ByteOrder byteOrder
= ByteOrder
.BIG_ENDIAN
;
54 Encoding encoding
= Encoding
.ASCII
;
56 IntegerDeclaration result
= new IntegerDeclaration(len
, signed
, base
,
57 byteOrder
, encoding
, null, 16);
59 assertNotNull(result
);
60 assertEquals(1, result
.getBase());
61 assertEquals(false, result
.isCharacter());
62 String outputValue
= "[declaration] integer[";
63 assertEquals(outputValue
,
64 result
.toString().substring(0, outputValue
.length()));
65 assertEquals(1, result
.getLength());
66 assertEquals(true, result
.isSigned());
70 * Run the int getBase() method test.
73 public void testGetBase() {
74 int result
= fixture
.getBase();
75 assertEquals(1, result
);
79 * Run the ByteOrder getByteOrder() method test.
82 public void testGetByteOrder() {
83 ByteOrder result
= fixture
.getByteOrder();
84 assertNotNull(result
);
85 assertEquals("BIG_ENDIAN", result
.toString());
89 * Run the Encoding getEncoding() method test.
92 public void testGetEncoding() {
93 Encoding result
= fixture
.getEncoding();
94 assertNotNull(result
);
95 assertEquals("ASCII", result
.name());
96 assertEquals("ASCII", result
.toString());
97 assertEquals(1, result
.ordinal());
101 * Run the int getLength() method test.
104 public void testGetLength() {
105 int result
= fixture
.getLength();
106 assertEquals(1, result
);
110 * Run the boolean isCharacter() method test.
113 public void testIsCharacter() {
114 boolean result
= fixture
.isCharacter();
115 assertEquals(false, result
);
119 * Run the boolean isCharacter() method test.
122 public void testIsCharacter_8bytes() {
123 IntegerDeclaration fixture8
= new IntegerDeclaration(8, true, 1,
124 ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, null, 8);
126 boolean result
= fixture8
.isCharacter();
127 assertEquals(true, result
);
131 * Run the boolean isSigned() method test.
134 public void testIsSigned_signed() {
135 boolean result
= fixture
.isSigned();
136 assertEquals(true, result
);
140 * Run the boolean isSigned() method test.
143 public void testIsSigned_unsigned() {
144 IntegerDeclaration fixture_unsigned
= new IntegerDeclaration(1, false,
145 1, ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, null, 8);
147 boolean result
= fixture_unsigned
.isSigned();
148 assertEquals(false, result
);
153 * Run the String toString() method test.
156 public void testToString() {
157 String result
= fixture
.toString();
158 String trunc
= result
.substring(0, 22);
159 assertEquals("[declaration] integer[", trunc
);