]> git.draconx.ca Git - gob-dx.git/blobdiff - tests/interface.at
Add missing g_type_init calls to test cases.
[gob-dx.git] / tests / interface.at
index 82771e17035b878a3bf3bc50eab70d23deb7c9c3..113c22a60e19ac7b6beb9e3e331f7224bc14eade 100644 (file)
@@ -3,31 +3,6 @@ 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.
 
-dnl TEST_TYPE_MODULE(Class:Name)
-dnl Create a GTypeModule (Class:Name:Mod) which registers the dynamic
-dnl type indiciated by Class:Name.
-m4_define([TEST_TYPE_MODULE],
-[TEST_TYPE_MODULE_([$1], m4_translit([[$1]], [:A-Z], [_a-z]),
-  m4_translit([[$1]], [:A-Z], [-a-z]))])
-
-m4_define([TEST_TYPE_MODULE_],
-[AT_KEYWORDS([dynamic])dnl
-
-AT_DATA([$3-mod.gob], [[%{
-#include "$3.h"
-%}
-class $1:Mod from G:Type:Module
-{
-  override (G:Type:Module) gboolean load(G:Type:Module *m)
-  {
-    $2_register_type(m);
-    return TRUE;
-  }
-}
-]])
-AT_CHECK([gob2 $3-mod.gob])
-TEST_COMPILE_GOBJECT([$3-mod.c], [0], [], [ignore])])
-
 dnl Create the Test:Fooable interface with the following interface method:
 dnl
 dnl   int foo(G:Object *obj);
