Debian Codegraph @

check/cpp-tests/common_t.cpp

raw
1 /*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2020 Slawomir Wojtasiak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /* Test suite initialization. */
21
22 #include "common_t.hpp"
23
24 #include <fcml_errors.h>
25 #include <fcml_common.hpp>
26 #include <fcml_errors.hpp>
27 #include <fcml_registers.hpp>
28
29 using namespace fcml;
30
31 fcml_bool fcml_tf_cpp_common_suite_init(void) {
32 return FCML_TRUE;
33 }
34
35 fcml_bool fcml_tf_cpp_common_suite_cleanup(void) {
36 return FCML_TRUE;
37 }
38
39
40 void fcml_tf_cpp_integer(void) {
41
42 Integer i1_fcml_uint8_t((fcml_uint8_t)0xFF);
43 Integer i1_fcml_int8_t((fcml_int8_t)0xFF);
44 Integer i1_fcml_uint16_t((fcml_uint16_t)0xFFFF);
45 Integer i1_fcml_int16_t((fcml_int16_t)0xFFFF);
46 Integer i1_fcml_uint32_t((fcml_uint32_t)0xFFFFFFFF);
47 Integer i1_fcml_int32_t((fcml_int32_t)0xFFFFFFFF);
48 Integer i1_fcml_uint64_t((fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL);
49 Integer i1_fcml_int64_t((fcml_int64_t)0xFFFFFFFFFFFFFFFFUL);
50
51 STF_ASSERT_EQUAL( (fcml_uint8_t)i1_fcml_uint8_t.getInt8(), (fcml_uint8_t)0xFF );
52 STF_ASSERT_EQUAL( i1_fcml_uint8_t.isSigned(), FCML_FALSE );
53 STF_ASSERT_EQUAL( i1_fcml_uint8_t.getSize(), FCML_DS_8 );
54
55 STF_ASSERT_EQUAL( (fcml_int8_t)i1_fcml_int8_t.getInt8(), (fcml_int8_t)0xFF );
56 STF_ASSERT_EQUAL( i1_fcml_int8_t.isSigned(), FCML_TRUE );
57 STF_ASSERT_EQUAL( i1_fcml_int8_t.getSize(), FCML_DS_8 );
58
59 STF_ASSERT_EQUAL( (fcml_uint16_t)i1_fcml_uint16_t.getInt16(), (fcml_uint16_t)0xFFFF );
60 STF_ASSERT_EQUAL( i1_fcml_uint16_t.isSigned(), FCML_FALSE );
61 STF_ASSERT_EQUAL( i1_fcml_uint16_t.getSize(), FCML_DS_16 );
62
63 STF_ASSERT_EQUAL( (fcml_int16_t)i1_fcml_int16_t.getInt16(), (fcml_int16_t)0xFFFF );
64 STF_ASSERT_EQUAL( i1_fcml_int16_t.isSigned(), FCML_TRUE );
65 STF_ASSERT_EQUAL( i1_fcml_int16_t.getSize(), FCML_DS_16 );
66
67 STF_ASSERT_EQUAL( (fcml_uint32_t)i1_fcml_uint32_t.getInt32(), (fcml_uint32_t)0xFFFFFFFF );
68 STF_ASSERT_EQUAL( i1_fcml_uint32_t.isSigned(), FCML_FALSE );
69 STF_ASSERT_EQUAL( i1_fcml_uint32_t.getSize(), FCML_DS_32 );
70
71 STF_ASSERT_EQUAL( (fcml_int32_t)i1_fcml_int32_t.getInt32(), (fcml_int32_t)0xFFFFFFFF );
72 STF_ASSERT_EQUAL( i1_fcml_int32_t.isSigned(), FCML_TRUE );
73 STF_ASSERT_EQUAL( i1_fcml_int32_t.getSize(), FCML_DS_32 );
74
75 STF_ASSERT_EQUAL( (fcml_uint64_t)i1_fcml_uint64_t.getInt64(), (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL );
76 STF_ASSERT_EQUAL( i1_fcml_uint64_t.isSigned(), FCML_FALSE );
77 STF_ASSERT_EQUAL( i1_fcml_uint64_t.getSize(), FCML_DS_64 );
78
79 STF_ASSERT_EQUAL( (fcml_int64_t)i1_fcml_int64_t.getInt64(), (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL );
80 STF_ASSERT_EQUAL( i1_fcml_int64_t.isSigned(), FCML_TRUE );
81 STF_ASSERT_EQUAL( i1_fcml_int64_t.getSize(), FCML_DS_64 );
82
83 }
84
85 void fcml_tf_cpp_integer_operator(void) {
86
87 Integer i1_fcml_uint8_t = (fcml_uint8_t)0xFF;
88 Integer i1_fcml_int8_t = (fcml_int8_t)0xFF;
89 Integer i1_fcml_uint16_t = (fcml_uint16_t)0xFFFF;
90 Integer i1_fcml_int16_t = (fcml_int16_t)0xFFFF;
91 Integer i1_fcml_uint32_t = (fcml_uint32_t)0xFFFFFFFF;
92 Integer i1_fcml_int32_t = (fcml_int32_t)0xFFFFFFFF;
93 Integer i1_fcml_uint64_t = (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL;
94 Integer i1_fcml_int64_t = (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL;
95
96 STF_ASSERT_EQUAL( (fcml_uint8_t)i1_fcml_uint8_t.getInt8(), (fcml_uint8_t)0xFF );
97 STF_ASSERT_EQUAL( i1_fcml_uint8_t.isSigned(), FCML_FALSE );
98 STF_ASSERT_EQUAL( i1_fcml_uint8_t.getSize(), FCML_DS_8 );
99
100 STF_ASSERT_EQUAL( (fcml_int8_t)i1_fcml_int8_t.getInt8(), (fcml_int8_t)0xFF );
101 STF_ASSERT_EQUAL( i1_fcml_int8_t.isSigned(), FCML_TRUE );
102 STF_ASSERT_EQUAL( i1_fcml_int8_t.getSize(), FCML_DS_8 );
103
104 STF_ASSERT_EQUAL( (fcml_uint16_t)i1_fcml_uint16_t.getInt16(), (fcml_uint16_t)0xFFFF );
105 STF_ASSERT_EQUAL( i1_fcml_uint16_t.isSigned(), FCML_FALSE );
106 STF_ASSERT_EQUAL( i1_fcml_uint16_t.getSize(), FCML_DS_16 );
107
108 STF_ASSERT_EQUAL( (fcml_int16_t)i1_fcml_int16_t.getInt16(), (fcml_int16_t)0xFFFF );
109 STF_ASSERT_EQUAL( i1_fcml_int16_t.isSigned(), FCML_TRUE );
110 STF_ASSERT_EQUAL( i1_fcml_int16_t.getSize(), FCML_DS_16 );
111
112 STF_ASSERT_EQUAL( (fcml_uint32_t)i1_fcml_uint32_t.getInt32(), (fcml_uint32_t)0xFFFFFFFF );
113 STF_ASSERT_EQUAL( i1_fcml_uint32_t.isSigned(), FCML_FALSE );
114 STF_ASSERT_EQUAL( i1_fcml_uint32_t.getSize(), FCML_DS_32 );
115
116 STF_ASSERT_EQUAL( (fcml_int32_t)i1_fcml_int32_t.getInt32(), (fcml_int32_t)0xFFFFFFFF );
117 STF_ASSERT_EQUAL( i1_fcml_int32_t.isSigned(), FCML_TRUE );
118 STF_ASSERT_EQUAL( i1_fcml_int32_t.getSize(), FCML_DS_32 );
119
120 STF_ASSERT_EQUAL( (fcml_uint64_t)i1_fcml_uint64_t.getInt64(), (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL );
121 STF_ASSERT_EQUAL( i1_fcml_uint64_t.isSigned(), FCML_FALSE );
122 STF_ASSERT_EQUAL( i1_fcml_uint64_t.getSize(), FCML_DS_64 );
123
124 STF_ASSERT_EQUAL( (fcml_int64_t)i1_fcml_int64_t.getInt64(), (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL );
125 STF_ASSERT_EQUAL( i1_fcml_int64_t.isSigned(), FCML_TRUE );
126 STF_ASSERT_EQUAL( i1_fcml_int64_t.getSize(), FCML_DS_64 );
127
128 }
129
130 void fcml_tf_cpp_integer_copy(void) {
131
132 Integer i1c_fcml_uint8_t = (fcml_uint8_t)0xFF;
133 Integer i1c_fcml_int8_t = (fcml_int8_t)0xFF;
134 Integer i1c_fcml_uint16_t = (fcml_uint16_t)0xFFFF;
135 Integer i1c_fcml_int16_t = (fcml_int16_t)0xFFFF;
136 Integer i1c_fcml_uint32_t = (fcml_uint32_t)0xFFFFFFFF;
137 Integer i1c_fcml_int32_t = (fcml_int32_t)0xFFFFFFFF;
138 Integer i1c_fcml_uint64_t = (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL;
139 Integer i1c_fcml_int64_t = (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL;
140
141 Integer i1_fcml_uint8_t = i1c_fcml_uint8_t;
142 Integer i1_fcml_int8_t = i1c_fcml_int8_t;
143 Integer i1_fcml_uint16_t = i1c_fcml_uint16_t;
144 Integer i1_fcml_int16_t = i1c_fcml_int16_t;
145 Integer i1_fcml_uint32_t = i1c_fcml_uint32_t;
146 Integer i1_fcml_int32_t = i1c_fcml_int32_t;
147 Integer i1_fcml_uint64_t = i1c_fcml_uint64_t;
148 Integer i1_fcml_int64_t = i1c_fcml_int64_t;
149
150 i1c_fcml_uint8_t = 0;
151 i1c_fcml_int8_t = 0;
152 i1c_fcml_uint16_t = 0;
153 i1c_fcml_int16_t = 0;
154 i1c_fcml_uint32_t = 0;
155 i1c_fcml_int32_t = 0;
156 i1c_fcml_uint64_t = 0;
157 i1c_fcml_int64_t = 0;
158
159 STF_ASSERT_EQUAL( (fcml_uint8_t)i1_fcml_uint8_t.getInt8(), (fcml_uint8_t)0xFF );
160 STF_ASSERT_EQUAL( i1_fcml_uint8_t.isSigned(), FCML_FALSE );
161 STF_ASSERT_EQUAL( i1_fcml_uint8_t.getSize(), FCML_DS_8 );
162
163 STF_ASSERT_EQUAL( (fcml_int8_t)i1_fcml_int8_t.getInt8(), (fcml_int8_t)0xFF );
164 STF_ASSERT_EQUAL( i1_fcml_int8_t.isSigned(), FCML_TRUE );
165 STF_ASSERT_EQUAL( i1_fcml_int8_t.getSize(), FCML_DS_8 );
166
167 STF_ASSERT_EQUAL( (fcml_uint16_t)i1_fcml_uint16_t.getInt16(), (fcml_uint16_t)0xFFFF );
168 STF_ASSERT_EQUAL( i1_fcml_uint16_t.isSigned(), FCML_FALSE );
169 STF_ASSERT_EQUAL( i1_fcml_uint16_t.getSize(), FCML_DS_16 );
170
171 STF_ASSERT_EQUAL( (fcml_int16_t)i1_fcml_int16_t.getInt16(), (fcml_int16_t)0xFFFF );
172 STF_ASSERT_EQUAL( i1_fcml_int16_t.isSigned(), FCML_TRUE );
173 STF_ASSERT_EQUAL( i1_fcml_int16_t.getSize(), FCML_DS_16 );
174
175 STF_ASSERT_EQUAL( (fcml_uint32_t)i1_fcml_uint32_t.getInt32(), (fcml_uint32_t)0xFFFFFFFF );
176 STF_ASSERT_EQUAL( i1_fcml_uint32_t.isSigned(), FCML_FALSE );
177 STF_ASSERT_EQUAL( i1_fcml_uint32_t.getSize(), FCML_DS_32 );
178
179 STF_ASSERT_EQUAL( (fcml_int32_t)i1_fcml_int32_t.getInt32(), (fcml_int32_t)0xFFFFFFFF );
180 STF_ASSERT_EQUAL( i1_fcml_int32_t.isSigned(), FCML_TRUE );
181 STF_ASSERT_EQUAL( i1_fcml_int32_t.getSize(), FCML_DS_32 );
182
183 STF_ASSERT_EQUAL( (fcml_uint64_t)i1_fcml_uint64_t.getInt64(), (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL );
184 STF_ASSERT_EQUAL( i1_fcml_uint64_t.isSigned(), FCML_FALSE );
185 STF_ASSERT_EQUAL( i1_fcml_uint64_t.getSize(), FCML_DS_64 );
186
187 STF_ASSERT_EQUAL( (fcml_int64_t)i1_fcml_int64_t.getInt64(), (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL );
188 STF_ASSERT_EQUAL( i1_fcml_int64_t.isSigned(), FCML_TRUE );
189 STF_ASSERT_EQUAL( i1_fcml_int64_t.getSize(), FCML_DS_64 );
190
191 }
192
193 void fcml_tf_cpp_integer_casting(void) {
194
195 Integer i1c_fcml_uint8_t = (fcml_uint8_t)0xFF;
196 Integer i1c_fcml_int8_t = (fcml_int8_t)0xFF;
197 Integer i1c_fcml_uint16_t = (fcml_uint16_t)0xFFFF;
198 Integer i1c_fcml_int16_t = (fcml_int16_t)0xFFFF;
199 Integer i1c_fcml_uint32_t = (fcml_uint32_t)0xFFFFFFFF;
200 Integer i1c_fcml_int32_t = (fcml_int32_t)0xFFFFFFFF;
201 Integer i1c_fcml_uint64_t = (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL;
202 Integer i1c_fcml_int64_t = (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL;
203
204 fcml_uint8_t i1_fcml_uint8_t = i1c_fcml_uint8_t;
205 fcml_int8_t i1_fcml_int8_t = i1c_fcml_int8_t;
206 fcml_uint16_t i1_fcml_uint16_t = i1c_fcml_uint16_t;
207 fcml_int16_t i1_fcml_int16_t = i1c_fcml_int16_t;
208 fcml_uint32_t i1_fcml_uint32_t = i1c_fcml_uint32_t;
209 fcml_int32_t i1_fcml_int32_t = i1c_fcml_int32_t;
210 fcml_uint64_t i1_fcml_uint64_t = i1c_fcml_uint64_t;
211 fcml_int64_t i1_fcml_int64_t = i1c_fcml_int64_t;
212
213 STF_ASSERT_EQUAL( i1_fcml_uint8_t, (fcml_uint8_t)0xFF );
214 STF_ASSERT_EQUAL( i1_fcml_int8_t, (fcml_int8_t)0xFF );
215 STF_ASSERT_EQUAL( i1_fcml_uint16_t, (fcml_uint16_t)0xFFFF );
216 STF_ASSERT_EQUAL( i1_fcml_int16_t, (fcml_int16_t)0xFFFF );
217 STF_ASSERT_EQUAL( i1_fcml_uint32_t, (fcml_uint32_t)0xFFFFFFFF );
218 STF_ASSERT_EQUAL( i1_fcml_int32_t, (fcml_int32_t)0xFFFFFFFF );
219 STF_ASSERT_EQUAL( i1_fcml_uint64_t, (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL );
220 STF_ASSERT_EQUAL( i1_fcml_int64_t, (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL );
221
222 // Conversion.
223
224 fcml_uint8_t conveted = i1c_fcml_int64_t;
225 STF_ASSERT_EQUAL( conveted, (fcml_uint8_t)0xFF );
226
227 }
228
229 void fcml_tf_cpp_integer_comparisions(void) {
230
231 Integer int1 = (fcml_int16_t)-1;
232 Integer int2 = (fcml_int8_t)-1;
233 Integer int3 = (fcml_int8_t)18;
234
235 STF_ASSERT( int1 == int2 );
236 STF_ASSERT( !(int1 != int2) );
237 STF_ASSERT( int1 != int3 );
238
239 Integer int4 = (fcml_uint8_t)0xFF;
240 Integer int5 = (fcml_uint16_t)0xFFFF;
241 Integer int6 = (fcml_uint32_t)0xFFFF;
242
243 STF_ASSERT( int4 != int5 );
244 STF_ASSERT( int5 == int6 );
245 }
246
247 void fcml_tf_cpp_integer_expressions(void) {
248
249 const Integer i1c_fcml_uint8_t = (fcml_uint8_t)0xFF;
250 const Integer i1c_fcml_int64_t = (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL;
251
252 // 255 + -1 = 254
253
254 const Integer resultInt = i1c_fcml_int64_t + i1c_fcml_uint8_t;
255
256 STF_ASSERT_EQUAL( resultInt.getSize(), FCML_DS_64 );
257 STF_ASSERT_EQUAL( resultInt.isSigned(), FCML_TRUE );
258 STF_ASSERT_EQUAL( resultInt.getInt64(), (fcml_int64_t)254 );
259
260 fcml_uint8_t result = i1c_fcml_int64_t + i1c_fcml_uint8_t;
261
262 STF_ASSERT_EQUAL( result, (fcml_uint8_t)254 );
263
264 Integer i1i_fcml_uint8_t = (fcml_uint8_t)4;
265 Integer i1i_fcml_int64_t = (fcml_int64_t)8;
266
267 result = i1i_fcml_int64_t / i1i_fcml_uint8_t;
268
269 STF_ASSERT_EQUAL( result, (fcml_uint8_t)2 );
270
271 result = i1i_fcml_int64_t * i1i_fcml_uint8_t;
272
273 STF_ASSERT_EQUAL( result, (fcml_uint8_t)32 );
274
275 result = i1i_fcml_int64_t - i1i_fcml_uint8_t;
276
277 STF_ASSERT_EQUAL( result, (fcml_uint8_t)4 );
278
279 Integer op_pp;
280
281 op_pp += 10;
282
283 STF_ASSERT_EQUAL( (fcml_uint64_t)op_pp.getInt64(), (fcml_uint64_t)10 );
284
285 op_pp *= 2;
286
287 STF_ASSERT_EQUAL( (fcml_uint64_t)op_pp.getInt64(), (fcml_uint64_t)20 );
288
289 op_pp /= 4;
290
291 STF_ASSERT_EQUAL( (fcml_uint64_t)op_pp.getInt64(), (fcml_uint64_t)5 );
292
293 op_pp -= 1;
294
295 STF_ASSERT_EQUAL( (fcml_uint64_t)op_pp.getInt64(), (fcml_uint64_t)4 );
296
297 Integer value_1((fcml_uint8_t)0xFE);
298 Integer value_2((fcml_uint8_t)0x01);
299 Integer value_3 = value_1 + value_2;
300
301 value_1 = *(&value_2);
302
303 STF_ASSERT_EQUAL( value_3.getSize(), FCML_DS_8 );
304 STF_ASSERT_EQUAL( value_3.isSigned(), FCML_FALSE );
305 STF_ASSERT_EQUAL( (fcml_uint8_t)value_3.getInt8(), (fcml_uint8_t)0xFF );
306
307 }
308
309 void fcml_tf_cpp_integer_example(void) {
310
311 Integer v1 = static_cast<fcml_uint8_t>( 10 );
312 Integer v2 = static_cast<fcml_uint8_t>( 20 );
313
314 fcml_uint8_t sum = v1 + v2;
315
316 STF_ASSERT( sum == 30 );
317
318 }
319
320 void fcml_tf_cpp_integer_example_1(void) {
321
322 Integer v1 = (fcml_int64_t)10;
323 Integer v2 = (fcml_uint8_t)20;
324
325 Integer sum = v2 + v1;
326
327 STF_ASSERT( sum == 30 );
328 STF_ASSERT( !sum.isSigned() );
329 STF_ASSERT_EQUAL( sum.getSize(), 8 );
330
331 }
332
333 void fcml_tf_cpp_registers(void) {
334
335 const Register &reg = AL;
336
337 if( reg == Register::AL() ) {
338 STF_ASSERT( true );
339 }
340
341 STF_ASSERT_EQUAL( reg.getReg(), FCML_REG_AL );
342 STF_ASSERT_EQUAL( reg.getSize(), FCML_DS_8 );
343 STF_ASSERT_EQUAL( reg.getType(), Register::REG_GPR );
344 STF_ASSERT_EQUAL( reg.getX64Exp(), FCML_FALSE );
345
346 Register regCons( FCML_REG_AL, FCML_DS_8 );
347
348 STF_ASSERT_EQUAL( regCons.getReg(), FCML_REG_AL );
349 STF_ASSERT_EQUAL( regCons.getSize(), FCML_DS_8 );
350 STF_ASSERT_EQUAL( regCons.getType(), Register::REG_GPR );
351 STF_ASSERT_EQUAL( regCons.getX64Exp(), FCML_FALSE );
352
353 STF_ASSERT( Register::EAX() == EAX );
354 STF_ASSERT( !(Register::EAX() == Register::ECX()) );
355 STF_ASSERT( Register::EAX() != Register::EBX() );
356 STF_ASSERT( !(Register::EAX() != Register::EAX()) );
357 }
358
359 void fcml_tf_cpp_far_pointer(void) {
360
361 FarPointer fp = FarPointer(0x3000, 0x000401000 );
362
363 STF_ASSERT_EQUAL( fp.getSegment(), 0x3000 );
364 STF_ASSERT_EQUAL( fp.getOffset16(), 0x0000 );
365 STF_ASSERT_EQUAL( fp.getOffset32(), 0x000401000 );
366 STF_ASSERT_EQUAL( fp.getOffsetSize(), FCML_DS_32 );
367
368 fp = FarPointer::off32( 0x3000, 0x000401000 );
369
370 STF_ASSERT_EQUAL( fp.getSegment(), 0x3000 );
371 STF_ASSERT_EQUAL( fp.getOffset16(), 0x0000 );
372 STF_ASSERT_EQUAL( fp.getOffset32(), 0x000401000 );
373 STF_ASSERT_EQUAL( fp.getOffsetSize(), FCML_DS_32 );
374
375 fp = FarPointer(0x3000, (fcml_int16_t)0x1212 );
376
377 STF_ASSERT_EQUAL( fp.getSegment(), 0x3000 );
378 STF_ASSERT_EQUAL( fp.getOffset16(), 0x1212 );
379 STF_ASSERT_EQUAL( fp.getOffset32(), 0x0000 );
380 STF_ASSERT_EQUAL( fp.getOffsetSize(), FCML_DS_16 );
381
382 fp = FarPointer::off16( 0x3000, 0x01212 );
383
384 STF_ASSERT_EQUAL( fp.getSegment(), 0x3000 );
385 STF_ASSERT_EQUAL( fp.getOffset16(), 0x1212 );
386 STF_ASSERT_EQUAL( fp.getOffset32(), 0x0000 );
387 STF_ASSERT_EQUAL( fp.getOffsetSize(), FCML_DS_16 );
388
389 }
390
391 void fcml_tf_cpp_segment_selector(void) {
392 SegmentSelector ss(Register::CS(),true);
393 STF_ASSERT_EQUAL( ss.getSegmentSelector().getReg(), FCML_REG_CS );
394 ss = EAX;
395 STF_ASSERT_EQUAL( ss.getSegmentSelector().getReg(), FCML_REG_EAX );
396 Register reg;
397 reg = ss;
398 STF_ASSERT_EQUAL( reg.getReg(), FCML_REG_EAX );
399 }
400
401 void fcml_tf_cpp_effective_address(void) {
402
403 EffectiveAddress empty;
404 STF_ASSERT_EQUAL( empty.getBase(), Register::UNDEF() );
405 STF_ASSERT_EQUAL( empty.getIndex(), Register::UNDEF() );
406 STF_ASSERT_EQUAL( empty.getScaleFactor(), (fcml_uint8_t)0 );
407 STF_ASSERT_EQUAL( empty.getDisplacement(), Integer() );
408
409 EffectiveAddress base( Register::EAX() );
410 STF_ASSERT_EQUAL( base.getBase(), Register::EAX() );
411 STF_ASSERT_EQUAL( base.getIndex(), Register::UNDEF() );
412 STF_ASSERT_EQUAL( base.getScaleFactor(), 0 );
413 STF_ASSERT_EQUAL( base.getDisplacement(), Integer::int8(0) );
414
415 EffectiveAddress base_disp( Register::EAX(), Integer::int8(67) );
416 STF_ASSERT_EQUAL( base_disp.getBase(), Register::EAX() );
417 STF_ASSERT_EQUAL( base_disp.getIndex(), Register::UNDEF() );
418 STF_ASSERT_EQUAL( base_disp.getScaleFactor(), 0 );
419 STF_ASSERT_EQUAL( base_disp.getDisplacement(), Integer::int8(67) );
420
421 EffectiveAddress index_scale_disp( Register::EAX(), 4, Integer::int32(400) );
422 STF_ASSERT_EQUAL( index_scale_disp.getBase(), Register::UNDEF() );
423 STF_ASSERT_EQUAL( index_scale_disp.getIndex(), Register::EAX() );
424 STF_ASSERT_EQUAL( index_scale_disp.getScaleFactor(), 4 );
425 STF_ASSERT_EQUAL( index_scale_disp.getDisplacement(), Integer::int16(400) );
426
427 EffectiveAddress base_index( Register::EAX(), Register::ECX() );
428 STF_ASSERT_EQUAL( base_index.getBase(), Register::EAX() );
429 STF_ASSERT_EQUAL( base_index.getIndex(), Register::ECX() );
430 STF_ASSERT_EQUAL( base_index.getScaleFactor(), 0 );
431 STF_ASSERT_EQUAL( base_index.getDisplacement(), Integer::int8(0) );
432
433 EffectiveAddress base_index_scale( Register::EAX(), Register::ECX(), 4 );
434 STF_ASSERT_EQUAL( base_index_scale.getBase(), Register::EAX() );
435 STF_ASSERT_EQUAL( base_index_scale.getIndex(), Register::ECX() );
436 STF_ASSERT_EQUAL( base_index_scale.getScaleFactor(), 4 );
437
438 EffectiveAddress full( Register::EAX(), Register::EDX(), 1, Integer::int8(67) );
439 STF_ASSERT_EQUAL( full.getBase(), Register::EAX() );
440 STF_ASSERT_EQUAL( full.getIndex(), Register::EDX() );
441 STF_ASSERT_EQUAL( full.getScaleFactor(), 1 );
442 STF_ASSERT_EQUAL( full.getDisplacement(), Integer::int8(67) );
443 }
444
445 void fcml_tf_cpp_effective_address_factory_methods(void) {
446
447 EffectiveAddress base = EffectiveAddress::addr( Register::EAX() );
448 STF_ASSERT_EQUAL( base.getBase(), Register::EAX() );
449 STF_ASSERT_EQUAL( base.getIndex(), Register::UNDEF() );
450 STF_ASSERT_EQUAL( base.getScaleFactor(), 0 );
451 STF_ASSERT_EQUAL( base.getDisplacement(), Integer::int8(0) );
452
453 EffectiveAddress base_disp = EffectiveAddress::addr( Register::EAX(), Integer::int8(67) );
454 STF_ASSERT_EQUAL( base_disp.getBase(), Register::EAX() );
455 STF_ASSERT_EQUAL( base_disp.getIndex(), Register::UNDEF() );
456 STF_ASSERT_EQUAL( base_disp.getScaleFactor(), 0 );
457 STF_ASSERT_EQUAL( base_disp.getDisplacement(), Integer::int8(67) );
458
459 EffectiveAddress index_scale_disp = EffectiveAddress::addr( Register::EAX(), 4, Integer::int32(400) );
460 STF_ASSERT_EQUAL( index_scale_disp.getBase(), Register::UNDEF() );
461 STF_ASSERT_EQUAL( index_scale_disp.getIndex(), Register::EAX() );
462 STF_ASSERT_EQUAL( index_scale_disp.getScaleFactor(), 4 );
463 STF_ASSERT_EQUAL( index_scale_disp.getDisplacement(), Integer::int16(400) );
464
465 EffectiveAddress base_index = EffectiveAddress::addr( Register::EAX(), Register::ECX() );
466 STF_ASSERT_EQUAL( base_index.getBase(), Register::EAX() );
467 STF_ASSERT_EQUAL( base_index.getIndex(), Register::ECX() );
468 STF_ASSERT_EQUAL( base_index.getScaleFactor(), 0 );
469 STF_ASSERT_EQUAL( base_index.getDisplacement(), Integer::int8(0) );
470
471 EffectiveAddress base_index_scale = EffectiveAddress::addr( Register::EAX(), Register::ECX(), 4 );
472 STF_ASSERT_EQUAL( base_index_scale.getBase(), Register::EAX() );
473 STF_ASSERT_EQUAL( base_index_scale.getIndex(), Register::ECX() );
474 STF_ASSERT_EQUAL( base_index_scale.getScaleFactor(), 4 );
475
476 EffectiveAddress full = EffectiveAddress::addr( Register::EAX(), Register::EDX(), 1, Integer::int8(67) );
477 STF_ASSERT_EQUAL( full.getBase(), Register::EAX() );
478 STF_ASSERT_EQUAL( full.getIndex(), Register::EDX() );
479 STF_ASSERT_EQUAL( full.getScaleFactor(), 1 );
480 STF_ASSERT_EQUAL( full.getDisplacement(), Integer::int8(67) );
481 }
482
483 void fcml_tf_cpp_address(void) {
484
485 Address address((fcml_uint32_t)0x401000);
486 STF_ASSERT_EQUAL( address.getAddressForm(), Address::AF_OFFSET );
487 STF_ASSERT_EQUAL( address.getSizeOperator(), FCML_DS_UNDEF );
488 STF_ASSERT_EQUAL( address.isOffset(), true );
489 STF_ASSERT( address.getOffset().getInt32() == 0x401000 );
490 STF_ASSERT_EQUAL( address.getOffset().getSize(), FCML_DS_32 );
491 STF_ASSERT_EQUAL( address.isEffectiveAddress(), false );
492
493 Address addressEffective(EffectiveAddress::addr(Register::EAX()), FCML_DS_32);
494 STF_ASSERT_EQUAL( addressEffective.getAddressForm(), Address::AF_COMBINED );
495 STF_ASSERT_EQUAL( addressEffective.getSizeOperator(), FCML_DS_32 );
496 STF_ASSERT_EQUAL( addressEffective.isOffset(), false );
497 STF_ASSERT_EQUAL( addressEffective.getEffectiveAddress().getBase(), Register::EAX() );
498 STF_ASSERT_EQUAL( addressEffective.isEffectiveAddress(), true );
499
500 addressEffective = Address::effective(EAX, FCML_DS_32);
501 STF_ASSERT_EQUAL( addressEffective.getAddressForm(), Address::AF_COMBINED );
502 STF_ASSERT_EQUAL( addressEffective.getSizeOperator(), FCML_DS_32 );
503 STF_ASSERT_EQUAL( addressEffective.isOffset(), false );
504 STF_ASSERT_EQUAL( addressEffective.getEffectiveAddress().getBase(), Register::EAX() );
505 STF_ASSERT_EQUAL( addressEffective.isEffectiveAddress(), true );
506 }
507
508
509 void fcml_tf_cpp_condition() {
510 Condition condition( Condition::CONDITION_LE, true );
511 STF_ASSERT_EQUAL( condition, Condition::NLE() );
512 if( condition.isNLE() && condition.isNegation() ) {
513 STF_ASSERT( true );
514 } else {
515 STF_ASSERT( false );
516 }
517 if( condition == Condition::NLE() ) {
518 STF_ASSERT( true );
519 } else {
520 STF_ASSERT( false );
521 }
522 }
523
524 void fcml_tf_cpp_operand() {
525
526 Operand imm(0x201000);
527 STF_ASSERT( imm.getImmediate() == (fcml_int32_t)0x201000 );
528 STF_ASSERT( imm.isImm() );
529
530 Operand far_ptr(FarPointer(0x1020, (fcml_int16_t)0x3030));
531 STF_ASSERT( far_ptr.getFarPointer().getSegment() == (fcml_int16_t)0x1020 );
532 STF_ASSERT( far_ptr.getFarPointer().getOffset16() == (fcml_int16_t)0x3030 );
533 STF_ASSERT( far_ptr.isFar() );
534
535 Operand operandImm = OB::imm( 0x401000 );
536 fcml_uint32_t value = operandImm.getImmediate();
537 STF_ASSERT_EQUAL( value, 0x401000 );
538
539 Operand operand;
540 operand.far_ptr(FarPointer(0x1020, (fcml_int16_t)0x3030));
541 STF_ASSERT( operand.getFarPointer().getSegment() == (fcml_int16_t)0x1020 );
542 STF_ASSERT( operand.getFarPointer().getOffset16() == (fcml_int16_t)0x3030 );
543 STF_ASSERT( operand.isFar() );
544
545 operand = OB::far_ptr(0x1020, (fcml_int16_t)0x3030);
546 STF_ASSERT( operand.getFarPointer().getSegment() == (fcml_int16_t)0x1020 );
547 STF_ASSERT( operand.getFarPointer().getOffset16() == (fcml_int16_t)0x3030 );
548 STF_ASSERT( operand.isFar() );
549
550 Operand addrSimple = OB::addr(EffectiveAddress(Register::EAX()));
551 STF_ASSERT( addrSimple.getAddress().isEffectiveAddress() );
552 STF_ASSERT_EQUAL( addrSimple.getAddress().getEffectiveAddress().getBase(), Register::EAX() );
553 STF_ASSERT( addrSimple.isAddr() );
554
555 Operand operandEA;
556 operandEA.addr(EffectiveAddress(Register::EAX()));
557 STF_ASSERT( operandEA.getAddress().isEffectiveAddress() );
558 STF_ASSERT_EQUAL( operandEA.getAddress().getEffectiveAddress().getBase(), Register::EAX() );
559 STF_ASSERT( operandEA.isAddr() );
560
561 Operand address = Operand(Address(EffectiveAddress(Register::EAX())));
562 STF_ASSERT( address.getAddress().isEffectiveAddress() );
563 STF_ASSERT_EQUAL( address.getAddress().getEffectiveAddress().getBase(), Register::EAX() );
564 STF_ASSERT( address.isAddr() );
565
566 Operand regSimple = OB::reg(Register::EAX());
567 STF_ASSERT( regSimple.isReg() );
568 STF_ASSERT_EQUAL( regSimple.getRegister(), Register::EAX() );
569 }
570
571 void fcml_tf_cpp_entry_point() {
572 EntryPoint entryPoint( EntryPoint::OM_32_BIT, 0x401000 );
573 STF_ASSERT_EQUAL( entryPoint.getOpMode(), EntryPoint::OM_32_BIT );
574 STF_ASSERT_EQUAL( entryPoint.getIP(), 0x401000 );
575
576 }
577
578 fcml_stf_test_case fcml_ti_cpp_common[] = {
579 { "fcml_tf_cpp_integer", fcml_tf_cpp_integer },
580 { "fcml_tf_cpp_integer_operator", fcml_tf_cpp_integer_operator },
581 { "fcml_tf_cpp_integer_casting", fcml_tf_cpp_integer_casting },
582 { "fcml_tf_cpp_integer_expressions", fcml_tf_cpp_integer_expressions },
583 { "fcml_tf_cpp_integer_comparisions", fcml_tf_cpp_integer_comparisions },
584 { "fcml_tf_cpp_registers", fcml_tf_cpp_registers },
585 { "fcml_tf_cpp_far_pointer", fcml_tf_cpp_far_pointer },
586 { "fcml_tf_cpp_effective_address", fcml_tf_cpp_effective_address },
587 { "fcml_tf_cpp_effective_address_factory_methods", fcml_tf_cpp_effective_address_factory_methods },
588 { "fcml_tf_cpp_address", fcml_tf_cpp_address },
589 { "fcml_tf_cpp_operand", fcml_tf_cpp_operand },
590 { "fcml_tf_cpp_segment_selector", fcml_tf_cpp_segment_selector },
591 { "fcml_tf_cpp_entry_point", fcml_tf_cpp_entry_point },
592 { "fcml_tf_cpp_integer_example", fcml_tf_cpp_integer_example },
593 { "fcml_tf_cpp_integer_example_1", fcml_tf_cpp_integer_example_1 },
594 { "fcml_tf_cpp_condition", fcml_tf_cpp_condition },
595 FCML_STF_NULL_TEST
596 };
597
598 fcml_stf_test_suite fcml_si_cpp_common = {
599 "suite-fcml-cpp-common", fcml_tf_cpp_common_suite_init, fcml_tf_cpp_common_suite_cleanup, fcml_ti_cpp_common
600 };