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