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
.After
;
22 import org
.junit
.Before
;
23 import org
.junit
.Test
;
26 * The class <code>IntegerDeclarationTest</code> contains tests for the class
27 * <code>{@link IntegerDeclaration}</code>.
30 * @version $Revision: 1.0 $
32 public class IntegerDeclarationTest
{
34 private IntegerDeclaration fixture
;
40 * the command line arguments
42 public static void main(String
[] args
) {
43 new org
.junit
.runner
.JUnitCore().run(IntegerDeclarationTest
.class);
47 * Perform pre-test initialization.
51 fixture
= new IntegerDeclaration(1, true, 1, ByteOrder
.BIG_ENDIAN
,
52 Encoding
.ASCII
, null, 32);
56 * Perform post-test clean-up.
59 public void tearDown() {
60 // Add additional tear down code here
64 * Run the IntegerDeclaration(int,boolean,int,ByteOrder,Encoding)
68 public void testIntegerDeclaration() {
70 boolean signed
= true;
72 ByteOrder byteOrder
= ByteOrder
.BIG_ENDIAN
;
73 Encoding encoding
= Encoding
.ASCII
;
75 IntegerDeclaration result
= new IntegerDeclaration(len
, signed
, base
,
76 byteOrder
, encoding
, null, 16);
78 assertNotNull(result
);
79 assertEquals(1, result
.getBase());
80 assertEquals(false, result
.isCharacter());
81 String outputValue
= "[declaration] integer["; //$NON-NLS-1$
82 assertEquals(outputValue
,
83 result
.toString().substring(0, outputValue
.length()));
84 assertEquals(1, result
.getLength());
85 assertEquals(true, result
.isSigned());
89 * Run the int getBase() method test.
92 public void testGetBase() {
93 int result
= fixture
.getBase();
94 assertEquals(1, result
);
98 * Run the ByteOrder getByteOrder() method test.
101 public void testGetByteOrder() {
102 ByteOrder result
= fixture
.getByteOrder();
103 assertNotNull(result
);
104 assertEquals("BIG_ENDIAN", result
.toString()); //$NON-NLS-1$
108 * Run the Encoding getEncoding() method test.
111 public void testGetEncoding() {
112 Encoding result
= fixture
.getEncoding();
113 assertNotNull(result
);
114 assertEquals("ASCII", result
.name()); //$NON-NLS-1$
115 assertEquals("ASCII", result
.toString()); //$NON-NLS-1$
116 assertEquals(1, result
.ordinal());
120 * Run the int getLength() method test.
123 public void testGetLength() {
124 int result
= fixture
.getLength();
125 assertEquals(1, result
);
129 * Run the boolean isCharacter() method test.
132 public void testIsCharacter() {
133 boolean result
= fixture
.isCharacter();
134 assertEquals(false, result
);
138 * Run the boolean isCharacter() method test.
141 public void testIsCharacter_8bytes() {
142 IntegerDeclaration fixture8
= new IntegerDeclaration(8, true, 1,
143 ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, null, 8);
145 boolean result
= fixture8
.isCharacter();
146 assertEquals(true, result
);
150 * Run the boolean isSigned() method test.
153 public void testIsSigned_signed() {
154 boolean result
= fixture
.isSigned();
155 assertEquals(true, result
);
159 * Run the boolean isSigned() method test.
162 public void testIsSigned_unsigned() {
163 IntegerDeclaration fixture_unsigned
= new IntegerDeclaration(1, false,
164 1, ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, null, 8);
166 boolean result
= fixture_unsigned
.isSigned();
167 assertEquals(false, result
);
172 * Run the String toString() method test.
175 public void testToString() {
176 String result
= fixture
.toString();
177 String trunc
= result
.substring(0, 22);
178 assertEquals("[declaration] integer[", trunc
); //$NON-NLS-1$