| 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 <assert.h> | 
 | 21 | #include <glib-object.h> | 
 | 22 |  | 
| Roger Meier | c75797d | 2012-04-28 11:33:58 +0000 | [diff] [blame] | 23 | #include "../src/thrift/thrift_struct.c" | 
| Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 24 |  | 
 | 25 | /* tests to ensure we can extend a ThriftStruct */ | 
 | 26 |  | 
 | 27 | struct _ThriftTestStruct | 
 | 28 | { | 
 | 29 |   ThriftStruct parent; | 
 | 30 | }; | 
 | 31 | typedef struct _ThriftTestStruct ThriftTestStruct; | 
 | 32 |  | 
 | 33 | struct _ThriftTestStructClass | 
 | 34 | { | 
 | 35 |   ThriftStructClass parent; | 
 | 36 | }; | 
 | 37 | typedef struct _ThriftTestStructClass ThriftTestStructClass; | 
 | 38 |  | 
 | 39 | GType thrift_test_struct_get_type (void); | 
 | 40 |  | 
 | 41 | #define THRIFT_TYPE_TEST_STRUCT (thrift_test_struct_get_type ()) | 
| Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 42 | #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 Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 47 |  | 
| Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 48 | G_DEFINE_TYPE(ThriftTestStruct, thrift_test_struct, THRIFT_TYPE_STRUCT) | 
| Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 49 |  | 
 | 50 | gint32 | 
 | 51 | thrift_test_struct_read (ThriftStruct *object, ThriftProtocol *protocol, | 
 | 52 |                          GError **error) | 
 | 53 | { | 
 | 54 |   return 0; | 
 | 55 | } | 
 | 56 |  | 
 | 57 | gint32 | 
 | 58 | thrift_test_struct_write (ThriftStruct *object, ThriftProtocol *protocol, | 
 | 59 |                           GError **error) | 
 | 60 | { | 
 | 61 |   return 0; | 
 | 62 | } | 
 | 63 |  | 
| Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 64 | static void | 
 | 65 | thrift_test_struct_class_init (ThriftTestStructClass *cls) | 
 | 66 | { | 
 | 67 |   ThriftStructClass *ts_cls = THRIFT_STRUCT_CLASS (cls); | 
 | 68 |   ts_cls->read = thrift_test_struct_read; | 
 | 69 |   ts_cls->write = thrift_test_struct_write; | 
 | 70 | } | 
 | 71 |  | 
 | 72 | static void | 
 | 73 | thrift_test_struct_init (ThriftTestStruct *s) | 
 | 74 | { | 
 | 75 |   THRIFT_UNUSED_VAR (s); | 
 | 76 | } | 
| Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 77 |  | 
 | 78 | static void | 
 | 79 | test_initialize_object (void) | 
 | 80 | { | 
 | 81 |   ThriftTestStruct *t = NULL; | 
 | 82 |  | 
 | 83 |   t = g_object_new (THRIFT_TYPE_TEST_STRUCT, NULL); | 
 | 84 |   assert ( THRIFT_IS_STRUCT (t)); | 
 | 85 |   thrift_struct_read (THRIFT_STRUCT (t), NULL, NULL); | 
 | 86 |   thrift_struct_write (THRIFT_STRUCT (t), NULL, NULL); | 
 | 87 |   thrift_test_struct_read (THRIFT_STRUCT (t), NULL, NULL); | 
 | 88 |   thrift_test_struct_write (THRIFT_STRUCT (t), NULL, NULL); | 
 | 89 |   g_object_unref (t); | 
 | 90 | } | 
 | 91 |  | 
 | 92 | int | 
| Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 93 | main(int argc, char *argv[]) | 
| Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 94 | { | 
| Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 95 |   g_type_init(); | 
 | 96 |   g_test_init (&argc, &argv, NULL); | 
| Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 97 |  | 
| Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 98 |   g_test_add_func ("/teststruct/InitializeObject", test_initialize_object); | 
 | 99 |  | 
 | 100 |   return g_test_run (); | 
| Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 101 | } |