struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / ultobcd.c
blob01d33911ef582878d40a162447db77f1912026d8
1 /*
2 ultobcd.c
3 */
5 #include <testfwk.h>
6 #include <stdio.h>
8 extern void __ultobcd (unsigned long v, unsigned char r[5]);
9 #define CHECK(v) \
10 do { \
11 static const unsigned char u[5] = { 0x##v % 0x100, (0x##v / 0x100) % 0x100, (0x##v / 0x10000) % 0x100, (0x##v / 0x1000000) % 0x100, (0x##v / 0x100000000) % 0x100 }; \
12 unsigned char r[5] = { 0xff, 0xff, 0xff, 0xff, 0xff }; \
13 __ultobcd (v, r); \
14 unsigned long bcd = r[4] * 0x100000000 + r[3] * 0x1000000 + r[2] * 0x10000 + r[1] * 0x100 + r[0]; \
15 ASSERT ((#v,(r[0]==u[0]&&r[1]==u[1]&&r[2]==u[2]&&r[3]==u[3]&&r[4]==u[4]))); \
16 } while (0)
18 void test__ultobcd (void)
20 #if defined(__SDCC_z80)
21 CHECK(0);
22 CHECK(1);
23 CHECK(2);
24 CHECK(9);
25 CHECK(10);
26 CHECK(11);
27 CHECK(15);
28 CHECK(16);
29 CHECK(100000);
30 CHECK(345678);
31 CHECK(2345678);
32 CHECK(12345678);
33 CHECK(16777215); //0x00ffffff
34 CHECK(234567890);
35 CHECK(2147483647); //0x7fffffff
36 CHECK(2147483648); //0x80000000
37 CHECK(3000000000);
38 CHECK(3999999999);
39 CHECK(4000000000);
40 CHECK(4294967295); //0xffffffff
41 #endif