1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
6 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDeclaration
;
7 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDefinitionScope
;
8 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDeclaration
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.VariantDeclaration
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.VariantDefinition
;
13 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.TestParams
;
14 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
15 import org
.junit
.After
;
16 import org
.junit
.Before
;
17 import org
.junit
.Test
;
20 * The class <code>VariantDeclarationTest</code> contains tests for the class
21 * <code>{@link VariantDeclaration}</code>.
24 * @version $Revision: 1.0 $
26 public class VariantDeclarationTest
{
28 private VariantDeclaration fixture
;
34 * the command line arguments
36 public static void main(String
[] args
) {
37 new org
.junit
.runner
.JUnitCore().run(VariantDeclarationTest
.class);
41 * Perform pre-test initialization.
45 fixture
= new VariantDeclaration();
49 * Perform post-test clean-up.
52 public void tearDown() {
53 // Add additional tear down code here
57 * Run the VariantDeclaration() constructor test.
60 public void testVariantDeclaration() {
61 assertNotNull(fixture
);
62 assertEquals(false, fixture
.isTagged());
63 String left
= "[declaration] variant["; //$NON-NLS-1$
64 assertEquals(left
, fixture
.toString().substring(0, left
.length()));
68 * Run the void addField(String,Declaration) method test.
71 public void testAddField() {
72 fixture
.setTag(""); //$NON-NLS-1$
73 String tag
= ""; //$NON-NLS-1$
74 IDeclaration declaration
= new StringDeclaration();
75 fixture
.addField(tag
, declaration
);
79 * Run the VariantDefinition createDefinition(DefinitionScope,String) method
82 * @throws CTFReaderException
85 public void testCreateDefinition() throws CTFReaderException
{
86 fixture
.setTag(""); //$NON-NLS-1$
87 IDefinitionScope definitionScope
= createDefinitionScope();
88 String fieldName
= ""; //$NON-NLS-1$
89 VariantDefinition result
= fixture
.createDefinition(definitionScope
,
92 assertNotNull(result
);
95 private static IDefinitionScope
createDefinitionScope() throws CTFReaderException
{
96 VariantDeclaration declaration
= new VariantDeclaration();
97 declaration
.setTag(""); //$NON-NLS-1$
98 VariantDeclaration variantDeclaration
= new VariantDeclaration();
99 variantDeclaration
.setTag(""); //$NON-NLS-1$
100 VariantDefinition variantDefinition
= new VariantDefinition(
101 variantDeclaration
, TestParams
.createTrace(), ""); //$NON-NLS-1$
102 IDefinitionScope definitionScope
= new StructDefinition(
103 new StructDeclaration(1L), variantDefinition
, ""); //$NON-NLS-1$
104 String fieldName
= ""; //$NON-NLS-1$
106 VariantDefinition result
= new VariantDefinition(declaration
,
107 definitionScope
, fieldName
);
112 * Run the boolean hasField(String) method test.
115 public void testHasField() {
116 fixture
.setTag(""); //$NON-NLS-1$
117 String tag
= ""; //$NON-NLS-1$
118 boolean result
= fixture
.hasField(tag
);
120 assertEquals(false, result
);
124 * Run the boolean isTagged() method test.
127 public void testIsTagged() {
128 fixture
.setTag(""); //$NON-NLS-1$
129 boolean result
= fixture
.isTagged();
131 assertEquals(true, result
);
135 * Run the boolean isTagged() method test.
138 public void testIsTagged_null() {
139 fixture
.setTag((String
) null);
140 boolean result
= fixture
.isTagged();
142 assertEquals(false, result
);
146 * Run the void setTag(String) method test.
149 public void testSetTag() {
150 fixture
.setTag(""); //$NON-NLS-1$
151 String tag
= ""; //$NON-NLS-1$
156 * Run the String toString() method test.
159 public void testToString() {
160 fixture
.setTag(""); //$NON-NLS-1$
161 String result
= fixture
.toString();
162 String left
= "[declaration] variant["; //$NON-NLS-1$
163 String right
= result
.substring(0, left
.length());
165 assertEquals(left
, right
);