os/ossrv/glib/tests/refcount/objects2.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/glib/tests/refcount/objects2.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,136 @@
     1.4 +/*
     1.5 +* Portions copyright (c) 2006-2009 Nokia Corporation.  All rights reserved.
     1.6 +*/
     1.7 +#include <unistd.h>
     1.8 +#include <glib.h>
     1.9 +#include <glib-object.h>
    1.10 +
    1.11 +#ifdef __SYMBIAN32__
    1.12 +#include "mrt2_glib2_test.h"
    1.13 +#endif /*__SYMBIAN32__*/
    1.14 +#define G_TYPE_TEST                (my_test_get_type ())
    1.15 +#define MY_TEST(test)              (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
    1.16 +#define MY_IS_TEST(test)           (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
    1.17 +#define MY_TEST_CLASS(tclass)      (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
    1.18 +#define MY_IS_TEST_CLASS(tclass)   (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
    1.19 +#define MY_TEST_GET_CLASS(test)    (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
    1.20 +
    1.21 +typedef struct _GTest GTest;
    1.22 +typedef struct _GTestClass GTestClass;
    1.23 +
    1.24 +struct _GTest
    1.25 +{
    1.26 +  GObject object;
    1.27 +};
    1.28 +
    1.29 +struct _GTestClass
    1.30 +{
    1.31 +  GObjectClass parent_class;
    1.32 +};
    1.33 +
    1.34 +static GType my_test_get_type (void);
    1.35 +
    1.36 +static void my_test_class_init (GTestClass * klass);
    1.37 +static void my_test_init (GTest * test);
    1.38 +static void my_test_dispose (GObject * object);
    1.39 +
    1.40 +static GObjectClass *parent_class = NULL;
    1.41 +
    1.42 +static GType
    1.43 +my_test_get_type (void)
    1.44 +{
    1.45 +  static GType test_type = 0;
    1.46 +
    1.47 +  if (!test_type) {
    1.48 +    static const GTypeInfo test_info = {
    1.49 +      sizeof (GTestClass),
    1.50 +      NULL,
    1.51 +      NULL,
    1.52 +      (GClassInitFunc) my_test_class_init,
    1.53 +      NULL,
    1.54 +      NULL,
    1.55 +      sizeof (GTest),
    1.56 +      0,
    1.57 +      (GInstanceInitFunc) my_test_init,
    1.58 +      NULL
    1.59 +    };
    1.60 +
    1.61 +    test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
    1.62 +        &test_info, 0);
    1.63 +  }
    1.64 +  return test_type;
    1.65 +}
    1.66 +
    1.67 +static void
    1.68 +my_test_class_init (GTestClass * klass)
    1.69 +{
    1.70 +  GObjectClass *gobject_class;
    1.71 +
    1.72 +  gobject_class = (GObjectClass *) klass;
    1.73 +
    1.74 +  parent_class = g_type_class_ref (G_TYPE_OBJECT);
    1.75 +
    1.76 +  gobject_class->dispose = my_test_dispose;
    1.77 +}
    1.78 +
    1.79 +static void
    1.80 +my_test_init (GTest * test)
    1.81 +{
    1.82 +  g_print ("init %p\n", test);
    1.83 +}
    1.84 +
    1.85 +static void
    1.86 +my_test_dispose (GObject * object)
    1.87 +{
    1.88 +  GTest *test;
    1.89 +
    1.90 +  test = MY_TEST (object);
    1.91 +
    1.92 +  g_print ("dispose %p!\n", object);
    1.93 +
    1.94 +  G_OBJECT_CLASS (parent_class)->dispose (object);
    1.95 +}
    1.96 +
    1.97 +static void
    1.98 +my_test_do_refcount (GTest * test)
    1.99 +{
   1.100 +  static guint i = 1;
   1.101 +  if (i++ % 100000 == 0)
   1.102 +    g_print (".");
   1.103 +  g_object_ref (test); 
   1.104 +  g_object_unref (test); 
   1.105 +}
   1.106 +
   1.107 +int
   1.108 +main (int argc, char **argv)
   1.109 +{
   1.110 +  gint i;
   1.111 +  GTest *test;
   1.112 +
   1.113 +  #ifdef __SYMBIAN32__
   1.114 +  
   1.115 +  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);
   1.116 +  g_set_print_handler(mrtPrintHandler);
   1.117 +  #endif /*__SYMBIAN32__*/
   1.118 +  g_thread_init (NULL);
   1.119 +  g_print ("START: %s\n", argv[0]);
   1.120 +  g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
   1.121 +  g_type_init ();
   1.122 +
   1.123 +  test = g_object_new (G_TYPE_TEST, NULL);
   1.124 +
   1.125 +#ifdef __SYMBIAN32__
   1.126 +  for (i=0; i<100000; i++) {
   1.127 +#else
   1.128 +  for (i=0; i<100000000; i++) {
   1.129 +#endif//__SYMBIAN32__  
   1.130 +    my_test_do_refcount (test);
   1.131 +  }
   1.132 +
   1.133 +  g_print ("\n");
   1.134 +  
   1.135 +#ifdef __SYMBIAN32__
   1.136 +  testResultXml("objects2");
   1.137 +#endif /* EMULATOR */
   1.138 +  return 0;
   1.139 +}