Tizen 2.1 base
[platform/upstream/glib2.0.git] / gobject / tests / dynamictests.c
index 1f2a5b7..2cd44ca 100644 (file)
@@ -25,7 +25,7 @@
 /* This test tests the macros for defining dynamic types.
  */
 
-static GMutex *sync_mutex = NULL;
+static GMutex sync_mutex;
 static gboolean loaded = FALSE;
 
 /* MODULE */
@@ -101,7 +101,7 @@ static GType test_module_get_type (void)
 }
 
 
-GTypeModule *
+static GTypeModule *
 test_module_new (TestModuleRegisterFunc register_func)
 {
   TestModule *test_module = g_object_new (TEST_TYPE_MODULE, NULL);
@@ -129,6 +129,7 @@ struct _DynamicObjectClass
   guint val;
 };
 
+static GType dynamic_object_get_type (void);
 G_DEFINE_DYNAMIC_TYPE(DynamicObject, dynamic_object, G_TYPE_OBJECT);
 
 static void
@@ -169,8 +170,8 @@ ref_unref_thread (gpointer data)
    */
   if (g_test_verbose())
     g_print ("WAITING!\n");
-  g_mutex_lock (sync_mutex);
-  g_mutex_unlock (sync_mutex);
+  g_mutex_lock (&sync_mutex);
+  g_mutex_unlock (&sync_mutex);
   if (g_test_verbose ())
     g_print ("STARTING\n");
 
@@ -198,38 +199,167 @@ test_multithreaded_dynamic_type_init (void)
   guint i;
 
   module = test_module_new (module_register);
+  g_assert (module != NULL);
+
   /* Not loaded until we call ref for the first time */
   class = g_type_class_peek (DYNAMIC_OBJECT_TYPE);
   g_assert (class == NULL);
   g_assert (!loaded);
 
   /* pause newly created threads */
-  g_mutex_lock (sync_mutex);
+  g_mutex_lock (&sync_mutex);
 
   /* create threads */
   for (i = 0; i < N_THREADS; i++) {
-    threads[i] = g_thread_create (ref_unref_thread, (gpointer) DYNAMIC_OBJECT_TYPE, TRUE, NULL);
+    threads[i] = g_thread_new ("test", ref_unref_thread, (gpointer) DYNAMIC_OBJECT_TYPE);
   }
 
   /* execute threads */
-  g_mutex_unlock (sync_mutex);
+  g_mutex_unlock (&sync_mutex);
 
   for (i = 0; i < N_THREADS; i++) {
     g_thread_join (threads[i]);
   }
 }
 
+enum
+{
+  PROP_0,
+  PROP_FOO
+};
+
+typedef struct _DynObj DynObj;
+typedef struct _DynObjClass DynObjClass;
+typedef struct _DynIfaceInterface DynIfaceInterface;
+
+struct _DynObj
+{
+  GObject obj;
+
+  gint foo;
+};
+
+struct _DynObjClass
+{
+  GObjectClass class;
+};
+
+struct _DynIfaceInterface
+{
+  GTypeInterface iface;
+};
+
+static void dyn_obj_iface_init (DynIfaceInterface *iface);
+
+static GType dyn_iface_get_type (void);
+G_DEFINE_INTERFACE (DynIface, dyn_iface, G_TYPE_OBJECT)
+
+static GType dyn_obj_get_type (void);
+G_DEFINE_DYNAMIC_TYPE_EXTENDED(DynObj, dyn_obj, G_TYPE_OBJECT, 0,
+                      G_IMPLEMENT_INTERFACE_DYNAMIC(dyn_iface_get_type (), dyn_obj_iface_init))
+
+
+static void
+dyn_iface_default_init (DynIfaceInterface *iface)
+{
+  g_object_interface_install_property (iface,
+    g_param_spec_int ("foo", NULL, NULL, 0, 100, 0, G_PARAM_READWRITE));
+}
+
+static void
+dyn_obj_iface_init (DynIfaceInterface *iface)
+{
+}
+
+static void
+dyn_obj_init (DynObj *obj)
+{
+  obj->foo = 0;
+}
+
+static void
+set_prop (GObject      *object,
+          guint         prop_id,
+          const GValue *value,
+          GParamSpec   *pspec)
+{
+  DynObj *obj = (DynObj *)object;
+
+  switch (prop_id)
+    {
+    case PROP_FOO:
+      obj->foo = g_value_get_int (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+get_prop (GObject    *object,
+          guint       prop_id,
+          GValue     *value,
+          GParamSpec *pspec)
+{
+  DynObj *obj = (DynObj *)object;
+
+  switch (prop_id)
+    {
+    case PROP_FOO:
+      g_value_set_int (value, obj->foo);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+dyn_obj_class_init (DynObjClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->set_property = set_prop;
+  object_class->get_property = get_prop;
+
+  g_object_class_override_property (object_class, PROP_FOO, "foo");
+}
+
+static void
+dyn_obj_class_finalize (DynObjClass *class)
+{
+}
+
+static void
+mod_register (GTypeModule *module)
+{
+  dyn_obj_register_type (module);
+}
+
+static void
+test_dynamic_interface_properties (void)
+{
+  GTypeModule *module;
+  DynObj *obj;
+
+  module = test_module_new (mod_register);
+  g_assert (module != NULL);
+
+  obj = g_object_new (dyn_obj_get_type (), "foo", 1, NULL);
+
+  g_object_unref (obj);
+}
+
 int
 main (int   argc,
       char *argv[])
 {
-  g_thread_init (NULL);
   g_test_init (&argc, &argv, NULL);
   g_type_init ();
 
-  sync_mutex = g_mutex_new();
-
   g_test_add_func ("/GObject/threaded-dynamic-ref-unref-init", test_multithreaded_dynamic_type_init);
+  g_test_add_func ("/GObject/dynamic-interface-properties", test_dynamic_interface_properties);
 
   return g_test_run();
 }