THRIFT-3455 struct write method's return value is incorrect Client: c_glib Compiler Patch: Nobuaki Sukegawa
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/362a5eda Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/362a5eda Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/362a5eda Branch: refs/heads/master Commit: 362a5eda211e3f8093b739aeaaee93b118ace199 Parents: 2e00c99 Author: Nobuaki Sukegawa <[email protected]> Authored: Tue Dec 1 22:17:24 2015 +0900 Committer: Nobuaki Sukegawa <[email protected]> Committed: Fri Dec 4 00:38:33 2015 +0900 ---------------------------------------------------------------------- .gitignore | 1 + compiler/cpp/src/generate/t_c_glib_generator.cc | 5 ++- lib/c_glib/test/CMakeLists.txt | 4 ++ lib/c_glib/test/Makefile.am | 7 ++++ lib/c_glib/test/testserialization.c | 40 ++++++++++++++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/362a5eda/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index bcbbd6f..957dc9f 100644 --- a/.gitignore +++ b/.gitignore @@ -138,6 +138,7 @@ erl_crash.dump /lib/c_glib/test/testthrifttest /lib/c_glib/test/testthrifttestclient /lib/c_glib/test/testtransportsocket +/lib/c_glib/test/testserialization /lib/c_glib/thriftc.pc /lib/c_glib/thrift_c_glib.pc /lib/csharp/**/bin/ http://git-wip-us.apache.org/repos/asf/thrift/blob/362a5eda/compiler/cpp/src/generate/t_c_glib_generator.cc ---------------------------------------------------------------------- diff --git a/compiler/cpp/src/generate/t_c_glib_generator.cc b/compiler/cpp/src/generate/t_c_glib_generator.cc index 6ca6a5e..e6b48a4 100644 --- a/compiler/cpp/src/generate/t_c_glib_generator.cc +++ b/compiler/cpp/src/generate/t_c_glib_generator.cc @@ -3699,7 +3699,10 @@ void t_c_glib_generator::generate_serialize_field(ofstream& out, } else if (type->is_enum()) { out << "i32 (protocol, (gint32) " << name; } - out << ", error)) < 0)" << endl << indent() << " return " << error_ret << ";" << endl; + out << ", error)) < 0)" << endl + << indent() << " return " << error_ret << ";" << endl + << indent() << "xfer += ret;" << endl + << endl; } else { printf("DO NOT KNOW HOW TO SERIALIZE FIELD '%s' TYPE '%s'\n", name.c_str(), http://git-wip-us.apache.org/repos/asf/thrift/blob/362a5eda/lib/c_glib/test/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/lib/c_glib/test/CMakeLists.txt b/lib/c_glib/test/CMakeLists.txt index bd5d1ee..61dc490 100644 --- a/lib/c_glib/test/CMakeLists.txt +++ b/lib/c_glib/test/CMakeLists.txt @@ -53,6 +53,10 @@ add_library(testgenc STATIC ${testgenc_SOURCES}) target_link_libraries(testgenc thrift_c_glib) +add_executable(testserialization testserialization.c) +target_link_libraries(testserialization testgenc thrift_c_glib) +add_test(NAME testserialization COMMAND testserialization) + add_executable(testapplicationexception testapplicationexception.c) target_link_libraries(testapplicationexception thrift_c_glib) add_test(NAME testapplicationexception COMMAND testapplicationexception) http://git-wip-us.apache.org/repos/asf/thrift/blob/362a5eda/lib/c_glib/test/Makefile.am ---------------------------------------------------------------------- diff --git a/lib/c_glib/test/Makefile.am b/lib/c_glib/test/Makefile.am index 7319743..555380c 100755 --- a/lib/c_glib/test/Makefile.am +++ b/lib/c_glib/test/Makefile.am @@ -43,6 +43,7 @@ AM_CXXFLAGS = $(AM_CFLAGS) AM_LDFLAGS = $(GLIB_LIBS) $(GOBJECT_LIBS) @GCOV_LDFLAGS@ check_PROGRAMS = \ + testserialization \ testapplicationexception \ testcontainertest \ testtransportsocket \ @@ -61,6 +62,12 @@ if WITH_CPP check_PROGRAMS += testthrifttestclient endif +testserialization_SOURCES = testserialization.c +testserialization_LDADD = \ + $(top_builddir)/lib/c_glib/src/thrift/c_glib/protocol/libthrift_c_glib_la-thrift_protocol.o \ + $(top_builddir)/lib/c_glib/src/thrift/c_glib/transport/libthrift_c_glib_la-thrift_transport.o \ + libtestgenc.la + testapplicationexception_SOURCES = testapplicationexception.c testapplicationexception_LDADD = \ $(top_builddir)/lib/c_glib/src/thrift/c_glib/libthrift_c_glib_la-thrift_application_exception.o \ http://git-wip-us.apache.org/repos/asf/thrift/blob/362a5eda/lib/c_glib/test/testserialization.c ---------------------------------------------------------------------- diff --git a/lib/c_glib/test/testserialization.c b/lib/c_glib/test/testserialization.c new file mode 100644 index 0000000..0ece2ad --- /dev/null +++ b/lib/c_glib/test/testserialization.c @@ -0,0 +1,40 @@ +#include <thrift/c_glib/protocol/thrift_binary_protocol.h> +#include <thrift/c_glib/protocol/thrift_protocol.h> +#include <thrift/c_glib/transport/thrift_memory_buffer.h> +#include <thrift/c_glib/transport/thrift_transport.h> +#include "gen-c_glib/t_test_debug_proto_test_types.h" + +static void struct_read_write_length_should_equal() { + GError* error = NULL; + ThriftTransport* transport + = THRIFT_TRANSPORT(g_object_new(THRIFT_TYPE_MEMORY_BUFFER, "buf_size", 2048, NULL)); + ThriftProtocol* protocol + = THRIFT_PROTOCOL(g_object_new(THRIFT_TYPE_BINARY_PROTOCOL, "transport", transport, NULL)); + TTestBonk* src = g_object_new(T_TEST_TYPE_BONK, NULL); + TTestBonk* dst = g_object_new(T_TEST_TYPE_BONK, NULL); + TTestBonkClass* cls = T_TEST_BONK_GET_CLASS(src); + + int write_len = THRIFT_STRUCT_CLASS(cls)->write(THRIFT_STRUCT(src), protocol, &error); + g_assert(!error); + g_assert(write_len > 0); + + int read_len = THRIFT_STRUCT_CLASS(cls)->read(THRIFT_STRUCT(dst), protocol, &error); + g_assert(!error); + g_assert_cmpint(write_len, ==, read_len); + + g_object_unref(dst); + g_object_unref(src); + g_object_unref(protocol); + g_object_unref(transport); +} + +int main(int argc, char* argv[]) { +#if (!GLIB_CHECK_VERSION(2, 36, 0)) + g_type_init(); +#endif + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/testserialization/StructReadWriteLengthShouldEqual", + struct_read_write_length_should_equal); + return g_test_run(); +}
