[libpeas] Moved PeasExtension test functions to libtesting



commit 1f388f9c7dc18ce925b8a4fd8b1579cfb025ef5c
Author: Garrett Regier <alias301 gmail com>
Date:   Mon Jan 17 03:06:34 2011 -0800

    Moved PeasExtension test functions to libtesting
    
    This will allow us to easily run the same tests on other loaders.

 .gitignore                                         |    2 +-
 configure.ac                                       |    3 +-
 tests/libpeas/Makefile.am                          |    6 +-
 tests/libpeas/extension-c.c                        |   28 ++
 tests/libpeas/plugins/Makefile.am                  |    2 +-
 tests/libpeas/plugins/callable/Makefile.am         |   19 -
 tests/libpeas/plugins/callable/callable.plugin     |    8 -
 tests/libpeas/plugins/extension-c/Makefile.am      |   23 ++
 .../{callable => extension-c}/callable-plugin.c    |   16 +-
 .../{callable => extension-c}/callable-plugin.h    |    4 +-
 .../plugins/extension-c/extension-c-plugin.c       |   46 +++
 .../plugins/extension-c/extension-c-plugin.h       |   33 ++
 .../extension-c.plugin}                            |    6 +-
 .../properties-plugin.c                            |   12 +-
 .../properties-plugin.h                            |    4 +-
 tests/libpeas/plugins/properties/Makefile.am       |   19 -
 tests/libpeas/testing/Makefile.am                  |   12 +-
 tests/libpeas/testing/testing-extension.c          |  386 ++++++++++++++++++++
 tests/libpeas/testing/testing-extension.h          |   96 +++++
 19 files changed, 641 insertions(+), 84 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index b5611c1..3725588 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,7 +69,7 @@ Makefile.in
 /tests/*-report.xml
 /tests/*/vgdump-*
 /tests/libpeas/engine
-/tests/libpeas/extension
+/tests/libpeas/extension-c
 /tests/libpeas/extension-set
 /tests/libpeas/plugin-info
 /tests/libpeas-gtk/plugin-manager
diff --git a/configure.ac b/configure.ac
index c5e9ca0..0e06e48 100644
--- a/configure.ac
+++ b/configure.ac
@@ -314,8 +314,7 @@ po/Makefile.in
 tests/Makefile
 tests/libpeas/Makefile
 tests/libpeas/plugins/Makefile
-tests/libpeas/plugins/callable/Makefile
-tests/libpeas/plugins/properties/Makefile
+tests/libpeas/plugins/extension-c/Makefile
 tests/libpeas/introspection/Makefile
 tests/libpeas/testing/Makefile
 tests/libpeas-gtk/Makefile
diff --git a/tests/libpeas/Makefile.am b/tests/libpeas/Makefile.am
index 109e398..2f4f3e0 100644
--- a/tests/libpeas/Makefile.am
+++ b/tests/libpeas/Makefile.am
@@ -19,15 +19,15 @@ progs_ldadd = \
 
 TEST_PROGS += \
 	engine		\
-	extension	\
+	extension-c	\
 	extension-set	\
 	plugin-info
 
 engine_SOURCES = engine.c
 engine_LDADD   = $(progs_ldadd)
 
-extension_SOURCES = extension.c
-extension_LDADD   = $(progs_ldadd)
+extension_c_SOURCES = extension-c.c
+extension_c_LDADD   = $(progs_ldadd)
 
 extension_set_SOURCES = extension-set.c
 extension_set_LDADD   = $(progs_ldadd)
