]> git.draconx.ca Git - gob-dx.git/blobdiff - tests/general.at
Add missing g_type_init calls to test cases.
[gob-dx.git] / tests / general.at
index 7b03f4e4fa7f51dd51227edf8c53d1d3beeda673..49fd6a2b8ff80303b45e2f66f884c7bb098dd57b 100644 (file)
@@ -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.
@@ -27,17 +27,18 @@ AT_DATA([main.c],
 
 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;
@@ -46,23 +47,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<str_lines
 while read l <&3; do
   AS_VAR_ARITH([total], [1 + $total])
-  AT_CHECK([awk -v line="$l" -v file="$str_gob" -NF : \
+  AT_CHECK([$AWK -v line="$l" -v file="$str_gob" -F : \
     '$1 == file && $2 == line { exit 42 }' str_stderr], [42])
 done
 exec 3<&-
 AT_CHECK([test x"$total" = x"2"])
 
 TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
-AT_CHECK([awk -NF : '$1 == "main.c" && $2 == "16" { exit 42 }' stderr], [42])
+AT_CHECK([$AWK -F : '$1 == "main.c" && $2 == "17" { exit 42 }' stderr], [42])
 
 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o])
 
@@ -83,18 +85,19 @@ 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>
 #include "test.h"
 int main(void)
 {
+  g_type_init();
   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
@@ -138,6 +141,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);
@@ -189,6 +194,7 @@ AT_DATA([test.in], [[@GOB2@
 cat >configure.ac <<EOF
 [m4@&t@_include([$builddir/gob2.m4])]
 [m4@&t@_pattern_forbid([^GOB2_])]
+[m4@&t@_pattern_forbid([^DX_])]
 [AC_INIT([gob2_check], [0])]
 [GOB2_CHECK(]m4_dquote(m4_defn([MYVER]))[)]
 GOB2=\`command -v \$GOB2\`
@@ -208,3 +214,95 @@ 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_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)));
+
+  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_init();
+  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