glib/tsrc/BC/tests/refcount/closures.c
changeset 72 403e7f6ed6c5
parent 0 e4d67989cc36
equal deleted inserted replaced
71:28ccaba883f4 72:403e7f6ed6c5
    43   void (*test_signal1) (GTest * test, gint an_int);
    43   void (*test_signal1) (GTest * test, gint an_int);
    44   void (*test_signal2) (GTest * test, gint an_int);
    44   void (*test_signal2) (GTest * test, gint an_int);
    45   void (*test_signal3) (GTest * test, gint an_int);
    45   void (*test_signal3) (GTest * test, gint an_int);
    46 } GTestClass;
    46 } GTestClass;
    47 
    47 
    48 #define G_TYPE_TEST               (g_test_get_type ())
    48 #define G_TYPE_TEST                (my_test_get_type ())
    49 #define G_TEST(test)              (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
    49 #define MY_TEST(test)              (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
    50 #define G_IS_TEST(test)           (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
    50 #define MY_IS_TEST(test)           (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
    51 #define G_TEST_CLASS(tclass)      (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
    51 #define MY_TEST_CLASS(tclass)      (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
    52 #define G_IS_TEST_CLASS(tclass)   (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
    52 #define MY_IS_TEST_CLASS(tclass)   (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
    53 #define G_TEST_GET_CLASS(test)    (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
    53 #define MY_TEST_GET_CLASS(test)    (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
    54 
    54 
    55 G_DEFINE_TYPE (GTest, g_test, G_TYPE_OBJECT);
    55 G_DEFINE_TYPE (GTest, my_test, G_TYPE_OBJECT);
    56 
    56 
    57 /* --- variables --- */
    57 /* --- variables --- */
    58 static volatile gboolean stopping = FALSE;
    58 static volatile gboolean stopping = FALSE;
    59 static guint             test_signal1 = 0;
    59 static guint             test_signal1 = 0;
    60 static guint             test_signal2 = 0;
    60 static guint             test_signal2 = 0;
    67 static gboolean          seen_thread1 = FALSE;
    67 static gboolean          seen_thread1 = FALSE;
    68 static gboolean          seen_thread2 = FALSE;
    68 static gboolean          seen_thread2 = FALSE;
    69 
    69 
    70 /* --- functions --- */
    70 /* --- functions --- */
    71 static void
    71 static void
    72 g_test_init (GTest * test)
    72 my_test_init (GTest * test)
    73 {
    73 {
    74   //g_print ("init %p\n", test);
    74   //g_print ("init %p\n", test);
    75 
    75 
    76   test->value = 0;
    76   test->value = 0;
    77   test->test_pointer1 = TEST_POINTER1;
    77   test->test_pointer1 = TEST_POINTER1;
    82   ARG_0,
    82   ARG_0,
    83   ARG_TEST_PROP
    83   ARG_TEST_PROP
    84 };
    84 };
    85 
    85 
    86 static void
    86 static void
    87 g_test_set_property (GObject      *object,
    87 my_test_set_property (GObject      *object,
    88                      guint         prop_id,
    88                      guint         prop_id,
    89                      const GValue *value,
    89                      const GValue *value,
    90                      GParamSpec   *pspec)
    90                      GParamSpec   *pspec)
    91 {
    91 {
    92   GTest *test = G_TEST (object);
    92   GTest *test = MY_TEST (object);
    93   switch (prop_id)
    93   switch (prop_id)
    94     {
    94     {
    95     case ARG_TEST_PROP:
    95     case ARG_TEST_PROP:
    96       test->value = g_value_get_int (value);
    96       test->value = g_value_get_int (value);
    97       break;
    97       break;
   100       break;
   100       break;
   101     }
   101     }
   102 }
   102 }
   103 
   103 
   104 static void
   104 static void
   105 g_test_get_property (GObject    *object,
   105 my_test_get_property (GObject    *object,
   106                      guint       prop_id,
   106                      guint       prop_id,
   107                      GValue     *value,
   107                      GValue     *value,
   108                      GParamSpec *pspec)
   108                      GParamSpec *pspec)
   109 {
   109 {
   110   GTest *test = G_TEST (object);
   110   GTest *test = MY_TEST (object);
   111   switch (prop_id)
   111   switch (prop_id)
   112     {
   112     {
   113     case ARG_TEST_PROP:
   113     case ARG_TEST_PROP:
   114       g_value_set_int (value, test->value);
   114       g_value_set_int (value, test->value);
   115       break;
   115       break;
   118       break;
   118       break;
   119     }
   119     }
   120 }
   120 }
   121 
   121 
   122 static void
   122 static void
   123 g_test_test_signal2 (GTest *test,
   123 my_test_test_signal2 (GTest *test,
   124                      gint   an_int)
   124                       gint   an_int)
   125 {
   125 {
   126 }
   126 }
   127 
   127 
   128 static void
   128 static void
   129 g_test_emit_test_signal1 (GTest *test,
   129 my_test_emit_test_signal1 (GTest *test,
       
   130                            gint   vint)
       
   131 {
       
   132   g_signal_emit (G_OBJECT (test), test_signal1, 0, vint);
       
   133 }
       
   134 
       
   135 static void
       
   136 my_test_emit_test_signal2 (GTest *test,
       
   137                            gint   vint)
       
   138 {
       
   139   g_signal_emit (G_OBJECT (test), test_signal2, 0, vint);
       
   140 }
       
   141 
       
   142 static void
       
   143 my_test_emit_test_signal3 (GTest *test,
   130                           gint   vint)
   144                           gint   vint)
   131 {
   145 {
   132   g_signal_emit (G_OBJECT (test), test_signal1, 0, vint);
       
   133 }
       
   134 
       
   135 static void
       
   136 g_test_emit_test_signal2 (GTest *test,
       
   137                           gint   vint)
       
   138 {
       
   139   g_signal_emit (G_OBJECT (test), test_signal2, 0, vint);
       
   140 }
       
   141 
       
   142 static void
       
   143 g_test_emit_test_signal3 (GTest *test,
       
   144                           gint   vint)
       
   145 {
       
   146   g_signal_emit (G_OBJECT (test), test_signal3, 0, vint);
   146   g_signal_emit (G_OBJECT (test), test_signal3, 0, vint);
   147 }
   147 }
   148 static void
   148 static void
   149 g_test_class_init (GTestClass *klass)
   149 my_test_class_init (GTestClass *klass)
   150 {
   150 {
   151   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   151   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   152 
   152 
   153   gobject_class->set_property = g_test_set_property;
   153   gobject_class->set_property = my_test_set_property;
   154   gobject_class->get_property = g_test_get_property;
   154   gobject_class->get_property = my_test_get_property;
   155 
   155 
   156   test_signal1 = g_signal_new ("test-signal1", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
   156   test_signal1 = g_signal_new ("test-signal1", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
   157                                G_STRUCT_OFFSET (GTestClass, test_signal1), NULL, NULL,
   157                                G_STRUCT_OFFSET (GTestClass, test_signal1), NULL, NULL,
   158                                g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
   158                                g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
   159   test_signal2 = g_signal_new ("test-signal2", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
   159   test_signal2 = g_signal_new ("test-signal2", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
   166 
   166 
   167 
   167 
   168   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TEST_PROP,
   168   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TEST_PROP,
   169                                    g_param_spec_int ("test-prop", "Test Prop", "Test property",
   169                                    g_param_spec_int ("test-prop", "Test Prop", "Test property",
   170                                                      0, 1, 0, G_PARAM_READWRITE));
   170                                                      0, 1, 0, G_PARAM_READWRITE));
   171   klass->test_signal2 = g_test_test_signal2;
   171   klass->test_signal2 = my_test_test_signal2;
   172   klass->test_signal3 = g_test_test_signal2;
   172   klass->test_signal3 = my_test_test_signal2;
   173 }
   173 }
   174 
   174 
   175 static inline guint32
   175 static inline guint32
   176 quick_rand32 (void)
   176 quick_rand32 (void)
   177 {
   177 {
   264 }
   264 }
   265 
   265 
   266 static void
   266 static void
   267 test_emissions (GTest *test)
   267 test_emissions (GTest *test)
   268 {
   268 {
   269   g_test_emit_test_signal1 (test, TEST_INT1);
   269   my_test_emit_test_signal1 (test, TEST_INT1);
   270   g_test_emit_test_signal2 (test, TEST_INT2);
   270   my_test_emit_test_signal2 (test, TEST_INT2);
   271   g_test_emit_test_signal3 (test, TEST_INT3);
   271   my_test_emit_test_signal3 (test, TEST_INT3);
   272 }
   272 }
   273 
   273 
   274 int
   274 int
   275 main (int    argc,
   275 main (int    argc,
   276       char **argv)
   276       char **argv)
   278   GThread *thread1, *thread2;
   278   GThread *thread1, *thread2;
   279   GClosure *closure, *closure1;
   279   GClosure *closure, *closure1;
   280   GTest *object;
   280   GTest *object;
   281   guint i;
   281   guint i;
   282 
   282 
   283   #ifdef SYMBIAN
   283   #ifdef __SYMBIAN32__
   284   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);
   284   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);
   285   g_set_print_handler(mrtPrintHandler);
   285   g_set_print_handler(mrtPrintHandler);
   286   #endif /*SYMBIAN*/
   286   #endif /*__SYMBIAN32__*/
   287   
       
   288   g_thread_init (NULL);
   287   g_thread_init (NULL);
   289   
   288   
   290   //g_print ("START: %s\n", argv[0]);
   289   //g_print ("START: %s\n", argv[0]);
   291   
   290   
   292   g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
   291   g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));