diff --git a/tests/libpeas/extension-c.c b/tests/libpeas/extension-c.c
new file mode 100644
index 0000000..a231db9
--- /dev/null
+++ b/tests/libpeas/extension-c.c
@@ -0,0 +1,28 @@
+/*
+ * extension-c.c
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2010 - Garrett Regier
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "testing/testing-extension.h"
+
+EXTENSION_TESTS ("c")
diff --git a/tests/libpeas/plugins/Makefile.am b/tests/libpeas/plugins/Makefile.am
index b3d0c9d..d60d2a5 100644
--- a/tests/libpeas/plugins/Makefile.am
+++ b/tests/libpeas/plugins/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = callable properties
+SUBDIRS = extension-c
 
 noinst_DATA = \
 	info-missing-iage.plugin	\
diff --git a/tests/libpeas/plugins/extension-c/Makefile.am b/tests/libpeas/plugins/extension-c/Makefile.am
new file mode 100644
index 0000000..700deb9
--- /dev/null
+++ b/tests/libpeas/plugins/extension-c/Makefile.am
@@ -0,0 +1,23 @@
+INCLUDES = \
+	-I$(top_srcdir)		\
+	-I$(srcdir)/../../introspection	\
+	$(PEAS_CFLAGS)		\
+	$(WARN_CFLAGS)		\
+	$(DISABLE_DEPRECATED)
+
+noinst_LTLIBRARIES = libextension-c.la
+
+libextension_c_la_SOURCES = \
+	callable-plugin.c	\
+	callable-plugin.h	\
+	extension-c-plugin.c	\
+	extension-c-plugin.h	\
+	properties-plugin.c	\
+	properties-plugin.h
+
+libextension_c_la_LDFLAGS = $(TEST_PLUGIN_LIBTOOL_FLAGS)
+libextension_c_la_LIBADD  = $(PEAS_LIBS)
+
+noinst_DATA = extension-c.plugin
+
+EXTRA_DIST = $(noinst_DATA)
diff --git a/tests/libpeas/plugins/callable/callable-plugin.c b/tests/libpeas/plugins/extension-c/callable-plugin.c
similarity index 85%
rename from tests/libpeas/plugins/callable/callable-plugin.c
rename to tests/libpeas/plugins/extension-c/callable-plugin.c
index 8a6fdab..8754cff 100644
--- a/tests/libpeas/plugins/callable/callable-plugin.c
+++ b/tests/libpeas/plugins/extension-c/callable-plugin.c
@@ -54,11 +54,6 @@ testing_callable_plugin_call_with_return (IntrospectionCallable *callable)
 }
 
 static void
-testing_callable_plugin_call_no_args (IntrospectionCallable *callable)
-{
-}
-
-static void
 testing_callable_plugin_call_single_arg (IntrospectionCallable *callable,
                                          gboolean              *called)
 {
@@ -85,7 +80,6 @@ static void
 introspection_callable_iface_init (IntrospectionCallableInterface *iface)
 {
   iface->call_with_return = testing_callable_plugin_call_with_return;
-  iface->call_no_args = testing_callable_plugin_call_no_args;
   iface->call_single_arg = testing_callable_plugin_call_single_arg;
   iface->call_multi_args = testing_callable_plugin_call_multi_args;
 }
@@ -95,12 +89,8 @@ testing_callable_plugin_class_finalize (TestingCallablePluginClass *klass)
 {
 }
 
-G_MODULE_EXPORT void
-peas_register_types (PeasObjectModule *module)
+void
+testing_callable_plugin_register (GTypeModule *module)
 {
-  testing_callable_plugin_register_type (G_TYPE_MODULE (module));
-
-  peas_object_module_register_extension_type (module,
-                                              INTROSPECTION_TYPE_CALLABLE,
-                                              TESTING_TYPE_CALLABLE_PLUGIN);
+  testing_callable_plugin_register_type (module);
 }
diff --git a/tests/libpeas/plugins/callable/callable-plugin.h b/tests/libpeas/plugins/extension-c/callable-plugin.h
similarity index 92%
rename from tests/libpeas/plugins/callable/callable-plugin.h
rename to tests/libpeas/plugins/extension-c/callable-plugin.h
index 911a7a4..8fd8924 100644
--- a/tests/libpeas/plugins/callable/callable-plugin.h
+++ b/tests/libpeas/plugins/extension-c/callable-plugin.h
@@ -44,8 +44,8 @@ struct _TestingCallablePluginClass {
   PeasExtensionBaseClass parent_class;
 };
 
-GType                 testing_callable_plugin_get_type (void) G_GNUC_CONST;
-G_MODULE_EXPORT void  peas_register_types              (PeasObjectModule *module);
+GType testing_callable_plugin_get_type (void) G_GNUC_CONST;
+void  testing_callable_plugin_register (GTypeModule *module);
 
 G_END_DECLS
 
diff --git a/tests/libpeas/plugins/extension-c/extension-c-plugin.c b/tests/libpeas/plugins/extension-c/extension-c-plugin.c
new file mode 100644
index 0000000..2006a4e
--- /dev/null
+++ b/tests/libpeas/plugins/extension-c/extension-c-plugin.c
@@ -0,0 +1,46 @@
+/*
+ * extension-c-plugin.c
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2011 - Garrett Regier
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "extension-c-plugin.h"
+
+#include "introspection-callable.h"
+#include "introspection-properties.h"
+
+#include "callable-plugin.h"
+#include "properties-plugin.h"
+
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+  testing_callable_plugin_register (G_TYPE_MODULE (module));
+  testing_properties_plugin_register (G_TYPE_MODULE (module));
+
+  peas_object_module_register_extension_type (module,
+                                              INTROSPECTION_TYPE_CALLABLE,
+                                              TESTING_TYPE_CALLABLE_PLUGIN);
+  peas_object_module_register_extension_type (module,
+                                              INTROSPECTION_TYPE_PROPERTIES,
+                                              TESTING_TYPE_PROPERTIES_PLUGIN);
+}
diff --git a/tests/libpeas/plugins/extension-c/extension-c-plugin.h b/tests/libpeas/plugins/extension-c/extension-c-plugin.h
new file mode 100644
index 0000000..5b3efb9
--- /dev/null
+++ b/tests/libpeas/plugins/extension-c/extension-c-plugin.h
@@ -0,0 +1,33 @@
+/*
+ * extension-c-plugin.h
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2011 - Garrett Regier
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __EXTENSION_C_PLUGIN_H__
+#define __EXTENSION_C_PLUGIN_H__
+
+#include <libpeas/peas.h>
+
+G_BEGIN_DECLS
+
+G_MODULE_EXPORT void  peas_register_types (PeasObjectModule *module);
+
+G_END_DECLS
+
+#endif /* __EXTENSION_C_PLUGIN_H__ */
diff --git a/tests/libpeas/plugins/properties/properties.plugin b/tests/libpeas/plugins/extension-c/extension-c.plugin
similarity index 56%
rename from tests/libpeas/plugins/properties/properties.plugin
rename to tests/libpeas/plugins/extension-c/extension-c.plugin
index bcfced4..fccd764 100644
--- a/tests/libpeas/plugins/properties/properties.plugin
+++ b/tests/libpeas/plugins/extension-c/extension-c.plugin
@@ -1,8 +1,8 @@
 [Plugin]
