ctf: Clean up unit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / IntegerDeclarationTest.java
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
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.linuxtools.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16
17 import java.nio.ByteOrder;
18
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;
23
24 /**
25 * The class <code>IntegerDeclarationTest</code> contains tests for the class
26 * <code>{@link IntegerDeclaration}</code>.
27 *
28 * @author ematkho
29 * @version $Revision: 1.0 $
30 */
31 public class IntegerDeclarationTest {
32
33 private IntegerDeclaration fixture;
34
35 /**
36 * Perform pre-test initialization.
37 */
38 @Before
39 public void setUp() {
40 fixture = new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
41 Encoding.ASCII, null, 32);
42 }
43
44 /**
45 * Run the IntegerDeclaration(int,boolean,int,ByteOrder,Encoding)
46 * constructor test.
47 */
48 @Test
49 public void testIntegerDeclaration() {
50 int len = 1;
51 boolean signed = true;
52 int base = 1;
53 ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
54 Encoding encoding = Encoding.ASCII;
55
56 IntegerDeclaration result = new IntegerDeclaration(len, signed, base,
57 byteOrder, encoding, null, 16);
58
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());
67 }
68
69 /**
70 * Run the int getBase() method test.
71 */
72 @Test
73 public void testGetBase() {
74 int result = fixture.getBase();
75 assertEquals(1, result);
76 }
77
78 /**
79 * Run the ByteOrder getByteOrder() method test.
80 */
81 @Test
82 public void testGetByteOrder() {
83 ByteOrder result = fixture.getByteOrder();
84 assertNotNull(result);
85 assertEquals("BIG_ENDIAN", result.toString());
86 }
87
88 /**
89 * Run the Encoding getEncoding() method test.
90 */
91 @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());
98 }
99
100 /**
101 * Run the int getLength() method test.
102 */
103 @Test
104 public void testGetLength() {
105 int result = fixture.getLength();
106 assertEquals(1, result);
107 }
108
109 /**
110 * Run the boolean isCharacter() method test.
111 */
112 @Test
113 public void testIsCharacter() {
114 boolean result = fixture.isCharacter();
115 assertEquals(false, result);
116 }
117
118 /**
119 * Run the boolean isCharacter() method test.
120 */
121 @Test
122 public void testIsCharacter_8bytes() {
123 IntegerDeclaration fixture8 = new IntegerDeclaration(8, true, 1,
124 ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
125
126 boolean result = fixture8.isCharacter();
127 assertEquals(true, result);
128 }
129
130 /**
131 * Run the boolean isSigned() method test.
132 */
133 @Test
134 public void testIsSigned_signed() {
135 boolean result = fixture.isSigned();
136 assertEquals(true, result);
137 }
138
139 /**
140 * Run the boolean isSigned() method test.
141 */
142 @Test
143 public void testIsSigned_unsigned() {
144 IntegerDeclaration fixture_unsigned = new IntegerDeclaration(1, false,
145 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
146
147 boolean result = fixture_unsigned.isSigned();
148 assertEquals(false, result);
149 }
150
151
152 /**
153 * Run the String toString() method test.
154 */
155 @Test
156 public void testToString() {
157 String result = fixture.toString();
158 String trunc = result.substring(0, 22);
159 assertEquals("[declaration] integer[", trunc);
160 }
161 }
This page took 0.03622 seconds and 6 git commands to generate.