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
.junit
.After
;
15 import org
.junit
.Before
;
16 import org
.junit
.Test
;
19 * The class <code>VariantDeclarationTest</code> contains tests for the class
20 * <code>{@link VariantDeclaration}</code>.
23 * @version $Revision: 1.0 $
25 public class VariantDeclarationTest
{
27 private VariantDeclaration fixture
;
33 * the command line arguments
35 public static void main(String
[] args
) {
36 new org
.junit
.runner
.JUnitCore().run(VariantDeclarationTest
.class);
40 * Perform pre-test initialization.
44 fixture
= new VariantDeclaration();
48 * Perform post-test clean-up.
51 public void tearDown() {
52 // Add additional tear down code here
56 * Run the VariantDeclaration() constructor test.
59 public void testVariantDeclaration() {
60 assertNotNull(fixture
);
61 assertEquals(false, fixture
.isTagged());
62 String left
= "[declaration] variant["; //$NON-NLS-1$
63 assertEquals(left
, fixture
.toString().substring(0, left
.length()));
67 * Run the void addField(String,Declaration) method test.
70 public void testAddField() {
71 fixture
.setTag(""); //$NON-NLS-1$
72 String tag
= ""; //$NON-NLS-1$
73 IDeclaration declaration
= new StringDeclaration();
74 fixture
.addField(tag
, declaration
);
78 * Run the VariantDefinition createDefinition(DefinitionScope,String) method
82 public void testCreateDefinition() {
83 fixture
.setTag(""); //$NON-NLS-1$
84 IDefinitionScope definitionScope
= createDefinitionScope();
85 String fieldName
= ""; //$NON-NLS-1$
86 VariantDefinition result
= fixture
.createDefinition(definitionScope
,
89 assertNotNull(result
);
92 private static IDefinitionScope
createDefinitionScope() {
93 VariantDeclaration declaration
= new VariantDeclaration();
94 declaration
.setTag(""); //$NON-NLS-1$
95 VariantDeclaration variantDeclaration
= new VariantDeclaration();
96 variantDeclaration
.setTag(""); //$NON-NLS-1$
97 VariantDefinition variantDefinition
= new VariantDefinition(
98 variantDeclaration
, TestParams
.createTrace(), ""); //$NON-NLS-1$
99 IDefinitionScope definitionScope
= new StructDefinition(
100 new StructDeclaration(1L), variantDefinition
, ""); //$NON-NLS-1$
101 String fieldName
= ""; //$NON-NLS-1$
103 VariantDefinition result
= new VariantDefinition(declaration
,
104 definitionScope
, fieldName
);
109 * Run the boolean hasField(String) method test.
112 public void testHasField() {
113 fixture
.setTag(""); //$NON-NLS-1$
114 String tag
= ""; //$NON-NLS-1$
115 boolean result
= fixture
.hasField(tag
);
117 assertEquals(false, result
);
121 * Run the boolean isTagged() method test.
124 public void testIsTagged() {
125 fixture
.setTag(""); //$NON-NLS-1$
126 boolean result
= fixture
.isTagged();
128 assertEquals(true, result
);
132 * Run the boolean isTagged() method test.
135 public void testIsTagged_null() {
136 fixture
.setTag((String
) null);
137 boolean result
= fixture
.isTagged();
139 assertEquals(false, result
);
143 * Run the void setTag(String) method test.
146 public void testSetTag() {
147 fixture
.setTag(""); //$NON-NLS-1$
148 String tag
= ""; //$NON-NLS-1$
153 * Run the String toString() method test.
156 public void testToString() {
157 fixture
.setTag(""); //$NON-NLS-1$
158 String result
= fixture
.toString();
159 String left
= "[declaration] variant["; //$NON-NLS-1$
160 String right
= result
.substring(0, left
.length());
162 assertEquals(left
, right
);