Commit | Line | Data |
---|---|---|
866e5b51 FC |
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 | ||
6 | import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration; | |
7 | import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope; | |
8 | import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; | |
9 | import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; | |
10 | import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; | |
11 | import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration; | |
12 | import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition; | |
13 | import org.eclipse.linuxtools.ctf.core.tests.TestParams; | |
14 | import org.junit.After; | |
15 | import org.junit.Before; | |
16 | import org.junit.Test; | |
17 | ||
18 | /** | |
19 | * The class <code>VariantDeclarationTest</code> contains tests for the class | |
20 | * <code>{@link VariantDeclaration}</code>. | |
21 | * | |
22 | * @author ematkho | |
23 | * @version $Revision: 1.0 $ | |
24 | */ | |
25 | public class VariantDeclarationTest { | |
26 | ||
27 | private VariantDeclaration fixture; | |
28 | ||
29 | /** | |
30 | * Launch the test. | |
31 | * | |
32 | * @param args | |
33 | * the command line arguments | |
34 | */ | |
35 | public static void main(String[] args) { | |
36 | new org.junit.runner.JUnitCore().run(VariantDeclarationTest.class); | |
37 | } | |
38 | ||
39 | /** | |
40 | * Perform pre-test initialization. | |
41 | */ | |
42 | @Before | |
43 | public void setUp() { | |
44 | fixture = new VariantDeclaration(); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Perform post-test clean-up. | |
49 | */ | |
50 | @After | |
51 | public void tearDown() { | |
52 | // Add additional tear down code here | |
53 | } | |
54 | ||
55 | /** | |
56 | * Run the VariantDeclaration() constructor test. | |
57 | */ | |
58 | @Test | |
59 | public void testVariantDeclaration() { | |
60 | assertNotNull(fixture); | |
61 | assertEquals(false, fixture.isTagged()); | |
62 | String left = "[declaration] variant["; //$NON-NLS-1$ | |
63 | assertEquals(left, fixture.toString().substring(0, left.length())); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Run the void addField(String,Declaration) method test. | |
68 | */ | |
69 | @Test | |
70 | public void testAddField() { | |
71 | fixture.setTag(""); //$NON-NLS-1$ | |
72 | String tag = ""; //$NON-NLS-1$ | |
73 | IDeclaration declaration = new StringDeclaration(); | |
74 | fixture.addField(tag, declaration); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Run the VariantDefinition createDefinition(DefinitionScope,String) method | |
79 | * test. | |
80 | */ | |
81 | @Test | |
82 | public void testCreateDefinition() { | |
83 | fixture.setTag(""); //$NON-NLS-1$ | |
84 | IDefinitionScope definitionScope = createDefinitionScope(); | |
85 | String fieldName = ""; //$NON-NLS-1$ | |
86 | VariantDefinition result = fixture.createDefinition(definitionScope, | |
87 | fieldName); | |
88 | ||
89 | assertNotNull(result); | |
90 | } | |
91 | ||
92 | private static IDefinitionScope createDefinitionScope() { | |
93 | VariantDeclaration declaration = new VariantDeclaration(); | |
94 | declaration.setTag(""); //$NON-NLS-1$ | |
95 | VariantDeclaration variantDeclaration = new VariantDeclaration(); | |
96 | variantDeclaration.setTag(""); //$NON-NLS-1$ | |
97 | VariantDefinition variantDefinition = new VariantDefinition( | |
98 | variantDeclaration, TestParams.createTrace(), ""); //$NON-NLS-1$ | |
99 | IDefinitionScope definitionScope = new StructDefinition( | |
100 | new StructDeclaration(1L), variantDefinition, ""); //$NON-NLS-1$ | |
101 | String fieldName = ""; //$NON-NLS-1$ | |
102 | ||
103 | VariantDefinition result = new VariantDefinition(declaration, | |
104 | definitionScope, fieldName); | |
105 | return result; | |
106 | } | |
107 | ||
108 | /** | |
109 | * Run the boolean hasField(String) method test. | |
110 | */ | |
111 | @Test | |
112 | public void testHasField() { | |
113 | fixture.setTag(""); //$NON-NLS-1$ | |
114 | String tag = ""; //$NON-NLS-1$ | |
115 | boolean result = fixture.hasField(tag); | |
116 | ||
117 | assertEquals(false, result); | |
118 | } | |
119 | ||
120 | /** | |
121 | * Run the boolean isTagged() method test. | |
122 | */ | |
123 | @Test | |
124 | public void testIsTagged() { | |
125 | fixture.setTag(""); //$NON-NLS-1$ | |
126 | boolean result = fixture.isTagged(); | |
127 | ||
128 | assertEquals(true, result); | |
129 | } | |
130 | ||
131 | /** | |
132 | * Run the boolean isTagged() method test. | |
133 | */ | |
134 | @Test | |
135 | public void testIsTagged_null() { | |
136 | fixture.setTag((String) null); | |
137 | boolean result = fixture.isTagged(); | |
138 | ||
139 | assertEquals(false, result); | |
140 | } | |
141 | ||
142 | /** | |
143 | * Run the void setTag(String) method test. | |
144 | */ | |
145 | @Test | |
146 | public void testSetTag() { | |
147 | fixture.setTag(""); //$NON-NLS-1$ | |
148 | String tag = ""; //$NON-NLS-1$ | |
149 | fixture.setTag(tag); | |
150 | } | |
151 | ||
152 | /** | |
153 | * Run the String toString() method test. | |
154 | */ | |
155 | @Test | |
156 | public void testToString() { | |
157 | fixture.setTag(""); //$NON-NLS-1$ | |
158 | String result = fixture.toString(); | |
159 | String left = "[declaration] variant["; //$NON-NLS-1$ | |
160 | String right = result.substring(0, left.length()); | |
161 | ||
162 | assertEquals(left, right); | |
163 | } | |
164 | } |