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 <math.h> |
| 21 | #include <glib-object.h> |
| 22 | |
| 23 | #ifndef M_PI |
| 24 | #define M_PI 3.1415926535897932385 |
| 25 | #endif |
| 26 | |
| 27 | #include "gen-c_glib/t_test_debug_proto_test_types.h" |
| 28 | |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 29 | static void |
| 30 | test_debug_proto(void) |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 31 | { |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 32 | TTestOneOfEach *ooe = NULL; |
| 33 | TTestNesting *n = NULL; |
| 34 | TTestHolyMoley *hm = NULL; |
Roger Meier | c75797d | 2012-04-28 11:33:58 +0000 | [diff] [blame] | 35 | gchar *random = g_strdup("random string"); |
| 36 | gchar *nothing = g_strdup("nothing"); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 37 | |
| 38 | ooe = g_object_new (T_TEST_TYPE_ONE_OF_EACH, NULL); |
| 39 | ooe->im_true = TRUE; |
| 40 | ooe->im_false = FALSE; |
| 41 | ooe->a_bite = 0xd6; |
| 42 | ooe->integer16 = 27000; |
| 43 | ooe->integer32 = 1<<24; |
| 44 | ooe->integer64 = (guint64) 6000 * 1000 * 1000; |
| 45 | ooe->double_precision = M_PI; |
Roger Meier | c75797d | 2012-04-28 11:33:58 +0000 | [diff] [blame] | 46 | ooe->some_characters = g_strdup("Debug THIS!"); |
| 47 | ooe->zomg_unicode = g_strdup("\xd7\n\a\t"); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 48 | |
| 49 | n = g_object_new (T_TEST_TYPE_NESTING, NULL); |
Roger Meier | c75797d | 2012-04-28 11:33:58 +0000 | [diff] [blame] | 50 | if (n->my_ooe != NULL) |
| 51 | g_object_unref(n->my_ooe); |
| 52 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 53 | n->my_ooe = ooe; |
| 54 | n->my_ooe->integer16 = 16; |
| 55 | n->my_ooe->integer32 = 32; |
| 56 | n->my_ooe->integer64 = 64; |
| 57 | n->my_ooe->double_precision = (sqrt(5.0) + 1) / 2; |
Roger Meier | c75797d | 2012-04-28 11:33:58 +0000 | [diff] [blame] | 58 | n->my_ooe->some_characters = g_strdup(":R (me going \"rrrr\")"); |
| 59 | n->my_ooe->zomg_unicode = g_strdup("\xd3\x80\xe2\x85\xae\xce\x9d\x20"); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 60 | n->my_bonk->type = 31337; |
Roger Meier | c75797d | 2012-04-28 11:33:58 +0000 | [diff] [blame] | 61 | n->my_bonk->message = g_strdup("I am a bonk... xor!"); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 62 | |
| 63 | hm = g_object_new (T_TEST_TYPE_HOLY_MOLEY, NULL); |
| 64 | g_ptr_array_add (hm->big, ooe); |
Roger Meier | c75797d | 2012-04-28 11:33:58 +0000 | [diff] [blame] | 65 | g_ptr_array_add (hm->big, g_object_ref(n->my_ooe)); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 66 | ((TTestOneOfEach *) g_ptr_array_index (hm->big, 0))->a_bite = 0x22; |
| 67 | ((TTestOneOfEach *) g_ptr_array_index (hm->big, 1))->a_bite = 0x33; |
| 68 | |
Roger Meier | c75797d | 2012-04-28 11:33:58 +0000 | [diff] [blame] | 69 | g_hash_table_insert (hm->contain, random, random); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 70 | |
| 71 | TTestBonk *bonk = NULL; |
| 72 | bonk = g_object_new (T_TEST_TYPE_BONK, NULL); |
Roger Meier | c75797d | 2012-04-28 11:33:58 +0000 | [diff] [blame] | 73 | GPtrArray *bonks = g_ptr_array_new_with_free_func (g_object_unref); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 74 | g_ptr_array_add (bonks, bonk); |
Roger Meier | c75797d | 2012-04-28 11:33:58 +0000 | [diff] [blame] | 75 | g_hash_table_insert (hm->bonks, nothing, bonks); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 76 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 77 | g_object_unref (hm); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 82 | int |
| 83 | main(int argc, char *argv[]) |
| 84 | { |
| 85 | g_type_init(); |
| 86 | g_test_init (&argc, &argv, NULL); |
| 87 | |
| 88 | g_test_add_func ("/testdebugproto/DebugProto", test_debug_proto); |
| 89 | |
| 90 | return g_test_run (); |
| 91 | } |
| 92 | |
| 93 | |