Bug 560253 - Add struture and boxed types to Everything test module
authorOwen Taylor <otaylor@src.gnome.org>
Thu, 13 Nov 2008 15:14:09 +0000 (15:14 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Thu, 13 Nov 2008 15:14:09 +0000 (15:14 +0000)
Add examples of:

 Plain old data structs
 Plain old data structs with nested fields
 Plain old data boxed
 Plain old data boxed with nested fields
 More complicated boxed types with internal state

svn path=/trunk/; revision=908

ChangeLog
tests/everything/gitesttypes.c
tests/everything/gitesttypes.h

index fd40a9e..f18e4a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-11-13  Owen Taylor  <otaylor@redhat.com>
+
+       Bug 560253 – Add structure and boxed types to Everything test module
+
+       * tests/everything/gitesttypes.[ch]: Add examples of:
+
+         Plain old data structs
+         Plain old data structs with nested fields
+         Plain old data boxed
+         Plain old data boxed with nested fields
+         More complicated boxed types with internal state
+
 2008-11-12  Johan Dahlin  <jdahlin@async.com.br>
 
        * tests/everything/gitesttypes.c (test_gtype_in):
index 9430e3b..a4d82a5 100644 (file)
@@ -364,3 +364,160 @@ void test_gslist_everything_in (GSList *in)
 
 /* ghash? */
 /* error? */
+
+/* structures */
+
+/**
+ * test_struct_a_clone:
+ * @a: the structure
+ * @a_out: (out): the cloned structure
+ *
+ * Make a copy of a TestStructA
+ */
+void
+test_struct_a_clone (TestStructA *a,
+                    TestStructA *a_out)
+{
+  *a_out = *a;
+}
+
+/**
+ * test_struct_a_clone:
+ * @a: the structure
+ * @b_out: (out): the cloned structure
+ *
+ * Make a copy of a TestStructA
+ */
+void
+test_struct_b_clone (TestStructB *b,
+                    TestStructB *b_out)
+{
+  *b_out = *b;
+}
+
+/* plain-old-data boxed types */
+
+TestSimpleBoxedA *
+test_simple_boxed_a_copy (TestSimpleBoxedA *a)
+{
+  TestSimpleBoxedA *new_a = g_slice_new (TestSimpleBoxedA);
+
+  *new_a = *a;
+
+  return new_a;
+}
+
+static void
+test_simple_boxed_a_free (TestSimpleBoxedA *a)
+{
+  g_slice_free (TestSimpleBoxedA, a);
+}
+
+GType
+test_simple_boxed_a_get_type (void)
+{
+  static GType our_type = 0;
+
+  if (our_type == 0)
+    our_type = g_boxed_type_register_static (g_intern_static_string ("TestSimpleBoxedA"),
+                                            (GBoxedCopyFunc)test_simple_boxed_a_copy,
+                                            (GBoxedFreeFunc)test_simple_boxed_a_free);
+  return our_type;
+}
+
+TestSimpleBoxedB *
+test_simple_boxed_b_copy (TestSimpleBoxedB *b)
+{
+  TestSimpleBoxedB *new_b = g_slice_new (TestSimpleBoxedB);
+
+  *new_b = *b;
+
+  return new_b;
+}
+
+gboolean
+test_simple_boxed_a_equals (TestSimpleBoxedA *a,
+                           TestSimpleBoxedA *other_a)
+{
+  return (a->some_int == other_a->some_int &&
+         a->some_int8 == other_a->some_int8 &&
+         a->some_double == other_a->some_double);
+}
+
+static void
+test_simple_boxed_b_free (TestSimpleBoxedB *a)
+{
+  g_slice_free (TestSimpleBoxedB, a);
+}
+
+GType
+test_simple_boxed_b_get_type (void)
+{
+  static GType our_type = 0;
+
+  if (our_type == 0)
+    our_type = g_boxed_type_register_static (g_intern_static_string ("TestSimpleBoxedB"),
+                                            (GBoxedCopyFunc)test_simple_boxed_b_copy,
+                                            (GBoxedFreeFunc)test_simple_boxed_b_free);
+  return our_type;
+}
+
+/* opaque boxed */
+
+struct _TestBoxedPrivate
+{
+  guint magic;
+};
+
+TestBoxed *
+test_boxed_new (void)
+{
+  TestBoxed *boxed = g_slice_new0(TestBoxed);
+  boxed->priv = g_slice_new0(TestBoxedPrivate);
+  boxed->priv->magic = 0xdeadbeef;
+
+  return boxed;
+}
+
+TestBoxed *
+test_boxed_copy (TestBoxed *boxed)
+{
+  TestBoxed *new_boxed = test_boxed_new();
+  TestBoxedPrivate *save;
+
+  save = new_boxed->priv;
+  *new_boxed = *boxed;
+  new_boxed->priv = save;
+
+  return new_boxed;
+}
+
+gboolean
+test_boxed_equals (TestBoxed *boxed,
+                  TestBoxed *other)
+{
+  return (other->some_int8 == boxed->some_int8 &&
+         test_simple_boxed_a_equals(&other->nested_a, &boxed->nested_a));
+}
+
+static void
+test_boxed_free (TestBoxed *boxed)
+{
+  g_assert (boxed->priv->magic == 0xdeadbeef);
+
+  g_slice_free (TestBoxedPrivate, boxed->priv);
+  g_slice_free (TestBoxed, boxed);
+}
+
+GType
+test_boxed_get_type (void)
+{
+  static GType our_type = 0;
+
+  if (our_type == 0)
+    our_type = g_boxed_type_register_static (g_intern_static_string ("TestBoxed"),
+                                            (GBoxedCopyFunc)test_boxed_copy,
+                                            (GBoxedFreeFunc)test_boxed_free);
+  return our_type;
+}
+
index fc44aa2..18bdceb 100644 (file)
@@ -64,4 +64,70 @@ void test_gslist_free (GSList *in);
 /* ghash? */
 /* error? */
 
+/* structures */
+typedef struct _TestStructA TestStructA;
+typedef struct _TestStructB TestStructB;
+
+struct _TestStructA
+{
+  gint some_int;
+  gint8 some_int8;
+  gdouble some_double;
+};
+
+void test_struct_a_clone (TestStructA *a,
+                         TestStructA *a_out);
+
+struct _TestStructB
+{
+  gint8 some_int8;
+  TestStructA nested_a;
+};
+
+void test_struct_b_clone (TestStructB *b,
+                         TestStructB *b_out);
+
+/* plain-old-data boxed types */
+typedef struct _TestSimpleBoxedA TestSimpleBoxedA;
+typedef struct _TestSimpleBoxedB TestSimpleBoxedB;
+
+struct _TestSimpleBoxedA
+{
+  gint some_int;
+  gint8 some_int8;
+  gdouble some_double;
+};
+
+GType             test_simple_boxed_a_get_type (void);
+TestSimpleBoxedA *test_simple_boxed_a_copy     (TestSimpleBoxedA *a);
+gboolean          test_simple_boxed_a_equals   (TestSimpleBoxedA *a,
+                                               TestSimpleBoxedA *other_a);
+
+struct _TestSimpleBoxedB
+{
+  gint8 some_int8;
+  TestSimpleBoxedA nested_a;
+};
+
+GType             test_simple_boxed_b_get_type (void);
+TestSimpleBoxedB *test_simple_boxed_b_copy     (TestSimpleBoxedB *b);
+
+/* opaque boxed */
+typedef struct _TestBoxed TestBoxed;
+typedef struct _TestBoxedPrivate TestBoxedPrivate;
+
+struct _TestBoxed
+{
+  gint8 some_int8;
+  TestSimpleBoxedA nested_a;
+
+  TestBoxedPrivate *priv;
+};
+
+GType      test_boxed_get_type (void);
+TestBoxed *test_boxed_new      (void);
+TestBoxed *test_boxed_copy     (TestBoxed *boxed);
+gboolean   test_boxed_equals   (TestBoxed *boxed,
+                               TestBoxed *other);
+
 #endif /* __GITESTTYPES_H__ */