ctf: Allow the test traces to be used by other plugins
[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.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;
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 static final int TRACE_INDEX = 0;
30
31 private VariantDeclaration fixture;
32
33 /**
34 * Launch the test.
35 *
36 * @param args
37 * the command line arguments
38 */
39 public static void main(String[] args) {
40 new org.junit.runner.JUnitCore().run(VariantDeclarationTest.class);
41 }
42
43 /**
44 * Perform pre-test initialization.
45 */
46 @Before
47 public void setUp() {
48 fixture = new VariantDeclaration();
49 }
50
51 /**
52 * Perform post-test clean-up.
53 */
54 @After
55 public void tearDown() {
56 // Add additional tear down code here
57 }
58
59 /**
60 * Run the VariantDeclaration() constructor test.
61 */
62 @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()));
68 }
69
70 /**
71 * Run the void addField(String,Declaration) method test.
72 */
73 @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);
79 }
80
81 /**
82 * Run the VariantDefinition createDefinition(DefinitionScope,String) method
83 * test.
84 *
85 * @throws CTFReaderException Should not happen
86 */
87 @Test
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,
93 fieldName);
94
95 assertNotNull(result);
96 }
97
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$
109
110 VariantDefinition result = new VariantDefinition(declaration,
111 definitionScope, fieldName);
112 return result;
113 }
114
115 /**
116 * Run the boolean hasField(String) method test.
117 */
118 @Test
119 public void testHasField() {
120 fixture.setTag(""); //$NON-NLS-1$
121 String tag = ""; //$NON-NLS-1$
122 boolean result = fixture.hasField(tag);
123
124 assertEquals(false, result);
125 }
126
127 /**
128 * Run the boolean isTagged() method test.
129 */
130 @Test
131 public void testIsTagged() {
132 fixture.setTag(""); //$NON-NLS-1$
133 boolean result = fixture.isTagged();
134
135 assertEquals(true, result);
136 }
137
138 /**
139 * Run the boolean isTagged() method test.
140 */
141 @Test
142 public void testIsTagged_null() {
143 fixture.setTag((String) null);
144 boolean result = fixture.isTagged();
145
146 assertEquals(false, result);
147 }
148
149 /**
150 * Run the void setTag(String) method test.
151 */
152 @Test
153 public void testSetTag() {
154 fixture.setTag(""); //$NON-NLS-1$
155 String tag = ""; //$NON-NLS-1$
156 fixture.setTag(tag);
157 }
158
159 /**
160 * Run the String toString() method test.
161 */
162 @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());
168
169 assertEquals(left, right);
170 }
171 }
This page took 0.035243 seconds and 6 git commands to generate.