internalize some CTF API
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / types / StringDefinitionTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.types;
2
3 import static org.junit.Assert.assertNotNull;
4
5 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
6 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
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.StringDefinition;
10 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
11 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
12 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
13 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
14 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
15 import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
16
17 import org.junit.After;
18 import org.junit.Before;
19 import org.junit.Test;
20
21 /**
22 * The class <code>StringDefinitionTest</code> contains tests for the class
23 * <code>{@link StringDefinition}</code>.
24 *
25 * @author ematkho
26 * @version $Revision: 1.0 $
27 */
28 public class StringDefinitionTest {
29
30 private StringDefinition fixture;
31
32 /**
33 * Launch the test.
34 *
35 * @param args
36 * the command line arguments
37 */
38 public static void main(String[] args) {
39 new org.junit.runner.JUnitCore().run(StringDefinitionTest.class);
40 }
41
42 /**
43 * Perform pre-test initialization.
44 *
45 * @throws CTFReaderException
46 */
47 @Before
48 public void setUp() throws CTFReaderException {
49 CTFTrace trace = TestParams.createTrace();
50 CTFTraceReader tr = new CTFTraceReader(trace);
51 String name = ""; //$NON-NLS-1$
52 StructDefinition structDef = null;
53 boolean found = false;
54
55 while (tr.hasMoreEvents() && !found) {
56 tr.advance();
57 EventDefinition ed = tr.getCurrentEventDef();
58 for (String key : ed.fields.getDefinitions().keySet()) {
59 structDef = ed.fields;
60 Definition d = structDef.lookupDefinition(key);
61 if (d instanceof StringDefinition) {
62 found = true;
63 name = key;
64 break;
65 }
66 }
67 }
68 fixture = structDef.lookupString(name);
69 }
70
71 /**
72 * Perform post-test clean-up.
73 */
74 @After
75 public void tearDown() {
76 // Add additional tear down code here
77 }
78
79 /**
80 * Run the StringDefinition(StringDeclaration,DefinitionScope,String)
81 * constructor test.
82 */
83 @Test
84 public void testStringDefinition() {
85 StringDeclaration declaration = new StringDeclaration();
86 IDefinitionScope definitionScope = null;
87 String fieldName = ""; //$NON-NLS-1$
88
89 StringDefinition result = new StringDefinition(declaration,
90 definitionScope, fieldName);
91
92 assertNotNull(result);
93 }
94
95 /**
96 * Run the StringDeclaration getDeclaration() method test.
97 */
98 @Test
99 public void testGetDeclaration() {
100 fixture.setString(new StringBuilder());
101 StringDeclaration result = fixture.getDeclaration();
102 assertNotNull(result);
103 }
104
105 /**
106 * Run the StringBuilder getString() method test.
107 */
108 @Test
109 public void testGetString() {
110 fixture.setString(new StringBuilder());
111 StringBuilder result = fixture.getString();
112 assertNotNull(result);
113 }
114
115 /**
116 * Run the String getValue() method test.
117 */
118 @Test
119 public void testGetValue() {
120 fixture.setString(new StringBuilder());
121 String result = fixture.getValue();
122 assertNotNull(result);
123 }
124
125 /**
126 * Run the void read(BitBuffer) method test.
127 */
128 @Test
129 public void testRead() {
130 fixture.setString(new StringBuilder());
131 BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
132 fixture.read(input);
133 }
134
135 /**
136 * Run the void setDeclaration(StringDeclaration) method test.
137 */
138 @Test
139 public void testSetDeclaration() {
140 fixture.setString(new StringBuilder());
141 StringDeclaration declaration = new StringDeclaration();
142 fixture.setDeclaration(declaration);
143 }
144
145 /**
146 * Run the void setString(StringBuilder) method test.
147 */
148 @Test
149 public void testSetString() {
150 fixture.setString(new StringBuilder());
151 StringBuilder string = new StringBuilder();
152 fixture.setString(string);
153 }
154
155 /**
156 * Run the String toString() method test.
157 */
158 @Test
159 public void testToString() {
160 fixture.setString(new StringBuilder());
161 String result = fixture.toString();
162 assertNotNull(result);
163 }
164 }
This page took 0.034371 seconds and 6 git commands to generate.