Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 1 | /* |
| 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 Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 20 | #include <glib-object.h> |
| 21 | |
Roger Meier | e3da768 | 2013-01-11 11:41:53 +0100 | [diff] [blame] | 22 | #include "../src/thrift/c_glib/thrift_struct.c" |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 23 | |
| 24 | /* tests to ensure we can extend a ThriftStruct */ |
| 25 | |
| 26 | struct _ThriftTestStruct |
| 27 | { |
| 28 | ThriftStruct parent; |
| 29 | }; |
| 30 | typedef struct _ThriftTestStruct ThriftTestStruct; |
| 31 | |
| 32 | struct _ThriftTestStructClass |
| 33 | { |
| 34 | ThriftStructClass parent; |
| 35 | }; |
| 36 | typedef struct _ThriftTestStructClass ThriftTestStructClass; |
| 37 | |
| 38 | GType thrift_test_struct_get_type (void); |
| 39 | |
| 40 | #define THRIFT_TYPE_TEST_STRUCT (thrift_test_struct_get_type ()) |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 41 | #define THRIFT_TEST_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_TEST_STRUCT, ThriftTestStruct)) |
| 42 | #define THRIFT_TEST_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_TEST_STRUCT, ThriftTestStructClass)) |
| 43 | #define THRIFT_IS_TEST_STRUCT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_TEST_STRUCT)) |
| 44 | #define THRIFT_IS_TEST_STRUCT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_TEST_STRUCT)) |
| 45 | #define THRIFT_TEST_STRUCT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_TEST_STRUCT, ThriftTestStructClass)) |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 46 | |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 47 | G_DEFINE_TYPE(ThriftTestStruct, thrift_test_struct, THRIFT_TYPE_STRUCT) |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 48 | |
| 49 | gint32 |
| 50 | thrift_test_struct_read (ThriftStruct *object, ThriftProtocol *protocol, |
| 51 | GError **error) |
| 52 | { |
Simon South | 38e7155 | 2015-08-03 10:51:16 +0000 | [diff] [blame] | 53 | THRIFT_UNUSED_VAR (object); |
| 54 | THRIFT_UNUSED_VAR (protocol); |
| 55 | THRIFT_UNUSED_VAR (error); |
| 56 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | gint32 |
| 61 | thrift_test_struct_write (ThriftStruct *object, ThriftProtocol *protocol, |
| 62 | GError **error) |
| 63 | { |
Simon South | 38e7155 | 2015-08-03 10:51:16 +0000 | [diff] [blame] | 64 | THRIFT_UNUSED_VAR (object); |
| 65 | THRIFT_UNUSED_VAR (protocol); |
| 66 | THRIFT_UNUSED_VAR (error); |
| 67 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 71 | static void |
| 72 | thrift_test_struct_class_init (ThriftTestStructClass *cls) |
| 73 | { |
| 74 | ThriftStructClass *ts_cls = THRIFT_STRUCT_CLASS (cls); |
| 75 | ts_cls->read = thrift_test_struct_read; |
| 76 | ts_cls->write = thrift_test_struct_write; |
| 77 | } |
| 78 | |
| 79 | static void |
| 80 | thrift_test_struct_init (ThriftTestStruct *s) |
| 81 | { |
| 82 | THRIFT_UNUSED_VAR (s); |
| 83 | } |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 84 | |
| 85 | static void |
| 86 | test_initialize_object (void) |
| 87 | { |
| 88 | ThriftTestStruct *t = NULL; |
| 89 | |
| 90 | t = g_object_new (THRIFT_TYPE_TEST_STRUCT, NULL); |
James E. King, III | 43f4bf2 | 2017-10-28 12:54:02 -0400 | [diff] [blame] | 91 | g_assert ( THRIFT_IS_STRUCT (t)); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 92 | thrift_struct_read (THRIFT_STRUCT (t), NULL, NULL); |
| 93 | thrift_struct_write (THRIFT_STRUCT (t), NULL, NULL); |
| 94 | thrift_test_struct_read (THRIFT_STRUCT (t), NULL, NULL); |
| 95 | thrift_test_struct_write (THRIFT_STRUCT (t), NULL, NULL); |
| 96 | g_object_unref (t); |
| 97 | } |
| 98 | |
| 99 | int |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 100 | main(int argc, char *argv[]) |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 101 | { |
Jens Geyer | 1c19027 | 2015-07-28 23:15:18 +0200 | [diff] [blame] | 102 | #if (!GLIB_CHECK_VERSION (2, 36, 0)) |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 103 | g_type_init(); |
Jens Geyer | 1c19027 | 2015-07-28 23:15:18 +0200 | [diff] [blame] | 104 | #endif |
| 105 | |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 106 | g_test_init (&argc, &argv, NULL); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 107 | |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 108 | g_test_add_func ("/teststruct/InitializeObject", test_initialize_object); |
| 109 | |
| 110 | return g_test_run (); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 111 | } |