blob: da20b892e451d36f4c28ea6031ad5f419ed680c3 [file] [log] [blame]
James E. King, III7edc8fa2017-01-20 10:11:41 -05001/*
David Reissea2cba82009-03-30 21:35:00 +00002 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +090020#include <limits>
21#include <locale>
22#include <ios>
Roger Meierca142b02011-06-07 17:59:07 +000023#include <iostream>
Sebastian Zenker39e505c2015-12-18 16:15:08 +010024#include <sstream>
Roger Meier49ff8b12012-04-13 09:12:31 +000025#include <thrift/protocol/TBinaryProtocol.h>
Roger Meier023192f2014-02-12 09:35:12 +010026#include <thrift/protocol/TCompactProtocol.h>
Dave Watson792db4e2015-01-16 11:22:01 -080027#include <thrift/protocol/THeaderProtocol.h>
Roger Meier49ff8b12012-04-13 09:12:31 +000028#include <thrift/protocol/TJSONProtocol.h>
29#include <thrift/transport/THttpClient.h>
30#include <thrift/transport/TTransportUtils.h>
31#include <thrift/transport/TSocket.h>
32#include <thrift/transport/TSSLSocket.h>
33#include <thrift/async/TEvhttpClientChannel.h>
34#include <thrift/server/TNonblockingServer.h> // <event.h>
Mark Sleee8540632006-05-30 09:24:40 +000035
James E. King, III7edc8fa2017-01-20 10:11:41 -050036#ifdef HAVE_STDINT_H
37#include <stdint.h>
38#endif
39#ifdef HAVE_INTTYPES_H
40#include <inttypes.h>
41#endif
42
Marc Slemko6be374b2006-08-04 03:16:25 +000043#include <boost/shared_ptr.hpp>
Roger Meierca142b02011-06-07 17:59:07 +000044#include <boost/program_options.hpp>
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053045#include <boost/filesystem.hpp>
Jake Farrell5d02b802014-01-07 21:42:01 -050046#include <thrift/cxxfunctional.h>
47#if _WIN32
Konrad Grochowski16a23a62014-11-13 15:33:38 +010048#include <thrift/windows/TWinsockSingleton.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050049#endif
Roger Meierca142b02011-06-07 17:59:07 +000050
Marc Slemko6be374b2006-08-04 03:16:25 +000051#include "ThriftTest.h"
52
Marc Slemko6be374b2006-08-04 03:16:25 +000053using namespace std;
T Jake Lucianib5e62212009-01-31 22:36:20 +000054using namespace apache::thrift;
55using namespace apache::thrift::protocol;
56using namespace apache::thrift::transport;
Marc Slemkobf4fd192006-08-15 21:29:39 +000057using namespace thrift::test;
Roger Meier7e056e72011-07-17 07:28:28 +000058using namespace apache::thrift::async;
59
Mark Slee95771002006-06-07 06:53:25 +000060// Current time, microseconds since the epoch
Konrad Grochowski16a23a62014-11-13 15:33:38 +010061uint64_t now() {
Roger Meier5f9614c2010-11-21 16:59:05 +000062 int64_t ret;
Mark Slee95771002006-06-07 06:53:25 +000063 struct timeval tv;
David Reiss0c90f6f2008-02-06 22:18:40 +000064
Jake Farrell5d02b802014-01-07 21:42:01 -050065 THRIFT_GETTIMEOFDAY(&tv, NULL);
Mark Slee95771002006-06-07 06:53:25 +000066 ret = tv.tv_sec;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010067 ret = ret * 1000 * 1000 + tv.tv_usec;
Mark Slee95771002006-06-07 06:53:25 +000068 return ret;
69}
70
Sebastian Zenker39e505c2015-12-18 16:15:08 +010071static void testString_clientReturn(event_base* base,
72 int testNr,
Konrad Grochowski16a23a62014-11-13 15:33:38 +010073 ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000074 try {
75 string s;
76 client->recv_testString(s);
Sebastian Zenker39e505c2015-12-18 16:15:08 +010077 std::ostringstream os;
78 os << "test" << testNr;
79 const bool ok = (s == os.str());
80 cout << "testString: " << s << " " << ((ok) ? "ok" : "failed") << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000081 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -050082 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000083 }
84
Sebastian Zenker39e505c2015-12-18 16:15:08 +010085 if (testNr == 9)
86 event_base_loopbreak(base); // end test
Roger Meier7e056e72011-07-17 07:28:28 +000087}
88
Sebastian Zenker39e505c2015-12-18 16:15:08 +010089static void testVoid_clientReturn(event_base* base, ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000090 try {
91 client->recv_testVoid();
92 cout << "testVoid" << endl;
93
Sebastian Zenker39e505c2015-12-18 16:15:08 +010094 for (int testNr = 0; testNr < 10; ++testNr) {
95 std::ostringstream os;
96 os << "test" << testNr;
97 client->testString(tcxx::bind(testString_clientReturn,
98 base,
99 testNr,
100 tcxx::placeholders::_1),
101 os.str());
102 }
Roger Meier7e056e72011-07-17 07:28:28 +0000103 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500104 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +0000105 }
106}
107
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900108// Workaround for absense of C++11 "auto" keyword.
109template <typename T>
110bool print_eq(T expected, T actual) {
111 cout << "(" << actual << ")" << endl;
112 if (expected != actual) {
113 cout << "*** FAILED ***" << endl << "Expected: " << expected << " but got: " << actual << endl;
114 return false;
115 }
116 return true;
117}
118
119#define BASETYPE_IDENTITY_TEST(func, value) \
120 cout << #func "(" << value << ") = "; \
121 try { \
122 if (!print_eq(value, testClient.func(value))) \
123 return_code |= ERR_BASETYPES; \
124 } catch (TTransportException&) { \
125 throw; \
126 } catch (exception & ex) { \
127 cout << "*** FAILED ***" << endl << ex.what() << endl; \
128 return_code |= ERR_BASETYPES; \
129 }
130
Mark Sleee8540632006-05-30 09:24:40 +0000131int main(int argc, char** argv) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900132 cout.precision(19);
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900133 int ERR_BASETYPES = 1;
134 int ERR_STRUCTS = 2;
135 int ERR_CONTAINERS = 4;
136 int ERR_EXCEPTIONS = 8;
137 int ERR_UNKNOWN = 64;
138
Nobuaki Sukegawac8744082016-03-09 19:55:56 +0900139 string testDir = boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string();
140 string pemPath = testDir + "/keys/CA.pem";
Jake Farrell5d02b802014-01-07 21:42:01 -0500141#if _WIN32
142 transport::TWinsockSingleton::create();
143#endif
Mark Sleee8540632006-05-30 09:24:40 +0000144 string host = "localhost";
145 int port = 9090;
146 int numTests = 1;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000147 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000148 string transport_type = "buffered";
149 string protocol_type = "binary";
150 string domain_socket = "";
pavlodd08f6e2015-10-08 16:43:56 -0400151 bool abstract_namespace = false;
Jens Geyerf4598682014-05-08 23:18:44 +0200152 bool noinsane = false;
Mark Sleee8540632006-05-30 09:24:40 +0000153
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900154 int return_code = 0;
155
Jake Farrell5d02b802014-01-07 21:42:01 -0500156 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100157 desc.add_options()("help,h",
158 "produce help message")("host",
159 boost::program_options::value<string>(&host)
160 ->default_value(host),
161 "Host to connect")("port",
162 boost::program_options::value<int>(
163 &port)->default_value(port),
164 "Port number to connect")(
165 "domain-socket",
166 boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
167 "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")(
pavlodd08f6e2015-10-08 16:43:56 -0400168 "abstract-namespace",
169 "Look for the domain socket in the Abstract Namespace (no connection with filesystem pathnames)")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100170 "transport",
171 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
172 "Transport: buffered, framed, http, evhttp")(
173 "protocol",
174 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
Dave Watson792db4e2015-01-16 11:22:01 -0800175 "Protocol: binary, header, compact, json")("ssl", "Encrypted Transport using SSL")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100176 "testloops,n",
177 boost::program_options::value<int>(&numTests)->default_value(numTests),
178 "Number of Tests")("noinsane", "Do not run insanity test");
Roger Meierca142b02011-06-07 17:59:07 +0000179
Jake Farrell5d02b802014-01-07 21:42:01 -0500180 boost::program_options::variables_map vm;
181 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
182 boost::program_options::notify(vm);
Roger Meierca142b02011-06-07 17:59:07 +0000183
184 if (vm.count("help")) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900185 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900186 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000187 }
Mark Sleea3302652006-10-25 19:03:32 +0000188
Jake Farrell5d02b802014-01-07 21:42:01 -0500189 try {
Roger Meierca142b02011-06-07 17:59:07 +0000190 if (!protocol_type.empty()) {
191 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100192 } else if (protocol_type == "compact") {
Dave Watson792db4e2015-01-16 11:22:01 -0800193 } else if (protocol_type == "header") {
Roger Meierca142b02011-06-07 17:59:07 +0000194 } else if (protocol_type == "json") {
195 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100196 throw invalid_argument("Unknown protocol type " + protocol_type);
Roger Meierca142b02011-06-07 17:59:07 +0000197 }
198 }
199
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100200 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000201 if (transport_type == "buffered") {
202 } else if (transport_type == "framed") {
203 } else if (transport_type == "http") {
Roger Meier7e056e72011-07-17 07:28:28 +0000204 } else if (transport_type == "evhttp") {
Roger Meierca142b02011-06-07 17:59:07 +0000205 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100206 throw invalid_argument("Unknown transport type " + transport_type);
Roger Meierca142b02011-06-07 17:59:07 +0000207 }
208 }
209
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900210 } catch (exception& e) {
Roger Meierca142b02011-06-07 17:59:07 +0000211 cerr << e.what() << endl;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900212 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900213 return ERR_UNKNOWN;
Roger Meierca142b02011-06-07 17:59:07 +0000214 }
215
216 if (vm.count("ssl")) {
217 ssl = true;
218 }
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530219
pavlodd08f6e2015-10-08 16:43:56 -0400220 if (vm.count("abstract-namespace")) {
221 abstract_namespace = true;
222 }
223
Jens Geyerf4598682014-05-08 23:18:44 +0200224 if (vm.count("noinsane")) {
225 noinsane = true;
226 }
Roger Meierca142b02011-06-07 17:59:07 +0000227
Roger Meier611f90c2011-12-11 22:08:51 +0000228 boost::shared_ptr<TTransport> transport;
229 boost::shared_ptr<TProtocol> protocol;
Roger Meierca142b02011-06-07 17:59:07 +0000230
Roger Meier611f90c2011-12-11 22:08:51 +0000231 boost::shared_ptr<TSocket> socket;
232 boost::shared_ptr<TSSLSocketFactory> factory;
Roger Meierca142b02011-06-07 17:59:07 +0000233
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000234 if (ssl) {
Roger Meier611f90c2011-12-11 22:08:51 +0000235 factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000236 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Nobuaki Sukegawac8744082016-03-09 19:55:56 +0900237 factory->loadTrustedCertificates(pemPath.c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000238 factory->authenticate(true);
239 socket = factory->createSocket(host, port);
240 } else {
Roger Meierca142b02011-06-07 17:59:07 +0000241 if (domain_socket != "") {
pavlodd08f6e2015-10-08 16:43:56 -0400242 if (abstract_namespace) {
243 std::string abstract_socket("\0", 1);
244 abstract_socket += domain_socket;
245 socket = boost::shared_ptr<TSocket>(new TSocket(abstract_socket));
246 } else {
247 socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket));
248 }
Roger Meierca142b02011-06-07 17:59:07 +0000249 port = 0;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100250 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000251 socket = boost::shared_ptr<TSocket>(new TSocket(host, port));
Roger Meierca142b02011-06-07 17:59:07 +0000252 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000253 }
Mark Sleea3302652006-10-25 19:03:32 +0000254
Roger Meierca142b02011-06-07 17:59:07 +0000255 if (transport_type.compare("http") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000256 boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service"));
Roger Meierca142b02011-06-07 17:59:07 +0000257 transport = httpSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100258 } else if (transport_type.compare("framed") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000259 boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000260 transport = framedSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100261 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000262 boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000263 transport = bufferedSocket;
264 }
265
Roger Meierca142b02011-06-07 17:59:07 +0000266 if (protocol_type.compare("json") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000267 boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000268 protocol = jsonProtocol;
Roger Meier023192f2014-02-12 09:35:12 +0100269 } else if (protocol_type.compare("compact") == 0) {
270 boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport));
271 protocol = compactProtocol;
Dave Watson792db4e2015-01-16 11:22:01 -0800272 } else if (protocol_type == "header") {
273 boost::shared_ptr<TProtocol> headerProtocol(new THeaderProtocol(transport));
274 protocol = headerProtocol;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100275 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000276 boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000277 protocol = binaryProtocol;
278 }
279
280 // Connection info
pavlodd08f6e2015-10-08 16:43:56 -0400281 cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: ";
282 if (abstract_namespace) {
283 cout << '@';
284 }
285 cout << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000286 if (port != 0) {
287 cout << host << ":" << port;
288 }
289 cout << endl;
290
Roger Meier7e056e72011-07-17 07:28:28 +0000291 if (transport_type.compare("evhttp") == 0) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100292 event_base* base = event_base_new();
Roger Meier7e056e72011-07-17 07:28:28 +0000293 cout << "Libevent Version: " << event_get_version() << endl;
294 cout << "Libevent Method: " << event_base_get_method(base) << endl;
295#if LIBEVENT_VERSION_NUMBER >= 0x02000000
296 cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl;
297#endif
298
Roger Meier611f90c2011-12-11 22:08:51 +0000299 boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Roger Meier7e056e72011-07-17 07:28:28 +0000300
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100301 boost::shared_ptr<TAsyncChannel> channel(
302 new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
Roger Meier7e056e72011-07-17 07:28:28 +0000303 ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100304 client->testVoid(tcxx::bind(testVoid_clientReturn,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100305 base,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100306 tcxx::placeholders::_1));
Jake Farrell5d02b802014-01-07 21:42:01 -0500307
Roger Meier7e056e72011-07-17 07:28:28 +0000308 event_base_loop(base, 0);
309 return 0;
310 }
311
Roger Meierca142b02011-06-07 17:59:07 +0000312 ThriftTestClient testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000313
314 uint64_t time_min = 0;
315 uint64_t time_max = 0;
316 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000317
Mark Sleee8540632006-05-30 09:24:40 +0000318 int test = 0;
319 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000320
Mark Slee95771002006-06-07 06:53:25 +0000321 try {
Mark Sleea3302652006-10-25 19:03:32 +0000322 transport->open();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900323 } catch (TTransportException& ex) {
324 cout << "Connect failed: " << ex.what() << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900325 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000326 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000327
Mark Sleed788b2e2006-09-07 01:26:35 +0000328 /**
329 * CONNECT TEST
330 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100331 printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000332
333 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000334
Mark Sleee8540632006-05-30 09:24:40 +0000335 /**
336 * VOID TEST
337 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000338 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900339 cout << "testVoid()" << flush;
Mark Sleee129a2d2007-02-21 05:17:48 +0000340 testClient.testVoid();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900341 cout << " = void" << endl;
342 } catch (TTransportException&) {
343 // Stop here if transport got broken
344 throw;
345 } catch (exception& ex) {
346 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200347 return_code |= ERR_BASETYPES;
Mark Sleee129a2d2007-02-21 05:17:48 +0000348 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000349
Mark Sleee8540632006-05-30 09:24:40 +0000350 /**
351 * STRING TEST
352 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900353 cout << "testString(\"Test\")" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000354 string s;
355 testClient.testString(s, "Test");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900356 cout << " = " << s << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200357 if (s != "Test") {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900358 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200359 return_code |= ERR_BASETYPES;
360 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000361
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900362 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500363#ifdef _MSC_VER
364#pragma warning( push )
365#pragma warning( disable : 4566 )
366#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900367 string str(
368 "}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, "
369 "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, "
370 "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, "
371 "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, "
372 "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, "
373 "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, "
374 "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, "
375 "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, "
376 "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, "
377 "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, "
378 "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, "
379 "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, "
380 "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, "
381 "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa "
382 "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa "
383 "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪"
384 "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, "
385 "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, "
386 "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, "
387 "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple "
388 "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, "
389 "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, "
390 "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, "
391 "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, "
392 "Bân-lâm-gú, 粵語");
James E. King, III7edc8fa2017-01-20 10:11:41 -0500393#ifdef _MSC_VER
394#pragma warning( pop )
395#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900396 cout << "testString(" << str << ") = " << flush;
397 testClient.testString(s, str);
398 cout << s << endl;
399 if (s != str) {
400 cout.imbue(locale("en_US.UTF8"));
401 cout << "*** FAILED ***" << endl << "Expected string: " << str << " but got: " << s << endl << "CLEAR";
402 return_code |= ERR_BASETYPES;
403 }
404 } catch (TTransportException&) {
405 throw;
406 } catch (exception& ex) {
407 cout << "*** FAILED ***" << endl << ex.what() << endl;
408 return_code |= ERR_BASETYPES;
409 return return_code;
410 }
411 try {
412 string str(
413 "quote: \" backslash:"
414 " forwardslash-escaped: \\/ "
415 " backspace: \b formfeed: \f newline: \n return: \r tab: "
416 " now-all-of-them-together: \"\\\\/\b\n\r\t"
417 " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><"
418 " char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ ");
419 cout << "testString(" << str << ") = " << flush;
420 testClient.testString(s, str);
421 cout << s << endl;
422 if (s != str) {
423 cout.imbue(locale("en_US.UTF8"));
424 cout << "*** FAILED ***" << endl
425 << "Expected string: " << str << " but got: " << s << endl
426 << "CLEAR";
427 ;
428 return_code |= ERR_BASETYPES;
429 }
430 } catch (TTransportException&) {
431 throw;
432 } catch (exception& ex) {
433 cout << "*** FAILED ***" << endl << ex.what() << endl;
434 return_code |= ERR_BASETYPES;
435 return return_code;
436 }
437
Mark Sleee8540632006-05-30 09:24:40 +0000438 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900439 * BOOL TEST
440 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900441 cout << boolalpha;
442 BASETYPE_IDENTITY_TEST(testBool, true);
443 BASETYPE_IDENTITY_TEST(testBool, false);
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900444
445 /**
Mark Sleee8540632006-05-30 09:24:40 +0000446 * BYTE TEST
447 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900448 BASETYPE_IDENTITY_TEST(testByte, (int8_t)0);
449 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-1);
450 BASETYPE_IDENTITY_TEST(testByte, (int8_t)42);
451 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-42);
452 BASETYPE_IDENTITY_TEST(testByte, (int8_t)127);
453 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-128);
David Reiss0c90f6f2008-02-06 22:18:40 +0000454
Mark Sleee8540632006-05-30 09:24:40 +0000455 /**
456 * I32 TEST
457 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900458 BASETYPE_IDENTITY_TEST(testI32, 0);
459 BASETYPE_IDENTITY_TEST(testI32, -1);
460 BASETYPE_IDENTITY_TEST(testI32, 190000013);
461 BASETYPE_IDENTITY_TEST(testI32, -190000013);
462 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::max());
463 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::min());
Mark Sleee8540632006-05-30 09:24:40 +0000464
465 /**
Mark Sleee8540632006-05-30 09:24:40 +0000466 * I64 TEST
467 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900468 BASETYPE_IDENTITY_TEST(testI64, (int64_t)0);
469 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1);
470 BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL);
471 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500472 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32));
473 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32));
474 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32) + 1);
475 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32) - 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900476 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::max());
477 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::min());
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100478
Mark Sleec98d0502006-09-06 02:42:25 +0000479 /**
480 * DOUBLE TEST
481 */
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900482 // Comparing double values with plain equality because Thrift handles full precision of double
483 BASETYPE_IDENTITY_TEST(testDouble, 0.0);
484 BASETYPE_IDENTITY_TEST(testDouble, -1.0);
485 BASETYPE_IDENTITY_TEST(testDouble, -5.2098523);
486 BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500487 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32));
488 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32) + 1);
489 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 53) - 1);
490 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32));
491 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32) - 1);
492 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 53) + 1);
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900493
494 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500495 double expected = pow(static_cast<double>(10), 307);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900496 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900497 double actual = testClient.testDouble(expected);
498 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500499 if (expected - actual > pow(static_cast<double>(10), 292)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900500 cout << "*** FAILED ***" << endl
501 << "Expected: " << expected << " but got: " << actual << endl;
502 }
503 } catch (TTransportException&) {
504 throw;
505 } catch (exception& ex) {
506 cout << "*** FAILED ***" << endl << ex.what() << endl;
507 return_code |= ERR_BASETYPES;
508 }
509
510 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500511 double expected = pow(static_cast<double>(10), -292);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900512 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900513 double actual = testClient.testDouble(expected);
514 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500515 if (expected - actual > pow(static_cast<double>(10), -307)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900516 cout << "*** FAILED ***" << endl
517 << "Expected: " << expected << " but got: " << actual << endl;
518 }
519 } catch (TTransportException&) {
520 throw;
521 } catch (exception& ex) {
522 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200523 return_code |= ERR_BASETYPES;
524 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000525
Mark Sleee8540632006-05-30 09:24:40 +0000526 /**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100527 * BINARY TEST
528 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900529 cout << "testBinary(empty)" << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900530 try {
531 string bin_result;
532 testClient.testBinary(bin_result, string());
533 if (!bin_result.empty()) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900534 cout << endl << "*** FAILED ***" << endl;
535 cout << "invalid length: " << bin_result.size() << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900536 return_code |= ERR_BASETYPES;
537 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900538 } catch (TTransportException&) {
539 throw;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900540 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900541 cout << "*** FAILED ***" << endl << ex.what() << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900542 return_code |= ERR_BASETYPES;
543 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900544 cout << "testBinary([-128..127]) = {" << flush;
Cody P Schafer31295492016-09-09 15:50:26 -0400545 const signed char bin_data[256]
Jens Geyerd629ea02015-09-23 21:16:50 +0200546 = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
547 -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
548 -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
549 -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
550 -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
551 -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
552 -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
553 -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
554 -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
555 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
556 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
557 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
558 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
559 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
560 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
561 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
562 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
563 127};
564 try {
565 string bin_result;
Cody P Schafer31295492016-09-09 15:50:26 -0400566 testClient.testBinary(bin_result, string(reinterpret_cast<const char *>(bin_data), 256));
Jens Geyerd629ea02015-09-23 21:16:50 +0200567 if (bin_result.size() != 256) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900568 cout << endl << "*** FAILED ***" << endl;
569 cout << "invalid length: " << bin_result.size() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200570 return_code |= ERR_BASETYPES;
571 } else {
572 bool first = true;
573 bool failed = false;
574 for (int i = 0; i < 256; ++i) {
575 if (!first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900576 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200577 else
578 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900579 cout << static_cast<int>(bin_result[i]);
Jens Geyerd629ea02015-09-23 21:16:50 +0200580 if (!failed && bin_result[i] != i - 128) {
581 failed = true;
582 }
583 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900584 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200585 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900586 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200587 return_code |= ERR_BASETYPES;
588 }
589 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900590 } catch (TTransportException&) {
591 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200592 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900593 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200594 return_code |= ERR_BASETYPES;
595 }
596
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100597
598 /**
Mark Sleee8540632006-05-30 09:24:40 +0000599 * STRUCT TEST
600 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900601 cout << "testStruct({\"Zero\", 1, -3, -5})" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000602 Xtruct out;
603 out.string_thing = "Zero";
604 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000605 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000606 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000607 Xtruct in;
608 testClient.testStruct(in, out);
Roger Meier0e814802014-01-17 21:07:58 +0100609 printf(" = {\"%s\", %d, %d, %" PRId64 "}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000610 in.string_thing.c_str(),
611 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000612 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000613 in.i64_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200614 if (in != out) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900615 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200616 return_code |= ERR_STRUCTS;
617 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000618
Mark Sleee8540632006-05-30 09:24:40 +0000619 /**
620 * NESTED STRUCT TEST
621 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900622 cout << "testNest({1, {\"Zero\", 1, -3, -5}), 5}" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000623 Xtruct2 out2;
624 out2.byte_thing = 1;
625 out2.struct_thing = out;
626 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000627 Xtruct2 in2;
628 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000629 in = in2.struct_thing;
Roger Meier0e814802014-01-17 21:07:58 +0100630 printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000631 in2.byte_thing,
632 in.string_thing.c_str(),
633 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000634 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000635 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000636 in2.i32_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200637 if (in2 != out2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900638 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200639 return_code |= ERR_STRUCTS;
640 }
Mark Sleee8540632006-05-30 09:24:40 +0000641
642 /**
643 * MAP TEST
644 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100645 map<int32_t, int32_t> mapout;
Mark Sleee8540632006-05-30 09:24:40 +0000646 for (int32_t i = 0; i < 5; ++i) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100647 mapout.insert(make_pair(i, i - 10));
Mark Sleee8540632006-05-30 09:24:40 +0000648 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900649 cout << "testMap({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000650 map<int32_t, int32_t>::const_iterator m_iter;
651 bool first = true;
652 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
653 if (first) {
654 first = false;
655 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900656 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000657 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900658 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000659 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900660 cout << "})";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100661 map<int32_t, int32_t> mapin;
Mark Slee1921d202007-01-24 19:43:06 +0000662 testClient.testMap(mapin, mapout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900663 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000664 first = true;
665 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
666 if (first) {
667 first = false;
668 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900669 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000670 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900671 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000672 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900673 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200674 if (mapin != mapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900675 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200676 return_code |= ERR_CONTAINERS;
677 }
Roger Meier4fce9602012-05-04 06:22:09 +0000678
679 /**
680 * STRING MAP TEST
Roger Meier4fce9602012-05-04 06:22:09 +0000681 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900682 cout << "testStringMap({a => 2, b => blah, some => thing}) = {" << flush;
Jens Geyerd629ea02015-09-23 21:16:50 +0200683 map<string, string> smapin;
684 map<string, string> smapout;
685 smapin["a"] = "2";
686 smapin["b"] = "blah";
687 smapin["some"] = "thing";
688 try {
689 testClient.testStringMap(smapout, smapin);
690 first = true;
691 for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) {
692 if (first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900693 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200694 else
695 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900696 cout << it->first << " => " << it->second;
Jens Geyerd629ea02015-09-23 21:16:50 +0200697 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900698 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200699 if (smapin != smapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900700 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200701 return_code |= ERR_CONTAINERS;
702 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900703 } catch (TTransportException&) {
704 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200705 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900706 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200707 return_code |= ERR_CONTAINERS;
708 }
Mark Sleee8540632006-05-30 09:24:40 +0000709
710 /**
711 * SET TEST
712 */
713 set<int32_t> setout;
714 for (int32_t i = -2; i < 3; ++i) {
715 setout.insert(i);
716 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900717 cout << "testSet({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000718 set<int32_t>::const_iterator s_iter;
719 first = true;
720 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
721 if (first) {
722 first = false;
723 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900724 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000725 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900726 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000727 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900728 cout << "})";
Mark Slee1921d202007-01-24 19:43:06 +0000729 set<int32_t> setin;
730 testClient.testSet(setin, setout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900731 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000732 first = true;
733 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
734 if (first) {
735 first = false;
736 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900737 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000738 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900739 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000740 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900741 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200742 if (setin != setout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900743 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200744 return_code |= ERR_CONTAINERS;
745 }
Mark Sleee8540632006-05-30 09:24:40 +0000746
747 /**
748 * LIST TEST
749 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900750 cout << "testList(empty)" << flush;
751 try {
752 vector<int32_t> listout;
753 testClient.testList(listout, vector<int32_t>());
754 if (!listout.empty()) {
755 cout << "*** FAILED ***" << endl;
756 cout << "invalid length: " << listout.size() << endl;
757 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000758 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900759 } catch (TTransportException&) {
760 throw;
761 } catch (exception& ex) {
762 cout << "*** FAILED ***" << endl << ex.what() << endl;
763 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000764 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900765 try {
766 vector<int32_t> listout;
767 for (int32_t i = -2; i < 3; ++i) {
768 listout.push_back(i);
Mark Sleee8540632006-05-30 09:24:40 +0000769 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900770 cout << "testList({" << flush;
771 vector<int32_t>::const_iterator l_iter;
772 first = true;
773 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
774 if (first) {
775 first = false;
776 } else {
777 cout << ",";
778 }
779 cout << *l_iter;
780 }
781 cout << "})";
782 vector<int32_t> listin;
783 testClient.testList(listin, listout);
784 cout << " = {";
785 first = true;
786 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
787 if (first) {
788 first = false;
789 } else {
790 cout << ",";
791 }
792 cout << *l_iter;
793 }
794 cout << "}" << endl;
795 if (listin != listout) {
796 cout << "*** FAILED ***" << endl;
797 return_code |= ERR_CONTAINERS;
798 }
799 } catch (TTransportException&) {
800 throw;
801 } catch (exception& ex) {
802 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200803 return_code |= ERR_CONTAINERS;
804 }
Mark Sleee8540632006-05-30 09:24:40 +0000805
806 /**
807 * ENUM TEST
808 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900809 cout << "testEnum(ONE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000810 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900811 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200812 if (ret != Numberz::ONE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900813 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200814 return_code |= ERR_STRUCTS;
815 }
Mark Sleee8540632006-05-30 09:24:40 +0000816
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900817 cout << "testEnum(TWO)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000818 ret = testClient.testEnum(Numberz::TWO);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900819 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200820 if (ret != Numberz::TWO) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900821 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200822 return_code |= ERR_STRUCTS;
823 }
Mark Sleee8540632006-05-30 09:24:40 +0000824
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900825 cout << "testEnum(THREE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000826 ret = testClient.testEnum(Numberz::THREE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900827 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200828 if (ret != Numberz::THREE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900829 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200830 return_code |= ERR_STRUCTS;
831 }
Mark Sleee8540632006-05-30 09:24:40 +0000832
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900833 cout << "testEnum(FIVE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000834 ret = testClient.testEnum(Numberz::FIVE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900835 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200836 if (ret != Numberz::FIVE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900837 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200838 return_code |= ERR_STRUCTS;
839 }
Mark Sleee8540632006-05-30 09:24:40 +0000840
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900841 cout << "testEnum(EIGHT)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000842 ret = testClient.testEnum(Numberz::EIGHT);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900843 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200844 if (ret != Numberz::EIGHT) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900845 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200846 return_code |= ERR_STRUCTS;
847 }
Mark Sleee8540632006-05-30 09:24:40 +0000848
849 /**
850 * TYPEDEF TEST
851 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900852 cout << "testTypedef(309858235082523)" << flush;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000853 UserId uid = testClient.testTypedef(309858235082523LL);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900854 cout << " = " << uid << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200855 if (uid != 309858235082523LL) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900856 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200857 return_code |= ERR_STRUCTS;
858 }
Mark Sleee8540632006-05-30 09:24:40 +0000859
860 /**
861 * NESTED MAP TEST
862 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900863 cout << "testMapMap(1)" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000864 map<int32_t, map<int32_t, int32_t> > mm;
865 testClient.testMapMap(mm, 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900866 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000867 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
868 for (mi = mm.begin(); mi != mm.end(); ++mi) {
869 printf("%d => {", mi->first);
870 map<int32_t, int32_t>::const_iterator mi2;
871 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900872 cout << mi2->first << " => " << mi2->second;
Mark Sleee8540632006-05-30 09:24:40 +0000873 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900874 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000875 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900876 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200877 if (mm.size() != 2 ||
878 mm[-4][-4] != -4 ||
879 mm[-4][-3] != -3 ||
880 mm[-4][-2] != -2 ||
881 mm[-4][-1] != -1 ||
882 mm[4][4] != 4 ||
883 mm[4][3] != 3 ||
884 mm[4][2] != 2 ||
885 mm[4][1] != 1) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900886 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200887 return_code |= ERR_CONTAINERS;
888 }
Mark Sleee8540632006-05-30 09:24:40 +0000889
890 /**
891 * INSANITY TEST
892 */
Jens Geyerf4598682014-05-08 23:18:44 +0200893 if (!noinsane) {
894 Insanity insane;
Jens Geyerd629ea02015-09-23 21:16:50 +0200895 insane.userMap.insert(make_pair(Numberz::FIVE, 5));
896 insane.userMap.insert(make_pair(Numberz::EIGHT, 8));
Jens Geyerf4598682014-05-08 23:18:44 +0200897 Xtruct truck;
Jens Geyerd629ea02015-09-23 21:16:50 +0200898 truck.string_thing = "Goodbye4";
899 truck.byte_thing = 4;
900 truck.i32_thing = 4;
901 truck.i64_thing = 4;
902 Xtruct truck2;
903 truck2.string_thing = "Hello2";
904 truck2.byte_thing = 2;
905 truck2.i32_thing = 2;
906 truck2.i64_thing = 2;
Jens Geyerf4598682014-05-08 23:18:44 +0200907 insane.xtructs.push_back(truck);
Jens Geyerd629ea02015-09-23 21:16:50 +0200908 insane.xtructs.push_back(truck2);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900909 cout << "testInsanity()" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100910 map<UserId, map<Numberz::type, Insanity> > whoa;
Jens Geyerf4598682014-05-08 23:18:44 +0200911 testClient.testInsanity(whoa, insane);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900912 cout << " = {";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100913 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Jens Geyerf4598682014-05-08 23:18:44 +0200914 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
915 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100916 map<Numberz::type, Insanity>::const_iterator i2_iter;
917 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Jens Geyerf4598682014-05-08 23:18:44 +0200918 printf("%d => {", i2_iter->first);
919 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
920 map<Numberz::type, UserId>::const_iterator um;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900921 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200922 for (um = userMap.begin(); um != userMap.end(); ++um) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900923 cout << um->first << " => " << um->second;
Jens Geyerf4598682014-05-08 23:18:44 +0200924 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900925 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000926
Jens Geyerf4598682014-05-08 23:18:44 +0200927 vector<Xtruct> xtructs = i2_iter->second.xtructs;
928 vector<Xtruct>::const_iterator x;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900929 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200930 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
931 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
932 x->string_thing.c_str(),
933 (int)x->byte_thing,
934 x->i32_thing,
935 x->i64_thing);
936 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900937 cout << "}";
Mark Sleee8540632006-05-30 09:24:40 +0000938
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900939 cout << "}, ";
Jens Geyerf4598682014-05-08 23:18:44 +0200940 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900941 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000942 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900943 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200944 bool failed = false;
945 map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1));
946 if (whoa.size() != 2) {
947 failed = true;
948 }
949 if (it1 == whoa.end()) {
950 failed = true;
951 } else {
952 map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO);
953 if (it12 == it1->second.end() || it12->second != insane) {
954 failed = true;
955 }
956 map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE);
957 if (it13 == it1->second.end() || it13->second != insane) {
958 failed = true;
959 }
960 }
961 map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2));
962 if (it2 == whoa.end()) {
963 failed = true;
964 } else {
965 map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX);
966 if (it26 == it1->second.end() || it26->second != Insanity()) {
967 failed = true;
968 }
969 }
970 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900971 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200972 return_code |= ERR_STRUCTS;
973 }
Mark Sleee8540632006-05-30 09:24:40 +0000974 }
Jens Geyerd629ea02015-09-23 21:16:50 +0200975
976 /**
977 * MULTI TEST
978 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900979 cout << "testMulti()" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200980 try {
981 map<int16_t, string> mul_map;
982 Xtruct mul_result;
983 mul_map[1] = "blah";
984 mul_map[2] = "thing";
985 testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24));
986 Xtruct xxs;
987 xxs.string_thing = "Hello2";
988 xxs.byte_thing = 42;
989 xxs.i32_thing = 4242;
990 xxs.i64_thing = 424242;
991 if (mul_result != xxs) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900992 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200993 return_code |= ERR_STRUCTS;
994 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900995 } catch (TTransportException&) {
996 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200997 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900998 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200999 return_code |= ERR_STRUCTS;
1000 }
1001
Marc Slemko71d4e472006-08-15 22:34:04 +00001002 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +00001003
Marc Slemkobf4fd192006-08-15 21:29:39 +00001004 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001005 cout << "testClient.testException(\"Xception\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001006 testClient.testException("Xception");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001007 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001008 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001009
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001010 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001011 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001012 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001013
Marc Slemkobf4fd192006-08-15 21:29:39 +00001014 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001015 cout << "testClient.testException(\"TException\") =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001016 testClient.testException("TException");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001017 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001018 return_code |= ERR_EXCEPTIONS;
Roger Meierf50df7f2012-05-02 22:49:55 +00001019
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001020 } catch (const TException&) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001021 cout << " Caught TException" << endl;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001022 }
Roger Meierf50df7f2012-05-02 22:49:55 +00001023
1024 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001025 cout << "testClient.testException(\"success\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001026 testClient.testException("success");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001027 cout << " void" << endl;
1028 } catch (exception & ex) { \
1029 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001030 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001031 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001032
Marc Slemko71d4e472006-08-15 22:34:04 +00001033 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +00001034
Marc Slemko71d4e472006-08-15 22:34:04 +00001035 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001036 cout << "testClient.testMultiException(\"Xception\", \"test 1\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001037 Xtruct result;
1038 testClient.testMultiException(result, "Xception", "test 1");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001039 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001040 return_code |= ERR_EXCEPTIONS;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001041 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001042 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
1043 }
1044
1045 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001046 cout << "testClient.testMultiException(\"Xception2\", \"test 2\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001047 Xtruct result;
1048 testClient.testMultiException(result, "Xception2", "test 2");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001049 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001050 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001051
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001052 } catch (Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001053 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001054 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001055
Marc Slemko71d4e472006-08-15 22:34:04 +00001056 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001057 cout << "testClient.testMultiException(\"success\", \"test 3\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001058 Xtruct result;
1059 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +00001060 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001061 } catch (exception & ex) { \
1062 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001063 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001064 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001065
David Reissc51986f2009-03-24 20:01:25 +00001066 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +00001067 {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001068 cout << "testClient.testOneway(1) =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001069 uint64_t startOneway = now();
1070 testClient.testOneway(1);
1071 uint64_t elapsed = now() - startOneway;
1072 if (elapsed > 200 * 1000) { // 0.2 seconds
Jens Geyerd629ea02015-09-23 21:16:50 +02001073 printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0);
1074 return_code |= ERR_BASETYPES;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001075 } else {
1076 printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
1077 }
David Reiss2ab6fe82008-02-18 02:11:44 +00001078 }
1079
David Reiss2845b522008-02-18 02:11:52 +00001080 /**
David Reissc51986f2009-03-24 20:01:25 +00001081 * redo a simple test after the oneway to make sure we aren't "off by one" --
1082 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +00001083 * fail since it will get the void confirmation rather than the correct
1084 * result. In this circumstance, the client will throw the exception:
1085 *
1086 * TApplicationException: Wrong method namea
1087 */
1088 /**
1089 * I32 TEST
1090 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001091 cout << "re-test testI32(-1)";
1092 int i32 = testClient.testI32(-1);
1093 cout << " = " << i32 << endl;
Roger Meier4fce9602012-05-04 06:22:09 +00001094 if (i32 != -1)
Jens Geyerd629ea02015-09-23 21:16:50 +02001095 return_code |= ERR_BASETYPES;
David Reiss2845b522008-02-18 02:11:52 +00001096
Marc Slemkobf4fd192006-08-15 21:29:39 +00001097 uint64_t stop = now();
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001098 uint64_t tot = stop - start;
Mark Sleed788b2e2006-09-07 01:26:35 +00001099
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001100 cout << "Total time: " << stop - start << " us" << endl;
David Reiss0c90f6f2008-02-06 22:18:40 +00001101
Mark Sleed788b2e2006-09-07 01:26:35 +00001102 time_tot += tot;
1103 if (time_min == 0 || tot < time_min) {
1104 time_min = tot;
1105 }
1106 if (tot > time_max) {
1107 time_max = tot;
1108 }
1109
Mark Sleea3302652006-10-25 19:03:32 +00001110 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +00001111 }
1112
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001113 cout << endl << "All tests done." << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001114
1115 uint64_t time_avg = time_tot / numTests;
1116
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001117 cout << "Min time: " << time_min << " us" << endl;
1118 cout << "Max time: " << time_max << " us" << endl;
1119 cout << "Avg time: " << time_avg << " us" << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001120
Jens Geyerd629ea02015-09-23 21:16:50 +02001121 return return_code;
Mark Sleee8540632006-05-30 09:24:40 +00001122}