ctf: Update copyright headers and add missing ones
[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.After;
22 import org.junit.Before;
23 import org.junit.Test;
24
25 /**
26 * The class <code>IntegerDeclarationTest</code> contains tests for the class
27 * <code>{@link IntegerDeclaration}</code>.
28 *
29 * @author ematkho
30 * @version $Revision: 1.0 $
31 */
32 public class IntegerDeclarationTest {
33
34 private IntegerDeclaration fixture;
35
36 /**
37 * Launch the test.
38 *
39 * @param args
40 * the command line arguments
41 */
42 public static void main(String[] args) {
43 new org.junit.runner.JUnitCore().run(IntegerDeclarationTest.class);
44 }
45
46 /**
47 * Perform pre-test initialization.
48 */
49 @Before
50 public void setUp() {
51 fixture = new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
52 Encoding.ASCII, null, 32);
53 }
54
55 /**
56 * Perform post-test clean-up.
57 */
58 @After
59 public void tearDown() {
60 // Add additional tear down code here
61 }
62
63 /**
64 * Run the IntegerDeclaration(int,boolean,int,ByteOrder,Encoding)
65 * constructor test.
66 */
67 @Test
68 public void testIntegerDeclaration() {
69 int len = 1;
70 boolean signed = true;
71 int base = 1;
72 ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
73 Encoding encoding = Encoding.ASCII;
74
75 IntegerDeclaration result = new IntegerDeclaration(len, signed, base,
76 byteOrder, encoding, null, 16);
77
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());
86 }
87
88 /**
89 * Run the int getBase() method test.
90 */
91 @Test
92 public void testGetBase() {
93 int result = fixture.getBase();
94 assertEquals(1, result);
95 }
96
97 /**
98 * Run the ByteOrder getByteOrder() method test.
99 */
100 @Test
101 public void testGetByteOrder() {
102 ByteOrder result = fixture.getByteOrder();
103 assertNotNull(result);
104 assertEquals("BIG_ENDIAN", result.toString()); //$NON-NLS-1$
105 }
106
107 /**
108 * Run the Encoding getEncoding() method test.
109 */
110 @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());
117 }
118
119 /**
120 * Run the int getLength() method test.
121 */
122 @Test
123 public void testGetLength() {
124 int result = fixture.getLength();
125 assertEquals(1, result);
126 }
127
128 /**
129 * Run the boolean isCharacter() method test.
130 */
131 @Test
132 public void testIsCharacter() {
133 boolean result = fixture.isCharacter();
134 assertEquals(false, result);
135 }
136
137 /**
138 * Run the boolean isCharacter() method test.
139 */
140 @Test
141 public void testIsCharacter_8bytes() {
142 IntegerDeclaration fixture8 = new IntegerDeclaration(8, true, 1,
143 ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
144
145 boolean result = fixture8.isCharacter();
146 assertEquals(true, result);
147 }
148
149 /**
150 * Run the boolean isSigned() method test.
151 */
152 @Test
153 public void testIsSigned_signed() {
154 boolean result = fixture.isSigned();
155 assertEquals(true, result);
156 }
157
158 /**
159 * Run the boolean isSigned() method test.
160 */
161 @Test
162 public void testIsSigned_unsigned() {
163 IntegerDeclaration fixture_unsigned = new IntegerDeclaration(1, false,
164 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
165
166 boolean result = fixture_unsigned.isSigned();
167 assertEquals(false, result);
168 }
169
170
171 /**
172 * Run the String toString() method test.
173 */
174 @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$
179 }
180 }
This page took 0.03379 seconds and 5 git commands to generate.