X-Git-Url: https://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/4ebed70c2119e843ce48ae4fa6076475d2100693..4e6eb5db5593f2d73c2c9af9c925e1a2866c8303:/tests/general.at diff --git a/tests/general.at b/tests/general.at index e35c578..52c3fca 100644 --- a/tests/general.at +++ b/tests/general.at @@ -21,23 +21,48 @@ AT_CLEANUP AT_SETUP([str.gob]) +# check if compiler supports format warnings +AT_DATA([fmt.c], +[[#include +#include + +void foo(const char *, ...) G_GNUC_PRINTF(1, 2); +void bar(void) { +#line 99 "VERIFY" +foo("%s", 0); +} +]]) +AT_DATA([fmt.awk], +[[BEGIN { pass=0; FS=":"; } +/%s/ && $1 == "VERIFY" && $2 == 99 { pass=1; } +END { exit(!pass); } +]]) + +fmt_warnings=false +set x $CPPFLAGS $CFLAGS $LIBGOBJECT_CFLAGS; shift +AS_IF([$CC "$@" -c fmt.c 1>/dev/null 2>out && $AWK -f fmt.awk out], + [fmt_warnings=:], + [AS_IF([$CC "$@" -Wformat -c fmt.c 1>/dev/null 2>out && $AWK -f fmt.awk out], + [CFLAGS="$CFLAGS -Wformat" fmt_warnings=:])]) + AT_DATA([main.c], [[#include #include "str.h" int main(void) { - g_type_init (); - - int the_answer = 42; + Str *test_good, *test_bad; char *stupid_pointer = "ug"; + int the_answer = 42; + + g_type_init (); /* This works fine. */ - Str *test_good = (Str *) (str_new ("%d", the_answer)); + test_good = (Str *) (str_new ("%d", the_answer)); test_good = test_good; /* This gets a warning thanks to our function attribute. */ - Str *test_bad = (Str *) (str_new ("%d", stupid_pointer)); + test_bad = (Str *) (str_new ("%d", stupid_pointer)); test_bad = test_bad; return 0; @@ -47,25 +72,45 @@ int main(void) str_gob=$abs_top_srcdir/t/str.gob AT_CHECK([gob2 "$str_gob"]) AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77]) + TEST_COMPILE_GOBJECT([str.c], [0], [], [stderr]) mv stderr str_stderr +TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr]) +mv stderr main_stderr +AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o]) -# Check for correct diagnostic messages on the target lines... -AT_CHECK([$AWK '/want a string/ { print NR }' "$str_gob" >str_lines]) -total=0 -exec 3 0) { + sub(/.*[\/]/, "", $1); + if (/%s/ && $1 == "str.gob" && $2 in lines) + lines[$2]--; + } -TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr]) -AT_CHECK([$AWK -F : '$1 == "main.c" && $2 == "16" { exit 42 }' stderr], [42]) + if (rc < 0) + exit(1); -AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o]) + count=0; + for (l in lines) { + if (lines[l]) + exit(1); + count++; + } + + exit(count != 2); +} +]]) + +# Check for correct diagnostic messages on the target lines... +AT_CHECK([$fmt_warnings || exit 77 +$AWK -f str.awk "$str_gob" || exit 1 +$AWK -f - main_stderr <<'EOF' +BEGIN { pass=0; FS=":"; } +/%d/ && $1 == "main.c" && $2 == 17 { pass=1; } +END { exit(!pass); } +EOF]) AT_CLEANUP @@ -91,6 +136,7 @@ AT_DATA([main.c], #include "test.h" int main(void) { + g_type_init(); test_register_type(NULL); } ]]) @@ -139,6 +185,8 @@ int main(void) guint handler; Test *t; + g_type_init(); + /* should fail, suppress internal glib logging... */ handler = g_log_set_handler("GLib-GObject", G_LOG_LEVEL_MASK, devnull, 0); t = g_object_new(test_get_type(), NULL); @@ -234,7 +282,10 @@ AT_DATA([main.c], [[#include int main(void) { - GObject *go = g_object_new(test_get_type(), NULL); + GObject *go; + + g_type_init(); + go = g_object_new(test_get_type(), NULL); printf("%d\n", test_get_x(go)); printf("%d\n", (test_set_x(go, 123), test_get_x(go))); @@ -280,6 +331,7 @@ int main(void) { GObject *go; + g_type_init(); g_type_module_use(g_object_new(test_mod_get_type(), NULL)); go = g_object_new(test_get_type(), NULL);