ctf: Disable NLS warnings in test plugin
[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[";
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("");
87 String tag = "";
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("");
101 IDefinitionScope definitionScope = createDefinitionScope();
102 String fieldName = "";
103 VariantDefinition result = fixture.createDefinition(definitionScope, fieldName);
104
105 assertNotNull(result);
106 }
107
108 private static IDefinitionScope createDefinitionScope() throws CTFReaderException {
109 assumeTrue(CtfTestTraces.tracesExist());
110 VariantDeclaration declaration = new VariantDeclaration();
111 declaration.setTag("");
112 VariantDeclaration variantDeclaration = new VariantDeclaration();
113 variantDeclaration.setTag("");
114 VariantDefinition variantDefinition = new VariantDefinition(
115 variantDeclaration, CtfTestTraces.getTestTrace(TRACE_INDEX), "");
116 IDefinitionScope definitionScope = new StructDefinition(
117 new StructDeclaration(1L), variantDefinition, "");
118 String fieldName = "";
119
120 VariantDefinition result = new VariantDefinition(declaration,
121 definitionScope, fieldName);
122 return result;
123 }
124
125 /**
126 * Run the boolean hasField(String) method test.
127 */
128 @Test
129 public void testHasField() {
130 fixture.setTag("");
131 String tag = "";
132 boolean result = fixture.hasField(tag);
133
134 assertEquals(false, result);
135 }
136
137 /**
138 * Run the boolean isTagged() method test.
139 */
140 @Test
141 public void testIsTagged() {
142 fixture.setTag("");
143 boolean result = fixture.isTagged();
144
145 assertEquals(true, result);
146 }
147
148 /**
149 * Run the boolean isTagged() method test.
150 */
151 @Test
152 public void testIsTagged_null() {
153 fixture.setTag((String) null);
154 boolean result = fixture.isTagged();
155
156 assertEquals(false, result);
157 }
158
159 /**
160 * Run the void setTag(String) method test.
161 */
162 @Test
163 public void testSetTag() {
164 fixture.setTag("");
165 String tag = "";
166 fixture.setTag(tag);
167 }
168
169 /**
170 * Run the String toString() method test.
171 */
172 @Test
173 public void testToString() {
174 fixture.setTag("");
175 String result = fixture.toString();
176 String left = "[declaration] variant[";
177 String right = result.substring(0, left.length());
178
179 assertEquals(left, right);
180 }
181 }
This page took 0.046226 seconds and 5 git commands to generate.