=== added file 'ChangeLog.some-testcases' --- ChangeLog.some-testcases 1970-01-01 00:00:00 +0000 +++ ChangeLog.some-testcases 2010-01-09 04:56:25 +0000 @@ -0,0 +1,22 @@ +2010-01-09 BVK Chaitanya + + Added some testcases. + + * tests/grub_script_vars1.in: Testcase for different types of + variable expansions and arguments. + * tests/grub_script_echo1.in: Likewise. + * tests/grub_script_echo_keywords.in: Likewise. + + * tests/grub_script_for1.in: GRUB script testcase for for-loop. + + * tests/grub_script_functions1.in: GRUB script testcase for + functions. + + * tests/grub_script_gettext1.in: GRUB script testcase for gettext. + + * tests/grub_sprintf.c: Whitebox testcase for grub_sprintf + routine. + + * conf/tests.rmk: Build rules for above testcases. + + === modified file 'conf/tests.rmk' --- conf/tests.rmk 2010-01-08 11:05:32 +0000 +++ conf/tests.rmk 2010-01-08 17:45:44 +0000 @@ -39,3 +39,29 @@ check_SCRIPTS += example_grub_script_test example_grub_script_test_SOURCES = tests/example_grub_script_test.in + +# +# Rules for real tests +# + +check_UTILITIES += grub_sprintf +grub_sprintf_SOURCES = tests/grub_sprintf.c kern/misc.c kern/list.c tests/lib/test.c tests/lib/unit_test.c +grub_sprintf_CFLAGS = -Wno-error -Wno-format + +check_SCRIPTS += grub_script_echo1 +grub_script_echo1_SOURCES = tests/grub_script_echo1.in + +check_SCRIPTS += grub_script_echo_keywords +grub_script_echo_keywords_SOURCES = tests/grub_script_echo_keywords.in + +check_SCRIPTS += grub_script_for1 +grub_script_for1_SOURCES = tests/grub_script_for1.in + +check_SCRIPTS += grub_script_functions1 +grub_script_functions1_SOURCES = tests/grub_script_functions1.in + +check_SCRIPTS += grub_script_vars1 +grub_script_vars1_SOURCES = tests/grub_script_vars1.in + +check_SCRIPTS += grub_script_gettext1 +grub_script_gettext1_SOURCES = tests/grub_script_gettext1.in === added file 'tests/grub_script_echo1.in' --- tests/grub_script_echo1.in 1970-01-01 00:00:00 +0000 +++ tests/grub_script_echo1.in 2010-01-08 17:40:13 +0000 @@ -0,0 +1,16 @@ +#! @builddir@/grub-shell-tester + +foo=bar +echo $foo ${foo} +echo "$foo" "${foo}" +echo '$foo' '${foo}' +echo a$foob a${foo}b +echo ab"cd"ef$foo'gh'ij${foo}kl\ mn\"op\'qr\$st\(uv\yz\) + +foo=c +bar=h +echo e"$foo"${bar}o +e"$foo"${bar}o hello world + +foo=echo +$foo 1234 === added file 'tests/grub_script_echo_keywords.in' --- tests/grub_script_echo_keywords.in 1970-01-01 00:00:00 +0000 +++ tests/grub_script_echo_keywords.in 2010-01-08 17:39:45 +0000 @@ -0,0 +1,3 @@ +#! @builddir@/grub-shell-tester + +echo if then else fi for do done === added file 'tests/grub_script_for1.in' --- tests/grub_script_for1.in 1970-01-01 00:00:00 +0000 +++ tests/grub_script_for1.in 2010-01-08 17:40:58 +0000 @@ -0,0 +1,27 @@ +#! @builddir@/grub-shell-tester + +for x in one two 'three 3' "four 4" five six-6; do echo $x; done + +for x in one two 'three 3' "four 4" five six-6 +do + echo $x +done + +foo="1 2" +for x in ab${foo}cd; do echo $x; done +for x in "ab${foo}cd"; do echo $x; done + +a="one two three" +y=foo +echo $y +for y in $a; do + echo $y +done +echo $y + + +b="one two three" +for z in $b; do + echo $z +done +echo $z === added file 'tests/grub_script_functions1.in' --- tests/grub_script_functions1.in 1970-01-01 00:00:00 +0000 +++ tests/grub_script_functions1.in 2010-01-08 17:40:26 +0000 @@ -0,0 +1,18 @@ +#! @builddir@/grub-shell-tester + +function foo { echo foo; }; foo +function foo2 +{ + echo foo2 +} +foo2 + +function bar { echo one; if true; then echo yes; else echo no; fi; echo bar; foo; }; bar +function bar +{ + foo; + foo2; + bar; +} + + === added file 'tests/grub_script_gettext1.in' --- tests/grub_script_gettext1.in 1970-01-01 00:00:00 +0000 +++ tests/grub_script_gettext1.in 2010-01-08 17:40:02 +0000 @@ -0,0 +1,4 @@ +#! @builddir@/grub-shell-tester --modules=gettext + +gettext "hello world" + === added file 'tests/grub_script_vars1.in' --- tests/grub_script_vars1.in 1970-01-01 00:00:00 +0000 +++ tests/grub_script_vars1.in 2010-01-08 17:41:08 +0000 @@ -0,0 +1,10 @@ +#! @builddir@/grub-shell-tester + +var=foo +echo $var +echo "$var" +echo ${var} +echo "${var}" + + + === added file 'tests/grub_sprintf.c' --- tests/grub_sprintf.c 1970-01-01 00:00:00 +0000 +++ tests/grub_sprintf.c 2010-01-08 17:38:44 +0000 @@ -0,0 +1,162 @@ +#include +#include +#include +#include + +#include +#include + +#define TEST(type,fmt,val) \ + do { \ + int r1, r2; \ + char b1[1024]; \ + char b2[1024]; \ + \ + b1[0] = b2[0] = '\0'; \ + r1 = sprintf (b1, fmt, val); \ + r2 = grub_sprintf (b2, fmt, val); \ + \ + grub_test_assert (strcmp (b1, b2) == 0, \ + "for (\"%s\","type") " \ + "result should be (\"%s\",%d) " \ + "but got (\"%s\",%d)", \ + fmt, val, b1, r1, b2, r2); \ + \ + grub_test_assert (r1 == r2, \ + "for (\"%s\","type") " \ + "result should be (\"%s\",%d) " \ + "but got (\"%s\",%d)", \ + fmt, val, b1, r1, b2, r2); \ + } while (0) + +#define D(fmt,v) TEST("%d",fmt,v) +#define U(fmt,v) TEST("%u",fmt,v) +#define x(fmt,v) TEST("%x",fmt,v) +#define X(fmt,v) TEST("%X",fmt,v) +#define P(fmt,v) TEST("%p",fmt,v) +#define S(fmt,s) TEST("%s",fmt,s) + +static void +sprintf_checks (void) +{ + D ("%d", -1); + D ("%d", 0); + D ("%d", 1); + D ("%5d", -1); + D ("%5d", 0); + D ("%5d", 1); + D ("%-5d", -1); + D ("%-5d", 0); + D ("%-5d", 1); + D ("%.5d", -1); + D ("%.5d", 0); + D ("%.5d", 1); + D ("%5.0d", -1); + D ("%5.0d", 0); + D ("%5.0d", 1); + D ("%-5.0d", -1); + D ("%-5.0d", 0); + D ("%-5.0d", 1); + + U ("%d", -1); + U ("%d", 0); + U ("%d", 1); + U ("%5d", -1); + U ("%5d", 0); + U ("%5d", 1); + U ("%-5d", -1); + U ("%-5d", 0); + U ("%-5d", 1); + U ("%.5d", -1); + U ("%.5d", 0); + U ("%.5d", 1); + U ("%5.0d", -1); + U ("%5.0d", 0); + U ("%5.0d", 1); + U ("%-5.0d", -1); + U ("%-5.0d", 0); + U ("%-5.0d", 1); + + x ("%d", -1); + x ("%d", 0); + x ("%d", 1); + x ("%5d", -1); + x ("%5d", 0); + x ("%5d", 1); + x ("%-5d", -1); + x ("%-5d", 0); + x ("%-5d", 1); + x ("%.5d", -1); + x ("%.5d", 0); + x ("%.5d", 1); + x ("%5.0d", -1); + x ("%5.0d", 0); + x ("%5.0d", 1); + x ("%-5.0d", -1); + x ("%-5.0d", 0); + x ("%-5.0d", 1); + + X ("%d", -1); + X ("%d", 0); + X ("%d", 1); + X ("%5d", -1); + X ("%5d", 0); + X ("%5d", 1); + X ("%-5d", -1); + X ("%-5d", 0); + X ("%-5d", 1); + X ("%.5d", -1); + X ("%.5d", 0); + X ("%.5d", 1); + X ("%5.0d", -1); + X ("%5.0d", 0); + X ("%5.0d", 1); + X ("%-5.0d", -1); + X ("%-5.0d", 0); + X ("%-5.0d", 1); + + P ("%p", NULL); + P ("%p", sprintf_checks); + + S ("%s", (char *) NULL); + S ("%s", "abcd"); + S ("%10s", "abcd"); + S ("%10.5s", "abcdefgh"); + S ("%10.5s", "ab"); + S ("%2.5s", "a"); + S ("%2.5s", "abcdefgh"); + + D ("%4.2d", 1); + D ("%4.2d", 12); + D ("%4.2d", 123); + D ("%4.2d", 1234); + D ("%4.2d", 12345); + D ("%3.3d", 12); + D ("%3.3d", 123); + D ("%3.3d", 1234); + D ("%2.4d", 12345); + D ("%2.4d", 1234); + D ("%2.4d", 123); + D ("%2.4d", 12); + D ("%2.4d", 1); + D ("%.0d", 0); + D ("%.0d", 1); + + S ("%4.2s", "1"); + S ("%4.2s", "12"); + S ("%4.2s", "123"); + S ("%4.2s", "1234"); + S ("%4.2s", "12345"); + S ("%3.3s", "12"); + S ("%3.3s", "123"); + S ("%3.3s", "1234"); + S ("%2.4s", "12345"); + S ("%2.4s", "1234"); + S ("%2.4s", "123"); + S ("%2.4s", "12"); + S ("%2.4s", "1"); + + /* add few more here, if necessary */ +} + +GRUB_UNIT_TEST ("grub_sprintf", sprintf_checks);