ctf: Re-enable the CTF parser unit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / VariantDeclarationTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.types;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assume.assumeTrue;
6
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;
19
20 /**
21 * The class <code>VariantDeclarationTest</code> contains tests for the class
22 * <code>{@link VariantDeclaration}</code>.
23 *
24 * @author ematkho
25 * @version $Revision: 1.0 $
26 */
27 public class VariantDeclarationTest {
28
29 private VariantDeclaration fixture;
30
31 /**
32 * Launch the test.
33 *
34 * @param args
35 * the command line arguments
36 */
37 public static void main(String[] args) {
38 new org.junit.runner.JUnitCore().run(VariantDeclarationTest.class);
39 }
40
41 /**
42 * Perform pre-test initialization.
43 */
44 @Before
45 public void setUp() {
46 fixture = new VariantDeclaration();
47 }
48
49 /**
50 * Perform post-test clean-up.
51 */
52 @After
53 public void tearDown() {
54 // Add additional tear down code here
55 }
56
57 /**
58 * Run the VariantDeclaration() constructor test.
59 */
60 @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()));
66 }
67
68 /**
69 * Run the void addField(String,Declaration) method test.
70 */
71 @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);
77 }
78
79 /**
80 * Run the VariantDefinition createDefinition(DefinitionScope,String) method
81 * test.
82 *
83 * @throws CTFReaderException Should not happen
84 */
85 @Test
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,
91 fieldName);
92
93 assertNotNull(result);
94 }
95
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$
107
108 VariantDefinition result = new VariantDefinition(declaration,
109 definitionScope, fieldName);
110 return result;
111 }
112
113 /**
114 * Run the boolean hasField(String) method test.
115 */
116 @Test
117 public void testHasField() {
118 fixture.setTag(""); //$NON-NLS-1$
119 String tag = ""; //$NON-NLS-1$
120 boolean result = fixture.hasField(tag);
121
122 assertEquals(false, result);
123 }
124
125 /**
126 * Run the boolean isTagged() method test.
127 */
128 @Test
129 public void testIsTagged() {
130 fixture.setTag(""); //$NON-NLS-1$
131 boolean result = fixture.isTagged();
132
133 assertEquals(true, result);
134 }
135
136 /**
137 * Run the boolean isTagged() method test.
138 */
139 @Test
140 public void testIsTagged_null() {
141 fixture.setTag((String) null);
142 boolean result = fixture.isTagged();
143
144 assertEquals(false, result);
145 }
146
147 /**
148 * Run the void setTag(String) method test.
149 */
150 @Test
151 public void testSetTag() {
152 fixture.setTag(""); //$NON-NLS-1$
153 String tag = ""; //$NON-NLS-1$
154 fixture.setTag(tag);
155 }
156
157 /**
158 * Run the String toString() method test.
159 */
160 @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());
166
167 assertEquals(left, right);
168 }
169 }
This page took 0.039552 seconds and 6 git commands to generate.