gobject-introspection r672 - trunk/tests/types



Author: lucasr
Date: Sat Oct 11 22:54:04 2008
New Revision: 672
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=672&view=rev

Log:
Added test files.


Added:
   trunk/tests/types/
   trunk/tests/types/Makefile.am
   trunk/tests/types/gitesttypes.c
   trunk/tests/types/gitesttypes.h

Added: trunk/tests/types/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/tests/types/Makefile.am	Sat Oct 11 22:54:04 2008
@@ -0,0 +1,43 @@
+AM_CFLAGS = $(GOBJECT_CFLAGS)
+AM_LDFLAGS = -module -avoid-version
+LIBS = $(GOBJECT_LIBS)
+
+testprefix = $(pkglibdir)/test
+
+testlibdir = $(testprefix)
+testlib_LTLIBRARIES = libgitesttypes.la
+
+girdir = $(testprefix)/gir
+dist_gir_DATA = $(GIRS)
+
+typelibdir = $(testprefix)/girepository
+typelib_DATA = $(TYPELIBS)
+
+libgitesttypes_la_SOURCES = $(srcdir)/gitesttypes.c $(srcdir)/gitesttypes.h
+
+if OS_WIN32
+AM_LDFLAGS += -no-undefined
+endif
+
+GIRS =
+SCANNER = $(top_srcdir)/tools/g-ir-scanner
+SCANNER_LIBS = $(top_srcdir)/giscanner/*.py \
+	       $(top_builddir)/giscanner/libgiscanner.la
+TYPELIBS = $(GIRS:.gir=.typelib)
+TXMLS = $(GIRS:.gir=.gir.txml)
+CLEANFILES = $(TYPELIBS) $(TXMLS) $(GIRS)
+BUILT_SOURCES = $(TYPELIBS) $(TXMLS) $(GIRS)
+
+%.gir: lib%.la %.c %.h $(SCANNER) $(SCANNER_LIBS)
+	PYTHONPATH=$(top_builddir):$$PYTHONPATH $(CHECK_DEBUG) $(SCANNER) -v \
+	--include=$(top_srcdir)/gir/GObject.gir \
+	--library=$* \
+	--namespace=$* \
+	--pkg gobject-2.0 \
+	$(srcdir)/$*.h $(srcdir)/$*.c \
+	--output $@
+GIRS += gitesttypes.gir
+
+%.typelib: %.gir $(top_builddir)/tools/g-ir-compiler$(EXEEXT) Makefile
+	$(top_builddir)/tools/g-ir-compiler --includedir=. --includedir=$(top_builddir)/gir $< -o $@
+	$(SCANNER) --typelib-xml $< > $<.tmp && mv $<.tmp $<.txml

Added: trunk/tests/types/gitesttypes.c
==============================================================================
--- (empty file)
+++ trunk/tests/types/gitesttypes.c	Sat Oct 11 22:54:04 2008
@@ -0,0 +1,316 @@
+
+#include <gitesttypes.h>
+
+/* basic types */
+gboolean test_boolean (gboolean in)
+{
+  return in;
+}
+
+gint8 test_int8 (gint8 in)
+{
+  return in;
+}
+
+guint8 test_uint8 (guint8 in)
+{
+  return in;
+}
+
+gint16 test_int16 (gint16 in)
+{
+  return in;
+}
+
+guint16 test_uint16 (guint16 in)
+{
+  return in;
+}
+
+gint32 test_int32 (gint32 in)
+{
+  return in;
+}
+
+guint32 test_uint32 (guint32 in)
+{
+  return in;
+}
+
+gint64 test_int64 (gint64 in)
+{
+  return in;
+}
+
+guint64 test_uint64 (guint64 in)
+{
+  return in;
+}
+
+gint test_int (gint in)
+{
+  return in;
+}
+
+guint test_uint (guint in)
+{
+  return in;
+}
+
+glong test_long (glong in)
+{
+  return in;
+}
+
+gulong test_ulong (gulong in)
+{
+  return in;
+}
+
+gssize test_ssize (gssize in)
+{
+  return in;
+}
+
+gsize test_size (gsize in)
+{
+  return in;
+}
+
+gfloat test_float (gfloat in)
+{
+  return in;
+}
+
+gdouble test_double (gdouble in)
+{
+  return in;
+}
+
+
+/* time_t? */
+GType test_gtype (GType in)
+{
+  return in;
+}
+
+#if 0
+/************************************************************************/
+/* utf8 */
+/* insert BLACK HEART SUIT to ensure UTF-8 doesn't get mangled */
+static const char utf8_const[]    = "const \xe2\x99\xa5 utf8";
+static const char utf8_nonconst[] = "nonconst \xe2\x99\xa5 utf8";
+
+/** test_utf8_const_return:
+ * Return value: <const char*> UTF-8 string
+ */
+G_CONST_RETURN char *test_utf8_const_return (void)
+{
+  return utf8_const;
+}
+
+/** test_utf8_nonconst_return:
+ * Return value: <char*> UTF-8 string
+ */
+char *test_utf8_nonconst_return (void)
+{
+  return g_strdup (utf8_nonconst);
+}
+
+void test_utf8_nonconst_in (char *in)
+{
+  g_assert (strcmp (in, utf8_nonconst) == 0);
+}
+
+void test_utf8_const_in (const char *in)
+{
+  g_assert (strcmp (in, utf8_const) == 0);
+}
+
+void test_utf8_out (char **out)
+{
+  *out = g_strdup (utf8_nonconst);
+}
+
+void test_utf8_inout (char **inout)
+{
+  g_assert (strcmp (*inout, utf8_const) == 0);
+  *input = g_strdup (utf8_nonconst);
+}
+#endif
+
+/* filename? */
+/* non-basic-types */
+/* array */
+/* interface */
+
+static const char *test_sequence[] = {"1", "2", "3"};
+
+/************************************************************************/
+/* GList */
+
+static /*const*/ GList *test_sequence_list()
+{
+    static GList *list = NULL;
+    if (!list) {
+        gsize i;
+        for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
+            list = g_list_prepend (list, (gpointer)test_sequence[i]);
+        }
+        list = g_list_reverse (list);
+    }
+    return list;
+}
+
+void test_glist_free (GList *in)
+{
+  g_list_foreach (in, (GFunc)g_free, NULL);
+  g_list_free (in);
+}
+
+/* free=none */
+G_CONST_RETURN GList *test_glist_nothing_return (void)
+{
+  return test_sequence_list ();
+}
+
+/* free=none */
+GList *test_glist_nothing_return2 (void)
+{
+  return test_sequence_list ();
+}
+
+/* free=g_list_free */
+GList *test_glist_container_return (void)
+{
+  return g_list_copy (test_sequence_list ());
+}
+
+/* free=test_glist_free */
+GList *test_glist_everything_return (void)
+{
+  GList *list;
+  GList *l;
+
+  list = g_list_copy (test_sequence_list ());
+  for (l = list; l != NULL; l = l->next)
+      l->data = g_strdup (l->data);
+  return list;
+}
+
+static void assert_test_sequence_list (const GList *in)
+{
+  const GList *l;
+  gsize i;
+
+  for (i = 0, l = in; l != NULL; ++i, l = l->next)
+      g_assert (strcmp (in->data, test_sequence[i]) == 0);
+}
+
+void test_glist_nothing_in (const GList *in)
+{
+  assert_test_sequence_list (in);
+}
+
+void test_glist_nothing_in2 (GList *in)
+{
+  assert_test_sequence_list (in);
+}
+
+void test_glist_container_in (GList *in)
+{
+  assert_test_sequence_list (in);
+  g_list_free (in);
+}
+
+void test_glist_everything_in (GList *in)
+{
+  assert_test_sequence_list (in);
+  test_glist_free (in);
+}
+
+/************************************************************************/
+/* GSList */
+
+static /*const*/ GSList *test_sequence_slist()
+{
+    static GSList *list = NULL;
+    if (!list) {
+        gsize i;
+        for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
+            list = g_slist_prepend (list, (gpointer)test_sequence[i]);
+        }
+        list = g_slist_reverse (list);
+    }
+    return list;
+}
+
+void test_gslist_free (GSList *in)
+{
+  g_slist_foreach (in, (GFunc)g_free, NULL);
+  g_slist_free (in);
+}
+
+/* free=none */
+G_CONST_RETURN GSList *test_gslist_nothing_return (void)
+{
+  return test_sequence_slist ();
+}
+
+/* free=none */
+GSList *test_gslist_nothing_return2 (void)
+{
+  return test_sequence_slist ();
+}
+
+/* free=g_slist_free */
+GSList *test_gslist_container_return (void)
+{
+  return g_slist_copy (test_sequence_slist ());
+}
+
+/* free=test_gslist_free */
+GSList *test_gslist_everything_return (void)
+{
+  GSList *list;
+  GSList *l;
+
+  list = g_slist_copy (test_sequence_slist ());
+  for (l = list; l != NULL; l = l->next)
+      l->data = g_strdup (l->data);
+  return list;
+}
+
+static void assert_test_sequence_slist (const GSList *in)
+{
+  const GSList *l;
+  gsize i;
+
+  for (i = 0, l = in; l != NULL; ++i, l = l->next)
+      g_assert (strcmp (in->data, test_sequence[i]) == 0);
+}
+
+void test_gslist_nothing_in (const GSList *in)
+{
+  assert_test_sequence_slist (in);
+}
+
+void test_gslist_nothing_in2 (GSList *in)
+{
+  assert_test_sequence_slist (in);
+}
+
+void test_gslist_container_in (GSList *in)
+{
+  assert_test_sequence_slist (in);
+  g_slist_free (in);
+}
+
+void test_gslist_everything_in (GSList *in)
+{
+  assert_test_sequence_slist (in);
+  test_gslist_free (in);
+}
+
+/* ghash? */
+/* error? */

