[libpeas] Add a test to check the refcount of the instance of C extensions
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Add a test to check the refcount of the instance of C extensions
- Date: Mon, 7 Mar 2011 17:21:27 +0000 (UTC)
commit 6ba828d38c7e3b985a64c12ba7ca7dd38d67de6d
Author: Steve Frécinaux <code istique net>
Date: Sun Mar 6 19:34:11 2011 +0100
Add a test to check the refcount of the instance of C extensions
To do so I had to make the "instance" property of PeasExtensionC readable.
loaders/c/peas-extension-c.c | 21 ++++++++++++++++++-
tests/libpeas/extension-c.c | 32 +++++++++++++++++++++++++++++
tests/libpeas/testing/testing-extension.h | 9 +++++++-
3 files changed, 60 insertions(+), 2 deletions(-)
---
diff --git a/loaders/c/peas-extension-c.c b/loaders/c/peas-extension-c.c
index ea8d293..2b2d44a 100644
--- a/loaders/c/peas-extension-c.c
+++ b/loaders/c/peas-extension-c.c
@@ -58,6 +58,24 @@ peas_extension_c_set_property (GObject *object,
}
}
+static void
+peas_extension_c_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PeasExtensionC *cexten = PEAS_EXTENSION_C (object);
+
+ switch (prop_id)
+ {
+ case PROP_INSTANCE:
+ g_value_set_object (value, cexten->instance);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
static gboolean
peas_extension_c_call (PeasExtension *exten,
GType gtype,
@@ -94,6 +112,7 @@ peas_extension_c_class_init (PeasExtensionCClass *klass)
PeasExtensionClass *extension_class = PEAS_EXTENSION_CLASS (klass);
object_class->set_property = peas_extension_c_set_property;
+ object_class->get_property = peas_extension_c_get_property;
object_class->dispose = peas_extension_c_dispose;
extension_class->call = peas_extension_c_call;
@@ -104,7 +123,7 @@ peas_extension_c_class_init (PeasExtensionCClass *klass)
"Extension Instance",
"The C Extension Instance",
G_TYPE_OBJECT,
- G_PARAM_WRITABLE |
+ G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
diff --git a/tests/libpeas/extension-c.c b/tests/libpeas/extension-c.c
index 4cc76cb..64b3cad 100644
--- a/tests/libpeas/extension-c.c
+++ b/tests/libpeas/extension-c.c
@@ -24,6 +24,36 @@
#endif
#include "testing/testing-extension.h"
+#include "introspection/introspection-callable.h"
+
+static void
+extension_c_instance_refcount (PeasEngine *engine)
+{
+ PeasPluginInfo *info;
+ PeasExtension *extension;
+ GObject *instance;
+
+ info = peas_engine_get_plugin_info (engine, "extension-c");
+
+ 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_object_get (extension, "instance", &instance, NULL);
+
+ /* The refcount of the returned object should be 2:
+ * - one ref for the PeasExtension
+ * - one ref added by g_object_get()
+ */
+ g_assert_cmpint (instance->ref_count, ==, 2);
+ g_object_unref (instance);
+
+ g_object_unref (extension);
+}
int
main (int argc,
@@ -34,5 +64,7 @@ main (int argc,
EXTENSION_TESTS ("c");
+ EXTENSION_TEST_ADD ("c", "instance-refcount", extension_c_instance_refcount);
+
return testing_run_tests ();
}
diff --git a/tests/libpeas/testing/testing-extension.h b/tests/libpeas/testing/testing-extension.h
index 3269723..c84ed7e 100644
--- a/tests/libpeas/testing/testing-extension.h
+++ b/tests/libpeas/testing/testing-extension.h
@@ -65,7 +65,6 @@ void testing_extension_properties_readwrite_ (PeasEngine *engine);
g_object_unref (peas_engine_get_default ()); \
testing_extension_set_plugin_ ("extension-" loader);
-
#define _EXTENSION_TEST(loader, path, ftest) \
g_test_add ("/extension/" loader "/" path, TestingExtensionFixture_, \
(gpointer) testing_extension_##ftest##_, \
@@ -97,6 +96,14 @@ void testing_extension_properties_readwrite_ (PeasEngine *engine);
_EXTENSION_TEST (loader, "properties-write-only", properties_write_only); \
_EXTENSION_TEST (loader, "properties-readwrite", properties_readwrite);
+/* This macro is there to add loader-specific tests. */
+#define EXTENSION_TEST_ADD(loader, path, func) \
+ g_test_add ("/extension/" loader "/" path, TestingExtensionFixture_, \
+ (gpointer) func, \
+ testing_extension_test_setup_, \
+ testing_extension_test_runner_, \
+ testing_extension_test_teardown_);
+
G_END_DECLS
#endif /* __TESTING__EXTENSION_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]