blob: 5d4baf3472a057965f3f9189dd0dcfc67302ddf0 [file] [log] [blame]
Roger Meierc1010922010-11-26 10:17:48 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
Roger Meier213a6642010-10-27 12:30:11 +000020#include <assert.h>
21#include <glib-object.h>
22
Roger Meiere3da7682013-01-11 11:41:53 +010023#include "../src/thrift/c_glib/thrift_struct.c"
Roger Meier213a6642010-10-27 12:30:11 +000024
25/* tests to ensure we can extend a ThriftStruct */
26
27struct _ThriftTestStruct
28{
29 ThriftStruct parent;
30};
31typedef struct _ThriftTestStruct ThriftTestStruct;
32
33struct _ThriftTestStructClass
34{
35 ThriftStructClass parent;
36};
37typedef struct _ThriftTestStructClass ThriftTestStructClass;
38
39GType thrift_test_struct_get_type (void);
40
41#define THRIFT_TYPE_TEST_STRUCT (thrift_test_struct_get_type ())
Roger Meierc1010922010-11-26 10:17:48 +000042#define THRIFT_TEST_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_TEST_STRUCT, ThriftTestStruct))
43#define THRIFT_TEST_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_TEST_STRUCT, ThriftTestStructClass))
44#define THRIFT_IS_TEST_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_TEST_STRUCT))
45#define THRIFT_IS_TEST_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_TEST_STRUCT))
46#define THRIFT_TEST_STRUCT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_TEST_STRUCT, ThriftTestStructClass))
Roger Meier213a6642010-10-27 12:30:11 +000047
Roger Meierc1010922010-11-26 10:17:48 +000048G_DEFINE_TYPE(ThriftTestStruct, thrift_test_struct, THRIFT_TYPE_STRUCT)
Roger Meier213a6642010-10-27 12:30:11 +000049
50gint32
51thrift_test_struct_read (ThriftStruct *object, ThriftProtocol *protocol,
52 GError **error)
53{
Simon South38e71552015-08-03 10:51:16 +000054 THRIFT_UNUSED_VAR (object);
55 THRIFT_UNUSED_VAR (protocol);
56 THRIFT_UNUSED_VAR (error);
57
Roger Meier213a6642010-10-27 12:30:11 +000058 return 0;
59}
60
61gint32
62thrift_test_struct_write (ThriftStruct *object, ThriftProtocol *protocol,
63 GError **error)
64{
Simon South38e71552015-08-03 10:51:16 +000065 THRIFT_UNUSED_VAR (object);
66 THRIFT_UNUSED_VAR (protocol);
67 THRIFT_UNUSED_VAR (error);
68
Roger Meier213a6642010-10-27 12:30:11 +000069 return 0;
70}
71
Roger Meierc1010922010-11-26 10:17:48 +000072static void
73thrift_test_struct_class_init (ThriftTestStructClass *cls)
74{
75 ThriftStructClass *ts_cls = THRIFT_STRUCT_CLASS (cls);
76 ts_cls->read = thrift_test_struct_read;
77 ts_cls->write = thrift_test_struct_write;
78}
79
80static void
81thrift_test_struct_init (ThriftTestStruct *s)
82{
83 THRIFT_UNUSED_VAR (s);
84}
Roger Meier213a6642010-10-27 12:30:11 +000085
86static void
87test_initialize_object (void)
88{
89 ThriftTestStruct *t = NULL;
90
91 t = g_object_new (THRIFT_TYPE_TEST_STRUCT, NULL);
92 assert ( THRIFT_IS_STRUCT (t));
93 thrift_struct_read (THRIFT_STRUCT (t), NULL, NULL);
94 thrift_struct_write (THRIFT_STRUCT (t), NULL, NULL);
95 thrift_test_struct_read (THRIFT_STRUCT (t), NULL, NULL);
96 thrift_test_struct_write (THRIFT_STRUCT (t), NULL, NULL);
97 g_object_unref (t);
98}
99
100int
Roger Meierc1010922010-11-26 10:17:48 +0000101main(int argc, char *argv[])
Roger Meier213a6642010-10-27 12:30:11 +0000102{
Jens Geyer1c190272015-07-28 23:15:18 +0200103#if (!GLIB_CHECK_VERSION (2, 36, 0))
Roger Meierc1010922010-11-26 10:17:48 +0000104 g_type_init();
Jens Geyer1c190272015-07-28 23:15:18 +0200105#endif
106
Roger Meierc1010922010-11-26 10:17:48 +0000107 g_test_init (&argc, &argv, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000108
Roger Meierc1010922010-11-26 10:17:48 +0000109 g_test_add_func ("/teststruct/InitializeObject", test_initialize_object);
110
111 return g_test_run ();
Roger Meier213a6642010-10-27 12:30:11 +0000112}