1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
5 import static org
.junit
.Assume
.assumeTrue
;
7 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDeclaration
;
8 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDefinitionScope
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StringDeclaration
;
10 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
11 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
12 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.VariantDeclaration
;
13 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.VariantDefinition
;
14 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.TestParams
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
16 import org
.junit
.After
;
17 import org
.junit
.Before
;
18 import org
.junit
.Test
;
21 * The class <code>VariantDeclarationTest</code> contains tests for the class
22 * <code>{@link VariantDeclaration}</code>.
25 * @version $Revision: 1.0 $
27 public class VariantDeclarationTest
{
29 private VariantDeclaration fixture
;
35 * the command line arguments
37 public static void main(String
[] args
) {
38 new org
.junit
.runner
.JUnitCore().run(VariantDeclarationTest
.class);
42 * Perform pre-test initialization.
46 fixture
= new VariantDeclaration();
50 * Perform post-test clean-up.
53 public void tearDown() {
54 // Add additional tear down code here
58 * Run the VariantDeclaration() constructor test.
61 public void testVariantDeclaration() {
62 assertNotNull(fixture
);
63 assertEquals(false, fixture
.isTagged());
64 String left
= "[declaration] variant["; //$NON-NLS-1$
65 assertEquals(left
, fixture
.toString().substring(0, left
.length()));
69 * Run the void addField(String,Declaration) method test.
72 public void testAddField() {
73 fixture
.setTag(""); //$NON-NLS-1$
74 String tag
= ""; //$NON-NLS-1$
75 IDeclaration declaration
= new StringDeclaration();
76 fixture
.addField(tag
, declaration
);
80 * Run the VariantDefinition createDefinition(DefinitionScope,String) method
83 * @throws CTFReaderException Should not happen
86 public void testCreateDefinition() throws CTFReaderException
{
87 fixture
.setTag(""); //$NON-NLS-1$
88 IDefinitionScope definitionScope
= createDefinitionScope();
89 String fieldName
= ""; //$NON-NLS-1$
90 VariantDefinition result
= fixture
.createDefinition(definitionScope
,
93 assertNotNull(result
);
96 private static IDefinitionScope
createDefinitionScope() throws CTFReaderException
{
97 assumeTrue(TestParams
.tracesExist());
98 VariantDeclaration declaration
= new VariantDeclaration();
99 declaration
.setTag(""); //$NON-NLS-1$
100 VariantDeclaration variantDeclaration
= new VariantDeclaration();
101 variantDeclaration
.setTag(""); //$NON-NLS-1$
102 VariantDefinition variantDefinition
= new VariantDefinition(
103 variantDeclaration
, TestParams
.createTrace(), ""); //$NON-NLS-1$
104 IDefinitionScope definitionScope
= new StructDefinition(
105 new StructDeclaration(1L), variantDefinition
, ""); //$NON-NLS-1$
106 String fieldName
= ""; //$NON-NLS-1$
108 VariantDefinition result
= new VariantDefinition(declaration
,
109 definitionScope
, fieldName
);
114 * Run the boolean hasField(String) method test.
117 public void testHasField() {
118 fixture
.setTag(""); //$NON-NLS-1$
119 String tag
= ""; //$NON-NLS-1$
120 boolean result
= fixture
.hasField(tag
);
122 assertEquals(false, result
);
126 * Run the boolean isTagged() method test.
129 public void testIsTagged() {
130 fixture
.setTag(""); //$NON-NLS-1$
131 boolean result
= fixture
.isTagged();
133 assertEquals(true, result
);
137 * Run the boolean isTagged() method test.
140 public void testIsTagged_null() {
141 fixture
.setTag((String
) null);
142 boolean result
= fixture
.isTagged();
144 assertEquals(false, result
);
148 * Run the void setTag(String) method test.
151 public void testSetTag() {
152 fixture
.setTag(""); //$NON-NLS-1$
153 String tag
= ""; //$NON-NLS-1$
158 * Run the String toString() method test.
161 public void testToString() {
162 fixture
.setTag(""); //$NON-NLS-1$
163 String result
= fixture
.toString();
164 String left
= "[declaration] variant["; //$NON-NLS-1$
165 String right
= result
.substring(0, left
.length());
167 assertEquals(left
, right
);