From 1921d2046b588cd1f19c40d323d44e74b02a4e1f Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Wed, 24 Jan 2007 19:43:06 +0000 Subject: [PATCH] Fix C++ Thrift test code to work with new gen'd code interface Reviewed By: tbr-aditya git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664938 13f79535-47bb-0310-9956-ffa450edef68 --- test/cpp/src/TestClient.cpp | 33 ++++++++++++++------- test/cpp/src/TestServer.cpp | 59 ++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp index db003478..d7191cab 100644 --- a/test/cpp/src/TestClient.cpp +++ b/test/cpp/src/TestClient.cpp @@ -110,7 +110,8 @@ int main(int argc, char** argv) { * STRING TEST */ printf("testString(\"Test\")"); - string s = testClient.testString("Test"); + string s; + testClient.testString(s, "Test"); printf(" = \"%s\"\n", s.c_str()); /** @@ -150,7 +151,8 @@ int main(int argc, char** argv) { out.byte_thing = 1; out.i32_thing = -3; out.i64_thing = -5; - Xtruct in = testClient.testStruct(out); + Xtruct in; + testClient.testStruct(in, out); printf(" = {\"%s\", %d, %d, %ld}\n", in.string_thing.c_str(), (int)in.byte_thing, @@ -165,7 +167,8 @@ int main(int argc, char** argv) { out2.byte_thing = 1; out2.struct_thing = out; out2.i32_thing = 5; - Xtruct2 in2 = testClient.testNest(out2); + Xtruct2 in2; + testClient.testNest(in2, out2); in = in2.struct_thing; printf(" = {%d, {\"%s\", %d, %d, %ld}, %d}\n", in2.byte_thing, @@ -194,7 +197,8 @@ int main(int argc, char** argv) { printf("%d => %d", m_iter->first, m_iter->second); } printf("})"); - map mapin = testClient.testMap(mapout); + map mapin; + testClient.testMap(mapin, mapout); printf(" = {"); first = true; for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { @@ -226,7 +230,8 @@ int main(int argc, char** argv) { printf("%d", *s_iter); } printf("})"); - set setin = testClient.testSet(setout); + set setin; + testClient.testSet(setin, setout); printf(" = {"); first = true; for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { @@ -258,7 +263,8 @@ int main(int argc, char** argv) { printf("%d", *l_iter); } printf("})"); - vector listin = testClient.testList(listout); + vector listin; + testClient.testList(listin, listout); printf(" = {"); first = true; for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { @@ -305,7 +311,8 @@ int main(int argc, char** argv) { * NESTED MAP TEST */ printf("testMapMap(1)"); - map > mm = testClient.testMapMap(1); + map > mm; + testClient.testMapMap(mm, 1); printf(" = {"); map >::const_iterator mi; for (mi = mm.begin(); mi != mm.end(); ++mi) { @@ -330,7 +337,8 @@ int main(int argc, char** argv) { truck.i64_thing = 8; insane.xtructs.push_back(truck); printf("testInsanity()"); - map > whoa = testClient.testInsanity(insane); + map > whoa; + testClient.testInsanity(whoa, insane); printf(" = {"); map >::const_iterator i_iter; for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { @@ -389,7 +397,8 @@ int main(int argc, char** argv) { try { printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); - Xtruct result = testClient.testMultiException("Xception", "test 1"); + Xtruct result; + testClient.testMultiException(result, "Xception", "test 1"); printf(" result\nFAILURE\n"); } catch(Xception& e) { printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); @@ -397,7 +406,8 @@ int main(int argc, char** argv) { try { printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>"); - Xtruct result = testClient.testMultiException("Xception2", "test 2"); + Xtruct result; + testClient.testMultiException(result, "Xception2", "test 2"); printf(" result\nFAILURE\n"); } catch(Xception2& e) { @@ -406,7 +416,8 @@ int main(int argc, char** argv) { try { printf("testClient.testMultiException(\"success\", \"test 3\") =>"); - Xtruct result = testClient.testMultiException("success", "test 3"); + Xtruct result; + testClient.testMultiException(result, "success", "test 3"); printf(" {{\"%s\"}}\n", result.string_thing.c_str()); } catch(...) { printf(" exception\nFAILURE\n"); diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp index 28a40fd0..bd6a2cff 100644 --- a/test/cpp/src/TestServer.cpp +++ b/test/cpp/src/TestServer.cpp @@ -29,43 +29,43 @@ class TestHandler : public ThriftTestIf { printf("testVoid()\n"); } - string testString(string thing) { + void testString(string& out, const string &thing) { printf("testString(\"%s\")\n", thing.c_str()); - return thing; + out = thing; } - int8_t testByte(int8_t thing) { + int8_t testByte(const int8_t thing) { printf("testByte(%d)\n", (int)thing); return thing; } - int32_t testI32(int32_t thing) { + int32_t testI32(const int32_t thing) { printf("testI32(%d)\n", thing); return thing; } - int64_t testI64(int64_t thing) { + int64_t testI64(const int64_t thing) { printf("testI64(%ld)\n", thing); return thing; } - double testDouble(double thing) { + double testDouble(const double thing) { printf("testDouble(%lf)\n", thing); return thing; } - Xtruct testStruct(Xtruct thing) { + void testStruct(Xtruct& out, const Xtruct &thing) { printf("testStruct({\"%s\", %d, %d, %ld})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing); - return thing; + out = thing; } - Xtruct2 testNest(Xtruct2 nest) { - Xtruct thing = nest.struct_thing; + void testNest(Xtruct2& out, const Xtruct2& nest) { + const Xtruct &thing = nest.struct_thing; printf("testNest({%d, {\"%s\", %d, %d, %ld}, %d})\n", (int)nest.byte_thing, thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing, nest.i32_thing); - return nest; + out = nest; } - map testMap(map thing) { + void testMap(map &out, const map &thing) { printf("testMap({"); map::const_iterator m_iter; bool first = true; @@ -78,10 +78,10 @@ class TestHandler : public ThriftTestIf { printf("%d => %d", m_iter->first, m_iter->second); } printf("})\n"); - return thing; + out = thing; } - set testSet(set thing) { + void testSet(set &out, const set &thing) { printf("testSet({"); set::const_iterator s_iter; bool first = true; @@ -94,10 +94,10 @@ class TestHandler : public ThriftTestIf { printf("%d", *s_iter); } printf("})\n"); - return thing; + out = thing; } - vector testList(vector thing) { + void testList(vector &out, const vector &thing) { printf("testList({"); vector::const_iterator l_iter; bool first = true; @@ -110,22 +110,21 @@ class TestHandler : public ThriftTestIf { printf("%d", *l_iter); } printf("})\n"); - return thing; + out = thing; } - Numberz testEnum(Numberz thing) { + Numberz testEnum(const Numberz thing) { printf("testEnum(%d)\n", thing); return thing; } - UserId testTypedef(UserId thing) { + UserId testTypedef(const UserId thing) { printf("testTypedef(%ld)\n", thing); return thing; } - map > testMapMap(int32_t hello) { + void testMapMap(map > &mapmap, const int32_t hello) { printf("testMapMap(%d)\n", hello); - map > mapmap; map pos; map neg; @@ -137,10 +136,9 @@ class TestHandler : public ThriftTestIf { mapmap.insert(make_pair(4, pos)); mapmap.insert(make_pair(-4, neg)); - return mapmap; } - map > testInsanity(Insanity argument) { + void testInsanity(map > &insane, const Insanity &argument) { printf("testInsanity()\n"); Xtruct hello; @@ -171,7 +169,6 @@ class TestHandler : public ThriftTestIf { second_map.insert(make_pair(SIX, looney)); - map > insane; insane.insert(make_pair(1, first_map)); insane.insert(make_pair(2, second_map)); @@ -207,22 +204,19 @@ class TestHandler : public ThriftTestIf { } printf("}\n"); - return insane; + } - Xtruct testMulti(int8_t arg0, int32_t arg1, int64_t arg2, std::map arg3, Numberz arg4, UserId arg5) { + void testMulti(Xtruct &hello, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map &arg3, const Numberz arg4, const UserId arg5) { printf("testMulti()\n"); - Xtruct hello; hello.string_thing = "Hello2"; hello.byte_thing = arg0; hello.i32_thing = arg1; hello.i64_thing = (int64_t)arg2; - - return hello; } - void testException(std::string arg) throw(Xception) { + void testException(const std::string &arg) throw(Xception) { printf("testException(%s)\n", arg.c_str()); if (arg.compare("Xception") == 0) { Xception e; @@ -236,7 +230,7 @@ class TestHandler : public ThriftTestIf { } } - Xtruct testMultiException(std::string arg0, std::string arg1) throw(Xception, Xception2) { + void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) { printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str()); @@ -251,9 +245,8 @@ class TestHandler : public ThriftTestIf { e.struct_thing.string_thing = "This is an Xception2"; throw e; } else { - Xtruct result; result.string_thing = arg1; - return result; + return; } } }; -- 2.17.1