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
.shared
.CtfTestTraces
;
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 static final int TRACE_INDEX
= 0;
31 private VariantDeclaration fixture
;
37 * the command line arguments
39 public static void main(String
[] args
) {
40 new org
.junit
.runner
.JUnitCore().run(VariantDeclarationTest
.class);
44 * Perform pre-test initialization.
48 fixture
= new VariantDeclaration();
52 * Perform post-test clean-up.
55 public void tearDown() {
56 // Add additional tear down code here
60 * Run the VariantDeclaration() constructor test.
63 public void testVariantDeclaration() {
64 assertNotNull(fixture
);
65 assertEquals(false, fixture
.isTagged());
66 String left
= "[declaration] variant["; //$NON-NLS-1$
67 assertEquals(left
, fixture
.toString().substring(0, left
.length()));
71 * Run the void addField(String,Declaration) method test.
74 public void testAddField() {
75 fixture
.setTag(""); //$NON-NLS-1$
76 String tag
= ""; //$NON-NLS-1$
77 IDeclaration declaration
= new StringDeclaration();
78 fixture
.addField(tag
, declaration
);
82 * Run the VariantDefinition createDefinition(DefinitionScope,String) method
85 * @throws CTFReaderException Should not happen
88 public void testCreateDefinition() throws CTFReaderException
{
89 fixture
.setTag(""); //$NON-NLS-1$
90 IDefinitionScope definitionScope
= createDefinitionScope();
91 String fieldName
= ""; //$NON-NLS-1$
92 VariantDefinition result
= fixture
.createDefinition(definitionScope
,
95 assertNotNull(result
);
98 private static IDefinitionScope
createDefinitionScope() throws CTFReaderException
{
99 assumeTrue(CtfTestTraces
.tracesExist());
100 VariantDeclaration declaration
= new VariantDeclaration();
101 declaration
.setTag(""); //$NON-NLS-1$
102 VariantDeclaration variantDeclaration
= new VariantDeclaration();
103 variantDeclaration
.setTag(""); //$NON-NLS-1$
104 VariantDefinition variantDefinition
= new VariantDefinition(
105 variantDeclaration
, CtfTestTraces
.getTestTrace(TRACE_INDEX
), ""); //$NON-NLS-1$
106 IDefinitionScope definitionScope
= new StructDefinition(
107 new StructDeclaration(1L), variantDefinition
, ""); //$NON-NLS-1$
108 String fieldName
= ""; //$NON-NLS-1$
110 VariantDefinition result
= new VariantDefinition(declaration
,
111 definitionScope
, fieldName
);
116 * Run the boolean hasField(String) method test.
119 public void testHasField() {
120 fixture
.setTag(""); //$NON-NLS-1$
121 String tag
= ""; //$NON-NLS-1$
122 boolean result
= fixture
.hasField(tag
);
124 assertEquals(false, result
);
128 * Run the boolean isTagged() method test.
131 public void testIsTagged() {
132 fixture
.setTag(""); //$NON-NLS-1$
133 boolean result
= fixture
.isTagged();
135 assertEquals(true, result
);
139 * Run the boolean isTagged() method test.
142 public void testIsTagged_null() {
143 fixture
.setTag((String
) null);
144 boolean result
= fixture
.isTagged();
146 assertEquals(false, result
);
150 * Run the void setTag(String) method test.
153 public void testSetTag() {
154 fixture
.setTag(""); //$NON-NLS-1$
155 String tag
= ""; //$NON-NLS-1$
160 * Run the String toString() method test.
163 public void testToString() {
164 fixture
.setTag(""); //$NON-NLS-1$
165 String result
= fixture
.toString();
166 String left
= "[declaration] variant["; //$NON-NLS-1$
167 String right
= result
.substring(0, left
.length());
169 assertEquals(left
, right
);