]> git.draconx.ca Git - gob-dx.git/commitdiff
Add simple test cases using private data members.
authorNick Bowler <nbowler@draconx.ca>
Fri, 7 Feb 2020 20:22:09 +0000 (15:22 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 8 Feb 2020 21:44:11 +0000 (16:44 -0500)
tests/general.at

index 7b03f4e4fa7f51dd51227edf8c53d1d3beeda673..a36e4df17a9c8e571d580fa486a4981ecdc3016e 100644 (file)
@@ -83,6 +83,7 @@ class :Test from G:Object (dynamic)
 }
 ]])
 AT_CHECK([gob2 test.gob])
 }
 ]])
 AT_CHECK([gob2 test.gob])
+TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
 
 AT_DATA([main.c],
 [[#include <config.h>
 
 AT_DATA([main.c],
 [[#include <config.h>
@@ -92,9 +93,8 @@ int main(void)
   test_register_type(NULL);
 }
 ]])
   test_register_type(NULL);
 }
 ]])
-
-TEST_COMPILE_GOBJECT([test.c], [0], [], [ignore])
 TEST_COMPILE_GOBJECT([main.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
 AT_CHECK([$CC $CFLAGS $LDFLAGS $LIBGOBJECT_LIBS -o main test.o main.o])
 
 AT_CLEANUP
@@ -208,3 +208,89 @@ AT_CHECK([$AUTOCONF --force])
 AT_CHECK([./configure], [1], [ignore], [ignore])
 
 AT_CLEANUP
 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])
+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])
+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