@@ -41,8 +16,8 @@ TEST_COMPILE_GOBJECT([test-fooable.c], [0], [], [ignore])])
 dnl TEST_FOOABLE_IMPL(Class:Name, Parent:Class, foo_body)
 dnl TEST_FOOABLE_IMPL_DYN(Class:Name, Parent:Class, foo_body)
 m4_define([TEST_FOOABLE_IMPL],
-  [TEST_FOOABLE_IMPL_([$1], m4_translit([[$1]], [:A-Z], [-a-z]),
-                      [$2], m4_translit([[$2]], [:A-Z], [-a-z]),
+  [TEST_FOOABLE_IMPL_([$1], TEST_CLASSNAME_REPLACE_SEP([$1], [-]),
+                      [$2], TEST_CLASSNAME_REPLACE_SEP([$2], [-]),
                       [$3], [$4])])
 
 m4_define([TEST_FOOABLE_IMPL_DYN],
@@ -50,7 +25,10 @@ m4_define([TEST_FOOABLE_IMPL_DYN],
 TEST_TYPE_MODULE([$1])])
 
 m4_define([TEST_FOOABLE_IMPL_],
-[AT_DATA([$2.gob], [[%{
+[AT_DATA([$2.gob], [[%ctop{
+#include <config.h>
+%}
+%{
 #include <stdio.h>
 #include <stdlib.h>
 #include "test-fooable.h"
@@ -65,6 +43,7 @@ class $1 from $3]m4_default_nblank([
   (interface Test:Fooable)
 {
   interface Test:Fooable private int foo(G:Object *go)
+    onerror 88
   {
     $5
     abort();
@@ -82,7 +61,8 @@ TEST_FOOABLE_IFACE()
 TEST_FOOABLE_IMPL([Test:A], [G:Object], [return 42;])
 
 AT_DATA([main.c],
-[[#include <stdio.h>
+[[#include <config.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include "test-fooable.h"
 #include "test-a.h"
@@ -91,6 +71,7 @@ int main(void)
 {
   int rc;
 
+  g_type_init();
   rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
   printf("%d\n", rc);
   if (rc < 0)
@@ -115,7 +96,8 @@ TEST_FOOABLE_IFACE()
 TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object], [return 54;])
 
 AT_DATA([main.c],
-[[#include <stdio.h>
+[[#include <config.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include "test-fooable.h"
 #include "test-a.h"
@@ -125,6 +107,7 @@ int main(void)
 {
   int rc;
 
+  g_type_init();
   g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
 
   rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
@@ -155,7 +138,8 @@ TEST_FOOABLE_IMPL([Test:B], [Test:A],
   [puts("Test:B foo called"); return 54;])
 
 AT_DATA([main.c],
-[[#include <stdio.h>
+[[#include <config.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include "test-fooable.h"
 #include "test-a.h"
@@ -165,6 +149,7 @@ int main(void)
 {
   int rc;
 
+  g_type_init();
   rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
   printf("%d\n", rc);
   if (rc < 0)
@@ -202,7 +187,9 @@ TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
   [puts("Test:B foo called"); return 54;])
 
 AT_DATA([main.c],
-[[#include <stdio.h>
+[[#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include "test-fooable.h"
 #include "test-a.h"
 #include "test-b.h"
@@ -212,6 +199,7 @@ int main(void)
 {
   int rc;
 
+  g_type_init();
   g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
 
   rc = test_foo(g_object_new(TEST_TYPE_A, NULL));
@@ -232,8 +220,6 @@ TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
   test-a.o test-b.o test-b-mod.o test-fooable.o main.o])
 
-# Currently borked
-AT_XFAIL_IF([:])
 AT_CHECK([./main], [0], [Test:A foo called
 42
 Test:B foo called
@@ -254,7 +240,9 @@ TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
   [puts("Test:B foo called"); return 54;])
 
 AT_DATA([main.c],
-[[#include <stdio.h>
+[[#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include "test-fooable.h"
 #include "test-a.h"
 #include "test-a-mod.h"
@@ -265,6 +253,7 @@ int main(void)
 {
   int rc;
 
+  g_type_init();
   g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
   g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
 
@@ -286,8 +275,6 @@ TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
   test-a.o test-a-mod.o test-b.o test-b-mod.o test-fooable.o main.o])
 
-# Currently borked
-AT_XFAIL_IF([:])
 AT_CHECK([./main], [0], [Test:A foo called
 42
 Test:B foo called
@@ -295,3 +282,103 @@ Test:B foo called
 ])
 
 AT_CLEANUP
+
+AT_SETUP([interface method chaining])
+AT_KEYWORDS([runtime])dnl
+
+TEST_FOOABLE_IFACE()
+TEST_FOOABLE_IMPL([Test:A], [G:Object],
+  [puts("Test:A foo called"); return PARENT_HANDLER(go);])
+TEST_FOOABLE_IMPL([Test:B], [Test:A],
+  [puts("Test:B foo called"); return PARENT_HANDLER(go);])
+TEST_FOOABLE_IMPL([Test:C], [Test:B],
+  [puts("Test:C foo called"); return PARENT_HANDLER(go);])
+
+AT_DATA([main.c],
+[[#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "test-fooable.h"
+#include "test-a.h"
+#include "test-b.h"
+#include "test-c.h"
+
+int main(void)
+{
+  int rc;
+
+  g_type_init();
+  rc = test_foo(g_object_new(TEST_TYPE_C, NULL));
+  printf("%d\n", rc);
+  if (rc < 0)
+    return EXIT_FAILURE;
+
+  return 0;
+}
+]])
+
+TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
+
+AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
+  test-a.o test-b.o test-c.o test-fooable.o main.o])
+AT_CHECK([./main], [0], [Test:C foo called
+Test:B foo called
+Test:A foo called
+88
+])
+
+AT_CLEANUP
+
+AT_SETUP([interface method chaining (dynamic)])
+AT_KEYWORDS([runtime])dnl
+
+TEST_FOOABLE_IFACE()
+TEST_FOOABLE_IMPL_DYN([Test:A], [G:Object],
+  [puts("Test:A foo called"); return PARENT_HANDLER(go);])
+TEST_FOOABLE_IMPL_DYN([Test:B], [Test:A],
+  [puts("Test:B foo called"); return PARENT_HANDLER(go);])
+TEST_FOOABLE_IMPL_DYN([Test:C], [Test:B],
+  [puts("Test:C foo called"); return PARENT_HANDLER(go);])
+
+AT_DATA([main.c],
+[[#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "test-fooable.h"
+#include "test-a.h"
+#include "test-a-mod.h"
+#include "test-b.h"
+#include "test-b-mod.h"
+#include "test-c.h"
+#include "test-c-mod.h"
+
+int main(void)
+{
+  int rc;
+
+  g_type_init();
+  g_type_module_use(g_object_new(TEST_TYPE_A_MOD, NULL));
+  g_type_module_use(g_object_new(TEST_TYPE_B_MOD, NULL));
+  g_type_module_use(g_object_new(TEST_TYPE_C_MOD, NULL));
+
+  rc = test_foo(g_object_new(TEST_TYPE_C, NULL));
+  printf("%d\n", rc);
+  if (rc < 0)
+    return EXIT_FAILURE;
+
+  return 0;
+}
+]])
+
+TEST_COMPILE_GOBJECT([main.c], [0], [], [ignore])
+
+AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main \
+  test-a.o test-a-mod.o test-b.o test-b-mod.o test-c.o test-c-mod.o \
+  test-fooable.o main.o])
+AT_CHECK([./main], [0], [Test:C foo called
+Test:B foo called
+Test:A foo called
+88
+])
+
+AT_CLEANUP