blob: cb401e2e2923ce754241ad2782ceeacc5fc7b284 [file] [log] [blame]
Roger Meier213a6642010-10-27 12:30:11 +00001#include <assert.h>
2#include <glib-object.h>
3
4#include "../src/thrift_struct.c"
5
6/* tests to ensure we can extend a ThriftStruct */
7
8struct _ThriftTestStruct
9{
10 ThriftStruct parent;
11};
12typedef struct _ThriftTestStruct ThriftTestStruct;
13
14struct _ThriftTestStructClass
15{
16 ThriftStructClass parent;
17};
18typedef struct _ThriftTestStructClass ThriftTestStructClass;
19
20GType thrift_test_struct_get_type (void);
21
22#define THRIFT_TYPE_TEST_STRUCT (thrift_test_struct_get_type ())
23#define THRIFT_TEST_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
24 THRIFT_TYPE_TEST_STRUCT, \
25 ThriftTestStruct))
26#define THRIFT_TEST_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
27 THRIFT_TYPE_TEST_STRUCT, \
28 ThriftTestStructClass))
29#define THRIFT_IS_TEST_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
30 THRIFT_TYPE_TEST_STRUCT))
31#define THRIFT_IS_TEST_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
32 THRIFT_TYPE_TEST_STRUCT))
33#define THRIFT_TEST_STRUCT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
34 THRIFT_TYPE_TEST_STRUCT, \
35 ThriftTestStructClass))
36
37/* test declarations */
38gint32 thrift_test_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
39 GError **error);
40gint32 thrift_test_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
41 GError **error);
42
43static void
44thrift_test_struct_class_init (ThriftTestStructClass *cls)
45{
46 ThriftStructClass *ts_cls = THRIFT_STRUCT_CLASS (cls);
47 ts_cls->read = thrift_test_struct_read;
48 ts_cls->write = thrift_test_struct_write;
49}
50
51static void
52thrift_test_struct_instance_init (ThriftTestStruct *s)
53{
54 (void) s;
55}
56
57GType
58thrift_test_struct_get_type (void)
59{
60 static GType type = 0;
61
62 if (type == 0)
63 {
64 static const GTypeInfo type_info =
65 {
66 sizeof (ThriftTestStructClass),
67 NULL,
68 NULL,
69 (GClassInitFunc) thrift_test_struct_class_init,
70 NULL,
71 NULL,
72 sizeof (ThriftTestStruct),
73 0,
74 (GInstanceInitFunc) thrift_test_struct_instance_init,
75 NULL,
76 };
77
78 type = g_type_register_static (THRIFT_TYPE_STRUCT,
79 "ThriftTestStructType", &type_info, 0);
80 }
81
82 return type;
83}
84
85gint32
86thrift_test_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
87 GError **error)
88{
89 return 0;
90}
91
92gint32
93thrift_test_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
94 GError **error)
95{
96 return 0;
97}
98
99
100static void
101test_initialize_object (void)
102{
103 ThriftTestStruct *t = NULL;
104
105 t = g_object_new (THRIFT_TYPE_TEST_STRUCT, NULL);
106 assert ( THRIFT_IS_STRUCT (t));
107 thrift_struct_read (THRIFT_STRUCT (t), NULL, NULL);
108 thrift_struct_write (THRIFT_STRUCT (t), NULL, NULL);
109 thrift_test_struct_read (THRIFT_STRUCT (t), NULL, NULL);
110 thrift_test_struct_write (THRIFT_STRUCT (t), NULL, NULL);
111 g_object_unref (t);
112}
113
114int
115main(void)
116{
117 g_type_init ();
118 test_initialize_object ();
119
120 return 0;
121}