File: common_t.cpp

package info (click to toggle)
fcml 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,536 kB
  • sloc: ansic: 57,510; cpp: 21,835; sh: 4,410; lex: 834; makefile: 508; yacc: 317
file content (600 lines) | stat: -rw-r--r-- 24,664 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
/*
 * FCML - Free Code Manipulation Library.
 * Copyright (C) 2010-2020 Slawomir Wojtasiak
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

/* Test suite initialization. */

#include "common_t.hpp"

#include <fcml_errors.h>
#include <fcml_common.hpp>
#include <fcml_errors.hpp>
#include <fcml_registers.hpp>

using namespace fcml;

fcml_bool fcml_tf_cpp_common_suite_init(void) {
    return FCML_TRUE;
}

fcml_bool fcml_tf_cpp_common_suite_cleanup(void) {
    return FCML_TRUE;
}


void fcml_tf_cpp_integer(void) {

    Integer i1_fcml_uint8_t((fcml_uint8_t)0xFF);
    Integer i1_fcml_int8_t((fcml_int8_t)0xFF);
    Integer i1_fcml_uint16_t((fcml_uint16_t)0xFFFF);
    Integer i1_fcml_int16_t((fcml_int16_t)0xFFFF);
    Integer i1_fcml_uint32_t((fcml_uint32_t)0xFFFFFFFF);
    Integer i1_fcml_int32_t((fcml_int32_t)0xFFFFFFFF);
    Integer i1_fcml_uint64_t((fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL);
    Integer i1_fcml_int64_t((fcml_int64_t)0xFFFFFFFFFFFFFFFFUL);

    STF_ASSERT_EQUAL( (fcml_uint8_t)i1_fcml_uint8_t.getInt8(), (fcml_uint8_t)0xFF );
    STF_ASSERT_EQUAL( i1_fcml_uint8_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint8_t.getSize(), FCML_DS_8 );

    STF_ASSERT_EQUAL( (fcml_int8_t)i1_fcml_int8_t.getInt8(), (fcml_int8_t)0xFF );
    STF_ASSERT_EQUAL( i1_fcml_int8_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int8_t.getSize(), FCML_DS_8 );

    STF_ASSERT_EQUAL( (fcml_uint16_t)i1_fcml_uint16_t.getInt16(), (fcml_uint16_t)0xFFFF );
    STF_ASSERT_EQUAL( i1_fcml_uint16_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint16_t.getSize(), FCML_DS_16 );

    STF_ASSERT_EQUAL( (fcml_int16_t)i1_fcml_int16_t.getInt16(), (fcml_int16_t)0xFFFF );
    STF_ASSERT_EQUAL( i1_fcml_int16_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int16_t.getSize(), FCML_DS_16 );

    STF_ASSERT_EQUAL( (fcml_uint32_t)i1_fcml_uint32_t.getInt32(), (fcml_uint32_t)0xFFFFFFFF );
    STF_ASSERT_EQUAL( i1_fcml_uint32_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint32_t.getSize(), FCML_DS_32 );

    STF_ASSERT_EQUAL( (fcml_int32_t)i1_fcml_int32_t.getInt32(), (fcml_int32_t)0xFFFFFFFF );
    STF_ASSERT_EQUAL( i1_fcml_int32_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int32_t.getSize(), FCML_DS_32 );

    STF_ASSERT_EQUAL( (fcml_uint64_t)i1_fcml_uint64_t.getInt64(), (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL );
    STF_ASSERT_EQUAL( i1_fcml_uint64_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint64_t.getSize(), FCML_DS_64 );

    STF_ASSERT_EQUAL( (fcml_int64_t)i1_fcml_int64_t.getInt64(), (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL );
    STF_ASSERT_EQUAL( i1_fcml_int64_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int64_t.getSize(), FCML_DS_64 );

}

void fcml_tf_cpp_integer_operator(void) {

    Integer i1_fcml_uint8_t = (fcml_uint8_t)0xFF;
    Integer i1_fcml_int8_t = (fcml_int8_t)0xFF;
    Integer i1_fcml_uint16_t = (fcml_uint16_t)0xFFFF;
    Integer i1_fcml_int16_t = (fcml_int16_t)0xFFFF;
    Integer i1_fcml_uint32_t = (fcml_uint32_t)0xFFFFFFFF;
    Integer i1_fcml_int32_t = (fcml_int32_t)0xFFFFFFFF;
    Integer i1_fcml_uint64_t = (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL;
    Integer i1_fcml_int64_t = (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL;

    STF_ASSERT_EQUAL( (fcml_uint8_t)i1_fcml_uint8_t.getInt8(), (fcml_uint8_t)0xFF );
    STF_ASSERT_EQUAL( i1_fcml_uint8_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint8_t.getSize(), FCML_DS_8 );

    STF_ASSERT_EQUAL( (fcml_int8_t)i1_fcml_int8_t.getInt8(), (fcml_int8_t)0xFF );
    STF_ASSERT_EQUAL( i1_fcml_int8_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int8_t.getSize(), FCML_DS_8 );

    STF_ASSERT_EQUAL( (fcml_uint16_t)i1_fcml_uint16_t.getInt16(), (fcml_uint16_t)0xFFFF );
    STF_ASSERT_EQUAL( i1_fcml_uint16_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint16_t.getSize(), FCML_DS_16 );

    STF_ASSERT_EQUAL( (fcml_int16_t)i1_fcml_int16_t.getInt16(), (fcml_int16_t)0xFFFF );
    STF_ASSERT_EQUAL( i1_fcml_int16_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int16_t.getSize(), FCML_DS_16 );

    STF_ASSERT_EQUAL( (fcml_uint32_t)i1_fcml_uint32_t.getInt32(), (fcml_uint32_t)0xFFFFFFFF );
    STF_ASSERT_EQUAL( i1_fcml_uint32_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint32_t.getSize(), FCML_DS_32 );

    STF_ASSERT_EQUAL( (fcml_int32_t)i1_fcml_int32_t.getInt32(), (fcml_int32_t)0xFFFFFFFF );
    STF_ASSERT_EQUAL( i1_fcml_int32_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int32_t.getSize(), FCML_DS_32 );

    STF_ASSERT_EQUAL( (fcml_uint64_t)i1_fcml_uint64_t.getInt64(), (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL );
    STF_ASSERT_EQUAL( i1_fcml_uint64_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint64_t.getSize(), FCML_DS_64 );

    STF_ASSERT_EQUAL( (fcml_int64_t)i1_fcml_int64_t.getInt64(), (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL );
    STF_ASSERT_EQUAL( i1_fcml_int64_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int64_t.getSize(), FCML_DS_64 );

}

void fcml_tf_cpp_integer_copy(void) {

    Integer i1c_fcml_uint8_t = (fcml_uint8_t)0xFF;
    Integer i1c_fcml_int8_t = (fcml_int8_t)0xFF;
    Integer i1c_fcml_uint16_t = (fcml_uint16_t)0xFFFF;
    Integer i1c_fcml_int16_t = (fcml_int16_t)0xFFFF;
    Integer i1c_fcml_uint32_t = (fcml_uint32_t)0xFFFFFFFF;
    Integer i1c_fcml_int32_t = (fcml_int32_t)0xFFFFFFFF;
    Integer i1c_fcml_uint64_t = (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL;
    Integer i1c_fcml_int64_t = (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL;

    Integer i1_fcml_uint8_t = i1c_fcml_uint8_t;
    Integer i1_fcml_int8_t = i1c_fcml_int8_t;
    Integer i1_fcml_uint16_t = i1c_fcml_uint16_t;
    Integer i1_fcml_int16_t = i1c_fcml_int16_t;
    Integer i1_fcml_uint32_t = i1c_fcml_uint32_t;
    Integer i1_fcml_int32_t = i1c_fcml_int32_t;
    Integer i1_fcml_uint64_t = i1c_fcml_uint64_t;
    Integer i1_fcml_int64_t = i1c_fcml_int64_t;

    i1c_fcml_uint8_t = 0;
    i1c_fcml_int8_t = 0;
    i1c_fcml_uint16_t = 0;
    i1c_fcml_int16_t = 0;
    i1c_fcml_uint32_t = 0;
    i1c_fcml_int32_t = 0;
    i1c_fcml_uint64_t = 0;
    i1c_fcml_int64_t = 0;

    STF_ASSERT_EQUAL( (fcml_uint8_t)i1_fcml_uint8_t.getInt8(), (fcml_uint8_t)0xFF );
    STF_ASSERT_EQUAL( i1_fcml_uint8_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint8_t.getSize(), FCML_DS_8 );

    STF_ASSERT_EQUAL( (fcml_int8_t)i1_fcml_int8_t.getInt8(), (fcml_int8_t)0xFF );
    STF_ASSERT_EQUAL( i1_fcml_int8_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int8_t.getSize(), FCML_DS_8 );

    STF_ASSERT_EQUAL( (fcml_uint16_t)i1_fcml_uint16_t.getInt16(), (fcml_uint16_t)0xFFFF );
    STF_ASSERT_EQUAL( i1_fcml_uint16_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint16_t.getSize(), FCML_DS_16 );

    STF_ASSERT_EQUAL( (fcml_int16_t)i1_fcml_int16_t.getInt16(), (fcml_int16_t)0xFFFF );
    STF_ASSERT_EQUAL( i1_fcml_int16_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int16_t.getSize(), FCML_DS_16 );

    STF_ASSERT_EQUAL( (fcml_uint32_t)i1_fcml_uint32_t.getInt32(), (fcml_uint32_t)0xFFFFFFFF );
    STF_ASSERT_EQUAL( i1_fcml_uint32_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint32_t.getSize(), FCML_DS_32 );

    STF_ASSERT_EQUAL( (fcml_int32_t)i1_fcml_int32_t.getInt32(), (fcml_int32_t)0xFFFFFFFF );
    STF_ASSERT_EQUAL( i1_fcml_int32_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int32_t.getSize(), FCML_DS_32 );

    STF_ASSERT_EQUAL( (fcml_uint64_t)i1_fcml_uint64_t.getInt64(), (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL );
    STF_ASSERT_EQUAL( i1_fcml_uint64_t.isSigned(), FCML_FALSE );
    STF_ASSERT_EQUAL( i1_fcml_uint64_t.getSize(), FCML_DS_64 );

    STF_ASSERT_EQUAL( (fcml_int64_t)i1_fcml_int64_t.getInt64(), (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL );
    STF_ASSERT_EQUAL( i1_fcml_int64_t.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( i1_fcml_int64_t.getSize(), FCML_DS_64 );

}

void fcml_tf_cpp_integer_casting(void) {

    Integer i1c_fcml_uint8_t = (fcml_uint8_t)0xFF;
    Integer i1c_fcml_int8_t = (fcml_int8_t)0xFF;
    Integer i1c_fcml_uint16_t = (fcml_uint16_t)0xFFFF;
    Integer i1c_fcml_int16_t = (fcml_int16_t)0xFFFF;
    Integer i1c_fcml_uint32_t = (fcml_uint32_t)0xFFFFFFFF;
    Integer i1c_fcml_int32_t = (fcml_int32_t)0xFFFFFFFF;
    Integer i1c_fcml_uint64_t = (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL;
    Integer i1c_fcml_int64_t = (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL;

    fcml_uint8_t  i1_fcml_uint8_t  = i1c_fcml_uint8_t;
    fcml_int8_t   i1_fcml_int8_t   = i1c_fcml_int8_t;
    fcml_uint16_t i1_fcml_uint16_t = i1c_fcml_uint16_t;
    fcml_int16_t  i1_fcml_int16_t  = i1c_fcml_int16_t;
    fcml_uint32_t i1_fcml_uint32_t = i1c_fcml_uint32_t;
    fcml_int32_t  i1_fcml_int32_t  = i1c_fcml_int32_t;
    fcml_uint64_t i1_fcml_uint64_t = i1c_fcml_uint64_t;
    fcml_int64_t  i1_fcml_int64_t  = i1c_fcml_int64_t;

    STF_ASSERT_EQUAL( i1_fcml_uint8_t, (fcml_uint8_t)0xFF );
    STF_ASSERT_EQUAL( i1_fcml_int8_t, (fcml_int8_t)0xFF );
    STF_ASSERT_EQUAL( i1_fcml_uint16_t, (fcml_uint16_t)0xFFFF );
    STF_ASSERT_EQUAL( i1_fcml_int16_t, (fcml_int16_t)0xFFFF );
    STF_ASSERT_EQUAL( i1_fcml_uint32_t, (fcml_uint32_t)0xFFFFFFFF );
    STF_ASSERT_EQUAL( i1_fcml_int32_t, (fcml_int32_t)0xFFFFFFFF );
    STF_ASSERT_EQUAL( i1_fcml_uint64_t, (fcml_uint64_t)0xFFFFFFFFFFFFFFFFUL );
    STF_ASSERT_EQUAL( i1_fcml_int64_t, (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL );

    // Conversion.

    fcml_uint8_t conveted = i1c_fcml_int64_t;
    STF_ASSERT_EQUAL( conveted, (fcml_uint8_t)0xFF );

}

void fcml_tf_cpp_integer_comparisions(void) {

    Integer int1 = (fcml_int16_t)-1;
    Integer int2 = (fcml_int8_t)-1;
    Integer int3 = (fcml_int8_t)18;

    STF_ASSERT( int1 == int2 );
    STF_ASSERT( !(int1 != int2) );
    STF_ASSERT( int1 != int3 );

    Integer int4 = (fcml_uint8_t)0xFF;
    Integer int5 = (fcml_uint16_t)0xFFFF;
    Integer int6 = (fcml_uint32_t)0xFFFF;

    STF_ASSERT( int4 != int5 );
    STF_ASSERT( int5 == int6 );
}

void fcml_tf_cpp_integer_expressions(void) {

    const Integer i1c_fcml_uint8_t = (fcml_uint8_t)0xFF;
    const Integer i1c_fcml_int64_t = (fcml_int64_t)0xFFFFFFFFFFFFFFFFUL;

    // 255 + -1 = 254

    const Integer resultInt = i1c_fcml_int64_t + i1c_fcml_uint8_t;

    STF_ASSERT_EQUAL( resultInt.getSize(), FCML_DS_64 );
    STF_ASSERT_EQUAL( resultInt.isSigned(), FCML_TRUE );
    STF_ASSERT_EQUAL( resultInt.getInt64(), (fcml_int64_t)254 );

    fcml_uint8_t result  = i1c_fcml_int64_t + i1c_fcml_uint8_t;

    STF_ASSERT_EQUAL( result, (fcml_uint8_t)254 );

    Integer i1i_fcml_uint8_t = (fcml_uint8_t)4;
    Integer i1i_fcml_int64_t = (fcml_int64_t)8;

    result  = i1i_fcml_int64_t / i1i_fcml_uint8_t;

    STF_ASSERT_EQUAL( result, (fcml_uint8_t)2 );

    result  = i1i_fcml_int64_t * i1i_fcml_uint8_t;

    STF_ASSERT_EQUAL( result, (fcml_uint8_t)32 );

    result  = i1i_fcml_int64_t - i1i_fcml_uint8_t;

    STF_ASSERT_EQUAL( result, (fcml_uint8_t)4 );

    Integer op_pp;

    op_pp += 10;

    STF_ASSERT_EQUAL( (fcml_uint64_t)op_pp.getInt64(), (fcml_uint64_t)10 );

    op_pp *= 2;

    STF_ASSERT_EQUAL( (fcml_uint64_t)op_pp.getInt64(), (fcml_uint64_t)20 );

    op_pp /= 4;

    STF_ASSERT_EQUAL( (fcml_uint64_t)op_pp.getInt64(), (fcml_uint64_t)5 );

    op_pp -= 1;

    STF_ASSERT_EQUAL( (fcml_uint64_t)op_pp.getInt64(), (fcml_uint64_t)4 );

    Integer value_1((fcml_uint8_t)0xFE);
	Integer value_2((fcml_uint8_t)0x01);
	Integer value_3 = value_1 + value_2;

	value_1 = *(&value_2);

	STF_ASSERT_EQUAL( value_3.getSize(), FCML_DS_8 );
	STF_ASSERT_EQUAL( value_3.isSigned(), FCML_FALSE );
	STF_ASSERT_EQUAL( (fcml_uint8_t)value_3.getInt8(), (fcml_uint8_t)0xFF );

}

void fcml_tf_cpp_integer_example(void) {

    Integer v1 = static_cast<fcml_uint8_t>( 10 );
    Integer v2 = static_cast<fcml_uint8_t>( 20 );

    fcml_uint8_t sum = v1 + v2;

    STF_ASSERT( sum == 30 );

}

void fcml_tf_cpp_integer_example_1(void) {

    Integer v1 = (fcml_int64_t)10;
    Integer v2 = (fcml_uint8_t)20;

    Integer sum = v2 + v1;

    STF_ASSERT( sum == 30 );
    STF_ASSERT( !sum.isSigned() );
    STF_ASSERT_EQUAL( sum.getSize(), 8 );

}

void fcml_tf_cpp_registers(void) {

    const Register &reg = AL;

    if( reg == Register::AL() ) {
        STF_ASSERT( true );
    }

    STF_ASSERT_EQUAL( reg.getReg(), FCML_REG_AL );
    STF_ASSERT_EQUAL( reg.getSize(), FCML_DS_8 );
    STF_ASSERT_EQUAL( reg.getType(), Register::REG_GPR );
    STF_ASSERT_EQUAL( reg.getX64Exp(), FCML_FALSE );

    Register regCons( FCML_REG_AL, FCML_DS_8 );

    STF_ASSERT_EQUAL( regCons.getReg(), FCML_REG_AL );
    STF_ASSERT_EQUAL( regCons.getSize(), FCML_DS_8 );
    STF_ASSERT_EQUAL( regCons.getType(), Register::REG_GPR );
    STF_ASSERT_EQUAL( regCons.getX64Exp(), FCML_FALSE );

    STF_ASSERT( Register::EAX() == EAX );
    STF_ASSERT( !(Register::EAX() == Register::ECX()) );
    STF_ASSERT( Register::EAX() != Register::EBX() );
    STF_ASSERT( !(Register::EAX() != Register::EAX()) );
}

void fcml_tf_cpp_far_pointer(void) {

    FarPointer fp = FarPointer(0x3000, 0x000401000 );

    STF_ASSERT_EQUAL( fp.getSegment(), 0x3000 );
    STF_ASSERT_EQUAL( fp.getOffset16(), 0x0000 );
    STF_ASSERT_EQUAL( fp.getOffset32(), 0x000401000 );
    STF_ASSERT_EQUAL( fp.getOffsetSize(), FCML_DS_32 );

    fp = FarPointer::off32( 0x3000, 0x000401000 );

    STF_ASSERT_EQUAL( fp.getSegment(), 0x3000 );
    STF_ASSERT_EQUAL( fp.getOffset16(), 0x0000 );
    STF_ASSERT_EQUAL( fp.getOffset32(), 0x000401000 );
    STF_ASSERT_EQUAL( fp.getOffsetSize(), FCML_DS_32 );

    fp = FarPointer(0x3000, (fcml_int16_t)0x1212 );

    STF_ASSERT_EQUAL( fp.getSegment(), 0x3000 );
    STF_ASSERT_EQUAL( fp.getOffset16(), 0x1212 );
    STF_ASSERT_EQUAL( fp.getOffset32(), 0x0000 );
    STF_ASSERT_EQUAL( fp.getOffsetSize(), FCML_DS_16 );

    fp = FarPointer::off16( 0x3000, 0x01212 );

    STF_ASSERT_EQUAL( fp.getSegment(), 0x3000 );
    STF_ASSERT_EQUAL( fp.getOffset16(), 0x1212 );
    STF_ASSERT_EQUAL( fp.getOffset32(), 0x0000 );
    STF_ASSERT_EQUAL( fp.getOffsetSize(), FCML_DS_16 );

}

void fcml_tf_cpp_segment_selector(void) {
    SegmentSelector ss(Register::CS(),true);
    STF_ASSERT_EQUAL( ss.getSegmentSelector().getReg(), FCML_REG_CS );
    ss = EAX;
    STF_ASSERT_EQUAL( ss.getSegmentSelector().getReg(), FCML_REG_EAX );
    Register reg;
    reg = ss;
    STF_ASSERT_EQUAL( reg.getReg(), FCML_REG_EAX );
}

void fcml_tf_cpp_effective_address(void) {

    EffectiveAddress empty;
    STF_ASSERT_EQUAL( empty.getBase(), Register::UNDEF() );
    STF_ASSERT_EQUAL( empty.getIndex(), Register::UNDEF() );
    STF_ASSERT_EQUAL( empty.getScaleFactor(), (fcml_uint8_t)0 );
    STF_ASSERT_EQUAL( empty.getDisplacement(), Integer() );

    EffectiveAddress base( Register::EAX() );
    STF_ASSERT_EQUAL( base.getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( base.getIndex(), Register::UNDEF() );
    STF_ASSERT_EQUAL( base.getScaleFactor(), 0 );
    STF_ASSERT_EQUAL( base.getDisplacement(), Integer::int8(0) );

    EffectiveAddress base_disp( Register::EAX(), Integer::int8(67) );
    STF_ASSERT_EQUAL( base_disp.getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( base_disp.getIndex(), Register::UNDEF() );
    STF_ASSERT_EQUAL( base_disp.getScaleFactor(), 0 );
    STF_ASSERT_EQUAL( base_disp.getDisplacement(), Integer::int8(67) );

    EffectiveAddress index_scale_disp( Register::EAX(), 4, Integer::int32(400) );
    STF_ASSERT_EQUAL( index_scale_disp.getBase(), Register::UNDEF() );
    STF_ASSERT_EQUAL( index_scale_disp.getIndex(), Register::EAX() );
    STF_ASSERT_EQUAL( index_scale_disp.getScaleFactor(), 4 );
    STF_ASSERT_EQUAL( index_scale_disp.getDisplacement(), Integer::int16(400) );

    EffectiveAddress base_index( Register::EAX(), Register::ECX() );
    STF_ASSERT_EQUAL( base_index.getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( base_index.getIndex(), Register::ECX() );
    STF_ASSERT_EQUAL( base_index.getScaleFactor(), 0 );
    STF_ASSERT_EQUAL( base_index.getDisplacement(), Integer::int8(0) );

    EffectiveAddress base_index_scale( Register::EAX(), Register::ECX(), 4 );
    STF_ASSERT_EQUAL( base_index_scale.getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( base_index_scale.getIndex(), Register::ECX() );
    STF_ASSERT_EQUAL( base_index_scale.getScaleFactor(), 4 );

    EffectiveAddress full( Register::EAX(), Register::EDX(), 1, Integer::int8(67) );
    STF_ASSERT_EQUAL( full.getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( full.getIndex(), Register::EDX() );
    STF_ASSERT_EQUAL( full.getScaleFactor(), 1 );
    STF_ASSERT_EQUAL( full.getDisplacement(), Integer::int8(67) );
}

void fcml_tf_cpp_effective_address_factory_methods(void) {

    EffectiveAddress base = EffectiveAddress::addr( Register::EAX() );
    STF_ASSERT_EQUAL( base.getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( base.getIndex(), Register::UNDEF() );
    STF_ASSERT_EQUAL( base.getScaleFactor(), 0 );
    STF_ASSERT_EQUAL( base.getDisplacement(), Integer::int8(0) );

    EffectiveAddress base_disp = EffectiveAddress::addr( Register::EAX(), Integer::int8(67) );
    STF_ASSERT_EQUAL( base_disp.getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( base_disp.getIndex(), Register::UNDEF() );
    STF_ASSERT_EQUAL( base_disp.getScaleFactor(), 0 );
    STF_ASSERT_EQUAL( base_disp.getDisplacement(), Integer::int8(67) );

    EffectiveAddress index_scale_disp = EffectiveAddress::addr( Register::EAX(), 4, Integer::int32(400) );
    STF_ASSERT_EQUAL( index_scale_disp.getBase(), Register::UNDEF() );
    STF_ASSERT_EQUAL( index_scale_disp.getIndex(), Register::EAX() );
    STF_ASSERT_EQUAL( index_scale_disp.getScaleFactor(), 4 );
    STF_ASSERT_EQUAL( index_scale_disp.getDisplacement(), Integer::int16(400) );

    EffectiveAddress base_index = EffectiveAddress::addr( Register::EAX(), Register::ECX() );
    STF_ASSERT_EQUAL( base_index.getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( base_index.getIndex(), Register::ECX() );
    STF_ASSERT_EQUAL( base_index.getScaleFactor(), 0 );
    STF_ASSERT_EQUAL( base_index.getDisplacement(), Integer::int8(0) );

    EffectiveAddress base_index_scale = EffectiveAddress::addr( Register::EAX(), Register::ECX(), 4 );
    STF_ASSERT_EQUAL( base_index_scale.getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( base_index_scale.getIndex(), Register::ECX() );
    STF_ASSERT_EQUAL( base_index_scale.getScaleFactor(), 4 );

    EffectiveAddress full = EffectiveAddress::addr( Register::EAX(), Register::EDX(), 1, Integer::int8(67) );
    STF_ASSERT_EQUAL( full.getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( full.getIndex(), Register::EDX() );
    STF_ASSERT_EQUAL( full.getScaleFactor(), 1 );
    STF_ASSERT_EQUAL( full.getDisplacement(), Integer::int8(67) );
}

void fcml_tf_cpp_address(void) {

    Address address((fcml_uint32_t)0x401000);
    STF_ASSERT_EQUAL( address.getAddressForm(), Address::AF_OFFSET );
    STF_ASSERT_EQUAL( address.getSizeOperator(), FCML_DS_UNDEF );
    STF_ASSERT_EQUAL( address.isOffset(), true );
    STF_ASSERT( address.getOffset().getInt32() == 0x401000 );
    STF_ASSERT_EQUAL( address.getOffset().getSize(), FCML_DS_32 );
    STF_ASSERT_EQUAL( address.isEffectiveAddress(), false );

    Address addressEffective(EffectiveAddress::addr(Register::EAX()), FCML_DS_32);
    STF_ASSERT_EQUAL( addressEffective.getAddressForm(), Address::AF_COMBINED );
    STF_ASSERT_EQUAL( addressEffective.getSizeOperator(), FCML_DS_32 );
    STF_ASSERT_EQUAL( addressEffective.isOffset(), false );
    STF_ASSERT_EQUAL( addressEffective.getEffectiveAddress().getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( addressEffective.isEffectiveAddress(), true );

    addressEffective = Address::effective(EAX, FCML_DS_32);
    STF_ASSERT_EQUAL( addressEffective.getAddressForm(), Address::AF_COMBINED );
    STF_ASSERT_EQUAL( addressEffective.getSizeOperator(), FCML_DS_32 );
    STF_ASSERT_EQUAL( addressEffective.isOffset(), false );
    STF_ASSERT_EQUAL( addressEffective.getEffectiveAddress().getBase(), Register::EAX() );
    STF_ASSERT_EQUAL( addressEffective.isEffectiveAddress(), true );
}


void fcml_tf_cpp_condition() {
    Condition condition( Condition::CONDITION_LE, true );
    STF_ASSERT_EQUAL( condition, Condition::NLE() );
    if( condition.isNLE() && condition.isNegation() ) {
        STF_ASSERT( true );
    } else {
        STF_ASSERT( false );
    }
    if( condition == Condition::NLE() ) {
        STF_ASSERT( true );
    } else {
        STF_ASSERT( false );
    }
}

void fcml_tf_cpp_operand() {

    Operand imm(0x201000);
    STF_ASSERT( imm.getImmediate() == (fcml_int32_t)0x201000 );
    STF_ASSERT( imm.isImm() );

    Operand far_ptr(FarPointer(0x1020, (fcml_int16_t)0x3030));
    STF_ASSERT( far_ptr.getFarPointer().getSegment() == (fcml_int16_t)0x1020 );
    STF_ASSERT( far_ptr.getFarPointer().getOffset16() == (fcml_int16_t)0x3030 );
    STF_ASSERT( far_ptr.isFar() );

    Operand operandImm = OB::imm( 0x401000 );
    fcml_uint32_t value = operandImm.getImmediate();
    STF_ASSERT_EQUAL( value, 0x401000 );

    Operand operand;
    operand.far_ptr(FarPointer(0x1020, (fcml_int16_t)0x3030));
    STF_ASSERT( operand.getFarPointer().getSegment() == (fcml_int16_t)0x1020 );
    STF_ASSERT( operand.getFarPointer().getOffset16() == (fcml_int16_t)0x3030 );
    STF_ASSERT( operand.isFar() );

    operand = OB::far_ptr(0x1020, (fcml_int16_t)0x3030);
    STF_ASSERT( operand.getFarPointer().getSegment() == (fcml_int16_t)0x1020 );
    STF_ASSERT( operand.getFarPointer().getOffset16() == (fcml_int16_t)0x3030 );
    STF_ASSERT( operand.isFar() );

    Operand addrSimple = OB::addr(EffectiveAddress(Register::EAX()));
    STF_ASSERT( addrSimple.getAddress().isEffectiveAddress() );
    STF_ASSERT_EQUAL( addrSimple.getAddress().getEffectiveAddress().getBase(), Register::EAX() );
    STF_ASSERT( addrSimple.isAddr() );

    Operand operandEA;
    operandEA.addr(EffectiveAddress(Register::EAX()));
    STF_ASSERT( operandEA.getAddress().isEffectiveAddress() );
    STF_ASSERT_EQUAL( operandEA.getAddress().getEffectiveAddress().getBase(), Register::EAX() );
    STF_ASSERT( operandEA.isAddr() );

	Operand address = Operand(Address(EffectiveAddress(Register::EAX())));
    STF_ASSERT( address.getAddress().isEffectiveAddress() );
    STF_ASSERT_EQUAL( address.getAddress().getEffectiveAddress().getBase(), Register::EAX() );
    STF_ASSERT( address.isAddr() );

    Operand regSimple = OB::reg(Register::EAX());
    STF_ASSERT( regSimple.isReg() );
    STF_ASSERT_EQUAL( regSimple.getRegister(), Register::EAX() );
}

void fcml_tf_cpp_entry_point() {
    EntryPoint entryPoint( EntryPoint::OM_32_BIT, 0x401000 );
    STF_ASSERT_EQUAL( entryPoint.getOpMode(), EntryPoint::OM_32_BIT );
    STF_ASSERT_EQUAL( entryPoint.getIP(), 0x401000 );

}

fcml_stf_test_case fcml_ti_cpp_common[] = {
    { "fcml_tf_cpp_integer", fcml_tf_cpp_integer },
    { "fcml_tf_cpp_integer_operator", fcml_tf_cpp_integer_operator },
    { "fcml_tf_cpp_integer_casting", fcml_tf_cpp_integer_casting },
    { "fcml_tf_cpp_integer_expressions", fcml_tf_cpp_integer_expressions },
    { "fcml_tf_cpp_integer_comparisions", fcml_tf_cpp_integer_comparisions },
    { "fcml_tf_cpp_registers", fcml_tf_cpp_registers },
    { "fcml_tf_cpp_far_pointer", fcml_tf_cpp_far_pointer },
    { "fcml_tf_cpp_effective_address", fcml_tf_cpp_effective_address },
    { "fcml_tf_cpp_effective_address_factory_methods", fcml_tf_cpp_effective_address_factory_methods },
    { "fcml_tf_cpp_address", fcml_tf_cpp_address },
    { "fcml_tf_cpp_operand", fcml_tf_cpp_operand },
    { "fcml_tf_cpp_segment_selector", fcml_tf_cpp_segment_selector },
    { "fcml_tf_cpp_entry_point", fcml_tf_cpp_entry_point },
    { "fcml_tf_cpp_integer_example", fcml_tf_cpp_integer_example },
    { "fcml_tf_cpp_integer_example_1", fcml_tf_cpp_integer_example_1 },
    { "fcml_tf_cpp_condition", fcml_tf_cpp_condition },
    FCML_STF_NULL_TEST
};

fcml_stf_test_suite fcml_si_cpp_common = {
    "suite-fcml-cpp-common", fcml_tf_cpp_common_suite_init, fcml_tf_cpp_common_suite_cleanup, fcml_ti_cpp_common
};