fe5f82130a4a2f071b975df8731f271f4c07aa2e
[platform/core/uifw/at-spi2-atk.git] / atk-tests / test-simple-text.c
1 /* This file contains both declaration and definition of the TestSimpleText class,  
2  * a simple wrapper for a text string not longer than MAX_DESCR_LENGTH symbols. 
3  */
4
5 #include "test-simple-text.h"
6
7 GType 
8 test_simple_text_get_type (void);
9
10 static GObjectClass *parent_class_simple_text = NULL;
11
12 /******************************************************************/
13 /*                    Implementation                              */
14 /******************************************************************/
15 static void
16 simple_text_instance_init (GTypeInstance *instance, gpointer g_class)
17 {
18     TestSimpleText *self = (TestSimpleText *)instance;
19     
20     self->disposed = FALSE;
21     self->text = g_new (char, MAX_DESCR_LENGTH + 1);
22     self->text[0] = '\0';
23     
24     //g_print ("\tCreate string\n");
25 }
26
27 static void
28 test_simple_text_dispose (GObject *obj)
29 {
30     TestSimpleText *self = (TestSimpleText *)obj;
31
32     if (self->disposed) 
33     {
34             return;
35     }
36     
37     /* Make sure dispose does not run twice. */
38     self->disposed = TRUE;
39     
40     g_free (self->text);
41     self->text = NULL;
42     //g_print ("\tDelete string\n");
43
44     /* Chain up to the parent class */
45     G_OBJECT_CLASS (parent_class_simple_text)->dispose (obj);
46 }
47
48 static void
49 test_simple_text_finalize (GObject *obj)
50 {
51     TestSimpleText *self = (TestSimpleText *)obj;
52     if (self)
53     {
54         /*free (self->pdata->descr);
55         g_free (self->pdata);*/
56     }
57     
58     /* Chain up to the parent class */
59     G_OBJECT_CLASS (parent_class_simple_text)->finalize (obj);
60 }
61
62 static void
63 test_simple_text_class_init (gpointer g_class, gpointer g_class_data)
64 {
65     GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
66     TestSimpleTextClass *klass = TEST_SIMPLE_TEXT_CLASS (g_class);
67
68     gobject_class->dispose = test_simple_text_dispose;
69     gobject_class->finalize = test_simple_text_finalize;
70
71     parent_class_simple_text = g_type_class_peek_parent (klass);
72 }
73
74 GType 
75 test_simple_text_get_type (void)
76 {
77     static GType type = 0;
78     if (type == 0) 
79     {
80             static const GTypeInfo info = 
81             {
82                     sizeof (TestSimpleTextClass),
83                     NULL,   /* base_init */
84                     NULL,   /* base_finalize */
85                     test_simple_text_class_init, /* class_init */
86                     NULL,   /* class_finalize */
87                     NULL,   /* class_data */
88                     sizeof (TestSimpleText),
89                     0,      /* n_preallocs */
90                     simple_text_instance_init    /* instance_init */
91             };
92
93             type = g_type_register_static (ATK_TYPE_OBJECT,
94                                            "TestSimpleTextType",
95                                            &info, 0);
96     }
97     return type;
98 }