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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.types
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assume
.assumeTrue
;
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
;
32 * The class <code>VariantDeclarationTest</code> contains tests for the class
33 * <code>{@link VariantDeclaration}</code>.
36 * @version $Revision: 1.0 $
38 public class VariantDeclarationTest
{
40 private static final int TRACE_INDEX
= 0;
42 private VariantDeclaration fixture
;
48 * the command line arguments
50 public static void main(String
[] args
) {
51 new org
.junit
.runner
.JUnitCore().run(VariantDeclarationTest
.class);
55 * Perform pre-test initialization.
59 fixture
= new VariantDeclaration();
63 * Perform post-test clean-up.
66 public void tearDown() {
67 // Add additional tear down code here
71 * Run the VariantDeclaration() constructor 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()));
82 * Run the void addField(String,Declaration) method 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
);
93 * Run the VariantDefinition createDefinition(DefinitionScope,String) method
96 * @throws CTFReaderException Should not happen
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
,
106 assertNotNull(result
);
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$
121 VariantDefinition result
= new VariantDefinition(declaration
,
122 definitionScope
, fieldName
);
127 * Run the boolean hasField(String) method test.
130 public void testHasField() {
131 fixture
.setTag(""); //$NON-NLS-1$
132 String tag
= ""; //$NON-NLS-1$
133 boolean result
= fixture
.hasField(tag
);
135 assertEquals(false, result
);
139 * Run the boolean isTagged() method test.
142 public void testIsTagged() {
143 fixture
.setTag(""); //$NON-NLS-1$
144 boolean result
= fixture
.isTagged();
146 assertEquals(true, result
);
150 * Run the boolean isTagged() method test.
153 public void testIsTagged_null() {
154 fixture
.setTag((String
) null);
155 boolean result
= fixture
.isTagged();
157 assertEquals(false, result
);
161 * Run the void setTag(String) method test.
164 public void testSetTag() {
165 fixture
.setTag(""); //$NON-NLS-1$
166 String tag
= ""; //$NON-NLS-1$
171 * Run the String toString() method 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());
180 assertEquals(left
, right
);