blob: 0211f5393911c4d47d4916391fbfc08d396f554c [file] [log] [blame]
Roger Meier213a6642010-10-27 12:30:11 +00001#include <assert.h>
2#include <netdb.h>
3
Chandler May3fe3df22016-01-18 11:05:40 -05004#include <thrift/c_glib/thrift.h>
Roger Meiere3da7682013-01-11 11:41:53 +01005#include <thrift/c_glib/transport/thrift_server_transport.h>
6#include <thrift/c_glib/transport/thrift_server_socket.h>
Roger Meier213a6642010-10-27 12:30:11 +00007
Chandler May3fe3df22016-01-18 11:05:40 -05008#include "t_test_thrift_test_types.h"
9#include "thrift_test_handler.h"
10
Roger Meier213a6642010-10-27 12:30:11 +000011static const char TEST_ADDRESS[] = "localhost";
12static const int TEST_PORT = 64444;
13
Roger Meier213a6642010-10-27 12:30:11 +000014static void
Jens Geyer1c190272015-07-28 23:15:18 +020015test_thrift_server (void)
Roger Meier213a6642010-10-27 12:30:11 +000016{
17 ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
Roger Meierc1010922010-11-26 10:17:48 +000018 "port", TEST_PORT, NULL);
Roger Meier213a6642010-10-27 12:30:11 +000019
20 g_object_unref (tsocket);
21}
22
Chandler May3fe3df22016-01-18 11:05:40 -050023static void
24set_indicator (gpointer data, GObject *where_the_object_was) {
25 THRIFT_UNUSED_VAR(where_the_object_was);
26
27 *(gboolean *) data = TRUE;
28}
29
30static void
31test_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 Meier213a6642010-10-27 12:30:11 +0000100int
Roger Meierc1010922010-11-26 10:17:48 +0000101main(int argc, char *argv[])
Roger Meier213a6642010-10-27 12:30:11 +0000102{
Jens Geyer1c190272015-07-28 23:15:18 +0200103#if (!GLIB_CHECK_VERSION (2, 36, 0))
Roger Meierc1010922010-11-26 10:17:48 +0000104 g_type_init();
Jens Geyer1c190272015-07-28 23:15:18 +0200105#endif
106
Roger Meierc1010922010-11-26 10:17:48 +0000107 g_test_init (&argc, &argv, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000108
Roger Meierc1010922010-11-26 10:17:48 +0000109 g_test_add_func ("/testthrift/Server", test_thrift_server);
Chandler May3fe3df22016-01-18 11:05:40 -0500110 g_test_add_func ("/testthrift/Handler", test_thrift_handler);
Roger Meierc1010922010-11-26 10:17:48 +0000111
112 return g_test_run ();
113}