Commit | Line | Data |
---|---|---|
4bd7f2db | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 Ericsson |
4bd7f2db AM |
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 | ||
f357bcd4 | 12 | package org.eclipse.tracecompass.ctf.core.tests.types; |
866e5b51 FC |
13 | |
14 | import static org.junit.Assert.assertEquals; | |
15 | import static org.junit.Assert.assertNotNull; | |
866e5b51 | 16 | |
866e5b51 FC |
17 | import java.nio.ByteOrder; |
18 | ||
f357bcd4 AM |
19 | import org.eclipse.tracecompass.ctf.core.event.types.Encoding; |
20 | import org.eclipse.tracecompass.ctf.core.event.types.EnumDeclaration; | |
21 | import org.eclipse.tracecompass.ctf.core.event.types.EnumDefinition; | |
22 | import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration; | |
23 | import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition; | |
866e5b51 FC |
24 | import org.junit.Before; |
25 | import org.junit.Test; | |
26 | ||
27 | /** | |
28 | * The class <code>EnumDefinitionTest</code> contains tests for the class | |
29 | * <code>{@link EnumDefinition}</code>. | |
284fdee8 | 30 | * |
866e5b51 FC |
31 | * @author ematkho |
32 | * @version $Revision: 1.0 $ | |
33 | */ | |
34 | public class EnumDefinitionTest { | |
35 | ||
a4fa4e36 MK |
36 | private EnumDefinition fixtureA; |
37 | private EnumDefinition fixtureB; | |
866e5b51 | 38 | |
866e5b51 FC |
39 | /** |
40 | * Perform pre-test initialization. | |
41 | */ | |
42 | @Before | |
43 | public void setUp() { | |
a4fa4e36 MK |
44 | IntegerDeclaration integerDeclaration = IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN, |
45 | Encoding.ASCII, "", 8); | |
866e5b51 | 46 | EnumDeclaration declaration = new EnumDeclaration( |
a4fa4e36 | 47 | integerDeclaration); |
4a9c1f07 AM |
48 | declaration.add(0, 10, "a"); |
49 | declaration.add(11, 20, "b"); | |
50 | String fieldName = ""; | |
866e5b51 | 51 | |
a4fa4e36 MK |
52 | fixtureA = new EnumDefinition(declaration, null, fieldName, new IntegerDefinition(integerDeclaration, null, fieldName, 4)); |
53 | fixtureB = new EnumDefinition(declaration, null, fieldName, new IntegerDefinition(integerDeclaration, null, fieldName, 12)); | |
866e5b51 FC |
54 | } |
55 | ||
866e5b51 FC |
56 | /** |
57 | * Run the EnumDefinition(EnumDeclaration,DefinitionScope,String) | |
58 | * constructor test. | |
59 | */ | |
60 | @Test | |
61 | public void testEnumDefinition() { | |
a4fa4e36 MK |
62 | assertNotNull(fixtureA); |
63 | assertNotNull(fixtureB); | |
866e5b51 FC |
64 | } |
65 | ||
66 | /** | |
67 | * Run the String getValue() method test. | |
68 | */ | |
69 | @Test | |
70 | public void testGetValue() { | |
a4fa4e36 | 71 | String result = fixtureA.getValue(); |
866e5b51 FC |
72 | |
73 | assertNotNull(result); | |
a4fa4e36 | 74 | assertEquals("a", result); |
866e5b51 FC |
75 | } |
76 | ||
77 | /** | |
78 | * Run the long getIntegerValue() method test. | |
79 | */ | |
80 | @Test | |
81 | public void testGetIntegerValue_one() { | |
a4fa4e36 MK |
82 | long result = fixtureA.getIntegerValue(); |
83 | assertEquals(4L, result); | |
866e5b51 | 84 | } |
419f09a8 SM |
85 | |
86 | /** | |
87 | * Run the String toString() method test. | |
88 | */ | |
89 | @Test | |
90 | public void testToString() { | |
a4fa4e36 | 91 | String result = fixtureB.toString(); |
419f09a8 | 92 | |
a4fa4e36 | 93 | assertEquals("{ value = b, container = 12 }", result); |
419f09a8 | 94 | } |
866e5b51 | 95 | } |