-
Notifications
You must be signed in to change notification settings - Fork 11
/
IntegerDefinitionTest.java
145 lines (126 loc) · 4.69 KB
/
IntegerDefinitionTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
* Copyright (c) 2013, 2014 Ericsson
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Matthew Khouzam - Initial API and implementation
*******************************************************************************/
package org.eclipse.tracecompass.ctf.core.tests.types;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.ctf.core.CTFException;
import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
import org.junit.Before;
import org.junit.Test;
/**
* The class <code>IntegerDefinitionTest</code> contains tests for the class
* <code>{@link IntegerDefinition}</code>.
*
* @author ematkho
* @version $Revision: 1.0 $
*/
public class IntegerDefinitionTest {
private IntegerDefinition fixture;
@NonNull private static final String NAME = "testInt";
@NonNull private static final String clockName = "clock";
/**
* Perform pre-test initialization.
*
* @throws CTFException
* won't happen
*/
@Before
public void setUp() throws CTFException {
IntegerDeclaration id = IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8, null);
ByteBuffer byb = ByteBuffer.allocate(128);
byb.mark();
byb.putInt(1);
byb.reset();
BitBuffer bb = new BitBuffer(byb);
fixture = id.createDefinition(null, NAME, bb);
}
/**
* Run the IntegerDefinition(IntegerDeclaration,DefinitionScope,String)
* constructor test.
*/
@Test
public void testIntegerDefinition() {
IntegerDeclaration declaration = IntegerDeclaration.createDeclaration(1, false, 1,
ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8, null);
IDefinitionScope definitionScope = null;
String fieldName = "";
IntegerDefinition result = new IntegerDefinition(declaration,
definitionScope, fieldName, 1);
assertNotNull(result);
}
/**
* Run the IntegerDeclaration getDeclaration() method test.
*/
@Test
public void testGetDeclaration() {
IntegerDeclaration result = fixture.getDeclaration();
assertNotNull(result);
}
/**
* Run the long getValue() method test.
*/
@Test
public void testGetValue() {
long result = fixture.getValue();
assertEquals(0L, result);
}
/**
* Run the String toString() method test.
*/
@Test
public void testToString() {
String result = fixture.toString();
assertEquals("0", result);
}
/**
* Run the IntegerDefinition formatNumber(Long, int, boolean) method test
* for unsigned values.
*/
@Test
public void testFormatNumber_unsignedLong() {
long unsignedLongValue = -64;
String result = IntegerDefinition.formatNumber(unsignedLongValue, 10, false);
// -64 + 2^64 = 18446744073709551552
assertEquals("18446744073709551552", result);
unsignedLongValue = -131940199973272L;
result = IntegerDefinition.formatNumber(unsignedLongValue, 10, false);
// -131940199973272l + 2^64 = 18446612133509578344
assertEquals("18446612133509578344", result);
unsignedLongValue = 123456789L;
result = IntegerDefinition.formatNumber(unsignedLongValue, 10, false);
assertEquals("123456789", result);
}
/**
* Run the IntegerDefinition formatNumber(Long, int, boolean) method test
* for signed values.
*/
@Test
public void testFormatNumber_signedLong() {
long signedValue = -64L;
String result = IntegerDefinition.formatNumber(signedValue, 10, true);
assertEquals("-64", result);
signedValue = -131940199973272L;
result = IntegerDefinition.formatNumber(signedValue, 10, true);
assertEquals("-131940199973272", result);
signedValue = 123456789L;
result = IntegerDefinition.formatNumber(signedValue, 10, true);
assertEquals("123456789", result);
}
}