blob: 23a934db996e4516d3bb86ee0b2448cb23ee5962 [file] [log] [blame]
Roger Meier213a6642010-10-27 12:30:11 +00001#include <netdb.h>
2
Chandler May3fe3df22016-01-18 11:05:40 -05003#include <thrift/c_glib/thrift.h>
Roger Meiere3da7682013-01-11 11:41:53 +01004#include <thrift/c_glib/transport/thrift_server_transport.h>
5#include <thrift/c_glib/transport/thrift_server_socket.h>
Roger Meier213a6642010-10-27 12:30:11 +00006
Chandler May3fe3df22016-01-18 11:05:40 -05007#include "t_test_thrift_test_types.h"
8#include "thrift_test_handler.h"
9
Roger Meier213a6642010-10-27 12:30:11 +000010static const char TEST_ADDRESS[] = "localhost";
11static const int TEST_PORT = 64444;
12
Roger Meier213a6642010-10-27 12:30:11 +000013static void
Jens Geyer1c190272015-07-28 23:15:18 +020014test_thrift_server (void)
Roger Meier213a6642010-10-27 12:30:11 +000015{
16 ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
Roger Meierc1010922010-11-26 10:17:48 +000017 "port", TEST_PORT, NULL);
Roger Meier213a6642010-10-27 12:30:11 +000018
19 g_object_unref (tsocket);
20}
21
Chandler May3fe3df22016-01-18 11:05:40 -050022static void
23set_indicator (gpointer data, GObject *where_the_object_was) {
24 THRIFT_UNUSED_VAR(where_the_object_was);
25
26 *(gboolean *) data = TRUE;
27}
28
29static void
30test_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, III43f4bf22017-10-28 12:54:02 -040089 g_assert (thrift_test_handler_test_insanity (NULL, &_return, argument, &error));
90 g_assert (! indicator);
Chandler May3fe3df22016-01-18 11:05:40 -050091
92 g_hash_table_unref (_return);
James E. King, III43f4bf22017-10-28 12:54:02 -040093 g_assert (! indicator);
Chandler May3fe3df22016-01-18 11:05:40 -050094
95 g_object_unref (argument);
James E. King, III43f4bf22017-10-28 12:54:02 -040096 g_assert (indicator);
Chandler May3fe3df22016-01-18 11:05:40 -050097}
98
Roger Meier213a6642010-10-27 12:30:11 +000099int
Roger Meierc1010922010-11-26 10:17:48 +0000100main(int argc, char *argv[])
Roger Meier213a6642010-10-27 12:30:11 +0000101{
Jens Geyer1c190272015-07-28 23:15:18 +0200102#if (!GLIB_CHECK_VERSION (2, 36, 0))
Roger Meierc1010922010-11-26 10:17:48 +0000103 g_type_init();
Jens Geyer1c190272015-07-28 23:15:18 +0200104#endif
105
Roger Meierc1010922010-11-26 10:17:48 +0000106 g_test_init (&argc, &argv, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000107
Roger Meierc1010922010-11-26 10:17:48 +0000108 g_test_add_func ("/testthrift/Server", test_thrift_server);
Chandler May3fe3df22016-01-18 11:05:40 -0500109 g_test_add_func ("/testthrift/Handler", test_thrift_handler);
Roger Meierc1010922010-11-26 10:17:48 +0000110
111 return g_test_run ();
112}