X-Git-Url: https://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/ee1d01180583f7a4940bce0d1bda85c8379b6b4b..4ebed70c2119e843ce48ae4fa6076475d2100693:/tests/general.at diff --git a/tests/general.at b/tests/general.at index 6643d4d..e35c578 100644 --- a/tests/general.at +++ b/tests/general.at @@ -1,4 +1,4 @@ -dnl Copyright © 2019-2020 Nick Bowler +dnl Copyright © 2019-2022 Nick Bowler dnl License GPLv2+: GNU General Public License version 2 or any later version. dnl This is free software: you are free to change and redistribute it. dnl There is NO WARRANTY, to the extent permitted by law. @@ -22,7 +22,8 @@ AT_CLEANUP AT_SETUP([str.gob]) AT_DATA([main.c], -[[#include "str.h" +[[#include +#include "str.h" int main(void) { @@ -45,23 +46,24 @@ 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 # Check for correct diagnostic messages on the target lines... -AT_CHECK([awk '/want a string/ { print NR }' "$str_gob" >str_lines]) +AT_CHECK([$AWK '/want a string/ { print NR }' "$str_gob" >str_lines]) total=0 exec 3 +%} +class :Test from G:Object (dynamic) { public void test(void) { @@ -80,17 +84,18 @@ AT_DATA([test.gob], } ]]) AT_CHECK([gob2 test.gob]) +TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore]) AT_DATA([main.c], -[[#include "test.h" +[[#include +#include "test.h" int main(void) { test_register_type(NULL); } ]]) - -TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore]) TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore]) + AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main test.o main.o]) AT_CLEANUP @@ -100,8 +105,10 @@ dnl dynamic type after registration. AT_SETUP([dynamic type registration]) AT_KEYWORDS([dynamic runtime]) -AT_DATA([test.gob], -[[%{ +AT_DATA([test.gob], [[%ctop{ +#include +%} +%{ #include %} class :Test from G:Object (dynamic) @@ -183,6 +190,7 @@ AT_DATA([test.in], [[@GOB2@ cat >configure.ac < +%} +class :Test from G:Object +{ + private int x = 42; + + public int get_x(G:Object *go) { return TEST(go)->_priv->x; } + public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; } +} +]]) +AT_CHECK([gob2 test.gob]) +AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77]) +TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore]) + +AT_DATA([main.c], [[#include +#include +#include "test.h" + +int main(void) +{ + GObject *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))); + + return 0; +} +]]) +TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore]) + +AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \ + test.o main.o]) +AT_CHECK([./main], [0], [42 +123 +]) + +AT_CLEANUP + +AT_SETUP([private data members (dynamic)]) + +AT_DATA([test.gob], [[%ctop{ +#include +%} +class :Test from G:Object (dynamic) +{ + private int x = 54; + + public int get_x(G:Object *go) { return TEST(go)->_priv->x; } + public void set_x(G:Object *go, int val) { TEST(go)->_priv->x = val; } +} +]]) +AT_CHECK([gob2 test.gob]) +AT_CHECK([$HAVE_GOBJECT_PRIVATES || exit 77]) +TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore]) + +TEST_TYPE_MODULE([:Test]) + +AT_DATA([main.c], [[#include +#include +#include "test.h" +#include "test-mod.h" + +int main(void) +{ + GObject *go; + + g_type_module_use(g_object_new(test_mod_get_type(), NULL)); + 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))); + + return 0; +} +]]) +TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore]) + +AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \ + test.o test-mod.o main.o]) +AT_CHECK([./main], [0], [54 +123 +]) + +AT_CLEANUP