glib/tsrc/BC/tests/refcount/properties2.c
changeset 72 403e7f6ed6c5
parent 0 e4d67989cc36
equal deleted inserted replaced
71:28ccaba883f4 72:403e7f6ed6c5
     7 #ifdef SYMBIAN
     7 #ifdef SYMBIAN
     8 #include "mrt2_glib2_test.h"
     8 #include "mrt2_glib2_test.h"
     9 #endif /*SYMBIAN*/
     9 #endif /*SYMBIAN*/
    10 
    10 
    11 
    11 
    12 #define G_TYPE_TEST               (g_test_get_type ())
    12 #define G_TYPE_TEST                (my_test_get_type ())
    13 #define G_TEST(test)              (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
    13 #define MY_TEST(test)              (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
    14 #define G_IS_TEST(test)           (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
    14 #define MY_IS_TEST(test)           (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
    15 #define G_TEST_CLASS(tclass)      (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
    15 #define MY_TEST_CLASS(tclass)      (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
    16 #define G_IS_TEST_CLASS(tclass)   (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
    16 #define MY_IS_TEST_CLASS(tclass)   (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
    17 #define G_TEST_GET_CLASS(test)    (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
    17 #define MY_TEST_GET_CLASS(test)    (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
    18 
    18 
    19 enum {
    19 enum {
    20   PROP_0,
    20   PROP_0,
    21   PROP_DUMMY
    21   PROP_DUMMY
    22 };
    22 };
    34 struct _GTestClass
    34 struct _GTestClass
    35 {
    35 {
    36   GObjectClass parent_class;
    36   GObjectClass parent_class;
    37 };
    37 };
    38 
    38 
    39 static GType g_test_get_type (void);
    39 static GType my_test_get_type (void);
    40 
    40 
    41 static void g_test_class_init (GTestClass * klass);
    41 static void my_test_class_init (GTestClass * klass);
    42 static void g_test_init (GTest * test);
    42 static void my_test_init (GTest * test);
    43 static void g_test_dispose (GObject * object);
    43 static void my_test_dispose (GObject * object);
    44 static void g_test_get_property (GObject    *object,
    44 static void my_test_get_property (GObject    *object,
    45 				 guint       prop_id,
    45                                   guint       prop_id,
    46 				 GValue     *value,
    46                                   GValue     *value,
    47 				 GParamSpec *pspec);
    47                                   GParamSpec *pspec);
    48 static void g_test_set_property (GObject      *object,
    48 static void my_test_set_property (GObject      *object,
    49 				 guint         prop_id,
    49                                   guint         prop_id,
    50 				 const GValue *value,
    50                                   const GValue *value,
    51 				 GParamSpec   *pspec);
    51                                   GParamSpec   *pspec);
    52 
    52 
    53 static GObjectClass *parent_class = NULL;
    53 static GObjectClass *parent_class = NULL;
    54 
    54 
    55 static GType
    55 static GType
    56 g_test_get_type (void)
    56 my_test_get_type (void)
    57 {
    57 {
    58   static GType test_type = 0;
    58   static GType test_type = 0;
    59 
    59 
    60   if (!test_type) {
    60   if (!test_type) {
    61     static const GTypeInfo test_info = {
    61     static const GTypeInfo test_info = {
    62       sizeof (GTestClass),
    62       sizeof (GTestClass),
    63       NULL,
    63       NULL,
    64       NULL,
    64       NULL,
    65       (GClassInitFunc) g_test_class_init,
    65       (GClassInitFunc) my_test_class_init,
    66       NULL,
    66       NULL,
    67       NULL,
    67       NULL,
    68       sizeof (GTest),
    68       sizeof (GTest),
    69       0,
    69       0,
    70       (GInstanceInitFunc) g_test_init,
    70       (GInstanceInitFunc) my_test_init,
    71       NULL
    71       NULL
    72     };
    72     };
    73 
    73 
    74     test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
    74     test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
    75         &test_info, 0);
    75         &test_info, 0);
    81   }
    81   }
    82   return test_type;
    82   return test_type;
    83 }
    83 }
    84 
    84 
    85 static void
    85 static void
    86 g_test_class_init (GTestClass * klass)
    86 my_test_class_init (GTestClass * klass)
    87 {
    87 {
    88   GObjectClass *gobject_class;
    88   GObjectClass *gobject_class;
    89   GParamSpec *gparam_spec;
    89   GParamSpec *gparam_spec;
    90 
    90 
    91   gobject_class = (GObjectClass *) klass;
    91   gobject_class = (GObjectClass *) klass;
    97   	g_assert(FALSE && "properties");	
    97   	g_assert(FALSE && "properties");	
    98   }
    98   }
    99     
    99     
   100   
   100   
   101 
   101 
   102   gobject_class->dispose = g_test_dispose;
   102   gobject_class->dispose = my_test_dispose;
   103   gobject_class->get_property = g_test_get_property;
   103   gobject_class->get_property = my_test_get_property;
   104   gobject_class->set_property = g_test_set_property;
   104   gobject_class->set_property = my_test_set_property;
   105 
   105 
   106   g_object_class_install_property (gobject_class,
   106   g_object_class_install_property (gobject_class,
   107 				   PROP_DUMMY,
   107 				   PROP_DUMMY,
   108 				   g_param_spec_int ("dummy",
   108 				   g_param_spec_int ("dummy",
   109 						     NULL, 
   109 						     NULL, 
   110 						     NULL,
   110 						     NULL,
   111 						     0, G_MAXINT, 0,
   111 						     0, G_MAXINT, 0,
   112 						     G_PARAM_READWRITE));
   112 						     G_PARAM_READWRITE));
   113   
   113 }
   114 }
   114 
   115 
   115 static void
   116 static void
   116 my_test_init (GTest * test)
   117 g_test_init (GTest * test)
       
   118 {
   117 {
   119   //g_print ("init %p\n", test);
   118   //g_print ("init %p\n", test);
   120 }
   119 }
   121 
   120 
   122 static void
   121 static void
   123 g_test_dispose (GObject * object)
   122 my_test_dispose (GObject * object)
   124 {
   123 {
   125   GTest *test;
   124   GTest *test;
   126 
   125 
   127   test = G_TEST (object);
   126   test = MY_TEST (object);
   128 
   127 
   129   g_print ("dispose %p!\n", object);
   128   g_print ("dispose %p!\n", object);
   130 
   129 
   131   G_OBJECT_CLASS (parent_class)->dispose (object);
   130   G_OBJECT_CLASS (parent_class)->dispose (object);
   132 }
   131 }
   133 
   132 
   134 static void 
   133 static void 
   135 g_test_get_property (GObject    *object,
   134 my_test_get_property (GObject    *object,
   136 		     guint       prop_id,
   135                       guint       prop_id,
   137 		     GValue     *value,
   136                       GValue     *value,
   138 		     GParamSpec *pspec)
   137                       GParamSpec *pspec)
   139 {
   138 {
   140   GTest *test;
   139   GTest *test;
   141 
   140 
   142   test = G_TEST (object);
   141   test = MY_TEST (object);
   143 
   142 
   144   switch (prop_id)
   143   switch (prop_id)
   145     {
   144     {
   146     case PROP_DUMMY:
   145     case PROP_DUMMY:
   147       g_value_set_int (value, test->dummy);
   146       g_value_set_int (value, test->dummy);
   151       break;
   150       break;
   152     }
   151     }
   153 }
   152 }
   154 
   153 
   155 static void 
   154 static void 
   156 g_test_set_property (GObject      *object,
   155 my_test_set_property (GObject      *object,
   157 		     guint         prop_id,
   156                       guint         prop_id,
   158 		     const GValue *value,
   157                       const GValue *value,
   159 		     GParamSpec   *pspec)
   158                       GParamSpec   *pspec)
   160 {
   159 {
   161   GTest *test;
   160   GTest *test;
   162 
   161 
   163   test = G_TEST (object);
   162   test = MY_TEST (object);
   164 
   163 
   165   switch (prop_id)
   164   switch (prop_id)
   166     {
   165     {
   167     case PROP_DUMMY:
   166     case PROP_DUMMY:
   168       test->dummy = g_value_get_int (value);
   167       test->dummy = g_value_get_int (value);
   183   //if (count % 10000 == 0)
   182   //if (count % 10000 == 0)
   184   //  g_print (".");
   183   //  g_print (".");
   185 }
   184 }
   186 
   185 
   187 static void
   186 static void
   188 g_test_do_property (GTest * test)
   187 my_test_do_property (GTest * test)
   189 {
   188 {
   190   gint dummy;
   189   gint dummy;
   191 
   190 
   192   g_object_get (test, "dummy", &dummy, NULL);
   191   g_object_get (test, "dummy", &dummy, NULL);
   193   g_object_set (test, "dummy", dummy + 1, NULL);
   192   g_object_set (test, "dummy", dummy + 1, NULL);
   223      g_print("properties2.c : g_signal_connect is failed @ line : %d",__LINE__);
   222      g_print("properties2.c : g_signal_connect is failed @ line : %d",__LINE__);
   224 
   223 
   225   g_assert (count == test->dummy);
   224   g_assert (count == test->dummy);
   226 
   225 
   227   for (i=0; i<1000; i++) {
   226   for (i=0; i<1000; i++) {
   228     g_test_do_property (test);
   227     my_test_do_property (test);
   229   }
   228   }
   230 
   229 
   231   g_assert (count == test->dummy);
   230   g_assert (count == test->dummy);
   232 #ifdef SYMBIAN
   231 #ifdef SYMBIAN
   233   testResultXml("properties2");
   232   testResultXml("properties2");