Commit | Line | Data |
---|---|---|
81c8e6f7 MK |
1 | package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor; |
2 | ||
3 | import static org.junit.Assert.assertEquals; | |
4 | import static org.junit.Assert.assertNotNull; | |
5 | ||
6 | import java.nio.ByteOrder; | |
7 | ||
8 | import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration; | |
9 | import org.eclipse.linuxtools.ctf.core.event.types.Definition; | |
10 | import org.eclipse.linuxtools.ctf.core.event.types.Encoding; | |
11 | import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration; | |
12 | import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition; | |
13 | import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration; | |
14 | import org.eclipse.linuxtools.ctf.core.event.types.SequenceDeclaration; | |
15 | import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration; | |
16 | import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; | |
17 | import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; | |
18 | import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer; | |
19 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventField; | |
20 | import org.junit.After; | |
21 | import org.junit.Before; | |
22 | import org.junit.Test; | |
23 | ||
24 | /** | |
25 | * The class <code>CtfTmfEventFieldTest</code> contains tests for the class | |
26 | * <code>{@link CtfTmfEventField}</code>. | |
27 | * | |
28 | * @generatedBy CodePro at 03/05/12 2:29 PM | |
29 | * @author ematkho | |
30 | * @version $Revision: 1.0 $ | |
31 | */ | |
32 | public class CtfTmfEventFieldTest { | |
33 | ||
34 | private static final String ROOT = "root"; //$NON-NLS-1$ | |
35 | private static final String SEQ = "seq"; //$NON-NLS-1$ | |
36 | private static final String ARRAY = "array"; //$NON-NLS-1$ | |
37 | private static final String STR = "str"; //$NON-NLS-1$ | |
38 | private static final String FLOAT = "float"; //$NON-NLS-1$ | |
39 | private static final String LEN = "len"; //$NON-NLS-1$ | |
40 | private static final String INT = "int"; //$NON-NLS-1$ | |
41 | private static final String NAME = "test"; //$NON-NLS-1$ | |
42 | ||
43 | /** | |
44 | * Run the CtfTmfEventField parseField(Definition,String) method test. | |
45 | * | |
46 | * @generatedBy CodePro at 03/05/12 2:29 PM | |
47 | */ | |
48 | @Test | |
49 | public void testParseField_1() { | |
50 | FloatDefinition fieldDef = (FloatDefinition) fixture | |
51 | .lookupDefinition(FLOAT); | |
52 | CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, "_"+NAME); //$NON-NLS-1$ | |
53 | String result2 =CtfTmfEventField.copyFrom(result).toString(); | |
54 | assertEquals( result2, "test=9.551467814359616E-38"); //$NON-NLS-1$ | |
55 | } | |
56 | ||
57 | /** | |
58 | * Run the CtfTmfEventField parseField(Definition,String) method test. | |
59 | * | |
60 | * @generatedBy CodePro at 03/05/12 2:29 PM | |
61 | */ | |
62 | @Test | |
63 | public void testParseField_2() { | |
64 | CtfTmfEventField result = CtfTmfEventField.parseField( | |
65 | fixture.lookupArray(ARRAY), NAME); | |
66 | String result2 =CtfTmfEventField.copyFrom(result).toString(); | |
67 | assertEquals( result2, "test={ 2, 2}"); //$NON-NLS-1$ | |
68 | } | |
69 | ||
70 | /** | |
71 | * Run the CtfTmfEventField parseField(Definition,String) method test. | |
72 | * | |
73 | * @generatedBy CodePro at 03/05/12 2:29 PM | |
74 | */ | |
75 | @Test | |
76 | public void testParseField_3() { | |
77 | Definition fieldDef = fixture.lookupDefinition(INT); | |
78 | CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME); | |
79 | String result2 =CtfTmfEventField.copyFrom(result).toString(); | |
80 | assertEquals( result2, "test=2"); //$NON-NLS-1$ | |
81 | } | |
82 | ||
83 | /** | |
84 | * Run the CtfTmfEventField parseField(Definition,String) method test. | |
85 | * | |
86 | * @generatedBy CodePro at 03/05/12 2:29 PM | |
87 | */ | |
88 | @Test | |
89 | public void testParseField_4() { | |
90 | Definition fieldDef = fixture.lookupDefinition(SEQ); | |
91 | CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME); | |
92 | String result2 =CtfTmfEventField.copyFrom(result).toString(); | |
93 | assertEquals( result2, "test={ 2, 2}"); //$NON-NLS-1$ | |
94 | } | |
95 | ||
96 | /** | |
97 | * Run the CtfTmfEventField parseField(Definition,String) method test. | |
98 | * | |
99 | * @throws Exception | |
100 | * | |
101 | * @generatedBy CodePro at 03/05/12 2:29 PM | |
102 | */ | |
103 | @Test | |
104 | public void testParseField_5() { | |
105 | Definition fieldDef = fixture.lookupDefinition(STR); | |
106 | CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME); | |
107 | String result2 =CtfTmfEventField.copyFrom(result).toString(); | |
108 | assertEquals( result2, "test=\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2\ 2"); //$NON-NLS-1$ | |
109 | } | |
110 | ||
111 | @Test | |
112 | public void testClone() { | |
113 | Definition fieldDef = fixture.lookupDefinition(STR); | |
114 | CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME); | |
115 | assertNotNull(result.clone()); | |
116 | } | |
117 | ||
118 | ||
119 | StructDefinition fixture; | |
120 | ||
121 | /** | |
122 | * Perform pre-test initialization. | |
123 | * | |
124 | * @throws Exception | |
125 | * if the initialization fails for some reason | |
126 | * | |
127 | * @generatedBy CodePro at 03/05/12 2:29 PM | |
128 | */ | |
129 | @Before | |
130 | public void setUp() throws Exception { | |
131 | StructDeclaration sDec = new StructDeclaration(1l); | |
132 | StringDeclaration strDec = new StringDeclaration(); | |
133 | IntegerDeclaration intDec = new IntegerDeclaration(8, false, 8, | |
134 | ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8); | |
135 | FloatDeclaration flDec = new FloatDeclaration(8, 24, | |
07002e0a | 136 | ByteOrder.BIG_ENDIAN, 8); |
81c8e6f7 MK |
137 | ArrayDeclaration arrDec = new ArrayDeclaration(2, intDec); |
138 | SequenceDeclaration seqDec = new SequenceDeclaration(LEN, intDec); | |
139 | sDec.addField(INT, intDec); | |
140 | sDec.addField(LEN, intDec); | |
141 | sDec.addField(FLOAT, flDec); | |
142 | sDec.addField(STR, strDec); | |
143 | sDec.addField(ARRAY, arrDec); | |
144 | sDec.addField(SEQ, seqDec); | |
145 | fixture = sDec.createDefinition(fixture, ROOT); | |
146 | int capacity = 1024; | |
147 | java.nio.ByteBuffer bb = java.nio.ByteBuffer.allocateDirect(capacity); | |
148 | for (int i = 0; i < capacity; i++) { | |
149 | bb.put((byte) 2); | |
150 | } | |
151 | bb.position(20); | |
152 | bb.put((byte) 0); | |
153 | bb.position(0); | |
154 | fixture.read(new BitBuffer(bb)); | |
155 | } | |
156 | ||
157 | /** | |
158 | * Perform post-test clean-up. | |
159 | * | |
160 | * @throws Exception | |
161 | * if the clean-up fails for some reason | |
162 | * | |
163 | * @generatedBy CodePro at 03/05/12 2:29 PM | |
164 | */ | |
165 | @After | |
166 | public void tearDown() throws Exception { | |
167 | // Add additional tear down code here | |
168 | } | |
169 | ||
170 | /** | |
171 | * Launch the test. | |
172 | * | |
173 | * @param args | |
174 | * the command line arguments | |
175 | * | |
176 | * @generatedBy CodePro at 03/05/12 2:29 PM | |
177 | */ | |
178 | public static void main(String[] args) { | |
179 | new org.junit.runner.JUnitCore().run(CtfTmfEventFieldTest.class); | |
180 | } | |
181 | } |