~vcs-imports/thrift/master

« back to all changes in this revision

Viewing changes to lib/c_glib/test/teststruct.c

  • Committer: roger
  • Date: 2010-10-27 12:30:11 UTC
  • Revision ID: git-v1:0237bc3312c640d20ae0168eacb538224e232adb
THRIFT-582 C(c_glib) implementation of Thrift

Patch: Anatol Pomozov and Michael Lum


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1027933 13f79535-47bb-0310-9956-ffa450edef68

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#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
 
 
8
struct _ThriftTestStruct
 
9
{
 
10
  ThriftStruct parent;
 
11
};
 
12
typedef struct _ThriftTestStruct ThriftTestStruct;
 
13
 
 
14
struct _ThriftTestStructClass
 
15
{
 
16
  ThriftStructClass parent;
 
17
};
 
18
typedef struct _ThriftTestStructClass ThriftTestStructClass;
 
19
 
 
20
GType 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 */
 
38
gint32 thrift_test_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
 
39
                                GError **error);
 
40
gint32 thrift_test_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
 
41
                                 GError **error);
 
42
 
 
43
static void
 
44
thrift_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
 
 
51
static void
 
52
thrift_test_struct_instance_init (ThriftTestStruct *s)
 
53
{
 
54
  (void) s;
 
55
}
 
56
 
 
57
GType
 
58
thrift_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
 
 
85
gint32
 
86
thrift_test_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
 
87
                         GError **error)
 
88
{
 
89
  return 0;
 
90
}
 
91
 
 
92
gint32
 
93
thrift_test_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
 
94
                          GError **error)
 
95
{
 
96
  return 0;
 
97
}
 
98
 
 
99
 
 
100
static void
 
101
test_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
 
 
114
int
 
115
main(void)
 
116
{
 
117
  g_type_init ();
 
118
  test_initialize_object ();
 
119
 
 
120
  return 0;
 
121
}