summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/thrift/test/c_glib
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/test/c_glib
parentInitial commit. (diff)
downloadceph-upstream/16.2.11+ds.tar.xz
ceph-upstream/16.2.11+ds.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/thrift/test/c_glib')
-rw-r--r--src/jaegertracing/thrift/test/c_glib/CMakeLists.txt55
-rwxr-xr-xsrc/jaegertracing/thrift/test/c_glib/Makefile.am82
-rw-r--r--src/jaegertracing/thrift/test/c_glib/src/test_client.c1825
-rw-r--r--src/jaegertracing/thrift/test/c_glib/src/test_server.c307
-rw-r--r--src/jaegertracing/thrift/test/c_glib/src/thrift_second_service_handler.c69
-rw-r--r--src/jaegertracing/thrift/test/c_glib/src/thrift_second_service_handler.h73
-rw-r--r--src/jaegertracing/thrift/test/c_glib/src/thrift_test_handler.c837
-rw-r--r--src/jaegertracing/thrift/test/c_glib/src/thrift_test_handler.h245
8 files changed, 3493 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/test/c_glib/CMakeLists.txt b/src/jaegertracing/thrift/test/c_glib/CMakeLists.txt
new file mode 100644
index 000000000..98173155b
--- /dev/null
+++ b/src/jaegertracing/thrift/test/c_glib/CMakeLists.txt
@@ -0,0 +1,55 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Contains the thrift specific LINK_AGAINST_THRIFT_LIBRARY
+include(ThriftMacros)
+
+find_package(GLIB REQUIRED COMPONENTS gobject)
+include_directories(SYSTEM "${GLIB_INCLUDE_DIR}")
+include_directories(SYSTEM "${GLIBCONFIG_INCLUDE_DIR}")
+
+#Make sure gen-c_glib files can be included
+include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+include_directories("${CMAKE_CURRENT_BINARY_DIR}/gen-c_glib")
+include_directories("${PROJECT_SOURCE_DIR}/lib/c_glib/src")
+
+set(crosstestgencglib_SOURCES
+ gen-c_glib/t_test_second_service.c
+ gen-c_glib/t_test_second_service.h
+ gen-c_glib/t_test_thrift_test.c
+ gen-c_glib/t_test_thrift_test.h
+ gen-c_glib/t_test_thrift_test_types.c
+ gen-c_glib/t_test_thrift_test_types.h
+)
+add_library(crosstestgencglib STATIC ${crosstestgencglib_SOURCES})
+LINK_AGAINST_THRIFT_LIBRARY(crosstestgencglib thrift_c_glib)
+
+add_executable(test_server src/test_server.c src/thrift_test_handler.c src/thrift_second_service_handler.c)
+target_link_libraries(test_server crosstestgencglib)
+
+add_executable(test_client src/test_client.c)
+target_link_libraries(test_client crosstestgencglib)
+
+#
+# Common thrift code generation rules
+#
+
+add_custom_command(OUTPUT gen-c_glib/t_test_second_service.c gen-c_glib/t_test_second_service.h gen-c_glib/t_test_thrift_test.c gen-c_glib/t_test_thrift_test.h gen-c_glib/t_test_thrift_test_types.c gen-c_glib/t_test_thrift_test_types.h
+ COMMAND ${THRIFT_COMPILER} --gen c_glib -r ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
+)
diff --git a/src/jaegertracing/thrift/test/c_glib/Makefile.am b/src/jaegertracing/thrift/test/c_glib/Makefile.am
new file mode 100755
index 000000000..98a373498
--- /dev/null
+++ b/src/jaegertracing/thrift/test/c_glib/Makefile.am
@@ -0,0 +1,82 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+AUTOMAKE_OPTIONS = subdir-objects serial-tests nostdinc
+
+noinst_LTLIBRARIES = libtestcglib.la
+nodist_libtestcglib_la_SOURCES = \
+ gen-c_glib/t_test_second_service.c \
+ gen-c_glib/t_test_second_service.h \
+ gen-c_glib/t_test_thrift_test.c \
+ gen-c_glib/t_test_thrift_test.h \
+ gen-c_glib/t_test_thrift_test_types.c \
+ gen-c_glib/t_test_thrift_test_types.h
+
+libtestcglib_la_LIBADD = $(top_builddir)/lib/c_glib/libthrift_c_glib.la
+
+precross: libtestcglib.la test_client test_server
+
+check_PROGRAMS = \
+ test_client \
+ test_server
+
+test_client_SOURCES = \
+ src/test_client.c
+
+test_client_LDADD = \
+ libtestcglib.la \
+ $(top_builddir)/lib/c_glib/libthrift_c_glib.la
+
+test_server_SOURCES = \
+ src/thrift_test_handler.c \
+ src/thrift_test_handler.h \
+ src/thrift_second_service_handler.c \
+ src/thrift_second_service_handler.h \
+ src/test_server.c
+
+test_server_LDADD = \
+ libtestcglib.la \
+ $(top_builddir)/lib/c_glib/libthrift_c_glib.la
+
+#
+# Common thrift code generation rules
+#
+gen-c_glib/t_test_second_service.c gen-c_glib/t_test_second_service.h gen-c_glib/t_test_thrift_test.c gen-c_glib/t_test_thrift_test.h gen-c_glib/t_test_thrift_test_types.c gen-c_glib/t_test_thrift_test_types.h: $(top_srcdir)/test/ThriftTest.thrift $(THRIFT)
+ $(THRIFT) --gen c_glib -r $<
+
+AM_CFLAGS = -g -Wall -Wextra $(GLIB_CFLAGS) $(GOBJECT_CFLAGS)
+AM_CXXFLAGS = $(AM_CFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/lib/c_glib/src -Igen-c_glib -I$(top_builddir)/lib/c_glib/src/thrift
+AM_LDFLAGS = $(GLIB_LIBS) $(GOBJECT_LIBS) @GCOV_LDFLAGS@
+
+clean-local:
+ $(RM) -r gen-c_glib/
+ $(RM) test_client
+ $(RM) test_server
+ $(RM) libtestcglib.la
+ find . -type f -iname "*.o" | xargs rm -f
+
+dist-hook:
+ $(RM) -r $(distdir)/gen-c_glib/
+ $(RM) $(distdir)/test_client
+ $(RM) $(distdir)/test_server
+ $(RM) $(distdir)/libtestcglib.la
+ find $(distdir) -type f -iname "*.o" | xargs rm -f
+
+EXTRA_DIST = \
+ src
diff --git a/src/jaegertracing/thrift/test/c_glib/src/test_client.c b/src/jaegertracing/thrift/test/c_glib/src/test_client.c
new file mode 100644
index 000000000..7126a86d8
--- /dev/null
+++ b/src/jaegertracing/thrift/test/c_glib/src/test_client.c
@@ -0,0 +1,1825 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <glib-object.h>
+#include <inttypes.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <sys/time.h>
+
+#include <thrift/c_glib/thrift.h>
+#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
+#include <thrift/c_glib/protocol/thrift_compact_protocol.h>
+#include <thrift/c_glib/protocol/thrift_multiplexed_protocol.h>
+#include <thrift/c_glib/transport/thrift_buffered_transport.h>
+#include <thrift/c_glib/transport/thrift_framed_transport.h>
+#include <thrift/c_glib/transport/thrift_ssl_socket.h>
+#include <thrift/c_glib/transport/thrift_socket.h>
+#include <thrift/c_glib/transport/thrift_transport.h>
+
+#include "../gen-c_glib/t_test_second_service.h"
+#include "../gen-c_glib/t_test_thrift_test.h"
+
+/* Handle SIGPIPE signals (indicating the server has closed the
+ connection prematurely) by outputting an error message before
+ exiting. */
+static void
+sigpipe_handler (int signal_number)
+{
+ THRIFT_UNUSED_VAR (signal_number);
+
+ /* Flush standard output to make sure the test results so far are
+ logged */
+ fflush (stdout);
+
+ fputs ("Broken pipe (server closed connection prematurely)\n", stderr);
+ fflush (stderr);
+
+ /* Re-raise the signal, this time invoking the default signal
+ handler, to terminate the program */
+ raise (SIGPIPE);
+}
+
+/* Compare two gint32 values. Used for sorting and finding integer
+ values within a GList. */
+static gint
+gint32_compare (gconstpointer a, gconstpointer b)
+{
+ gint32 int32_a = *(gint32 *)a;
+ gint32 int32_b = *(gint32 *)b;
+ int result = 0;
+
+ if (int32_a < int32_b)
+ result = -1;
+ else if (int32_a > int32_b)
+ result = 1;
+
+ return result;
+}
+
+/**
+ * It gets a multiplexed protocol which uses a concrete protocol underneath
+ * @param protocol_name the fully qualified protocol path (e.g. "binary:multi")
+ * @param transport the underlying transport
+ * @param service_name the single supported service name
+ * @todo need to allow multiple services to fully test multiplexed
+ * @return a multiplexed protocol wrapping the correct underlying protocol
+ */
+ThriftProtocol *
+get_multiplexed_protocol(gchar *protocol_name, ThriftTransport *transport, gchar *service_name)
+{
+ ThriftProtocol * multiplexed_protocol = NULL;
+
+ if ( strncmp(protocol_name, "binary:", 7) == 0) {
+ multiplexed_protocol = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL,
+ "transport", transport,
+ NULL);
+ } else if ( strncmp(protocol_name, "compact:", 8) == 0) {
+ multiplexed_protocol = g_object_new (THRIFT_TYPE_COMPACT_PROTOCOL,
+ "transport", transport,
+ NULL);
+ } else {
+ fprintf(stderr, "Unknown multiplex protocol name: %s\n", protocol_name);
+ return NULL;
+ }
+
+ return g_object_new (THRIFT_TYPE_MULTIPLEXED_PROTOCOL,
+ "transport", transport,
+ "protocol", multiplexed_protocol,
+ "service-name", service_name,
+ NULL);
+}
+
+int
+main (int argc, char **argv)
+{
+ static gchar * host = NULL;
+ static gint port = 9090;
+ static gchar * path = NULL;
+ static gboolean ssl = FALSE;
+ static gchar * transport_option = NULL;
+ static gchar * protocol_option = NULL;
+ static gint num_tests = 1;
+
+ static
+ GOptionEntry option_entries[] ={
+ { "host", 'h', 0, G_OPTION_ARG_STRING, &host,
+ "Host to connect (=localhost)", NULL },
+ { "port", 'p', 0, G_OPTION_ARG_INT, &port,
+ "Port number to connect (=9090)", NULL },
+ { "domain-socket", 0, 0, G_OPTION_ARG_STRING, &path,
+ "Unix socket domain path to connect", NULL },
+ { "ssl", 's', 0, G_OPTION_ARG_NONE, &ssl,
+ "Enable SSL", NULL },
+ { "transport", 't', 0, G_OPTION_ARG_STRING, &transport_option,
+ "Transport: buffered, framed (=buffered)", NULL },
+ { "protocol", 'r', 0, G_OPTION_ARG_STRING, &protocol_option,
+ "Protocol: binary, compact, multi, multic (=binary)", NULL },
+ { "testloops", 'n', 0, G_OPTION_ARG_INT, &num_tests,
+ "Number of tests (=1)", NULL },
+ { NULL }
+ };
+
+ struct sigaction sigpipe_action;
+
+ GType socket_type = THRIFT_TYPE_SOCKET;
+ gchar *socket_name = "ip";
+ GType transport_type = THRIFT_TYPE_BUFFERED_TRANSPORT;
+ gchar *transport_name = "buffered";
+ GType protocol_type = THRIFT_TYPE_BINARY_PROTOCOL;
+ gchar *protocol_name = "binary";
+
+ ThriftSocket *socket = NULL;
+ ThriftTransport *transport = NULL;
+ ThriftProtocol *protocol = NULL;
+ ThriftProtocol *protocol2 = NULL; // for multiplexed tests
+
+ TTestThriftTestIf *test_client = NULL;
+ TTestSecondServiceIf *second_service = NULL; // for multiplexed tests
+
+ struct timeval time_start, time_stop, time_elapsed;
+ guint64 time_elapsed_usec, time_total_usec = 0;
+ guint64 time_min_usec = G_MAXUINT64, time_max_usec = 0, time_avg_usec;
+
+ GOptionContext *option_context;
+ gboolean options_valid = TRUE;
+ int test_num = 0;
+ int fail_count = 0;
+ GError *error = NULL;
+
+#if (!GLIB_CHECK_VERSION (2, 36, 0))
+ g_type_init ();
+#endif
+
+ /* Configure and parse our command-line options */
+ option_context = g_option_context_new (NULL);
+ g_option_context_add_main_entries (option_context,
+ option_entries,
+ NULL);
+ if (!g_option_context_parse (option_context,
+ &argc,
+ &argv,
+ &error)) {
+ fprintf (stderr, "%s\n", error->message);
+ return 255;
+ }
+ g_option_context_free (option_context);
+
+ /* Set remaining default values for unspecified options */
+ if (host == NULL)
+ host = g_strdup ("localhost");
+
+ /* Validate the parsed options */
+ if (protocol_option != NULL) {
+ if (strncmp (protocol_option, "compact", 8) == 0) {
+ protocol_type = THRIFT_TYPE_COMPACT_PROTOCOL;
+ protocol_name = "compact";
+ }
+ else if (strncmp (protocol_option, "multi", 6) == 0) {
+ protocol_type = THRIFT_TYPE_MULTIPLEXED_PROTOCOL;
+ protocol_name = "binary:multi";
+ }
+ else if (strncmp (protocol_option, "multic", 7) == 0) {
+ protocol_type = THRIFT_TYPE_MULTIPLEXED_PROTOCOL;
+ protocol_name = "compact:multic";
+ }
+ else if (strncmp (protocol_option, "binary", 7) == 0) {
+ printf("We are going with default protocol\n");
+ }
+ else {
+ fprintf (stderr, "Unknown protocol type %s\n", protocol_option);
+ options_valid = FALSE;
+ }
+ }
+
+ if (transport_option != NULL) {
+ if (strncmp (transport_option, "framed", 7) == 0) {
+ transport_type = THRIFT_TYPE_FRAMED_TRANSPORT;
+ transport_name = "framed";
+ }
+ else if (strncmp (transport_option, "buffered", 9) != 0) {
+ fprintf (stderr, "Unknown transport type %s\n", transport_option);
+ options_valid = FALSE;
+ }
+ }
+
+ if (ssl) {
+ socket_type = THRIFT_TYPE_SSL_SOCKET;
+ socket_name = "ip-ssl";
+ printf("Type name %s\n", g_type_name (socket_type));
+ }
+
+ if (!options_valid)
+ return 254;
+
+ if (path) {
+ printf ("Connecting (%s/%s) to: %s/%s\n",
+ transport_name,
+ protocol_name,
+ socket_name,
+ path);
+ } else {
+ printf ("Connecting (%s/%s) to: %s/%s:%d\n",
+ transport_name,
+ protocol_name,
+ socket_name,
+ host,
+ port);
+ }
+
+ /* Install our SIGPIPE handler, which outputs an error message to
+ standard error before exiting so testers can know what
+ happened */
+ memset (&sigpipe_action, 0, sizeof (sigpipe_action));
+ sigpipe_action.sa_handler = sigpipe_handler;
+ sigpipe_action.sa_flags = SA_RESETHAND;
+ sigaction (SIGPIPE, &sigpipe_action, NULL);
+
+ if (ssl) {
+ thrift_ssl_socket_initialize_openssl();
+ }
+
+ /* Establish all our connection objects */
+ if (path) {
+ socket = g_object_new (socket_type,
+ "path", path,
+ NULL);
+ } else {
+ socket = g_object_new (socket_type,
+ "hostname", host,
+ "port", port,
+ NULL);
+ }
+
+ if (ssl && !thrift_ssl_load_cert_from_file(THRIFT_SSL_SOCKET(socket), "../keys/CA.pem")) {
+ fprintf(stderr, "Unable to load validation certificate ../keys/CA.pem - did you run in the test/c_glib directory?\n");
+ g_clear_object (&socket);
+ return 253;
+ }
+
+ transport = g_object_new (transport_type,
+ "transport", socket,
+ NULL);
+
+ if(protocol_type==THRIFT_TYPE_MULTIPLEXED_PROTOCOL) {
+ // TODO: A multiplexed test should also test "Second" (see Java TestServer)
+ // The context comes from the name of the thrift file. If multiple thrift
+ // schemas are used we have to redo the way this is done.
+ protocol = get_multiplexed_protocol(protocol_name, transport, "ThriftTest");
+ if (NULL == protocol) {
+ g_clear_object (&transport);
+ g_clear_object (&socket);
+ return 252;
+ }
+
+ // Make a second protocol and client running on the same multiplexed transport
+ protocol2 = get_multiplexed_protocol(protocol_name, transport, "SecondService");
+ second_service = g_object_new (T_TEST_TYPE_SECOND_SERVICE_CLIENT,
+ "input_protocol", protocol2,
+ "output_protocol", protocol2,
+ NULL);
+
+ }else{
+ protocol = g_object_new (protocol_type,
+ "transport", transport,
+ NULL);
+ }
+
+ test_client = g_object_new (T_TEST_TYPE_THRIFT_TEST_CLIENT,
+ "input_protocol", protocol,
+ "output_protocol", protocol,
+ NULL);
+
+ /* Execute the actual tests */
+ for (test_num = 0; test_num < num_tests; ++test_num) {
+ if (thrift_transport_open (transport, &error)) {
+ gchar *string = NULL;
+ gboolean boolean = 0;
+ gint8 byte = 0;
+ gint32 int32 = 0;
+ gint64 int64 = 0;
+ gdouble dub = 0;
+
+ gint byte_thing, i32_thing, inner_byte_thing, inner_i32_thing;
+ gint64 i64_thing, inner_i64_thing;
+
+ TTestXtruct *xtruct_out, *xtruct_out2, *xtruct_in, *inner_xtruct_in;
+ TTestXtruct2 *xtruct2_out, *xtruct2_in;
+
+ GHashTable *map_out, *map_in, *inner_map_in;
+ GHashTable *set_out, *set_in;
+ gpointer key, value;
+ gint32 *i32_key_ptr, *i32_value_ptr;
+ GHashTableIter hash_table_iter, inner_hash_table_iter;
+ GList *keys_out, *keys_in, *keys_elem;
+
+ GArray *list_out, *list_in;
+
+ TTestNumberz numberz;
+ TTestNumberz numberz2;
+
+ TTestUserId user_id, *user_id_ptr, *user_id_ptr2;
+
+ TTestInsanity *insanity_out, *insanity_in;
+ GHashTable *user_map;
+ GHashTableIter user_map_iter;
+ GPtrArray *xtructs;
+
+ TTestXception *xception = NULL;
+ TTestXception2 *xception2 = NULL;
+
+ gboolean oneway_result;
+ struct timeval oneway_start, oneway_end, oneway_elapsed;
+ gint oneway_elapsed_usec;
+
+ gboolean first;
+ gint32 i, j;
+
+ if (path) {
+ printf ("Test #%d, connect %s\n", test_num + 1, path);
+ } else {
+ printf ("Test #%d, connect %s:%d\n", test_num + 1, host, port);
+ }
+ gettimeofday (&time_start, NULL);
+
+ /* These test routines have been ported from the C++ test
+ client, care being taken to ensure their output remains as
+ close as possible to the original to facilitate diffs.
+
+ For simplicity comments have been omitted, but every routine
+ has the same basic structure:
+
+ - Create and populate data structures as necessary.
+
+ - Format and output (to the console) a representation of the
+ outgoing data.
+
+ - Issue the remote method call to the server.
+
+ - Format and output a representation of the returned data.
+
+ - Verify the returned data matches what was expected.
+
+ - Deallocate any created data structures.
+
+ Note the recognized values and expected behaviour of each
+ remote method are described in ThriftTest.thrift, which
+ you'll find in the top-level "test" folder. */
+
+ /**
+ * VOID TEST
+ */
+ printf ("testVoid()");
+ if (t_test_thrift_test_if_test_void (test_client, &error)) {
+ printf (" = void\n");
+ }
+ else {
+ if(error!=NULL){
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ fail_count++;
+ }
+
+ /**
+ * STRING TEST
+ */
+ printf ("testString(\"Test\")");
+ if (t_test_thrift_test_if_test_string (test_client,
+ &string,
+ "Test",
+ &error)) {
+ printf (" = \"%s\"\n", string);
+ if (strncmp (string, "Test", 5) != 0)
+ fail_count++;
+
+ g_free (string);
+ string = NULL;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ /**
+ * Multiplexed Test - do this right in the middle of the normal Test Client run
+ */
+ if (second_service) {
+ printf ("testSecondServiceMultiplexSecondTestString(\"2nd\")");
+ if (t_test_second_service_if_secondtest_string (second_service,
+ &string,
+ "2nd",
+ &error)) {
+ printf (" = \"%s\"\n", string);
+ if (strcmp (string, "testString(\"2nd\")") != 0) {
+ ++fail_count;
+ }
+
+ g_free (string);
+ string = NULL;
+ } else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ ++fail_count;
+ }
+ }
+
+ /**
+ * BOOL TEST
+ */
+ printf ("testByte(true)");
+ if (t_test_thrift_test_if_test_bool (test_client,
+ &boolean,
+ 1,
+ &error)) {
+ printf (" = %s\n", boolean ? "true" : "false");
+ if (boolean != 1)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+ printf ("testByte(false)");
+ if (t_test_thrift_test_if_test_bool (test_client,
+ &boolean,
+ 0,
+ &error)) {
+ printf (" = %s\n", boolean ? "true" : "false");
+ if (boolean != 0)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ /**
+ * BYTE TEST
+ */
+ printf ("testByte(1)");
+ if (t_test_thrift_test_if_test_byte (test_client,
+ &byte,
+ 1,
+ &error)) {
+ printf (" = %d\n", byte);
+ if (byte != 1)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+ printf ("testByte(-1)");
+ if (t_test_thrift_test_if_test_byte (test_client,
+ &byte,
+ -1,
+ &error)) {
+ printf (" = %d\n", byte);
+ if (byte != -1)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ /**
+ * I32 TEST
+ */
+ printf ("testI32(-1)");
+ if (t_test_thrift_test_if_test_i32 (test_client,
+ &int32,
+ -1,
+ &error)) {
+ printf (" = %d\n", int32);
+ if (int32 != -1)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ /**
+ * I64 TEST
+ */
+ printf ("testI64(-34359738368)");
+ if (t_test_thrift_test_if_test_i64 (test_client,
+ &int64,
+ (gint64)-34359738368,
+ &error)) {
+ printf (" = %" PRId64 "\n", int64);
+ if (int64 != (gint64)-34359738368)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ /**
+ * DOUBLE TEST
+ */
+ printf("testDouble(-5.2098523)");
+ if (t_test_thrift_test_if_test_double (test_client,
+ &dub,
+ -5.2098523,
+ &error)) {
+ printf (" = %f\n", dub);
+ if ((dub - (-5.2098523)) > 0.001)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ /**
+ * BINARY TEST
+ */
+ printf ("testBinary(empty)");
+ GByteArray *emptyArray = g_byte_array_new();
+ GByteArray *result = NULL;
+ if (t_test_thrift_test_if_test_binary (test_client,
+ &result,
+ emptyArray,
+ &error)) {
+ GBytes *response = g_byte_array_free_to_bytes(result); // frees result
+ result = NULL;
+ gsize siz = g_bytes_get_size(response);
+ if (siz == 0) {
+ printf(" = empty\n");
+ } else {
+ printf(" = not empty (%ld bytes)\n", (long)siz);
+ ++fail_count;
+ }
+ g_bytes_unref(response);
+ } else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+ g_byte_array_unref(emptyArray);
+ emptyArray = NULL;
+
+ // TODO: add testBinary() with data
+ printf ("testBinary([-128..127]) = {");
+ const signed char bin_data[256]
+ = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
+ -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
+ -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
+ -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
+ -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
+ -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
+ -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
+ -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
+ -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
+ 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
+ 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
+ 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
+ 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
+ 127};
+ GByteArray *fullArray = g_byte_array_new();
+ g_byte_array_append(fullArray, (guint8 *)(&bin_data[0]), 256);
+ if (t_test_thrift_test_if_test_binary (test_client,
+ &result,
+ fullArray,
+ &error)) {
+ GBytes *response = g_byte_array_free_to_bytes(result); // frees result
+ result = NULL;
+ gsize siz = g_bytes_get_size(response);
+ gconstpointer ptr = g_bytes_get_data(response, &siz);
+ if (siz == 256) {
+ gboolean first = 1;
+ gboolean failed = 0;
+ int i;
+
+ for (i = 0; i < 256; ++i) {
+ if (!first)
+ printf(",");
+ else
+ first = 0;
+ int val = ((signed char *)ptr)[i];
+ printf("%d", val);
+ if (!failed && val != i - 128) {
+ failed = 1;
+ }
+ }
+ printf("} ");
+ if (failed) {
+ printf("FAIL (bad content) size %ld OK\n", (long)siz);
+ ++fail_count;
+ } else {
+ printf("OK size %ld OK\n", (long)siz);
+ }
+ } else {
+ printf(" = bad size %ld\n", (long)siz);
+ ++fail_count;
+ }
+ g_bytes_unref(response);
+ } else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+ g_byte_array_unref(fullArray);
+ fullArray = NULL;
+
+ /**
+ * STRUCT TEST
+ */
+ printf ("testStruct({\"Zero\", 1, -3, -5})");
+ xtruct_out = g_object_new (T_TEST_TYPE_XTRUCT,
+ "string_thing", "Zero",
+ "byte_thing", 1,
+ "i32_thing", -3,
+ "i64_thing", -5LL,
+ NULL);
+ xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
+
+ if (t_test_thrift_test_if_test_struct (test_client,
+ &xtruct_in,
+ xtruct_out,
+ &error)) {
+ g_object_get (xtruct_in,
+ "string_thing", &string,
+ "byte_thing", &byte_thing,
+ "i32_thing", &i32_thing,
+ "i64_thing", &i64_thing,
+ NULL);
+
+ printf (" = {\"%s\", %d, %d, %" PRId64 "}\n",
+ string,
+ byte_thing,
+ i32_thing,
+ i64_thing);
+ if ((string == NULL || strncmp (string, "Zero", 5) != 0) ||
+ byte_thing != 1 ||
+ i32_thing != -3 ||
+ i64_thing != (gint64)-5)
+ fail_count++;
+
+ if (string) {
+ g_free (string);
+ string = NULL;
+ }
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+ // g_clear_object(&xtruct_out); used below
+ g_clear_object(&xtruct_in);
+
+ /**
+ * NESTED STRUCT TEST
+ */
+ printf ("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
+ xtruct2_out = g_object_new (T_TEST_TYPE_XTRUCT2,
+ "byte_thing", 1,
+ "struct_thing", xtruct_out,
+ "i32_thing", 5,
+ NULL);
+ xtruct2_in = g_object_new (T_TEST_TYPE_XTRUCT2, NULL);
+
+ if (t_test_thrift_test_if_test_nest (test_client,
+ &xtruct2_in,
+ xtruct2_out,
+ &error)) {
+ g_object_get (xtruct2_in,
+ "byte_thing", &byte_thing,
+ "struct_thing", &xtruct_in,
+ "i32_thing", &i32_thing,
+ NULL);
+ g_object_get (xtruct_in,
+ "string_thing", &string,
+ "byte_thing", &inner_byte_thing,
+ "i32_thing", &inner_i32_thing,
+ "i64_thing", &inner_i64_thing,
+ NULL);
+
+ printf (" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
+ byte_thing,
+ string,
+ inner_byte_thing,
+ inner_i32_thing,
+ inner_i64_thing,
+ i32_thing);
+ if (byte_thing != 1 ||
+ (string == NULL || strncmp (string, "Zero", 5) != 0) ||
+ inner_byte_thing != 1 ||
+ inner_i32_thing != -3 ||
+ inner_i64_thing != (gint64)-5 ||
+ i32_thing != 5)
+ fail_count++;
+
+ if (string) {
+ g_free(string);
+ string = NULL;
+ }
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ g_clear_object(&xtruct_in);
+ g_clear_object(&xtruct2_in);
+ g_clear_object(&xtruct2_out);
+ g_clear_object(&xtruct_out);
+
+ /**
+ * MAP TEST
+ */
+ map_out = g_hash_table_new_full (g_int_hash,
+ g_int_equal,
+ g_free,
+ g_free);
+ for (i = 0; i < 5; ++i) {
+ i32_key_ptr = g_malloc (sizeof *i32_key_ptr);
+ i32_value_ptr = g_malloc (sizeof *i32_value_ptr);
+
+ *i32_key_ptr = i;
+ *i32_value_ptr = i - 10;
+
+ g_hash_table_insert (map_out, i32_key_ptr, i32_value_ptr);
+ }
+ printf ("testMap({");
+ first = TRUE;
+ g_hash_table_iter_init (&hash_table_iter, map_out);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("%d => %d", *(gint32 *)key, *(gint32 *)value);
+ }
+ printf ("})");
+
+ map_in = g_hash_table_new_full (g_int_hash,
+ g_int_equal,
+ g_free,
+ g_free);
+
+ if (t_test_thrift_test_if_test_map (test_client,
+ &map_in,
+ map_out,
+ &error)) {
+ printf (" = {");
+ first = TRUE;
+ g_hash_table_iter_init (&hash_table_iter, map_in);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("%d => %d", *(gint32 *)key, *(gint32 *)value);
+ }
+ printf ("}\n");
+
+ if (g_hash_table_size (map_in) != g_hash_table_size (map_out))
+ fail_count++;
+ else {
+ g_hash_table_iter_init (&hash_table_iter, map_out);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ gpointer in_value = g_hash_table_lookup (map_in, key);
+ if (in_value == NULL ||
+ *(gint32 *)in_value != *(gint32 *)value) {
+ fail_count++;
+ break;
+ }
+ }
+ }
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ g_hash_table_unref (map_in);
+ g_hash_table_unref (map_out);
+
+ /**
+ * STRING MAP TEST
+ */
+ map_out = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ NULL,
+ NULL);
+ g_hash_table_insert (map_out, "a", "2");
+ g_hash_table_insert (map_out, "b", "blah");
+ g_hash_table_insert (map_out, "some", "thing");
+ printf ("testStringMap({");
+ first = TRUE;
+ g_hash_table_iter_init (&hash_table_iter, map_out);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("\"%s\" => \"%s\"", (gchar *)key, (gchar *)value);
+ }
+ printf (")}");
+
+ map_in = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_free);
+
+ if (t_test_thrift_test_if_test_string_map (test_client,
+ &map_in,
+ map_out,
+ &error)) {
+ printf (" = {");
+ first = TRUE;
+ g_hash_table_iter_init (&hash_table_iter, map_in);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("\"%s\" => \"%s\"", (gchar *)key, (gchar *)value);
+ }
+ printf ("}\n");
+
+ if (g_hash_table_size (map_in) != g_hash_table_size (map_out))
+ fail_count++;
+ else {
+ g_hash_table_iter_init (&hash_table_iter, map_out);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ gpointer in_value = g_hash_table_lookup (map_in, key);
+ if (in_value == NULL ||
+ strcmp ((gchar *)in_value, (gchar *)value) != 0) {
+ fail_count++;
+ break;
+ }
+ }
+ }
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ g_hash_table_unref (map_in);
+ g_hash_table_unref (map_out);
+
+ /**
+ * SET TEST
+ */
+ set_out = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
+ for (i = -2; i < 3; ++i) {
+ i32_key_ptr = g_malloc (sizeof *i32_key_ptr);
+ *i32_key_ptr = i;
+
+ g_hash_table_insert (set_out, i32_key_ptr, NULL);
+ }
+ printf ("testSet({");
+ first = TRUE;
+ keys_out = g_hash_table_get_keys (set_out);
+ keys_elem = keys_out;
+ while (keys_elem != NULL) {
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("%d", *(gint32 *)keys_elem->data);
+
+ keys_elem = keys_elem->next;
+ }
+ printf ("})");
+
+ set_in = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
+
+ if (t_test_thrift_test_if_test_set (test_client,
+ &set_in,
+ set_out,
+ &error)) {
+ printf(" = {");
+ first = TRUE;
+ keys_in = g_hash_table_get_keys (set_in);
+ keys_elem = keys_in;
+ while (keys_elem != NULL) {
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("%d", *(gint32 *)keys_elem->data);
+
+ keys_elem = keys_elem->next;
+ }
+ printf ("}\n");
+
+ if (g_list_length (keys_in) != g_list_length (keys_out))
+ fail_count++;
+ else {
+ keys_elem = keys_out;
+ while (keys_elem != NULL) {
+ if (g_list_find_custom (keys_in,
+ keys_elem->data,
+ gint32_compare) == NULL) {
+ fail_count++;
+ break;
+ }
+
+ keys_elem = keys_elem->next;
+ }
+ }
+
+ g_list_free (keys_in);
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ g_hash_table_unref (set_in);
+ g_list_free (keys_out);
+ g_hash_table_unref (set_out);
+
+ /**
+ * LIST TEST
+ */
+ list_out = g_array_new (FALSE, TRUE, sizeof (gint32));
+ for (i = -2; i < 3; ++i) {
+ g_array_append_val (list_out, i);
+ }
+ printf ("testList({");
+ first = TRUE;
+ for (i = 0; i < (gint32)list_out->len; ++i) {
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("%d", g_array_index (list_out, gint32, i));
+ }
+ printf ("})");
+
+ list_in = g_array_new (FALSE, TRUE, sizeof (gint32));
+
+ if (t_test_thrift_test_if_test_list (test_client,
+ &list_in,
+ list_out,
+ &error)) {
+ printf (" = {");
+ first = TRUE;
+ for (i = 0; i < (gint32)list_in->len; ++i) {
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("%d", g_array_index (list_in, gint32, i));
+ }
+ printf ("}\n");
+
+ if (list_in->len != list_out->len ||
+ memcmp (list_in->data,
+ list_out->data,
+ list_in->len * sizeof (gint32)) != 0)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ g_array_unref (list_in);
+ g_array_unref (list_out);
+
+ /**
+ * ENUM TEST
+ */
+ printf("testEnum(ONE)");
+ if (t_test_thrift_test_if_test_enum (test_client,
+ &numberz,
+ T_TEST_NUMBERZ_ONE,
+ &error)) {
+ printf(" = %d\n", numberz);
+ if (numberz != T_TEST_NUMBERZ_ONE)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ printf("testEnum(TWO)");
+ if (t_test_thrift_test_if_test_enum (test_client,
+ &numberz,
+ T_TEST_NUMBERZ_TWO,
+ &error)) {
+ printf(" = %d\n", numberz);
+ if (numberz != T_TEST_NUMBERZ_TWO)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ printf("testEnum(THREE)");
+ if (t_test_thrift_test_if_test_enum (test_client,
+ &numberz,
+ T_TEST_NUMBERZ_THREE,
+ &error)) {
+ printf(" = %d\n", numberz);
+ if (numberz != T_TEST_NUMBERZ_THREE)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ printf("testEnum(FIVE)");
+ if (t_test_thrift_test_if_test_enum (test_client,
+ &numberz,
+ T_TEST_NUMBERZ_FIVE,
+ &error)) {
+ printf(" = %d\n", numberz);
+ if (numberz != T_TEST_NUMBERZ_FIVE)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ printf("testEnum(EIGHT)");
+ if (t_test_thrift_test_if_test_enum (test_client,
+ &numberz,
+ T_TEST_NUMBERZ_EIGHT,
+ &error)) {
+ printf(" = %d\n", numberz);
+ if (numberz != T_TEST_NUMBERZ_EIGHT)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ /**
+ * TYPEDEF TEST
+ */
+ printf ("testTypedef(309858235082523)");
+ if (t_test_thrift_test_if_test_typedef (test_client,
+ &user_id,
+ 309858235082523LL,
+ &error)) {
+ printf(" = %" PRId64 "\n", user_id);
+ if (user_id != 309858235082523LL)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ /**
+ * NESTED MAP TEST
+ */
+ printf ("testMapMap(1)");
+ map_in = g_hash_table_new_full (g_int_hash,
+ g_int_equal,
+ g_free,
+ (GDestroyNotify)g_hash_table_unref);
+ if (t_test_thrift_test_if_test_map_map (test_client,
+ &map_in,
+ 1,
+ &error)) {
+ g_hash_table_iter_init (&hash_table_iter, map_in);
+
+ printf (" = {");
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ printf ("%d => {", *(gint32 *)key);
+
+ g_hash_table_iter_init (&inner_hash_table_iter,
+ (GHashTable *)value);
+ while (g_hash_table_iter_next (&inner_hash_table_iter,
+ &key,
+ &value)) {
+ printf ("%d => %d, ", *(gint32 *)key, *(gint32 *)value);
+ }
+
+ printf ("}, ");
+ }
+ printf ("}\n");
+
+ if (g_hash_table_size (map_in) != 2)
+ fail_count++;
+ else {
+ gint32 inner_keys[] = {1, 2, 3, 4};
+ gint32 i32_key;
+
+ i32_key = -4;
+ inner_map_in = g_hash_table_lookup (map_in, &i32_key);
+ if (inner_map_in == NULL ||
+ g_hash_table_size (inner_map_in) != 4)
+ fail_count++;
+ else {
+ keys_in = g_hash_table_get_keys (inner_map_in);
+ keys_in = g_list_sort (keys_in, gint32_compare);
+
+ for (i = 0; i < 4; i++) {
+ keys_elem = g_list_nth (keys_in, 3 - i);
+
+ if (*(gint32 *)keys_elem->data != (-1 * inner_keys[i]) ||
+ *(gint32 *)g_hash_table_lookup (inner_map_in,
+ keys_elem->data) !=
+ (-1 * inner_keys[i])) {
+ fail_count++;
+ break;
+ }
+ }
+
+ g_list_free (keys_in);
+ }
+
+ i32_key = 4;
+ inner_map_in = g_hash_table_lookup (map_in, &i32_key);
+ if (inner_map_in == NULL ||
+ g_hash_table_size (inner_map_in) != 4)
+ fail_count++;
+ else {
+ keys_in = g_hash_table_get_keys (inner_map_in);
+ keys_in = g_list_sort (keys_in, gint32_compare);
+
+ for (i = 0; i < 4; i++) {
+ keys_elem = g_list_nth (keys_in, i);
+
+ if (*(gint32 *)keys_elem->data != inner_keys[i] ||
+ *(gint32 *)g_hash_table_lookup (inner_map_in,
+ keys_elem->data) !=
+ inner_keys[i]) {
+ fail_count++;
+ break;
+ }
+ }
+
+ g_list_free (keys_in);
+ }
+ }
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ g_hash_table_unref (map_in);
+
+ /**
+ * INSANITY TEST
+ */
+ insanity_out = g_object_new (T_TEST_TYPE_INSANITY, NULL);
+ g_object_get (insanity_out,
+ "userMap", &user_map,
+ "xtructs", &xtructs,
+ NULL);
+
+ numberz = T_TEST_NUMBERZ_FIVE;
+ numberz2 = T_TEST_NUMBERZ_EIGHT;
+ user_id_ptr = g_malloc (sizeof *user_id_ptr);
+ *user_id_ptr = 5;
+ user_id_ptr2 = g_malloc (sizeof *user_id_ptr);
+ *user_id_ptr2 = 8;
+ g_hash_table_insert (user_map, (gpointer)numberz, user_id_ptr);
+ g_hash_table_insert (user_map, (gpointer)numberz2, user_id_ptr2);
+ g_hash_table_unref (user_map);
+
+ xtruct_out = g_object_new (T_TEST_TYPE_XTRUCT,
+ "string_thing", "Hello2",
+ "byte_thing", 2,
+ "i32_thing", 2,
+ "i64_thing", 2LL,
+ NULL);
+ xtruct_out2 = g_object_new (T_TEST_TYPE_XTRUCT,
+ "string_thing", "Goodbye4",
+ "byte_thing", 4,
+ "i32_thing", 4,
+ "i64_thing", 4LL,
+ NULL);
+ g_ptr_array_add (xtructs, xtruct_out2);
+ g_ptr_array_add (xtructs, xtruct_out);
+ g_ptr_array_unref (xtructs);
+
+ map_in = g_hash_table_new_full (g_int64_hash,
+ g_int64_equal,
+ g_free,
+ (GDestroyNotify)g_hash_table_unref);
+
+ printf("testInsanity()");
+ if (t_test_thrift_test_if_test_insanity (test_client,
+ &map_in,
+ insanity_out,
+ &error)) {
+ printf (" = {");
+ g_hash_table_iter_init (&hash_table_iter, map_in);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ printf ("%" PRId64 " => {", *(TTestUserId *)key);
+
+ g_hash_table_iter_init (&inner_hash_table_iter,
+ (GHashTable *)value);
+ while (g_hash_table_iter_next (&inner_hash_table_iter,
+ &key,
+ &value)) {
+ printf ("%d => {", (TTestNumberz)key);
+
+ g_object_get ((TTestInsanity *)value,
+ "userMap", &user_map,
+ "xtructs", &xtructs,
+ NULL);
+
+ printf ("{");
+ g_hash_table_iter_init (&user_map_iter, user_map);
+ while (g_hash_table_iter_next (&user_map_iter,
+ &key,
+ &value)) {
+ printf ("%d => %" PRId64 ", ",
+ (TTestNumberz)key,
+ *(TTestUserId *)value);
+ }
+ printf ("}, ");
+ g_hash_table_unref (user_map);
+
+ printf("{");
+ for (i = 0; i < (gint32)xtructs->len; ++i) {
+ xtruct_in = g_ptr_array_index (xtructs, i);
+ g_object_get (xtruct_in,
+ "string_thing", &string,
+ "byte_thing", &byte_thing,
+ "i32_thing", &i32_thing,
+ "i64_thing", &i64_thing,
+ NULL);
+
+ printf ("{\"%s\", %d, %d, %" PRId64 "}, ",
+ string,
+ byte_thing,
+ i32_thing,
+ i64_thing);
+ }
+ printf ("}");
+ g_ptr_array_unref (xtructs);
+
+ printf ("}, ");
+ }
+ printf("}, ");
+ }
+ printf("}\n");
+
+ if (g_hash_table_size (map_in) != 2)
+ fail_count++;
+ else {
+ TTestNumberz numberz_key_values[] = {
+ T_TEST_NUMBERZ_TWO, T_TEST_NUMBERZ_THREE
+ };
+ gint user_map_values[] = { 5, 8 };
+ TTestUserId user_id_key;
+
+ user_id_key = 1;
+ inner_map_in = g_hash_table_lookup (map_in, &user_id_key);
+ if (inner_map_in == NULL ||
+ g_hash_table_size (inner_map_in) != 2)
+ fail_count++;
+ else {
+ TTestNumberz numberz_key;
+
+ for (i = 0; i < 2; ++i) {
+ numberz_key = numberz_key_values[i];
+ insanity_in =
+ g_hash_table_lookup (inner_map_in,
+ (gconstpointer)numberz_key);
+ if (insanity_in == NULL)
+ fail_count++;
+ else {
+ g_object_get (insanity_in,
+ "userMap", &user_map,
+ "xtructs", &xtructs,
+ NULL);
+
+ if (user_map == NULL)
+ fail_count++;
+ else {
+ if (g_hash_table_size (user_map) != 2)
+ fail_count++;
+ else {
+ for (j = 0; j < 2; ++j) {
+ numberz_key = (TTestNumberz)user_map_values[j];
+
+ value =
+ g_hash_table_lookup (user_map,
+ (gconstpointer)numberz_key);
+ if (value == NULL ||
+ *(TTestUserId *)value != (TTestUserId)user_map_values[j])
+ fail_count++;
+ }
+ }
+
+ g_hash_table_unref (user_map);
+ }
+
+ if (xtructs == NULL)
+ fail_count++;
+ else {
+ if (xtructs->len != 2)
+ fail_count++;
+ else {
+ xtruct_in = g_ptr_array_index (xtructs, 0);
+ g_object_get (xtruct_in,
+ "string_thing", &string,
+ "byte_thing", &byte_thing,
+ "i32_thing", &i32_thing,
+ "i64_thing", &i64_thing,
+ NULL);
+ if ((string == NULL ||
+ strncmp (string, "Goodbye4", 9) != 0) ||
+ byte_thing != 4 ||
+ i32_thing != 4 ||
+ i64_thing != 4)
+ fail_count++;
+
+ if (string != NULL)
+ g_free (string);
+
+ xtruct_in = g_ptr_array_index (xtructs, 1);
+ g_object_get (xtruct_in,
+ "string_thing", &string,
+ "byte_thing", &byte_thing,
+ "i32_thing", &i32_thing,
+ "i64_thing", &i64_thing,
+ NULL);
+ if ((string == NULL ||
+ strncmp (string, "Hello2", 7) != 0) ||
+ byte_thing != 2 ||
+ i32_thing != 2 ||
+ i64_thing != 2)
+ fail_count++;
+
+ if (string != NULL)
+ g_free (string);
+ }
+
+ g_ptr_array_unref (xtructs);
+ }
+ }
+ }
+ }
+
+ user_id_key = 2;
+ inner_map_in = g_hash_table_lookup (map_in, &user_id_key);
+ if (inner_map_in == NULL ||
+ g_hash_table_size (inner_map_in) != 1)
+ fail_count++;
+ else {
+ insanity_in =
+ g_hash_table_lookup (inner_map_in,
+ (gconstpointer)T_TEST_NUMBERZ_SIX);
+ if (insanity_in == NULL)
+ fail_count++;
+ else {
+ g_object_get (insanity_in,
+ "userMap", &user_map,
+ "xtructs", &xtructs,
+ NULL);
+
+ if (user_map == NULL)
+ fail_count++;
+ else {
+ if (g_hash_table_size (user_map) != 0)
+ fail_count++;
+
+ g_hash_table_unref (user_map);
+ }
+
+ if (xtructs == NULL)
+ fail_count++;
+ else {
+ if (xtructs->len != 0)
+ fail_count++;
+
+ g_ptr_array_unref (xtructs);
+ }
+ }
+ }
+ }
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ g_hash_table_unref (map_in);
+ g_clear_object (&insanity_out);
+
+ /* test exception */
+ printf ("testClient.testException(\"Xception\") =>");
+ if (!t_test_thrift_test_if_test_exception (test_client,
+ "Xception",
+ &xception,
+ &error) &&
+ xception != NULL) {
+ g_object_get (xception,
+ "errorCode", &int32,
+ "message", &string,
+ NULL);
+ printf (" {%u, \"%s\"}\n", int32, string);
+ g_free (string);
+
+ g_clear_object (&xception);
+
+ g_error_free (error);
+ error = NULL;
+ }
+ else {
+ printf (" void\nFAILURE\n");
+ fail_count++;
+
+ if (xception != NULL) {
+ g_object_unref (xception);
+ xception = NULL;
+ }
+
+ if (error != NULL) {
+ g_error_free (error);
+ error = NULL;
+ }
+ }
+
+ printf ("testClient.testException(\"TException\") =>");
+ if (!t_test_thrift_test_if_test_exception (test_client,
+ "TException",
+ &xception,
+ &error) &&
+ xception == NULL &&
+ error != NULL) {
+ printf (" Caught TException\n");
+
+ g_error_free (error);
+ error = NULL;
+ }
+ else {
+ printf (" void\nFAILURE\n");
+ fail_count++;
+
+ g_clear_object (&xception);
+
+ if (error != NULL) {
+ g_error_free (error);
+ error = NULL;
+ }
+ }
+
+ printf ("testClient.testException(\"success\") =>");
+ if (t_test_thrift_test_if_test_exception (test_client,
+ "success",
+ &xception,
+ &error))
+ printf (" void\n");
+ else {
+ printf (" void\nFAILURE\n");
+ fail_count++;
+
+ g_clear_object (&xception);
+
+ g_error_free (error);
+ error = NULL;
+ }
+
+ g_assert (error == NULL);
+
+ /* test multi exception */
+ printf ("testClient.testMultiException(\"Xception\", \"test 1\") =>");
+ xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
+ if (!t_test_thrift_test_if_test_multi_exception (test_client,
+ &xtruct_in,
+ "Xception",
+ "test 1",
+ &xception,
+ &xception2,
+ &error) &&
+ xception != NULL &&
+ xception2 == NULL) {
+ g_object_get (xception,
+ "errorCode", &int32,
+ "message", &string,
+ NULL);
+ printf (" {%u, \"%s\"}\n", int32, string);
+ g_free (string);
+
+ g_object_unref (xception);
+ xception = NULL;
+
+ g_error_free (error);
+ error = NULL;
+ }
+ else {
+ printf (" result\nFAILURE\n");
+ fail_count++;
+
+ g_clear_object (&xception);
+ g_clear_object (&xception2);
+
+ if (error != NULL) {
+ g_error_free (error);
+ error = NULL;
+ }
+ }
+ g_object_unref (xtruct_in);
+
+ printf ("testClient.testMultiException(\"Xception2\", \"test 2\") =>");
+ xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
+ if (!t_test_thrift_test_if_test_multi_exception (test_client,
+ &xtruct_in,
+ "Xception2",
+ "test 2",
+ &xception,
+ &xception2,
+ &error) &&
+ xception == NULL &&
+ xception2 != NULL) {
+ g_object_get (xception2,
+ "errorCode", &int32,
+ "struct_thing", &inner_xtruct_in,
+ NULL);
+ g_object_get (inner_xtruct_in,
+ "string_thing", &string,
+ NULL);
+ printf (" {%u, {\"%s\"}}\n", int32, string);
+ g_free (string);
+
+ g_clear_object (&inner_xtruct_in);
+ g_clear_object (&xception2);
+
+ g_error_free (error);
+ error = NULL;
+ }
+ else {
+ printf (" result\nFAILURE\n");
+ fail_count++;
+
+ g_clear_object (&xception);
+ g_clear_object (&xception2);
+
+ if (error != NULL) {
+ g_error_free (error);
+ error = NULL;
+ }
+ }
+ g_clear_object (&xtruct_in);
+
+ printf ("testClient.testMultiException(\"success\", \"test 3\") =>");
+ xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
+ if (t_test_thrift_test_if_test_multi_exception (test_client,
+ &xtruct_in,
+ "success",
+ "test 3",
+ &xception,
+ &xception2,
+ &error) &&
+ xception == NULL &&
+ xception2 == NULL) {
+ g_object_get (xtruct_in,
+ "string_thing", &string,
+ NULL);
+ printf (" {{\"%s\"}}\n", string);
+ g_free (string);
+ }
+ else {
+ printf (" result\nFAILURE\n");
+ fail_count++;
+
+ g_clear_object (&xception);
+ g_clear_object (&xception2);
+
+ if (error != NULL) {
+ g_error_free (error);
+ error = NULL;
+ }
+ }
+ g_clear_object (&xtruct_in);
+
+ /* test oneway void */
+ printf ("testClient.testOneway(1) =>");
+ gettimeofday (&oneway_start, NULL);
+ oneway_result = t_test_thrift_test_if_test_oneway (test_client,
+ 1,
+ &error);
+ gettimeofday (&oneway_end, NULL);
+ timersub (&oneway_end, &oneway_start, &oneway_elapsed);
+ oneway_elapsed_usec =
+ oneway_elapsed.tv_sec * 1000 * 1000 + oneway_elapsed.tv_usec;
+
+ if (oneway_result) {
+ if (oneway_elapsed_usec > 200 * 1000) {
+ printf (" FAILURE - took %.2f ms\n",
+ (double)oneway_elapsed_usec / 1000.0);
+ fail_count++;
+ }
+ else
+ printf (" success - took %.2f ms\n",
+ (double)oneway_elapsed_usec / 1000.0);
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ /**
+ * redo a simple test after the oneway to make sure we aren't "off by
+ * one" -- if the server treated oneway void like normal void, this next
+ * test will fail since it will get the void confirmation rather than
+ * the correct result. In this circumstance, the client will receive the
+ * error:
+ *
+ * application error: Wrong method name
+ */
+ /**
+ * I32 TEST
+ */
+ printf ("re-test testI32(-1)");
+ if (t_test_thrift_test_if_test_i32 (test_client,
+ &int32,
+ -1,
+ &error)) {
+ printf (" = %d\n", int32);
+ if (int32 != -1)
+ fail_count++;
+ }
+ else {
+ printf ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ fail_count++;
+ }
+
+ gettimeofday (&time_stop, NULL);
+ timersub (&time_stop, &time_start, &time_elapsed);
+ time_elapsed_usec =
+ time_elapsed.tv_sec * 1000 * 1000 + time_elapsed.tv_usec;
+
+ printf("Total time: %" PRIu64 " us\n", time_elapsed_usec);
+
+ time_total_usec += time_elapsed_usec;
+ if (time_elapsed_usec < time_min_usec)
+ time_min_usec = time_elapsed_usec;
+ if (time_elapsed_usec > time_max_usec)
+ time_max_usec = time_elapsed_usec;
+
+ thrift_transport_close (transport, &error);
+ }
+ else {
+ printf ("Connect failed: %s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+
+ return 1;
+ }
+ }
+
+ /* All done---output statistics */
+ puts ("\nAll tests done.");
+ printf("Number of failures: %d\n", fail_count);
+
+ time_avg_usec = time_total_usec / num_tests;
+
+ printf ("Min time: %" PRIu64 " us\n", time_min_usec);
+ printf ("Max time: %" PRIu64 " us\n", time_max_usec);
+ printf ("Avg time: %" PRIu64 " us\n", time_avg_usec);
+
+ g_clear_object(&second_service);
+ g_clear_object(&protocol2);
+ g_clear_object(&test_client);
+ g_clear_object(&protocol);
+ g_clear_object(&transport);
+ g_clear_object(&socket);
+
+ if (ssl) {
+ thrift_ssl_socket_finalize_openssl();
+ }
+
+ return fail_count;
+}
diff --git a/src/jaegertracing/thrift/test/c_glib/src/test_server.c b/src/jaegertracing/thrift/test/c_glib/src/test_server.c
new file mode 100644
index 000000000..0819b8ca5
--- /dev/null
+++ b/src/jaegertracing/thrift/test/c_glib/src/test_server.c
@@ -0,0 +1,307 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <glib-object.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <thrift/c_glib/thrift.h>
+#include <thrift/c_glib/processor/thrift_multiplexed_processor.h>
+#include <thrift/c_glib/protocol/thrift_binary_protocol_factory.h>
+#include <thrift/c_glib/protocol/thrift_compact_protocol_factory.h>
+#include <thrift/c_glib/server/thrift_server.h>
+#include <thrift/c_glib/server/thrift_simple_server.h>
+#include <thrift/c_glib/transport/thrift_buffered_transport.h>
+#include <thrift/c_glib/transport/thrift_buffered_transport_factory.h>
+#include <thrift/c_glib/transport/thrift_framed_transport.h>
+#include <thrift/c_glib/transport/thrift_framed_transport_factory.h>
+#include <thrift/c_glib/transport/thrift_server_socket.h>
+#include <thrift/c_glib/transport/thrift_server_transport.h>
+#include <thrift/c_glib/transport/thrift_transport.h>
+#include <thrift/c_glib/transport/thrift_transport_factory.h>
+
+#include "../gen-c_glib/t_test_thrift_test.h"
+#include "../gen-c_glib/t_test_second_service.h"
+
+#include "thrift_test_handler.h"
+#include "thrift_second_service_handler.h"
+
+/* Our server object, declared globally so it is accessible within the SIGINT
+ signal handler */
+ThriftServer *server = NULL;
+
+/* A flag that indicates whether the server was interrupted with SIGINT
+ (i.e. Ctrl-C) so we can tell whether its termination was abnormal */
+gboolean sigint_received = FALSE;
+
+/* Handle SIGINT ("Ctrl-C") signals by gracefully stopping the server */
+static void
+sigint_handler (int signal_number)
+{
+ THRIFT_UNUSED_VAR (signal_number);
+
+ /* Take note we were called */
+ sigint_received = TRUE;
+
+ /* Shut down the server gracefully */
+ if (server != NULL)
+ thrift_server_stop (server);
+}
+
+int
+main (int argc, char **argv)
+{
+ static gint port = 9090;
+ static gchar *path_option = NULL;
+ static gchar *server_type_option = NULL;
+ static gchar *transport_option = NULL;
+ static gchar *protocol_option = NULL;
+ static gint string_limit = 0;
+ static gint container_limit = 0;
+
+ static
+ GOptionEntry option_entries[] = {
+ { "port", 0, 0, G_OPTION_ARG_INT, &port,
+ "Port number to connect (=9090)", NULL },
+ { "domain-socket", 0, 0, G_OPTION_ARG_STRING, &path_option,
+ "Unix socket domain path to connect", NULL },
+ { "server-type", 0, 0, G_OPTION_ARG_STRING, &server_type_option,
+ "Type of server: simple (=simple)", NULL },
+ { "transport", 0, 0, G_OPTION_ARG_STRING, &transport_option,
+ "Transport: buffered, framed (=buffered)", NULL },
+ { "protocol", 0, 0, G_OPTION_ARG_STRING, &protocol_option,
+ "Protocol: binary, compact (=binary)", NULL },
+ { "string-limit", 0, 0, G_OPTION_ARG_INT, &string_limit,
+ "Max string length (=none)", NULL },
+ { "container-limit", 0, 0, G_OPTION_ARG_INT, &container_limit,
+ "Max container length (=none)", NULL },
+ { NULL }
+ };
+
+ gchar *server_name = "simple";
+ gchar *transport_name = "buffered";
+ GType transport_factory_type = THRIFT_TYPE_BUFFERED_TRANSPORT_FACTORY;
+ gchar *protocol_name = "binary";
+ GType protocol_factory_type = THRIFT_TYPE_BINARY_PROTOCOL_FACTORY;
+
+ TTestThriftTestHandler *handler;
+ TTestThriftTestHandler *handler_second_service = NULL;
+ ThriftProcessor *processor;
+ ThriftProcessor *processor_test = NULL;
+ ThriftProcessor *processor_second_service = NULL;
+ ThriftServerTransport *server_transport;
+ ThriftTransportFactory *transport_factory;
+ ThriftProtocolFactory *protocol_factory;
+
+ struct sigaction sigint_action;
+
+ GOptionContext *option_context;
+ gboolean options_valid = TRUE;
+
+ GError *error = NULL;
+
+#if (!GLIB_CHECK_VERSION (2, 36, 0))
+ g_type_init ();
+#endif
+
+ /* Configure and parse our command-line options */
+ option_context = g_option_context_new (NULL);
+ g_option_context_add_main_entries (option_context,
+ option_entries,
+ NULL);
+ if (g_option_context_parse (option_context,
+ &argc,
+ &argv,
+ &error) == FALSE) {
+ fprintf (stderr, "%s\n", error->message);
+ return 255;
+ }
+ g_option_context_free (option_context);
+
+ /* Validate the parsed options */
+ if (server_type_option != NULL &&
+ strncmp (server_type_option, "simple", 7) != 0) {
+ fprintf (stderr, "Unknown server type %s\n", protocol_option);
+ options_valid = FALSE;
+ }
+
+ if (protocol_option != NULL) {
+ if (strncmp (protocol_option, "compact", 8) == 0) {
+ protocol_factory_type = THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY;
+ protocol_name = "compact";
+ }
+ else if (strncmp (protocol_option, "multi", 6) == 0) {
+ protocol_name = "binary:multi";
+ }
+ else if (strncmp (protocol_option, "multic", 7) == 0) {
+ protocol_factory_type = THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY;
+ protocol_name = "compact:multic";
+ }
+ else if (strncmp (protocol_option, "binary", 7) != 0) {
+ fprintf (stderr, "Unknown protocol type %s\n", protocol_option);
+ options_valid = FALSE;
+ }
+ }
+
+ if (transport_option != NULL) {
+ if (strncmp (transport_option, "framed", 7) == 0) {
+ transport_factory_type = THRIFT_TYPE_FRAMED_TRANSPORT_FACTORY;
+ transport_name = "framed";
+ }
+ else if (strncmp (transport_option, "buffered", 9) != 0) {
+ fprintf (stderr, "Unknown transport type %s\n", transport_option);
+ options_valid = FALSE;
+ }
+ }
+
+ if (!options_valid)
+ return 254;
+
+ /* Establish all our connection objects */
+ handler = g_object_new (TYPE_THRIFT_TEST_HANDLER,
+ NULL);
+
+
+
+ if(strstr(protocol_name, ":multi")){
+ /* When a multiplexed processor is involved the handler is not
+ registered as usual. We create the processor and the real
+ processor is registered. Multiple processors can be registered
+ at once. This is why we don't have a constructor property */
+ processor = g_object_new (THRIFT_TYPE_MULTIPLEXED_PROCESSOR,
+ NULL);
+
+ handler_second_service = g_object_new (TYPE_SECOND_SERVICE_HANDLER,
+ NULL);
+
+ processor_test = g_object_new (T_TEST_TYPE_THRIFT_TEST_PROCESSOR,
+ "handler", handler,
+ NULL);
+ processor_second_service = g_object_new (T_TEST_TYPE_SECOND_SERVICE_PROCESSOR,
+ "handler", handler_second_service,
+ NULL);
+
+ /* We register a test processor with Multiplexed name ThriftTest */
+ if(!thrift_multiplexed_processor_register_processor(processor,
+ "ThriftTest", processor_test,
+ &error)){
+ g_message ("thrift_server_serve: %s",
+ error != NULL ? error->message : "(null)");
+ g_clear_error (&error);
+ }
+ /* We register a second test processor with Multiplexed name SecondService
+ * we are responsible of freeing the processor when it's not used anymore */
+ if(!thrift_multiplexed_processor_register_processor(processor,
+ "SecondService", processor_second_service,
+ &error)){
+ g_message ("thrift_server_serve: %s",
+ error != NULL ? error->message : "(null)");
+ g_clear_error (&error);
+ }
+
+ }else{
+ processor = g_object_new (T_TEST_TYPE_THRIFT_TEST_PROCESSOR,
+ "handler", handler,
+ NULL);
+ }
+ if (path_option) {
+ server_transport = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
+ "path", path_option,
+ NULL);
+ } else {
+ server_transport = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
+ "port", port,
+ NULL);
+ }
+ transport_factory = g_object_new (transport_factory_type,
+ NULL);
+
+ if (strstr (protocol_name, "compact") != NULL) {
+ protocol_factory = g_object_new (protocol_factory_type,
+ "string_limit", string_limit,
+ "container_limit", container_limit,
+ NULL);
+ } else {
+ protocol_factory = g_object_new (protocol_factory_type,
+ NULL);
+ }
+
+ server = g_object_new (THRIFT_TYPE_SIMPLE_SERVER,
+ "processor", processor,
+ "server_transport", server_transport,
+ "input_transport_factory", transport_factory,
+ "output_transport_factory", transport_factory,
+ "input_protocol_factory", protocol_factory,
+ "output_protocol_factory", protocol_factory,
+ NULL);
+
+ /* Install our SIGINT handler, which handles Ctrl-C being pressed by stopping
+ the server gracefully */
+ memset (&sigint_action, 0, sizeof (sigint_action));
+ sigint_action.sa_handler = sigint_handler;
+ sigint_action.sa_flags = SA_RESETHAND;
+ sigaction (SIGINT, &sigint_action, NULL);
+
+ if (path_option) {
+ printf ("Starting \"%s\" server (%s/%s) listen on: %s\n",
+ server_name,
+ transport_name,
+ protocol_name,
+ path_option);
+ } else {
+ printf ("Starting \"%s\" server (%s/%s) listen on: %d\n",
+ server_name,
+ transport_name,
+ protocol_name,
+ port);
+ }
+ fflush (stdout);
+
+ /* Serve clients until SIGINT is received (Ctrl-C is pressed) */
+ thrift_server_serve (server, &error);
+
+ /* If the server stopped for any reason other than being interrupted by the
+ user, report the error */
+ if (!sigint_received) {
+ g_message ("thrift_server_serve: %s",
+ error != NULL ? error->message : "(null)");
+ g_clear_error (&error);
+ }
+
+ puts ("done.");
+
+ g_object_unref (server);
+ g_object_unref (protocol_factory);
+ g_object_unref (transport_factory);
+ g_object_unref (server_transport);
+ g_object_unref (processor);
+ g_object_unref (handler);
+ if(handler_second_service){
+ g_object_unref (handler_second_service);
+ }
+ if(processor_test){
+ g_object_unref (processor_test);
+ }
+ if(processor_second_service){
+ g_object_unref (processor_second_service);
+ }
+
+ return 0;
+}
diff --git a/src/jaegertracing/thrift/test/c_glib/src/thrift_second_service_handler.c b/src/jaegertracing/thrift/test/c_glib/src/thrift_second_service_handler.c
new file mode 100644
index 000000000..66ac7bca2
--- /dev/null
+++ b/src/jaegertracing/thrift/test/c_glib/src/thrift_second_service_handler.c
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <inttypes.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <thrift/c_glib/thrift.h>
+#include <thrift/c_glib/thrift_application_exception.h>
+
+#include "thrift_second_service_handler.h"
+
+/* A handler that implements the TTestSecondServiceIf interface */
+
+G_DEFINE_TYPE (SecondServiceHandler,
+ second_service_handler,
+ T_TEST_TYPE_SECOND_SERVICE_HANDLER);
+
+
+gboolean
+second_service_handler_secondtest_string (TTestSecondServiceIf *iface,
+ gchar **_return,
+ const gchar *thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+ gchar buffer[256];
+
+ printf ("testSecondServiceMultiplexSecondTestString(\"%s\")\n", thing);
+ snprintf(buffer, 255, "testString(\"%s\")", thing);
+ *_return = g_strdup (buffer);
+
+ return TRUE;
+}
+
+static void
+second_service_handler_init (SecondServiceHandler *self)
+{
+ THRIFT_UNUSED_VAR (self);
+}
+
+static void
+second_service_handler_class_init (SecondServiceHandlerClass *klass)
+{
+ TTestSecondServiceHandlerClass *base_class =
+ T_TEST_SECOND_SERVICE_HANDLER_CLASS (klass);
+
+
+ base_class->secondtest_string =
+ second_service_handler_secondtest_string;
+
+}
diff --git a/src/jaegertracing/thrift/test/c_glib/src/thrift_second_service_handler.h b/src/jaegertracing/thrift/test/c_glib/src/thrift_second_service_handler.h
new file mode 100644
index 000000000..bbe048cec
--- /dev/null
+++ b/src/jaegertracing/thrift/test/c_glib/src/thrift_second_service_handler.h
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _SECOND_SERVICE_HANDLER_H
+#define _SECOND_SERVICE_HANDLER_H
+
+#include <glib-object.h>
+#include <stdio.h>
+
+#include "../gen-c_glib/t_test_second_service.h"
+
+G_BEGIN_DECLS
+
+/* A handler that implements the TTestSecondServiceIf interface */
+
+#define TYPE_SECOND_SERVICE_HANDLER (second_service_handler_get_type ())
+
+#define SECOND_SERVICE_HANDLER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ TYPE_SECOND_SERVICE_HANDLER, \
+ SecondServiceHandler))
+#define IS_SECOND_SERVICE_HANDLER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ TYPE_SECOND_SERVICE_HANDLER))
+#define SECOND_SERVICE_HANDLER_CLASS(c) \
+ (G_TYPE_CHECK_CLASS_CAST ((c), \
+ TYPE_SECOND_SERVICE_HANDLER, \
+ SecondServiceHandlerClass))
+#define IS_SECOND_SERVICE_HANDLER_CLASS(c) \
+ (G_TYPE_CHECK_CLASS_TYPE ((c), \
+ TYPE_SECOND_SERVICE_HANDLER))
+#define SECOND_SERVICE_HANDLER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ TYPE_SECOND_SERVICE_HANDLER, \
+ SecondServiceHandlerClass))
+
+typedef struct _SecondServiceHandler SecondServiceHandler;
+typedef struct _SecondServiceHandlerClass SecondServiceHandlerClass;
+
+struct _SecondServiceHandler {
+ TTestSecondServiceHandler parent;
+};
+
+struct _SecondServiceHandlerClass {
+ TTestSecondServiceHandlerClass parent;
+
+};
+
+/* Used by SECOND_SERVICE_HANDLER_GET_TYPE */
+GType second_service_handler_get_type (void);
+
+gboolean second_service_handler_blah_blah (TTestSecondServiceIf *iface, GError **error);
+gboolean second_service_handler_secondtest_string (TTestSecondServiceIf *iface, gchar ** _return, const gchar * thing, GError **error);
+
+G_END_DECLS
+
+#endif /* _SECOND_SERVICE_HANDLER_H */
diff --git a/src/jaegertracing/thrift/test/c_glib/src/thrift_test_handler.c b/src/jaegertracing/thrift/test/c_glib/src/thrift_test_handler.c
new file mode 100644
index 000000000..f6c759e1a
--- /dev/null
+++ b/src/jaegertracing/thrift/test/c_glib/src/thrift_test_handler.c
@@ -0,0 +1,837 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <inttypes.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <thrift/c_glib/thrift.h>
+#include <thrift/c_glib/thrift_application_exception.h>
+
+#include "thrift_test_handler.h"
+
+/* A handler that implements the TTestThriftTestIf interface */
+
+G_DEFINE_TYPE (ThriftTestHandler,
+ thrift_test_handler,
+ T_TEST_TYPE_THRIFT_TEST_HANDLER)
+
+gboolean
+thrift_test_handler_test_void (TTestThriftTestIf *iface,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testVoid()\n");
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_string (TTestThriftTestIf *iface,
+ gchar **_return,
+ const gchar *thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testString(\"%s\")\n", thing);
+ *_return = g_strdup (thing);
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_bool (TTestThriftTestIf *iface,
+ gboolean *_return,
+ const gboolean thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testBool(%s)\n", thing ? "true" : "false");
+ *_return = thing;
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_byte (TTestThriftTestIf *iface,
+ gint8 *_return,
+ const gint8 thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testByte(%d)\n", (gint)thing);
+ *_return = thing;
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_i32 (TTestThriftTestIf *iface,
+ gint32 *_return,
+ const gint32 thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testI32(%d)\n", thing);
+ *_return = thing;
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_i64 (TTestThriftTestIf *iface,
+ gint64 *_return,
+ const gint64 thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testI64(%" PRId64 ")\n", thing);
+ *_return = thing;
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_double (TTestThriftTestIf *iface,
+ gdouble *_return,
+ const gdouble thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testDouble(%f)\n", thing);
+ *_return = thing;
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_binary (TTestThriftTestIf *iface,
+ GByteArray ** _return,
+ const GByteArray * thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testBinary()\n"); // TODO: hex output
+ g_byte_array_ref((GByteArray *)thing);
+ *_return = (GByteArray *)thing;
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_struct (TTestThriftTestIf *iface,
+ TTestXtruct **_return,
+ const TTestXtruct *thing,
+ GError **error)
+{
+ gchar *string_thing = NULL;
+ gint byte_thing;
+ gint i32_thing;
+ gint64 i64_thing;
+
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ g_object_get ((TTestXtruct *)thing,
+ "string_thing", &string_thing,
+ "byte_thing", &byte_thing,
+ "i32_thing", &i32_thing,
+ "i64_thing", &i64_thing,
+ NULL);
+
+ printf ("testStruct({\"%s\", %d, %d, %" PRId64 "})\n",
+ string_thing,
+ (gint)byte_thing,
+ i32_thing,
+ i64_thing);
+
+ g_object_set (*_return,
+ "string_thing", string_thing,
+ "byte_thing", byte_thing,
+ "i32_thing", i32_thing,
+ "i64_thing", i64_thing,
+ NULL);
+
+ if (string_thing != NULL)
+ g_free (string_thing);
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_nest (TTestThriftTestIf *iface,
+ TTestXtruct2 **_return,
+ const TTestXtruct2 *thing,
+ GError **error)
+{
+ gchar *inner_string_thing = NULL;
+ gint byte_thing, inner_byte_thing;
+ gint i32_thing, inner_i32_thing;
+ gint64 inner_i64_thing;
+ TTestXtruct *struct_thing;
+
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ g_object_get ((TTestXtruct2 *)thing,
+ "byte_thing", &byte_thing,
+ "struct_thing", &struct_thing,
+ "i32_thing", &i32_thing,
+ NULL);
+ g_object_get (struct_thing,
+ "string_thing", &inner_string_thing,
+ "byte_thing", &inner_byte_thing,
+ "i32_thing", &inner_i32_thing,
+ "i64_thing", &inner_i64_thing,
+ NULL);
+
+ printf ("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n",
+ byte_thing,
+ inner_string_thing,
+ inner_byte_thing,
+ inner_i32_thing,
+ inner_i64_thing,
+ i32_thing);
+
+ g_object_set (*_return,
+ "byte_thing", byte_thing,
+ "struct_thing", struct_thing,
+ "i32_thing", i32_thing,
+ NULL);
+
+ if (inner_string_thing != NULL)
+ g_free (inner_string_thing);
+ g_object_unref (struct_thing);
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_map (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const GHashTable *thing,
+ GError **error)
+{
+ GHashTableIter hash_table_iter;
+ gpointer key;
+ gpointer value;
+ gboolean first = TRUE;
+
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testMap({");
+ g_hash_table_iter_init (&hash_table_iter, (GHashTable *)thing);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ gint32 *new_key;
+ gint32 *new_value;
+
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("%d => %d", *(gint32 *)key, *(gint32 *)value);
+
+ new_key = g_malloc (sizeof *new_key);
+ *new_key = *(gint32 *)key;
+ new_value = g_malloc (sizeof *new_value);
+ *new_value = *(gint32 *)value;
+ g_hash_table_insert (*_return, new_key, new_value);
+ }
+ printf ("})\n");
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_string_map (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const GHashTable *thing,
+ GError **error)
+{
+ GHashTableIter hash_table_iter;
+ gpointer key;
+ gpointer value;
+ gboolean first = TRUE;
+
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testStringMap({");
+ g_hash_table_iter_init (&hash_table_iter, (GHashTable *)thing);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ gchar *new_key;
+ gchar *new_value;
+
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("%s => %s", (gchar *)key, (gchar *)value);
+
+ new_key = g_strdup ((gchar *)key);
+ new_value = g_strdup ((gchar *)value);
+ g_hash_table_insert (*_return, new_key, new_value);
+ }
+ printf ("})\n");
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_set (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const GHashTable *thing,
+ GError **error)
+{
+ GHashTableIter hash_table_iter;
+ gpointer key;
+ gboolean first = TRUE;
+
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testSet({");
+ g_hash_table_iter_init (&hash_table_iter, (GHashTable *)thing);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ NULL)) {
+ gint32 *new_key;
+
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ printf ("%d", *(gint32 *)key);
+
+ new_key = g_malloc (sizeof *new_key);
+ *new_key = *(gint32 *)key;
+ g_hash_table_insert (*_return, new_key, NULL);
+ }
+ printf ("})\n");
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_list (TTestThriftTestIf *iface,
+ GArray **_return,
+ const GArray *thing,
+ GError **error)
+{
+ guint i;
+ gboolean first = TRUE;
+
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testList({");
+ for (i = 0; i < thing->len; i += 1) {
+ gint32 value;
+ gint32 *new_value;
+
+ if (first)
+ first = FALSE;
+ else
+ printf (", ");
+
+ value = g_array_index (thing, gint32, i);
+ printf ("%d", value);
+
+ new_value = g_malloc (sizeof *new_value);
+ *new_value = value;
+ g_array_append_val (*_return, *new_value);
+ }
+ printf ("})\n");
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_enum (TTestThriftTestIf *iface,
+ TTestNumberz *_return,
+ const TTestNumberz thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testEnum(%d)\n", thing);
+ *_return = thing;
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_typedef (TTestThriftTestIf *iface,
+ TTestUserId *_return,
+ const TTestUserId thing,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testTypedef(%" PRId64 ")\n", thing);
+ *_return = thing;
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_map_map (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const gint32 hello,
+ GError **error)
+{
+ GHashTable *positive;
+ GHashTable *negative;
+ gint32 *key;
+ gint32 *value;
+ guint i;
+
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testMapMap(%d)\n", hello);
+
+ positive = g_hash_table_new_full (g_int_hash,
+ g_int_equal,
+ g_free,
+ g_free);
+ negative = g_hash_table_new_full (g_int_hash,
+ g_int_equal,
+ g_free,
+ g_free);
+
+ for (i = 1; i < 5; i += 1) {
+ key = g_malloc (sizeof *key);
+ value = g_malloc (sizeof *value);
+ *key = i;
+ *value = i;
+ g_hash_table_insert (positive, key, value);
+
+ key = g_malloc (sizeof *key);
+ value = g_malloc (sizeof *value);
+ *key = -i;
+ *value = -i;
+ g_hash_table_insert (negative, key, value);
+ }
+
+ key = g_malloc (sizeof *key);
+ *key = 4;
+ g_hash_table_insert (*_return, key, positive);
+
+ key = g_malloc (sizeof *key);
+ *key = -4;
+ g_hash_table_insert (*_return, key, negative);
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_insanity (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const TTestInsanity *argument,
+ GError **error)
+{
+ TTestXtruct *xtruct_in;
+
+ gchar *string_thing = NULL;
+ gint byte_thing;
+ gint i32_thing;
+ gint64 i64_thing;
+
+ GPtrArray *xtructs;
+
+ TTestInsanity *looney;
+
+ GHashTable *user_map;
+ GHashTable *first_map;
+ GHashTable *second_map;
+
+ GHashTableIter hash_table_iter;
+ GHashTableIter inner_hash_table_iter;
+ GHashTableIter user_map_iter;
+
+ gpointer key;
+ gpointer value;
+
+ TTestUserId *user_id;
+
+ guint i;
+
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testInsanity()\n");
+
+ first_map = g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ NULL,
+ g_object_unref);
+ second_map = g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ NULL,
+ g_object_unref);
+
+ g_hash_table_insert (first_map,
+ GINT_TO_POINTER (T_TEST_NUMBERZ_TWO),
+ (gpointer)argument);
+ g_hash_table_insert (first_map,
+ GINT_TO_POINTER (T_TEST_NUMBERZ_THREE),
+ (gpointer)argument);
+
+ /* Increment argument's ref count by two because first_map now holds
+ two references to it and the caller is not aware we have made any
+ additional references to argument. (That is, caller owns argument
+ and will unref it explicitly in addition to unref-ing *_return.)
+
+ We do this instead of creating a copy of argument in order to mimic
+ the C++ implementation (and since, frankly, the world needs less
+ argument, not more). */
+ g_object_ref ((gpointer)argument);
+ g_object_ref ((gpointer)argument);
+
+ looney = g_object_new (T_TEST_TYPE_INSANITY, NULL);
+ g_hash_table_insert (second_map,
+ GINT_TO_POINTER (T_TEST_NUMBERZ_SIX),
+ looney);
+
+ user_id = g_malloc (sizeof *user_id);
+ *user_id = 1;
+ g_hash_table_insert (*_return, user_id, first_map);
+
+ user_id = g_malloc (sizeof *user_id);
+ *user_id = 2;
+ g_hash_table_insert (*_return, user_id, second_map);
+
+ printf ("return");
+ printf (" = {");
+ g_hash_table_iter_init (&hash_table_iter, *_return);
+ while (g_hash_table_iter_next (&hash_table_iter,
+ &key,
+ &value)) {
+ printf ("%" PRId64 " => {", *(TTestUserId *)key);
+
+ g_hash_table_iter_init (&inner_hash_table_iter,
+ (GHashTable *)value);
+ while (g_hash_table_iter_next (&inner_hash_table_iter,
+ &key,
+ &value)) {
+ printf ("%d => {", (TTestNumberz)key);
+
+ g_object_get ((TTestInsanity *)value,
+ "userMap", &user_map,
+ "xtructs", &xtructs,
+ NULL);
+
+ printf ("{");
+ g_hash_table_iter_init (&user_map_iter, user_map);
+ while (g_hash_table_iter_next (&user_map_iter,
+ &key,
+ &value)) {
+ printf ("%d => %" PRId64 ", ",
+ (TTestNumberz)key,
+ *(TTestUserId *)value);
+ }
+ printf ("}, ");
+ g_hash_table_unref (user_map);
+
+ printf ("{");
+ for (i = 0; i < xtructs->len; ++i) {
+ xtruct_in = g_ptr_array_index (xtructs, i);
+ g_object_get (xtruct_in,
+ "string_thing", &string_thing,
+ "byte_thing", &byte_thing,
+ "i32_thing", &i32_thing,
+ "i64_thing", &i64_thing,
+ NULL);
+
+ printf ("{\"%s\", %d, %d, %" PRId64 "}, ",
+ string_thing,
+ byte_thing,
+ i32_thing,
+ i64_thing);
+ }
+ printf ("}");
+ g_ptr_array_unref (xtructs);
+
+ printf ("}, ");
+ }
+ printf ("}, ");
+ }
+ printf ("}\n");
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_multi (TTestThriftTestIf *iface,
+ TTestXtruct **_return,
+ const gint8 arg0,
+ const gint32 arg1,
+ const gint64 arg2,
+ const GHashTable *arg3,
+ const TTestNumberz arg4,
+ const TTestUserId arg5,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+ THRIFT_UNUSED_VAR (arg3);
+ THRIFT_UNUSED_VAR (arg4);
+ THRIFT_UNUSED_VAR (arg5);
+
+ printf ("testMulti()\n");
+
+ g_object_set (*_return,
+ "string_thing", g_strdup ("Hello2"),
+ "byte_thing", arg0,
+ "i32_thing", arg1,
+ "i64_thing", arg2,
+ NULL);
+
+ return TRUE;
+}
+
+gboolean
+thrift_test_handler_test_exception (TTestThriftTestIf *iface,
+ const gchar *arg,
+ TTestXception **err1,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+
+ TTestXtruct *xtruct;
+ gboolean result;
+
+ printf ("testException(%s)\n", arg);
+
+ /* Unlike argument objects, exception objects are not pre-created */
+ g_assert (*err1 == NULL);
+
+ if (strncmp (arg, "Xception", 9) == 0) {
+ /* "Throw" a custom exception: Set the corresponding exception
+ argument, set *error to NULL and return FALSE */
+ *err1 = g_object_new (T_TEST_TYPE_XCEPTION,
+ "errorCode", 1001,
+ "message", g_strdup (arg),
+ NULL);
+ *error = NULL;
+ result = FALSE;
+ }
+ else if (strncmp (arg, "TException", 11) == 0) {
+ /* "Throw" a generic TException (ThriftApplicationException): Set
+ all exception arguments to NULL, set *error and return FALSE */
+ *err1 = NULL;
+ g_set_error (error,
+ thrift_application_exception_error_quark (),
+ THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN,
+ "Default TException.");
+ result = FALSE;
+ }
+ else {
+ *err1 = NULL;
+ *error = NULL;
+
+ /* This code is duplicated from the C++ test suite, though it
+ appears to serve no purpose */
+ xtruct = g_object_new (T_TEST_TYPE_XTRUCT,
+ "string_thing", g_strdup (arg),
+ NULL);
+ g_object_unref (xtruct);
+
+ result = TRUE;
+ }
+
+ return result;
+}
+
+gboolean
+thrift_test_handler_test_multi_exception (TTestThriftTestIf *iface,
+ TTestXtruct **_return,
+ const gchar *arg0,
+ const gchar *arg1,
+ TTestXception **err1,
+ TTestXception2 **err2,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ TTestXtruct *struct_thing;
+ gboolean result;
+
+ printf ("testMultiException(%s, %s)\n", arg0, arg1);
+
+ g_assert (*err1 == NULL);
+ g_assert (*err2 == NULL);
+
+ if (strncmp (arg0, "Xception", 8) == 0 && strlen(arg0) == 8) {
+ *err1 = g_object_new (T_TEST_TYPE_XCEPTION,
+ "errorCode", 1001,
+ "message", g_strdup ("This is an Xception"),
+ NULL);
+ result = FALSE;
+ }
+ else if (strncmp (arg0, "Xception2", 9) == 0) {
+ *err2 = g_object_new (T_TEST_TYPE_XCEPTION2,
+ "errorCode", 2002,
+ NULL);
+
+ g_object_get (*err2,
+ "struct_thing", &struct_thing,
+ NULL);
+ g_object_set (struct_thing,
+ "string_thing", g_strdup ("This is an Xception2"),
+ NULL);
+ g_object_set (*err2,
+ "struct_thing", struct_thing,
+ NULL);
+ g_object_unref (struct_thing);
+
+ result = FALSE;
+ }
+ else {
+ g_object_set (*_return,
+ "string_thing", g_strdup (arg1),
+ NULL);
+ result = TRUE;
+ }
+
+ return result;
+}
+
+gboolean
+thrift_test_handler_test_oneway (TTestThriftTestIf *iface,
+ const gint32 secondsToSleep,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (iface);
+ THRIFT_UNUSED_VAR (error);
+
+ printf ("testOneway(%d): Sleeping...\n", secondsToSleep);
+ sleep (secondsToSleep);
+ printf ("testOneway(%d): done sleeping!\n", secondsToSleep);
+
+ return TRUE;
+}
+
+static void
+thrift_test_handler_init (ThriftTestHandler *self)
+{
+ THRIFT_UNUSED_VAR (self);
+}
+
+static void
+thrift_test_handler_class_init (ThriftTestHandlerClass *klass)
+{
+ TTestThriftTestHandlerClass *base_class =
+ T_TEST_THRIFT_TEST_HANDLER_CLASS (klass);
+
+ base_class->test_void =
+ klass->test_void =
+ thrift_test_handler_test_void;
+ base_class->test_string =
+ klass->test_string =
+ thrift_test_handler_test_string;
+ base_class->test_bool =
+ klass->test_bool =
+ thrift_test_handler_test_bool;
+ base_class->test_byte =
+ klass->test_byte =
+ thrift_test_handler_test_byte;
+ base_class->test_i32 =
+ klass->test_i32 =
+ thrift_test_handler_test_i32;
+ base_class->test_i64 =
+ klass->test_i64 =
+ thrift_test_handler_test_i64;
+ base_class->test_double =
+ klass->test_double =
+ thrift_test_handler_test_double;
+ base_class->test_binary =
+ klass->test_binary =
+ thrift_test_handler_test_binary;
+ base_class->test_struct =
+ klass->test_struct =
+ thrift_test_handler_test_struct;
+ base_class->test_nest =
+ klass->test_nest =
+ thrift_test_handler_test_nest;
+ base_class->test_map =
+ klass->test_map =
+ thrift_test_handler_test_map;
+ base_class->test_string_map =
+ klass->test_string_map =
+ thrift_test_handler_test_string_map;
+ base_class->test_set =
+ klass->test_set =
+ thrift_test_handler_test_set;
+ base_class->test_list =
+ klass->test_list =
+ thrift_test_handler_test_list;
+ base_class->test_enum =
+ klass->test_enum =
+ thrift_test_handler_test_enum;
+ base_class->test_typedef =
+ klass->test_typedef =
+ thrift_test_handler_test_typedef;
+ base_class->test_map_map =
+ klass->test_map_map =
+ thrift_test_handler_test_map_map;
+ base_class->test_insanity =
+ klass->test_insanity =
+ thrift_test_handler_test_insanity;
+ base_class->test_multi =
+ klass->test_multi =
+ thrift_test_handler_test_multi;
+ base_class->test_exception =
+ klass->test_exception =
+ thrift_test_handler_test_exception;
+ base_class->test_multi_exception =
+ klass->test_multi_exception =
+ thrift_test_handler_test_multi_exception;
+ base_class->test_oneway =
+ klass->test_oneway =
+ thrift_test_handler_test_oneway;
+}
diff --git a/src/jaegertracing/thrift/test/c_glib/src/thrift_test_handler.h b/src/jaegertracing/thrift/test/c_glib/src/thrift_test_handler.h
new file mode 100644
index 000000000..b64cb16f2
--- /dev/null
+++ b/src/jaegertracing/thrift/test/c_glib/src/thrift_test_handler.h
@@ -0,0 +1,245 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef _THRIFT_TEST_HANDLER_H
+#define _THRIFT_TEST_HANDLER_H
+
+#include <glib-object.h>
+#include <stdio.h>
+
+#include "../gen-c_glib/t_test_thrift_test.h"
+
+G_BEGIN_DECLS
+
+/* A handler that implements the TTestThriftTestIf interface */
+
+#define TYPE_THRIFT_TEST_HANDLER (thrift_test_handler_get_type ())
+
+#define THRIFT_TEST_HANDLER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ TYPE_THRIFT_TEST_HANDLER, \
+ ThriftTestHandler))
+#define IS_THRIFT_TEST_HANDLER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ TYPE_THRIFT_TEST_HANDLER))
+#define THRIFT_TEST_HANDLER_CLASS(c) \
+ (G_TYPE_CHECK_CLASS_CAST ((c), \
+ TYPE_THRIFT_TEST_HANDLER, \
+ ThriftTestHandlerClass))
+#define IS_THRIFT_TEST_HANDLER_CLASS(c) \
+ (G_TYPE_CHECK_CLASS_TYPE ((c), \
+ TYPE_THRIFT_TEST_HANDLER))
+#define THRIFT_TEST_HANDLER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ TYPE_THRIFT_TEST_HANDLER, \
+ ThriftTestHandlerClass))
+
+typedef struct _ThriftTestHandler ThriftTestHandler;
+typedef struct _ThriftTestHandlerClass ThriftTestHandlerClass;
+
+struct _ThriftTestHandler {
+ TTestThriftTestHandler parent;
+};
+
+struct _ThriftTestHandlerClass {
+ TTestThriftTestHandlerClass parent;
+
+ gboolean (*test_void) (TTestThriftTestIf *iface,
+ GError **error);
+ gboolean (*test_string) (TTestThriftTestIf *iface,
+ gchar **_return,
+ const gchar *thing,
+ GError **error);
+ gboolean (*test_bool) (TTestThriftTestIf *iface,
+ gboolean*_return,
+ const gboolean thing,
+ GError **error);
+ gboolean (*test_byte) (TTestThriftTestIf *iface,
+ gint8*_return,
+ const gint8 thing,
+ GError **error);
+ gboolean (*test_i32) (TTestThriftTestIf *iface,
+ gint32*_return,
+ const gint32 thing,
+ GError **error);
+ gboolean (*test_i64) (TTestThriftTestIf *iface,
+ gint64*_return,
+ const gint64 thing,
+ GError **error);
+ gboolean (*test_double) (TTestThriftTestIf *iface,
+ gdouble*_return,
+ const gdouble thing,
+ GError **error);
+ gboolean (*test_binary) (TTestThriftTestIf *iface,
+ GByteArray **_return,
+ const GByteArray *thing,
+ GError **error);
+ gboolean (*test_struct) (TTestThriftTestIf *iface,
+ TTestXtruct **_return,
+ const TTestXtruct *thing,
+ GError **error);
+ gboolean (*test_nest) (TTestThriftTestIf *iface,
+ TTestXtruct2 **_return,
+ const TTestXtruct2 *thing,
+ GError **error);
+ gboolean (*test_map) (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const GHashTable *thing,
+ GError **error);
+ gboolean (*test_string_map) (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const GHashTable *thing,
+ GError **error);
+ gboolean (*test_set) (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const GHashTable *thing,
+ GError **error);
+ gboolean (*test_list) (TTestThriftTestIf *iface,
+ GArray **_return,
+ const GArray *thing,
+ GError **error);
+ gboolean (*test_enum) (TTestThriftTestIf *iface,
+ TTestNumberz*_return,
+ const TTestNumberz thing,
+ GError **error);
+ gboolean (*test_typedef) (TTestThriftTestIf *iface,
+ TTestUserId*_return,
+ const TTestUserId thing,
+ GError **error);
+ gboolean (*test_map_map) (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const gint32 hello,
+ GError **error);
+ gboolean (*test_insanity) (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const TTestInsanity *argument,
+ GError **error);
+ gboolean (*test_multi) (TTestThriftTestIf *iface,
+ TTestXtruct **_return,
+ const gint8 arg0,
+ const gint32 arg1,
+ const gint64 arg2,
+ const GHashTable *arg3,
+ const TTestNumberz arg4,
+ const TTestUserId arg5,
+ GError **error);
+ gboolean (*test_exception) (TTestThriftTestIf *iface,
+ const gchar *arg,
+ TTestXception **err1,
+ GError **error);
+ gboolean (*test_multi_exception) (TTestThriftTestIf *iface,
+ TTestXtruct **_return,
+ const gchar *arg0,
+ const gchar *arg1,
+ TTestXception **err1,
+ TTestXception2 **err2,
+ GError **error);
+ gboolean (*test_oneway) (TTestThriftTestIf *iface,
+ const gint32 secondsToSleep,
+ GError **error);
+};
+
+/* Used by THRIFT_TEST_HANDLER_GET_TYPE */
+GType thrift_test_handler_get_type (void);
+
+gboolean thrift_test_handler_test_void (TTestThriftTestIf *iface,
+ GError **error);
+gboolean thrift_test_handler_test_string (TTestThriftTestIf *iface,
+ gchar **_return,
+ const gchar *thing,
+ GError **error);
+gboolean thrift_test_handler_test_byte (TTestThriftTestIf *iface,
+ gint8*_return,
+ const gint8 thing,
+ GError **error);
+gboolean t_test_thrift_test_if_test_i32 (TTestThriftTestIf *iface,
+ gint32*_return,
+ const gint32 thing,
+ GError **error);
+gboolean thrift_test_handler_test_i64 (TTestThriftTestIf *iface,
+ gint64*_return,
+ const gint64 thing,
+ GError **error);
+gboolean thrift_test_handler_test_double (TTestThriftTestIf *iface,
+ gdouble*_return,
+ const gdouble thing,
+ GError **error);
+gboolean thrift_test_handler_test_struct (TTestThriftTestIf *iface,
+ TTestXtruct **_return,
+ const TTestXtruct *thing,
+ GError **error);
+gboolean thrift_test_handler_test_nest (TTestThriftTestIf *iface,
+ TTestXtruct2 **_return,
+ const TTestXtruct2 *thing,
+ GError **error);
+gboolean thrift_test_handler_test_map (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const GHashTable *thing,
+ GError **error);
+gboolean thrift_test_handler_test_string_map (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const GHashTable *thing,
+ GError **error);
+gboolean thrift_test_handler_test_set (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const GHashTable *thing,
+ GError **error);
+gboolean thrift_test_handler_test_list (TTestThriftTestIf *iface,
+ GArray **_return,
+ const GArray *thing,
+ GError **error);
+gboolean thrift_test_handler_test_typedef (TTestThriftTestIf *iface,
+ TTestUserId*_return,
+ const TTestUserId thing,
+ GError **error);
+gboolean thrift_test_handler_test_map_map (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const gint32 hello,
+ GError **error);
+gboolean thrift_test_handler_test_insanity (TTestThriftTestIf *iface,
+ GHashTable **_return,
+ const TTestInsanity *argument,
+ GError **error);
+gboolean thrift_test_handler_test_multi (TTestThriftTestIf *iface,
+ TTestXtruct **_return,
+ const gint8 arg0,
+ const gint32 arg1,
+ const gint64 arg2,
+ const GHashTable *arg3,
+ const TTestNumberz arg4,
+ const TTestUserId arg5,
+ GError **error);
+gboolean thrift_test_handler_test_exception (TTestThriftTestIf *iface,
+ const gchar *arg,
+ TTestXception **err1,
+ GError **error);
+gboolean thrift_test_handler_test_multi_exception (TTestThriftTestIf *iface,
+ TTestXtruct **_return,
+ const gchar *arg0,
+ const gchar *arg1,
+ TTestXception **err1,
+ TTestXception2 **err2,
+ GError **error);
+gboolean thrift_test_handler_test_oneway (TTestThriftTestIf *iface,
+ const gint32 secondsToSleep,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* _THRIFT_TEST_HANDLER_H */