-Module=properties
+Module=extension-c
 IAge=2
-Name=Properties
-Description=This plugin can be loaded and has properties.
+Name=Extension C
+Description=This plugin is for the C PeasExtension tests.
 Authors=Garrett Regier
 Copyright=Copyright © 2010 Garrett Regier
 Website=http://live.gnome.org/Libpeas
diff --git a/tests/libpeas/plugins/properties/properties-plugin.c b/tests/libpeas/plugins/extension-c/properties-plugin.c
similarity index 93%
rename from tests/libpeas/plugins/properties/properties-plugin.c
rename to tests/libpeas/plugins/extension-c/properties-plugin.c
index 727d0d2..469b1d6 100644
--- a/tests/libpeas/plugins/properties/properties-plugin.c
+++ b/tests/libpeas/plugins/extension-c/properties-plugin.c
@@ -82,7 +82,7 @@ testing_properties_plugin_set_property (GObject      *object,
       break;
 
     case PROP_WRITE_ONLY:
-      /* Don't bother doing anything */
+      /* Don't bother actually doing anythin */
       break;
 
     case PROP_READWRITE:
@@ -173,12 +173,8 @@ testing_properties_plugin_class_finalize (TestingPropertiesPluginClass *klass)
 {
 }
 
-G_MODULE_EXPORT void
-peas_register_types (PeasObjectModule *module)
+void
+testing_properties_plugin_register (GTypeModule *module)
 {
-  testing_properties_plugin_register_type (G_TYPE_MODULE (module));
-
-  peas_object_module_register_extension_type (module,
-                                              INTROSPECTION_TYPE_PROPERTIES,
-                                              TESTING_TYPE_PROPERTIES_PLUGIN);
+  testing_properties_plugin_register_type (module);
 }
diff --git a/tests/libpeas/plugins/properties/properties-plugin.h b/tests/libpeas/plugins/extension-c/properties-plugin.h
similarity index 93%
rename from tests/libpeas/plugins/properties/properties-plugin.h
rename to tests/libpeas/plugins/extension-c/properties-plugin.h
index 5f5a477..826bcb9 100644
--- a/tests/libpeas/plugins/properties/properties-plugin.h
+++ b/tests/libpeas/plugins/extension-c/properties-plugin.h
@@ -47,8 +47,8 @@ struct _TestingPropertiesPluginClass {
   PeasExtensionBaseClass parent_class;
 };
 
-GType                 testing_properties_plugin_get_type (void) G_GNUC_CONST;
-G_MODULE_EXPORT void  peas_register_types                (PeasObjectModule *module);
+GType testing_properties_plugin_get_type (void) G_GNUC_CONST;
+void  testing_properties_plugin_register (GTypeModule *module);
 
 G_END_DECLS
 
diff --git a/tests/libpeas/testing/Makefile.am b/tests/libpeas/testing/Makefile.am
index ebd6457..c7736e5 100644
--- a/tests/libpeas/testing/Makefile.am
+++ b/tests/libpeas/testing/Makefile.am
@@ -1,6 +1,7 @@
 INCLUDES = \
 	-I$(top_srcdir)				\
 	-I$(srcdir)				\
+	-I../introspection			\
 	$(PEAS_CFLAGS)				\
 	$(WARN_CFLAGS)				\
 	$(DISABLE_DEPRECATED)			\
@@ -12,7 +13,12 @@ libtesting_la_LDFLAGS = \
 	-export-dynamic -no-undefined -export-symbols-regex "^[^_].*"
 
 libtesting_la_LIBADD = \
-	$(PEAS_LIBS)				\
-	$(top_builddir)/libpeas/libpeas-1.0.la
+	$(PEAS_LIBS)					\
+	$(top_builddir)/libpeas/libpeas-1.0.la		\
+	../introspection/libintrospection-1.0.la
 
-libtesting_la_SOURCES = testing.c testing.h
+libtesting_la_SOURCES = \
+	testing.c		\
+	testing.h		\
+	testing-extension.c	\
+	testing-extension.h
diff --git a/tests/libpeas/testing/testing-extension.c b/tests/libpeas/testing/testing-extension.c
new file mode 100644
index 0000000..d1ca6a3
--- /dev/null
+++ b/tests/libpeas/testing/testing-extension.c
@@ -0,0 +1,386 @@
+/*
+ * testing-extensin.c
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2011 - Garrett Regier
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <glib.h>
+#include <libpeas/peas.h>
+
+#include "testing.h"
+#include "testing-extension.h"
+
+#include "introspection-callable.h"
+#include "introspection-properties.h"
+#include "introspection-unimplemented.h"
+
+/* TODO:
+ *        - IntrospectionCallable:
+ *            - No Invoker
+ *            - No Struct Field
+ */
+
+static gchar *extension_plugin;
+
+void
+testing_extension_set_plugin_ (const gchar *plugin)
+{
+  extension_plugin = (gchar *) plugin;
+}
+
+void
+testing_extension_test_setup_ (TestingExtensionFixture_ *fixture,
+                               gconstpointer             data)
+{
+  fixture->engine = testing_engine_new ();
+}
+
+void
+testing_extension_test_teardown_ (TestingExtensionFixture_ *fixture,
+                                  gconstpointer             data)
+{
+  testing_engine_free (fixture->engine);
+}
+
+void
+testing_extension_test_runner_  (TestingExtensionFixture_ *fixture,
+                               gconstpointer             data)
+{
+  ((void (*) (PeasEngine *engine)) data) (fixture->engine);
+}
+
+void
+testing_extension_create_valid_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_CALLABLE,
+                                            NULL);
+
+  g_assert (PEAS_IS_EXTENSION (extension));
+  g_assert (INTROSPECTION_IS_CALLABLE (extension));
+
+  g_object_unref (extension);
+}
+
+void
+testing_extension_create_invalid_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  /* Not loaded */
+  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
+    {
+      extension = peas_engine_create_extension (engine, info,
+                                                INTROSPECTION_TYPE_CALLABLE,
+                                                NULL);
+      /* Resident Modules */
+      g_object_unref (extension);
+      exit (0);
+    }
+  /* Resident modules cause this to fail?
+  g_test_trap_assert_failed ();*/
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  /* Invalid GType */
+  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
+    {
+      extension = peas_engine_create_extension (engine, info,
+                                                G_TYPE_INVALID,
+                                                NULL);
+      exit (0);
+    }
+  g_test_trap_assert_failed ();
+  g_test_trap_assert_stderr ("*CRITICAL*");
+
+
+  /* GObject but not a GInterface */
+  extension = peas_engine_create_extension (engine, info,
+                                            PEAS_TYPE_ENGINE,
+                                            NULL);
+  g_assert (!PEAS_IS_EXTENSION (extension));
+
+
+  /* Does not implement this GType */
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_UNIMPLEMENTED,
+                                            NULL);
+  g_assert (!PEAS_IS_EXTENSION (extension));
+}
+
+void
+testing_extension_call_invalid_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_CALLABLE,
+                                            NULL);
+
+  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
+    {
+      peas_extension_call (extension, "invalid", NULL);
+      exit (0);
+    }
+  g_test_trap_assert_failed ();
+  g_test_trap_assert_stderr ("*Method 'IntrospectionCallable.invalid' not found*");
+
+  g_object_unref (extension);
+}
+
+void
+testing_extension_call_no_args_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+  IntrospectionCallable *callable;
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_CALLABLE,
+                                            NULL);
+
+  callable = INTROSPECTION_CALLABLE (extension);
+
+  introspection_callable_call_no_args (callable);
+
+  g_object_unref (extension);
+}
+
+void
+testing_extension_call_with_return_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+  IntrospectionCallable *callable;
+  const gchar *return_val = NULL;
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_CALLABLE,
+                                            NULL);
+
+  callable = INTROSPECTION_CALLABLE (extension);
+
+  return_val = introspection_callable_call_with_return (callable);
+  g_assert_cmpstr (return_val, ==, "Hello, World!");
+
+  g_object_unref (extension);
+}
+
+void
+testing_extension_call_single_arg_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+  IntrospectionCallable *callable;
+  gboolean called = FALSE;
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_CALLABLE,
+                                            NULL);
+
+  callable = INTROSPECTION_CALLABLE (extension);
+
+  introspection_callable_call_single_arg (callable, &called);
+  g_assert (called);
+
+  g_object_unref (extension);
+}
+
+void
+testing_extension_call_multi_args_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+  IntrospectionCallable *callable;
+  gboolean params[3] = { FALSE, FALSE, FALSE };
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_CALLABLE,
+                                            NULL);
+
+  callable = INTROSPECTION_CALLABLE (extension);
+
+  introspection_callable_call_multi_args (callable, &params[0],
+                                          &params[1], &params[2]);
+  g_assert (params[0] && params[1] && params[2]);
+
+  g_object_unref (extension);
+}
+
+void
+testing_extension_properties_construct_only_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+  gchar *construct_only;
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  FILE *saved_stdout = stdout;
+  FILE *saved_stderr = stderr;
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  stdout = saved_stdout;
+  stderr = saved_stderr;
+
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_PROPERTIES,
+                                            "construct-only", "my-construct-only",
+                                            NULL);
+
+
+  g_object_get (extension, "construct-only", &construct_only, NULL);
+  g_assert_cmpstr (construct_only, ==, "my-construct-only");
+  g_free (construct_only);
+
+  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
+    {
+      g_object_set (extension, "construct-only", "other-construct-only", NULL);
+      exit (0);
+    }
+  g_test_trap_assert_failed ();
+  g_test_trap_assert_stderr ("*WARNING*");
+
+  g_object_unref (extension);
+}
+
+void
+testing_extension_properties_read_only_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+  gchar *read_only;
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_PROPERTIES,
+                                            NULL);
+
+  g_object_get (extension, "read-only", &read_only, NULL);
+  g_assert_cmpstr (read_only, ==, "read-only");
+  g_free (read_only);
+
+  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
+    {
+      g_object_set (extension, "read-only", "my-read-only", NULL);
+      exit (0);
+    }
+  g_test_trap_assert_failed ();
+  g_test_trap_assert_stderr ("*WARNING*");
+
+  g_object_unref (extension);
+}
+
+void
+testing_extension_properties_write_only_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_PROPERTIES,
+                                            NULL);
+
+  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
+    {
+      gchar *write_only = NULL;
+
+      g_object_get (extension, "write-only", &write_only, NULL);
+      exit (0);
+    }
+  g_test_trap_assert_failed ();
+  g_test_trap_assert_stderr ("*WARNING*");
+
+  g_object_set (extension, "write-only", "my-write-only", NULL);
+
+  g_object_unref (extension);
+}
+
+void
+testing_extension_properties_readwrite_ (PeasEngine *engine)
+{
+  PeasPluginInfo *info;
+  PeasExtension *extension;
+  gchar *readwrite;
+
+  info = peas_engine_get_plugin_info (engine, extension_plugin);
+
+  g_assert (peas_engine_load_plugin (engine, info));
+
+  extension = peas_engine_create_extension (engine, info,
+                                            INTROSPECTION_TYPE_PROPERTIES,
+                                            NULL);
+
+  g_object_get (extension, "readwrite", &readwrite, NULL);
+  g_assert_cmpstr (readwrite, ==, "readwrite");
+  g_free (readwrite);
+
+  g_object_set (extension, "readwrite", "my-readwrite", NULL);
+
+  g_object_get (extension, "readwrite", &readwrite, NULL);
+  g_assert_cmpstr (readwrite, ==, "my-readwrite");
+  g_free (readwrite);
+
+  g_object_unref (extension);
+}
diff --git a/tests/libpeas/testing/testing-extension.h b/tests/libpeas/testing/testing-extension.h
new file mode 100644
index 0000000..27138f8
--- /dev/null
+++ b/tests/libpeas/testing/testing-extension.h
@@ -0,0 +1,96 @@
+/*
+ * testing-extension.h
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2011 - Garrett Regier
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __TESTING_EXTENSION_H__
+#define __TESTING_EXTENSION_H__
+
+#include <libpeas/peas-engine.h>
+
+G_BEGIN_DECLS
+
+typedef struct _TestingExtensionFixture_ TestingExtensionFixture_;
+
+struct _TestingExtensionFixture_ {
+  PeasEngine *engine;
+};
+
+void testing_extension_set_plugin_    (const gchar              *plugin);
+
+void testing_extension_test_setup_    (TestingExtensionFixture_ *fixture,
+                                       gconstpointer             data);
+void testing_extension_test_teardown_ (TestingExtensionFixture_ *fixture,
+                                       gconstpointer             data);
+void testing_extension_test_runner_   (TestingExtensionFixture_ *fixture,
+                                       gconstpointer             data);
+
+void testing_extension_create_valid_              (PeasEngine *engine);
+void testing_extension_create_invalid_            (PeasEngine *engine);
+void testing_extension_call_invalid_              (PeasEngine *engine);
+void testing_extension_call_no_args_              (PeasEngine *engine);
+void testing_extension_call_with_return_          (PeasEngine *engine);
+void testing_extension_call_single_arg_           (PeasEngine *engine);
+void testing_extension_call_multi_args_           (PeasEngine *engine);
+void testing_extension_properties_construct_only_ (PeasEngine *engine);
+void testing_extension_properties_read_only_      (PeasEngine *engine);
+void testing_extension_properties_write_only_     (PeasEngine *engine);
+void testing_extension_properties_readwrite_      (PeasEngine *engine);
+
+
+#define _EXTENSION_TEST(loader, path, ftest) \
+  g_test_add ("/extension/" loader "/" path, TestingExtensionFixture_, \
+              (gpointer) testing_extension_##ftest##_, \
+              testing_extension_test_setup_, \
+              testing_extension_test_runner_, \
+              testing_extension_test_teardown_);
+
+#define EXTENSION_TESTS(loader) \
+int \
+main (int   argc, \
+      char *argv[]) \
+{ \
+  g_test_init (&argc, &argv, NULL); \
+\
+  g_type_init (); \
+\
+  testing_extension_set_plugin_ ("extension-" loader); \
+\
+  _EXTENSION_TEST (loader, "create-valid", create_valid); \
+  _EXTENSION_TEST (loader, "create-invalid", create_invalid); \
+\
+  _EXTENSION_TEST (loader, "call-invalid", call_invalid); \
+  _EXTENSION_TEST (loader, "call-no-args", call_no_args); \
+  _EXTENSION_TEST (loader, "call-with-return", call_with_return); \
+  _EXTENSION_TEST (loader, "call-single-arg", call_single_arg); \
+  _EXTENSION_TEST (loader, "call-multi-args", call_multi_args); \
+\
+  _EXTENSION_TEST (loader, "properties-construct-only", properties_construct_only); \
+  _EXTENSION_TEST (loader, "properties-read-only", properties_read_only); \
+  _EXTENSION_TEST (loader, "properties-write-only", properties_write_only); \
+  _EXTENSION_TEST (loader, "properties-readwrite", properties_readwrite); \
+\
+  g_object_unref (peas_engine_get_default ()); \
+\
+  return g_test_run (); \
+}
+
+G_END_DECLS
+
+#endif /* __TESTING__EXTENSION_H__ */



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