]> git.draconx.ca Git - gob-dx.git/blobdiff - tests/general.at
Bump dxcommon to pull in build portability improvements.
[gob-dx.git] / tests / general.at
index 10f6f0fc7962c14de29b08ffae4e1cccf14af29e..624af5a9a8199e09e0a98a32bae22c55dfacde47 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.
@@ -22,7 +22,8 @@ AT_CLEANUP
 AT_SETUP([str.gob])
 
 AT_DATA([main.c],
-[[#include "str.h"
+[[#include <config.h>
+#include "str.h"
 
 int main(void)
 {
@@ -45,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
 
@@ -61,7 +63,7 @@ exec 3<&-
 AT_CHECK([test x"$total" = x"2"])
 
 TEST_COMPILE_GOBJECT([main.c], [0], [], [stderr])
-AT_CHECK([awk -NF : '$1 == "main.c" && $2 == "15" { exit 42 }' stderr], [42])
+AT_CHECK([awk -NF : '$1 == "main.c" && $2 == "16" { exit 42 }' stderr], [42])
 
 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main str.o main.o])
 
@@ -71,8 +73,10 @@ dnl Check that dynamic types are accepted and compile OK...
 AT_SETUP([dynamic types])
 AT_KEYWORDS([dynamic])
 
-AT_DATA([test.gob],
-[[class :Test from G:Object (dynamic)
+AT_DATA([test.gob], [[%ctop{
+#include <config.h>
+%}
+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 <config.h>
+#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 <config.h>
+%}
+%{
 #include <stdio.h>
 %}
 class :Test from G:Object (dynamic)
@@ -115,31 +122,20 @@ class :Test from G:Object (dynamic)
   }
 }
 ]])
+AT_CHECK([gob2 test.gob])
+TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
 
-AT_DATA([mod.gob],
-[[%{
-#include "test.h"
-%}
-class :Mod from G:Type:Module
-{
-  override (G:Type:Module) gboolean load(G:Type:Module *m)
-  {
-    test_register_type(m);
-    return TRUE;
-  }
-}
-]])
+TEST_TYPE_MODULE([:Test])
 
 AT_DATA([main.c],
-[[#include <stdio.h>
-#include "mod.h"
+[[#include <stdlib.h>
 #include "test.h"
+#include "test-mod.h"
 
 void devnull(const char *a, GLogLevelFlags b, const char *c, gpointer d) { }
 
 int main(void)
 {
-  GTypeModule *m = g_object_new(mod_get_type(), NULL);
   guint handler;
   Test *t;
 
@@ -150,7 +146,9 @@ int main(void)
     return EXIT_FAILURE;
   g_log_remove_handler("GLib-GObject", handler);
 
-  g_type_module_use(m);
+  /* Register dynamic type */
+  g_type_module_use(g_object_new(test_mod_get_type(), NULL));
+
   /* should work now */
   t = g_object_new(test_get_type(), "s", "Hello, World", (char *)NULL);
   if (!t)
@@ -160,109 +158,11 @@ int main(void)
   return EXIT_SUCCESS;
 }
 ]])
-
-AT_CHECK([gob2 mod.gob])
-AT_CHECK([gob2 test.gob])
-TEST_COMPILE_GOBJECT([mod.c], [0], [], [ignore])
-TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
 TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
-AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main mod.o test.o main.o])
-AT_CHECK([./main], [0], [Hello, World
-])
-
-AT_CLEANUP
-
-dnl Dynamic types: check that we can call interface methods of dynamic types.
-AT_SETUP([dynamic interface implementation])
-AT_KEYWORDS([dynamic runtime interface])
-
-AT_DATA([iface.h],
-[[#define IF_TYPE_TEST if_test_get_type()
-
-typedef struct IFTestIface {
-  GTypeInterface parent;
-
-  void (*test)(GObject *obj);
-} IFTestIface;
-
-GType if_test_get_type(void);
-]])
 
-AT_DATA([test.gob],
-[[%{
-#include <stdio.h>
-#include "iface.h"
-%}
-
-class :Test from G:Object (dynamic)
-  (interface IF:Test)
-{
-  private const char *s = { "Hello, World!" };
-  interface IF:Test private void test(G:Object *o)
-  {
-    Self *self = SELF(o);
-    printf("%s\n", self->_priv->s);
-  }
-}
-]])
-
-AT_DATA([mod.gob],
-[[%{
-#include "test.h"
-%}
-class :Mod from G:Type:Module
-{
-  override (G:Type:Module) gboolean load(G:Type:Module *m)
-  {
-    test_register_type(m);
-    return TRUE;
-  }
-}
-]])
-
-AT_DATA([main.c],
-[[#include "test.h"
-#include "mod.h"
-#include "iface.h"
-
-GType if_test_get_type(void)
-{
-  static GType type = 0;
-  if (type == 0) {
-    static const GTypeInfo info = {
-      sizeof (IFTestIface),
-      NULL,
-      NULL,
-    };
-
-    type = g_type_register_static(G_TYPE_INTERFACE, "IFTest", &info, 0);
-  }
-  return type;
-}
-
-int main(void)
-{
-  GTypeModule *m = g_object_new(TYPE_MOD, NULL);
-  GObject *t;
-
-  g_type_module_use(m);
-  t = g_object_new(TYPE_TEST, NULL);
-
-  g_return_val_if_fail(G_TYPE_CHECK_INSTANCE_TYPE(t, IF_TYPE_TEST),
-                       EXIT_FAILURE);
-  G_TYPE_INSTANCE_GET_INTERFACE(t, IF_TYPE_TEST, IFTestIface)->test(t);
-
-  return EXIT_SUCCESS;
-}
-]])
-
-AT_CHECK([gob2 mod.gob])
-AT_CHECK([gob2 test.gob])
-TEST_COMPILE_GOBJECT([mod.c], [0], [], [ignore])
-TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
-TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
-AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main mod.o test.o main.o])
-AT_CHECK([./main], [0], [Hello, World!
+AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
+  test.o test-mod.o main.o])
+AT_CHECK([./main], [0], [Hello, World
 ])
 
 AT_CLEANUP
@@ -278,7 +178,6 @@ AT_CHECK([$AUTOCONF && test -f configure || exit 77], [0], [ignore], [ignore])
 
 m4_define([MYVER],
   m4_bpatsubst(m4_dquote(m4_defn([AT_PACKAGE_VERSION])), [[^][0-9.]]))
-m4_if(m4_defn([MYVER]), m4_defn([AT_PACKAGE_VERSION]), [], [AT_XFAIL_IF([:])])
 
 m4_define([MYVER_P1], m4_dquote(m4_reverse(m4_unquote(
   m4_split(m4_defn([MYVER]), [[.]])))))
@@ -289,8 +188,9 @@ AT_DATA([test.in], [[@GOB2@
 ]])
 
 cat >configure.ac <<EOF
-[m4@&t@_include([$srcdir/gob2.m4])]
+[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\`
@@ -310,3 +210,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