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