]> git.draconx.ca Git - gob-dx.git/blobdiff - tests/general.at
Fix testsuite on ancient GLib.
[gob-dx.git] / tests / general.at
index 7b03f4e4fa7f51dd51227edf8c53d1d3beeda673..d7be50244874f9e03f215e5865afc79ce943f87c 100644 (file)
@@ -1,4 +1,4 @@
-dnl Copyright © 2019-2020 Nick Bowler
+dnl Copyright © 2019-2021 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.
@@ -46,6 +46,7 @@ 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
 
@@ -83,6 +84,7 @@ class :Test from G:Object (dynamic)
 }
 ]])
 AT_CHECK([gob2 test.gob])
+TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
 
 AT_DATA([main.c],
 [[#include <config.h>
@@ -92,9 +94,8 @@ 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
@@ -208,3 +209,91 @@ AT_CHECK([$AUTOCONF --force])
 AT_CHECK([./configure], [1], [ignore], [ignore])
 
 AT_CLEANUP
+
+AT_SETUP([private data members])
+
+AT_DATA([test.gob], [[%ctop{
+#include <config.h>
+%}
+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 <config.h>
+#include <stdio.h>
+#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 <config.h>
+%}
+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 <config.h>
+#include <stdio.h>
+#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