Added: trunk/tests/types/gitesttypes.h
==============================================================================
--- (empty file)
+++ trunk/tests/types/gitesttypes.h	Sat Oct 11 22:54:04 2008
@@ -0,0 +1,64 @@
+#ifndef __GITESTTYPES_H__
+#define __GITESTTYPES_H__
+
+#include <glib-object.h>
+
+/* basic types */
+gboolean test_boolean (gboolean in);
+gint8 test_int8 (gint8 in);
+guint8 test_uint8 (guint8 in);
+gint16 test_int16 (gint16 in);
+guint16 test_uint16 (guint16 in);
+gint32 test_int32 (gint32 in);
+guint32 test_uint32 (guint32 in);
+gint64 test_int64 (gint64 in);
+guint64 test_uint64 (guint64 in);
+gint test_int (gint in);
+guint test_uint (guint in);
+glong test_long (glong in);
+gulong test_ulong (gulong in);
+gssize test_ssize (gssize in);
+gsize test_size (gsize in);
+gfloat test_float (gfloat in);
+gdouble test_double (gdouble in);
+/* time_t? */
+GType test_gtype (GType in);
+#if 0
+/* utf8 */
+G_CONST_RETURN char *test_utf8_const_return (void);
+char *test_utf8_nonconst_return (void);
+void test_utf8_nonconst_in (char *in);
+void test_utf8_const_in (const char *in);
+void test_utf8_out (char **out);
+void test_utf8_inout (char **inout);
+#endif
+/* filename? */
+/* non-basic-types */
+/* array */
+/* interface */
+/* GList */
+G_CONST_RETURN GList *test_glist_nothing_return (void);
+GList *test_glist_nothing_return2 (void);
+GList *test_glist_container_return (void);
+GList *test_glist_everything_return (void);
+void test_glist_nothing_in (const GList *in);
+void test_glist_nothing_in2 (GList *in);
+void test_glist_container_in (GList *in);
+void test_glist_everything_in (GList *in);
+void test_glist_free (GList *in);
+
+/* GSList */
+G_CONST_RETURN GSList *test_gslist_nothing_return (void);
+GSList *test_gslist_nothing_return2 (void);
+GSList *test_gslist_container_return (void);
+GSList *test_gslist_everything_return (void);
+void test_gslist_nothing_in (const GSList *in);
+void test_gslist_nothing_in2 (GSList *in);
+void test_gslist_container_in (GSList *in);
+void test_gslist_everything_in (GSList *in);
+void test_gslist_free (GSList *in);
+
+/* ghash? */
+/* error? */
+
+#endif /* __GITESTTYPES_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]