sl@0: /* sl@0: * Portions copyright (c) 2006-2009 Nokia Corporation. All rights reserved. sl@0: */ sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*__SYMBIAN32__*/ sl@0: #define G_TYPE_TEST (my_test_get_type ()) sl@0: #define MY_TEST(test) (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest)) sl@0: #define MY_IS_TEST(test) (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST)) sl@0: #define MY_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass)) sl@0: #define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST)) sl@0: #define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass)) sl@0: sl@0: enum { sl@0: PROP_0, sl@0: PROP_DUMMY sl@0: }; sl@0: sl@0: typedef struct _GTest GTest; sl@0: typedef struct _GTestClass GTestClass; sl@0: sl@0: struct _GTest sl@0: { sl@0: GObject object; sl@0: sl@0: gint dummy; sl@0: }; sl@0: sl@0: struct _GTestClass sl@0: { sl@0: GObjectClass parent_class; sl@0: }; sl@0: sl@0: static GType my_test_get_type (void); sl@0: sl@0: static void my_test_class_init (GTestClass * klass); sl@0: static void my_test_init (GTest * test); sl@0: static void my_test_dispose (GObject * object); sl@0: static void my_test_get_property (GObject *object, sl@0: guint prop_id, sl@0: GValue *value, sl@0: GParamSpec *pspec); sl@0: static void my_test_set_property (GObject *object, sl@0: guint prop_id, sl@0: const GValue *value, sl@0: GParamSpec *pspec); sl@0: sl@0: static GObjectClass *parent_class = NULL; sl@0: sl@0: static GType sl@0: my_test_get_type (void) sl@0: { sl@0: static GType test_type = 0; sl@0: sl@0: if (!test_type) { sl@0: static const GTypeInfo test_info = { sl@0: sizeof (GTestClass), sl@0: NULL, sl@0: NULL, sl@0: (GClassInitFunc) my_test_class_init, sl@0: NULL, sl@0: NULL, sl@0: sizeof (GTest), sl@0: 0, sl@0: (GInstanceInitFunc) my_test_init, sl@0: NULL sl@0: }; sl@0: sl@0: test_type = g_type_register_static (G_TYPE_OBJECT, "GTest", sl@0: &test_info, 0); sl@0: } sl@0: return test_type; sl@0: } sl@0: sl@0: static void sl@0: my_test_class_init (GTestClass * klass) sl@0: { sl@0: GObjectClass *gobject_class; sl@0: sl@0: gobject_class = (GObjectClass *) klass; sl@0: sl@0: parent_class = g_type_class_ref (G_TYPE_OBJECT); sl@0: sl@0: gobject_class->dispose = my_test_dispose; sl@0: gobject_class->get_property = my_test_get_property; sl@0: gobject_class->set_property = my_test_set_property; sl@0: sl@0: g_object_class_install_property (gobject_class, sl@0: PROP_DUMMY, sl@0: g_param_spec_int ("dummy", sl@0: NULL, sl@0: NULL, sl@0: 0, G_MAXINT, 0, sl@0: G_PARAM_READWRITE)); sl@0: } sl@0: sl@0: static void sl@0: my_test_init (GTest * test) sl@0: { sl@0: g_print ("init %p\n", test); sl@0: } sl@0: sl@0: static void sl@0: my_test_dispose (GObject * object) sl@0: { sl@0: GTest *test; sl@0: sl@0: test = MY_TEST (object); sl@0: sl@0: g_print ("dispose %p!\n", object); sl@0: sl@0: G_OBJECT_CLASS (parent_class)->dispose (object); sl@0: } sl@0: sl@0: static void sl@0: my_test_get_property (GObject *object, sl@0: guint prop_id, sl@0: GValue *value, sl@0: GParamSpec *pspec) sl@0: { sl@0: GTest *test; sl@0: sl@0: test = MY_TEST (object); sl@0: sl@0: switch (prop_id) sl@0: { sl@0: case PROP_DUMMY: sl@0: g_value_set_int (value, test->dummy); sl@0: break; sl@0: default: sl@0: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: static void sl@0: my_test_set_property (GObject *object, sl@0: guint prop_id, sl@0: const GValue *value, sl@0: GParamSpec *pspec) sl@0: { sl@0: GTest *test; sl@0: sl@0: test = MY_TEST (object); sl@0: sl@0: switch (prop_id) sl@0: { sl@0: case PROP_DUMMY: sl@0: test->dummy = g_value_get_int (value); sl@0: break; sl@0: default: sl@0: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: static gint count = 0; sl@0: sl@0: static void sl@0: dummy_notify (GObject *object, sl@0: GParamSpec *pspec) sl@0: { sl@0: count++; sl@0: if (count % 10000 == 0) sl@0: g_print ("."); sl@0: } sl@0: sl@0: static void sl@0: my_test_do_property (GTest * test) sl@0: { sl@0: gint dummy; sl@0: sl@0: g_object_get (test, "dummy", &dummy, NULL); sl@0: g_object_set (test, "dummy", dummy + 1, NULL); sl@0: } sl@0: sl@0: int sl@0: main (int argc, char **argv) sl@0: { sl@0: gint i; sl@0: GTest *test; sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL); sl@0: g_set_print_handler(mrtPrintHandler); sl@0: #endif /*__SYMBIAN32__*/ sl@0: g_thread_init (NULL); sl@0: g_print ("START: %s\n", argv[0]); sl@0: g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK)); sl@0: g_type_init (); sl@0: sl@0: test = g_object_new (G_TYPE_TEST, NULL); sl@0: sl@0: g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL); sl@0: sl@0: g_assert (count == test->dummy); sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: for (i=0; i<10000; i++) { sl@0: #else sl@0: for (i=0; i<1000000; i++) { sl@0: #endif//__SYMBIAN32__ sl@0: my_test_do_property (test); sl@0: } sl@0: sl@0: g_assert (count == test->dummy); sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("properties2"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return 0; sl@0: }