1 #include <netdb.h>
2 
3 #include <thrift/c_glib/thrift.h>
4 #include <thrift/c_glib/transport/thrift_server_transport.h>
5 #include <thrift/c_glib/transport/thrift_server_socket.h>
6 
7 #include "t_test_thrift_test_types.h"
8 #include "thrift_test_handler.h"
9 
10 static const char TEST_ADDRESS[] = "localhost";
11 static const int TEST_PORT = 64444;
12 
13 static void
test_thrift_server(void)14 test_thrift_server (void)
15 {
16   ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
17                                               "port", TEST_PORT, NULL);
18 
19   g_object_unref (tsocket);
20 }
21 
22 static void
set_indicator(gpointer data,GObject * where_the_object_was)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
test_thrift_handler(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 
89   g_assert (thrift_test_handler_test_insanity (NULL, &_return, argument, &error));
90   g_assert (! indicator);
91 
92   g_hash_table_unref (_return);
93   g_assert (! indicator);
94 
95   g_object_unref (argument);
96   g_assert (indicator);
97 }
98 
99 int
main(int argc,char * argv[])100 main(int argc, char *argv[])
101 {
102 #if (!GLIB_CHECK_VERSION (2, 36, 0))
103   g_type_init();
104 #endif
105 
106   g_test_init (&argc, &argv, NULL);
107 
108   g_test_add_func ("/testthrift/Server", test_thrift_server);
109   g_test_add_func ("/testthrift/Handler", test_thrift_handler);
110 
111   return g_test_run ();
112 }
113