-
Notifications
You must be signed in to change notification settings - Fork 11
/
EnumDefinitionTest.java
119 lines (101 loc) · 3.86 KB
/
EnumDefinitionTest.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
/*******************************************************************************
* Copyright (c) 2013, 2020 Ericsson, École Polytechnique de Montréal
*
* 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.ByteOrder;
import org.eclipse.tracecompass.ctf.core.event.types.Encoding;
import org.eclipse.tracecompass.ctf.core.event.types.EnumDeclaration;
import org.eclipse.tracecompass.ctf.core.event.types.EnumDefinition;
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>EnumDefinitionTest</code> contains tests for the class
* <code>{@link EnumDefinition}</code>.
*
* @author Matthew Khouzam
* @version $Revision: 1.0 $
*/
public class EnumDefinitionTest {
private EnumDefinition fixtureA;
private EnumDefinition fixtureB;
/**
* Perform pre-test initialization.
*/
@Before
public void setUp() {
IntegerDeclaration integerDeclaration = IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
Encoding.ASCII, "", 8, null);
EnumDeclaration declaration = new EnumDeclaration(
integerDeclaration);
declaration.add(0, 10, "a");
declaration.add(11, 20, "b");
String fieldName = "";
fixtureA = new EnumDefinition(declaration, null, fieldName, new IntegerDefinition(integerDeclaration, null, fieldName, 4));
fixtureB = new EnumDefinition(declaration, null, fieldName, new IntegerDefinition(integerDeclaration, null, fieldName, 12));
}
/**
* Run the EnumDefinition(EnumDeclaration,DefinitionScope,String)
* constructor test.
*/
@Test
public void testEnumDefinition() {
assertNotNull(fixtureA);
assertNotNull(fixtureB);
}
/**
* Run the String getValue() method test.
*/
@Test
public void testGetValue() {
String result = fixtureA.getValue();
assertNotNull(result);
assertEquals("a", result);
}
/**
* Run the long getIntegerValue() method test.
*/
@Test
public void testGetIntegerValue_one() {
long result = fixtureA.getIntegerValue();
assertEquals(4L, result);
}
/**
* Run the String toString() method test.
*/
@Test
public void testToString() {
String result = fixtureB.toString();
assertEquals("{ value = b, container = 12 }", result);
}
/**
* Test results of an unknown enumeration value
*/
@Test
public void testUnknownEnum() {
IntegerDeclaration integerDeclaration = IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
Encoding.ASCII, "", 8, null);
EnumDeclaration declaration = new EnumDeclaration(
integerDeclaration);
declaration.add(0, 10, "a");
declaration.add(11, 20, "b");
String fieldName = "unknownValue";
// Test with a value of 0, where 0 is not part of the enumeration
EnumDefinition fixture = new EnumDefinition(declaration, null, fieldName, new IntegerDefinition(integerDeclaration, null, fieldName, 22));
assertEquals("<unknown> (22)", fixture.getValue());
assertEquals("{ value = <unknown> (22), container = 22 }", fixture.toString());
}
}