Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 1 | #include <netdb.h> |
| 2 | |
Chandler May | 3fe3df2 | 2016-01-18 11:05:40 -0500 | [diff] [blame] | 3 | #include <thrift/c_glib/thrift.h> |
Roger Meier | e3da768 | 2013-01-11 11:41:53 +0100 | [diff] [blame] | 4 | #include <thrift/c_glib/transport/thrift_server_transport.h> |
| 5 | #include <thrift/c_glib/transport/thrift_server_socket.h> |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 6 | |
Chandler May | 3fe3df2 | 2016-01-18 11:05:40 -0500 | [diff] [blame] | 7 | #include "t_test_thrift_test_types.h" |
| 8 | #include "thrift_test_handler.h" |
| 9 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 10 | static const char TEST_ADDRESS[] = "localhost"; |
| 11 | static const int TEST_PORT = 64444; |
| 12 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 13 | static void |
Jens Geyer | 1c19027 | 2015-07-28 23:15:18 +0200 | [diff] [blame] | 14 | test_thrift_server (void) |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 15 | { |
| 16 | ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 17 | "port", TEST_PORT, NULL); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 18 | |
| 19 | g_object_unref (tsocket); |
| 20 | } |
| 21 | |
Chandler May | 3fe3df2 | 2016-01-18 11:05:40 -0500 | [diff] [blame] | 22 | static void |
| 23 | set_indicator (gpointer data, GObject *where_the_object_was) { |
| 24 | THRIFT_UNUSED_VAR(where_the_object_was); |
| 25 | |
| 26 | *(gboolean *) data = TRUE; |
| 27 | } |
| 28 | |
| 29 | static void |
| 30 | test_thrift_handler (void) |
| 31 | { |
| 32 | GError *error; |
| 33 | GHashTable *_return; |
| 34 | TTestInsanity *argument; |
| 35 | gboolean indicator; |
| 36 | |
| 37 | TTestXtruct *xtruct, *xtruct2; |
| 38 | TTestNumberz numberz; |
| 39 | TTestNumberz numberz2; |
| 40 | TTestUserId user_id, *user_id_ptr, *user_id_ptr2; |
| 41 | GHashTable *user_map; |
| 42 | GPtrArray *xtructs; |
| 43 | |
| 44 | error = NULL; |
| 45 | indicator = FALSE; |
| 46 | |
| 47 | user_map = NULL; |
| 48 | xtructs = NULL; |
| 49 | |
| 50 | argument = g_object_new (T_TEST_TYPE_INSANITY, NULL); |
| 51 | g_object_get (argument, |
| 52 | "userMap", &user_map, |
| 53 | "xtructs", &xtructs, |
| 54 | NULL); |
| 55 | |
| 56 | numberz = T_TEST_NUMBERZ_FIVE; |
| 57 | numberz2 = T_TEST_NUMBERZ_EIGHT; |
| 58 | user_id_ptr = g_malloc (sizeof *user_id_ptr); |
| 59 | *user_id_ptr = 5; |
| 60 | user_id_ptr2 = g_malloc (sizeof *user_id_ptr); |
| 61 | *user_id_ptr2 = 8; |
| 62 | g_hash_table_insert (user_map, (gpointer)numberz, user_id_ptr); |
| 63 | g_hash_table_insert (user_map, (gpointer)numberz2, user_id_ptr2); |
| 64 | g_hash_table_unref (user_map); |
| 65 | |
| 66 | xtruct = g_object_new (T_TEST_TYPE_XTRUCT, |
| 67 | "string_thing", "Hello2", |
| 68 | "byte_thing", 2, |
| 69 | "i32_thing", 2, |
| 70 | "i64_thing", 2LL, |
| 71 | NULL); |
| 72 | xtruct2 = g_object_new (T_TEST_TYPE_XTRUCT, |
| 73 | "string_thing", "Goodbye4", |
| 74 | "byte_thing", 4, |
| 75 | "i32_thing", 4, |
| 76 | "i64_thing", 4LL, |
| 77 | NULL); |
| 78 | g_ptr_array_add (xtructs, xtruct2); |
| 79 | g_ptr_array_add (xtructs, xtruct); |
| 80 | g_ptr_array_unref (xtructs); |
| 81 | |
| 82 | _return = g_hash_table_new_full (g_int64_hash, |
| 83 | g_int64_equal, |
| 84 | g_free, |
| 85 | (GDestroyNotify)g_hash_table_unref); |
| 86 | |
| 87 | g_object_weak_ref (G_OBJECT (argument), set_indicator, (gpointer) &indicator); |
| 88 | |
James E. King, III | 43f4bf2 | 2017-10-28 12:54:02 -0400 | [diff] [blame] | 89 | g_assert (thrift_test_handler_test_insanity (NULL, &_return, argument, &error)); |
| 90 | g_assert (! indicator); |
Chandler May | 3fe3df2 | 2016-01-18 11:05:40 -0500 | [diff] [blame] | 91 | |
| 92 | g_hash_table_unref (_return); |
James E. King, III | 43f4bf2 | 2017-10-28 12:54:02 -0400 | [diff] [blame] | 93 | g_assert (! indicator); |
Chandler May | 3fe3df2 | 2016-01-18 11:05:40 -0500 | [diff] [blame] | 94 | |
| 95 | g_object_unref (argument); |
James E. King, III | 43f4bf2 | 2017-10-28 12:54:02 -0400 | [diff] [blame] | 96 | g_assert (indicator); |
Chandler May | 3fe3df2 | 2016-01-18 11:05:40 -0500 | [diff] [blame] | 97 | } |
| 98 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 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 ("/testthrift/Server", test_thrift_server); |
Chandler May | 3fe3df2 | 2016-01-18 11:05:40 -0500 | [diff] [blame] | 109 | g_test_add_func ("/testthrift/Handler", test_thrift_handler); |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 110 | |
| 111 | return g_test_run (); |
| 112 | } |