ctf: Update copyright headers and add missing ones
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / VariantDeclarationTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.linuxtools.ctf.core.tests.types;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assume.assumeTrue;
17
18 import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
19 import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
20 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
21 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
22 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
23 import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
24 import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
25 import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTraces;
26 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 /**
32 * The class <code>VariantDeclarationTest</code> contains tests for the class
33 * <code>{@link VariantDeclaration}</code>.
34 *
35 * @author ematkho
36 * @version $Revision: 1.0 $
37 */
38 public class VariantDeclarationTest {
39
40 private static final int TRACE_INDEX = 0;
41
42 private VariantDeclaration fixture;
43
44 /**
45 * Launch the test.
46 *
47 * @param args
48 * the command line arguments
49 */
50 public static void main(String[] args) {
51 new org.junit.runner.JUnitCore().run(VariantDeclarationTest.class);
52 }
53
54 /**
55 * Perform pre-test initialization.
56 */
57 @Before
58 public void setUp() {
59 fixture = new VariantDeclaration();
60 }
61
62 /**
63 * Perform post-test clean-up.
64 */
65 @After
66 public void tearDown() {
67 // Add additional tear down code here
68 }
69
70 /**
71 * Run the VariantDeclaration() constructor test.
72 */
73 @Test
74 public void testVariantDeclaration() {
75 assertNotNull(fixture);
76 assertEquals(false, fixture.isTagged());
77 String left = "[declaration] variant["; //$NON-NLS-1$
78 assertEquals(left, fixture.toString().substring(0, left.length()));
79 }
80
81 /**
82 * Run the void addField(String,Declaration) method test.
83 */
84 @Test
85 public void testAddField() {
86 fixture.setTag(""); //$NON-NLS-1$
87 String tag = ""; //$NON-NLS-1$
88 IDeclaration declaration = new StringDeclaration();
89 fixture.addField(tag, declaration);
90 }
91
92 /**
93 * Run the VariantDefinition createDefinition(DefinitionScope,String) method
94 * test.
95 *
96 * @throws CTFReaderException Should not happen
97 */
98 @Test
99 public void testCreateDefinition() throws CTFReaderException {
100 fixture.setTag(""); //$NON-NLS-1$
101 IDefinitionScope definitionScope = createDefinitionScope();
102 String fieldName = ""; //$NON-NLS-1$
103 VariantDefinition result = fixture.createDefinition(definitionScope,
104 fieldName);
105
106 assertNotNull(result);
107 }
108
109 private static IDefinitionScope createDefinitionScope() throws CTFReaderException {
110 assumeTrue(CtfTestTraces.tracesExist());
111 VariantDeclaration declaration = new VariantDeclaration();
112 declaration.setTag(""); //$NON-NLS-1$
113 VariantDeclaration variantDeclaration = new VariantDeclaration();
114 variantDeclaration.setTag(""); //$NON-NLS-1$
115 VariantDefinition variantDefinition = new VariantDefinition(
116 variantDeclaration, CtfTestTraces.getTestTrace(TRACE_INDEX), ""); //$NON-NLS-1$
117 IDefinitionScope definitionScope = new StructDefinition(
118 new StructDeclaration(1L), variantDefinition, ""); //$NON-NLS-1$
119 String fieldName = ""; //$NON-NLS-1$
120
121 VariantDefinition result = new VariantDefinition(declaration,
122 definitionScope, fieldName);
123 return result;
124 }
125
126 /**
127 * Run the boolean hasField(String) method test.
128 */
129 @Test
130 public void testHasField() {
131 fixture.setTag(""); //$NON-NLS-1$
132 String tag = ""; //$NON-NLS-1$
133 boolean result = fixture.hasField(tag);
134
135 assertEquals(false, result);
136 }
137
138 /**
139 * Run the boolean isTagged() method test.
140 */
141 @Test
142 public void testIsTagged() {
143 fixture.setTag(""); //$NON-NLS-1$
144 boolean result = fixture.isTagged();
145
146 assertEquals(true, result);
147 }
148
149 /**
150 * Run the boolean isTagged() method test.
151 */
152 @Test
153 public void testIsTagged_null() {
154 fixture.setTag((String) null);
155 boolean result = fixture.isTagged();
156
157 assertEquals(false, result);
158 }
159
160 /**
161 * Run the void setTag(String) method test.
162 */
163 @Test
164 public void testSetTag() {
165 fixture.setTag(""); //$NON-NLS-1$
166 String tag = ""; //$NON-NLS-1$
167 fixture.setTag(tag);
168 }
169
170 /**
171 * Run the String toString() method test.
172 */
173 @Test
174 public void testToString() {
175 fixture.setTag(""); //$NON-NLS-1$
176 String result = fixture.toString();
177 String left = "[declaration] variant["; //$NON-NLS-1$
178 String right = result.substring(0, left.length());
179
180 assertEquals(left, right);
181 }
182 }
This page took 0.034425 seconds and 5 git commands to generate.