os/ossrv/glib/tests/refcount/objects2.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Portions copyright (c) 2006-2009 Nokia Corporation.  All rights reserved.
     3 */
     4 #include <unistd.h>
     5 #include <glib.h>
     6 #include <glib-object.h>
     7 
     8 #ifdef __SYMBIAN32__
     9 #include "mrt2_glib2_test.h"
    10 #endif /*__SYMBIAN32__*/
    11 #define G_TYPE_TEST                (my_test_get_type ())
    12 #define MY_TEST(test)              (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
    13 #define MY_IS_TEST(test)           (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
    14 #define MY_TEST_CLASS(tclass)      (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
    15 #define MY_IS_TEST_CLASS(tclass)   (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
    16 #define MY_TEST_GET_CLASS(test)    (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
    17 
    18 typedef struct _GTest GTest;
    19 typedef struct _GTestClass GTestClass;
    20 
    21 struct _GTest
    22 {
    23   GObject object;
    24 };
    25 
    26 struct _GTestClass
    27 {
    28   GObjectClass parent_class;
    29 };
    30 
    31 static GType my_test_get_type (void);
    32 
    33 static void my_test_class_init (GTestClass * klass);
    34 static void my_test_init (GTest * test);
    35 static void my_test_dispose (GObject * object);
    36 
    37 static GObjectClass *parent_class = NULL;
    38 
    39 static GType
    40 my_test_get_type (void)
    41 {
    42   static GType test_type = 0;
    43 
    44   if (!test_type) {
    45     static const GTypeInfo test_info = {
    46       sizeof (GTestClass),
    47       NULL,
    48       NULL,
    49       (GClassInitFunc) my_test_class_init,
    50       NULL,
    51       NULL,
    52       sizeof (GTest),
    53       0,
    54       (GInstanceInitFunc) my_test_init,
    55       NULL
    56     };
    57 
    58     test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
    59         &test_info, 0);
    60   }
    61   return test_type;
    62 }
    63 
    64 static void
    65 my_test_class_init (GTestClass * klass)
    66 {
    67   GObjectClass *gobject_class;
    68 
    69   gobject_class = (GObjectClass *) klass;
    70 
    71   parent_class = g_type_class_ref (G_TYPE_OBJECT);
    72 
    73   gobject_class->dispose = my_test_dispose;
    74 }
    75 
    76 static void
    77 my_test_init (GTest * test)
    78 {
    79   g_print ("init %p\n", test);
    80 }
    81 
    82 static void
    83 my_test_dispose (GObject * object)
    84 {
    85   GTest *test;
    86 
    87   test = MY_TEST (object);
    88 
    89   g_print ("dispose %p!\n", object);
    90 
    91   G_OBJECT_CLASS (parent_class)->dispose (object);
    92 }
    93 
    94 static void
    95 my_test_do_refcount (GTest * test)
    96 {
    97   static guint i = 1;
    98   if (i++ % 100000 == 0)
    99     g_print (".");
   100   g_object_ref (test); 
   101   g_object_unref (test); 
   102 }
   103 
   104 int
   105 main (int argc, char **argv)
   106 {
   107   gint i;
   108   GTest *test;
   109 
   110   #ifdef __SYMBIAN32__
   111   
   112   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);
   113   g_set_print_handler(mrtPrintHandler);
   114   #endif /*__SYMBIAN32__*/
   115   g_thread_init (NULL);
   116   g_print ("START: %s\n", argv[0]);
   117   g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
   118   g_type_init ();
   119 
   120   test = g_object_new (G_TYPE_TEST, NULL);
   121 
   122 #ifdef __SYMBIAN32__
   123   for (i=0; i<100000; i++) {
   124 #else
   125   for (i=0; i<100000000; i++) {
   126 #endif//__SYMBIAN32__  
   127     my_test_do_refcount (test);
   128   }
   129 
   130   g_print ("\n");
   131   
   132 #ifdef __SYMBIAN32__
   133   testResultXml("objects2");
   134 #endif /* EMULATOR */
   135   return 0;
   136 }