ctf: potential memory optimization
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / IntegerDefinitionTest.java
CommitLineData
4bd7f2db
AM
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
866e5b51
FC
12package org.eclipse.linuxtools.ctf.core.tests.types;
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16
17import java.nio.ByteOrder;
18
486efb2e 19import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
866e5b51
FC
20import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
21import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
22import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
23import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
db8e8f7d 24import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
866e5b51
FC
25import org.junit.Before;
26import org.junit.Test;
27
28/**
29 * The class <code>IntegerDefinitionTest</code> contains tests for the class
30 * <code>{@link IntegerDefinition}</code>.
284fdee8 31 *
866e5b51
FC
32 * @author ematkho
33 * @version $Revision: 1.0 $
34 */
35public class IntegerDefinitionTest {
36
37 private IntegerDefinition fixture;
4a9c1f07
AM
38 String name = "testInt";
39 String clockName = "clock";
40
866e5b51 41 /**
a34d8eee 42 * Perform pre-test initialization.
866e5b51
FC
43 */
44 @Before
be6df2d8 45 public void setUp() {
4311ac8b 46 IntegerDeclaration id = new IntegerDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
024373d7 47 fixture = id.createDefinition(null, name);
866e5b51
FC
48 }
49
866e5b51
FC
50 /**
51 * Run the IntegerDefinition(IntegerDeclaration,DefinitionScope,String)
52 * constructor test.
53 */
54 @Test
55 public void testIntegerDefinition() {
4311ac8b 56 IntegerDeclaration declaration = new IntegerDeclaration(1, false, 1,
fd74e6c1 57 ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
866e5b51 58 IDefinitionScope definitionScope = null;
4a9c1f07 59 String fieldName = "";
866e5b51
FC
60
61 IntegerDefinition result = new IntegerDefinition(declaration,
62 definitionScope, fieldName);
63 assertNotNull(result);
64 }
65
66 /**
67 * Run the IntegerDeclaration getDeclaration() method test.
68 */
69 @Test
70 public void testGetDeclaration() {
71 fixture.setValue(1L);
72
73 IntegerDeclaration result = fixture.getDeclaration();
74 assertNotNull(result);
75 }
76
77 /**
78 * Run the long getValue() method test.
79 */
80 @Test
81 public void testGetValue() {
82 fixture.setValue(1L);
83
84 long result = fixture.getValue();
85 assertEquals(1L, result);
86 }
87
88 /**
89 * Run the void read(BitBuffer) method test.
db8e8f7d 90 * @throws CTFReaderException error
866e5b51
FC
91 */
92 @Test
db8e8f7d 93 public void testRead() throws CTFReaderException {
866e5b51
FC
94 fixture.setValue(1L);
95 BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
96
97 fixture.read(input);
98 }
99
100 /**
101 * Run the String toString() method test.
102 */
103 @Test
104 public void testToString() {
105 fixture.setValue(1L);
106
107 String result = fixture.toString();
108 assertNotNull(result);
109 }
3b11ddc7
JCK
110
111 /**
112 * Run the IntegerDefinition formatNumber(Long, int, boolean) method test
113 * for unsigned values.
114 */
115 @Test
116 public void testFormatNumber_unsignedLong() {
117
118 long unsignedLongValue = -64;
119 String result = IntegerDefinition.formatNumber(unsignedLongValue, 10, false);
120 // -64 + 2^64 = 18446744073709551552
121 assertEquals("18446744073709551552", result);
122
123 unsignedLongValue = -131940199973272L;
124 result = IntegerDefinition.formatNumber(unsignedLongValue, 10, false);
125 // -131940199973272l + 2^64 = 18446612133509578344
126 assertEquals("18446612133509578344", result);
127
128 unsignedLongValue = 123456789L;
129 result = IntegerDefinition.formatNumber(unsignedLongValue, 10, false);
130 assertEquals("123456789", result);
131 }
132
133 /**
134 * Run the IntegerDefinition formatNumber(Long, int, boolean) method test
135 * for signed values.
136 */
137 @Test
138 public void testFormatNumber_signedLong() {
139 long signedValue = -64L;
140 String result = IntegerDefinition.formatNumber(signedValue, 10, true);
141 assertEquals("-64", result);
142
143 signedValue = -131940199973272L;
144 result = IntegerDefinition.formatNumber(signedValue, 10, true);
145 assertEquals("-131940199973272", result);
146
147 signedValue = 123456789L;
148 result = IntegerDefinition.formatNumber(signedValue, 10, true);
149 assertEquals("123456789", result);
150 }
284fdee8 151}
This page took 0.051628 seconds and 5 git commands to generate.