#include #include #include #include "dk3maul.h" #include "dk3mastr.h" #include "dk3numco.h" $!trace-include static void test_um_hex(void) { char buf[64]; dk3_um_t x; x = 0; if (dk3ma_um_to_c8_hex_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 1; if (dk3ma_um_to_c8_hex_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 4095; if (dk3ma_um_to_c8_hex_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 4096; if (dk3ma_um_to_c8_hex_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 18446744073709551614ULL; if (dk3ma_um_to_c8_hex_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 18446744073709551615ULL; if (dk3ma_um_to_c8_hex_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 18446744073709551616ULL; if (dk3ma_um_to_c8_hex_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } } static void test_um(void) { char buf[64]; dk3_um_t x; x = 0; if (dk3ma_um_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 1; if (dk3ma_um_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 4095; if (dk3ma_um_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 4096; if (dk3ma_um_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 18446744073709551614ULL; if (dk3ma_um_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 18446744073709551615ULL; if (dk3ma_um_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 18446744073709551616ULL; if (dk3ma_um_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } } static void test_im(void) { char buf[64]; dk3_im_t x; x = DK3_IM_MIN; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = -9223372036854775808LL; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = -9223372036854775807LL; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = -4097L; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = -4096L; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = -4095L; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 0L; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 8191L; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 8192L; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 8193L; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 9223372036854775806LL; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 9223372036854775807LL; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } x = 9223372036854775808LL; if (dk3ma_im_to_c8_string(buf, sizeof(buf), x)) { fputs(buf, stdout); fputc('\n', stdout); } } static char const * test_ma_strings[] = { $!string-table -18446744073709551617 -18446744073709551616 -18446744073709551615 -18446744073709551614 -9223372036854775809 -9223372036854775808 -9223372036854775807 -42949672967blablubb -42949672967 -4294967295 -2147483649 -2147483648 -2147483647 -65537 -65536 -65535 -32769 -32768 -32767 -4097 -4096 -4095 -25 0 1 4095 4096 4097 32767 32768 32769 65535 65536 65537 2147483647 2147483648 2147483649 4294967295 42949672967 42949672967blablubb 9223372036854775807 9223372036854775808 9223372036854775809 18446744073709551614 18446744073709551615 18446744073709551616 18446744073709551617 $!end }; static void test_ma_read_um(void) { char buf[128]; char const **ptr; dk3_um_t umval; int mec; int res; ptr = test_ma_strings; while(*ptr) { printf("String: \"%s\"\n", *ptr); mec = 0; res = dk3ma_um_from_c8_string(&umval, *ptr, &mec); printf("Result: %d\n", res); printf("EC: %d\n", mec); if (res) { if (dk3ma_um_to_c8_string(buf, sizeof(buf), umval)) { printf("Number: %s\n", buf); } else { printf("Failed to convert number to string!\n"); } } printf("\n"); ptr++; } } static void test_ma_read_im(void) { char buf[128]; char const **ptr; dk3_im_t imval; int mec; int res; ptr = test_ma_strings; while(*ptr) { printf("String: \"%s\"\n", *ptr); mec = 0; res = dk3ma_im_from_c8_string(&imval, *ptr, &mec); printf("Result: %d\n", res); printf("EC: %d\n", mec); if (res) { if (dk3ma_im_to_c8_string(buf, sizeof(buf), imval)) { printf("Number: %s\n", buf); } else { printf("Failed to convert number to string!\n"); } } printf("\n"); ptr++; } } int main(int argc, char *argv[]) { $!trace-init test-ma.deb fputs("Reading dk3_im_t\n", stdout); test_ma_read_im(); fputs("Reading dk3_um_t\n", stdout); test_ma_read_um(); fputs("Test hex\n", stdout); test_um_hex(); fputs("Test unsigned\n", stdout); test_um(); fputs("test signed\n", stdout); test_im(); $!trace-end exit(0); return 0; }