From: Peter Johnson Date: Tue, 18 Sep 2001 23:21:04 +0000 (-0000) Subject: Completely test ConvertRegToEA(). X-Git-Tag: v0.1.0~323 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a95f135cc22a1be27dfbc482a8846c4c8574bd33;p=yasm Completely test ConvertRegToEA(). svn path=/trunk/yasm/; revision=195 --- diff --git a/libyasm/tests/bytecode_test.c b/libyasm/tests/bytecode_test.c index 75697494..d9a8077b 100644 --- a/libyasm/tests/bytecode_test.c +++ b/libyasm/tests/bytecode_test.c @@ -10,11 +10,32 @@ START_TEST(test_ConvertRegToEA) { - effaddr static_val, *allocp, *retp; + effaddr static_val, *retp; + int i; - /* Test with static passing */ + /* Test with non-NULL */ fail_unless(ConvertRegToEA(&static_val, 1) == &static_val, - "No allocation should be performed if non-NULL passed in ptr"); + "Should return ptr if non-NULL passed in ptr"); + + /* Test with NULL */ + retp = ConvertRegToEA(NULL, 1); + fail_unless(retp != NULL, + "Should return static structure if NULL passed in ptr"); + + /* Test structure values function should set */ + fail_unless(retp->len == 0, "len should be 0"); + fail_unless(retp->segment == 0, "Should be no segment override"); + fail_unless(retp->valid_modrm == 1, "Mod/RM should be valid"); + fail_unless(retp->need_modrm == 1, "Mod/RM should be needed"); + fail_unless(retp->valid_sib == 0, "SIB should be invalid"); + fail_unless(retp->need_sib == 0, "SIB should not be needed"); + + /* Exhaustively test generated Mod/RM byte with register values */ + for(i=0; i<8; i++) { + ConvertRegToEA(&static_val, i); + fail_unless(static_val.modrm == 0xC0 | (i & 0x07), + "Invalid Mod/RM byte generated"); + } } END_TEST diff --git a/src/tests/bytecode_test.c b/src/tests/bytecode_test.c index 75697494..d9a8077b 100644 --- a/src/tests/bytecode_test.c +++ b/src/tests/bytecode_test.c @@ -10,11 +10,32 @@ START_TEST(test_ConvertRegToEA) { - effaddr static_val, *allocp, *retp; + effaddr static_val, *retp; + int i; - /* Test with static passing */ + /* Test with non-NULL */ fail_unless(ConvertRegToEA(&static_val, 1) == &static_val, - "No allocation should be performed if non-NULL passed in ptr"); + "Should return ptr if non-NULL passed in ptr"); + + /* Test with NULL */ + retp = ConvertRegToEA(NULL, 1); + fail_unless(retp != NULL, + "Should return static structure if NULL passed in ptr"); + + /* Test structure values function should set */ + fail_unless(retp->len == 0, "len should be 0"); + fail_unless(retp->segment == 0, "Should be no segment override"); + fail_unless(retp->valid_modrm == 1, "Mod/RM should be valid"); + fail_unless(retp->need_modrm == 1, "Mod/RM should be needed"); + fail_unless(retp->valid_sib == 0, "SIB should be invalid"); + fail_unless(retp->need_sib == 0, "SIB should not be needed"); + + /* Exhaustively test generated Mod/RM byte with register values */ + for(i=0; i<8; i++) { + ConvertRegToEA(&static_val, i); + fail_unless(static_val.modrm == 0xC0 | (i & 0x07), + "Invalid Mod/RM byte generated"); + } } END_TEST