blob: a918bfba44d733146c309b4d89f65a996e67d127 [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
James E. King, III06190872017-02-20 08:52:11 -0500139 string testDir = boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string();
140 string caPath = testDir + "/keys/CA.pem";
141 string certPath = testDir + "/keys/client.crt";
142 string keyPath = testDir + "/keys/client.key";
143
Jake Farrell5d02b802014-01-07 21:42:01 -0500144#if _WIN32
145 transport::TWinsockSingleton::create();
146#endif
Mark Sleee8540632006-05-30 09:24:40 +0000147 string host = "localhost";
148 int port = 9090;
149 int numTests = 1;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000150 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000151 string transport_type = "buffered";
152 string protocol_type = "binary";
153 string domain_socket = "";
pavlodd08f6e2015-10-08 16:43:56 -0400154 bool abstract_namespace = false;
Jens Geyerf4598682014-05-08 23:18:44 +0200155 bool noinsane = false;
Mark Sleee8540632006-05-30 09:24:40 +0000156
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900157 int return_code = 0;
158
Jake Farrell5d02b802014-01-07 21:42:01 -0500159 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100160 desc.add_options()("help,h",
161 "produce help message")("host",
162 boost::program_options::value<string>(&host)
163 ->default_value(host),
164 "Host to connect")("port",
165 boost::program_options::value<int>(
166 &port)->default_value(port),
167 "Port number to connect")(
168 "domain-socket",
169 boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
170 "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")(
pavlodd08f6e2015-10-08 16:43:56 -0400171 "abstract-namespace",
172 "Look for the domain socket in the Abstract Namespace (no connection with filesystem pathnames)")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100173 "transport",
174 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
175 "Transport: buffered, framed, http, evhttp")(
176 "protocol",
177 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
Dave Watson792db4e2015-01-16 11:22:01 -0800178 "Protocol: binary, header, compact, json")("ssl", "Encrypted Transport using SSL")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100179 "testloops,n",
180 boost::program_options::value<int>(&numTests)->default_value(numTests),
181 "Number of Tests")("noinsane", "Do not run insanity test");
Roger Meierca142b02011-06-07 17:59:07 +0000182
Jake Farrell5d02b802014-01-07 21:42:01 -0500183 boost::program_options::variables_map vm;
184 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
185 boost::program_options::notify(vm);
Roger Meierca142b02011-06-07 17:59:07 +0000186
187 if (vm.count("help")) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900188 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900189 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000190 }
Mark Sleea3302652006-10-25 19:03:32 +0000191
Jake Farrell5d02b802014-01-07 21:42:01 -0500192 try {
Roger Meierca142b02011-06-07 17:59:07 +0000193 if (!protocol_type.empty()) {
194 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100195 } else if (protocol_type == "compact") {
Dave Watson792db4e2015-01-16 11:22:01 -0800196 } else if (protocol_type == "header") {
Roger Meierca142b02011-06-07 17:59:07 +0000197 } else if (protocol_type == "json") {
198 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100199 throw invalid_argument("Unknown protocol type " + protocol_type);
Roger Meierca142b02011-06-07 17:59:07 +0000200 }
201 }
202
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100203 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000204 if (transport_type == "buffered") {
205 } else if (transport_type == "framed") {
206 } else if (transport_type == "http") {
Roger Meier7e056e72011-07-17 07:28:28 +0000207 } else if (transport_type == "evhttp") {
Roger Meierca142b02011-06-07 17:59:07 +0000208 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100209 throw invalid_argument("Unknown transport type " + transport_type);
Roger Meierca142b02011-06-07 17:59:07 +0000210 }
211 }
212
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900213 } catch (exception& e) {
Roger Meierca142b02011-06-07 17:59:07 +0000214 cerr << e.what() << endl;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900215 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900216 return ERR_UNKNOWN;
Roger Meierca142b02011-06-07 17:59:07 +0000217 }
218
219 if (vm.count("ssl")) {
220 ssl = true;
221 }
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530222
pavlodd08f6e2015-10-08 16:43:56 -0400223 if (vm.count("abstract-namespace")) {
224 abstract_namespace = true;
225 }
226
Jens Geyerf4598682014-05-08 23:18:44 +0200227 if (vm.count("noinsane")) {
228 noinsane = true;
229 }
Roger Meierca142b02011-06-07 17:59:07 +0000230
Roger Meier611f90c2011-12-11 22:08:51 +0000231 boost::shared_ptr<TTransport> transport;
232 boost::shared_ptr<TProtocol> protocol;
Roger Meierca142b02011-06-07 17:59:07 +0000233
Roger Meier611f90c2011-12-11 22:08:51 +0000234 boost::shared_ptr<TSocket> socket;
235 boost::shared_ptr<TSSLSocketFactory> factory;
Roger Meierca142b02011-06-07 17:59:07 +0000236
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000237 if (ssl) {
James E. King, III06190872017-02-20 08:52:11 -0500238 cout << "Client Certificate File: " << certPath << endl;
239 cout << "Client Key File: " << keyPath << endl;
240 cout << "CA File: " << caPath << endl;
241
Roger Meier611f90c2011-12-11 22:08:51 +0000242 factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000243 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
James E. King, III06190872017-02-20 08:52:11 -0500244 factory->loadTrustedCertificates(caPath.c_str());
245 factory->loadCertificate(certPath.c_str());
246 factory->loadPrivateKey(keyPath.c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000247 factory->authenticate(true);
248 socket = factory->createSocket(host, port);
249 } else {
Roger Meierca142b02011-06-07 17:59:07 +0000250 if (domain_socket != "") {
pavlodd08f6e2015-10-08 16:43:56 -0400251 if (abstract_namespace) {
252 std::string abstract_socket("\0", 1);
253 abstract_socket += domain_socket;
254 socket = boost::shared_ptr<TSocket>(new TSocket(abstract_socket));
255 } else {
256 socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket));
257 }
Roger Meierca142b02011-06-07 17:59:07 +0000258 port = 0;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100259 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000260 socket = boost::shared_ptr<TSocket>(new TSocket(host, port));
Roger Meierca142b02011-06-07 17:59:07 +0000261 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000262 }
Mark Sleea3302652006-10-25 19:03:32 +0000263
Roger Meierca142b02011-06-07 17:59:07 +0000264 if (transport_type.compare("http") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000265 boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service"));
Roger Meierca142b02011-06-07 17:59:07 +0000266 transport = httpSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100267 } else if (transport_type.compare("framed") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000268 boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000269 transport = framedSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100270 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000271 boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000272 transport = bufferedSocket;
273 }
274
Roger Meierca142b02011-06-07 17:59:07 +0000275 if (protocol_type.compare("json") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000276 boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000277 protocol = jsonProtocol;
Roger Meier023192f2014-02-12 09:35:12 +0100278 } else if (protocol_type.compare("compact") == 0) {
279 boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport));
280 protocol = compactProtocol;
Dave Watson792db4e2015-01-16 11:22:01 -0800281 } else if (protocol_type == "header") {
282 boost::shared_ptr<TProtocol> headerProtocol(new THeaderProtocol(transport));
283 protocol = headerProtocol;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100284 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000285 boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000286 protocol = binaryProtocol;
287 }
288
289 // Connection info
pavlodd08f6e2015-10-08 16:43:56 -0400290 cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: ";
291 if (abstract_namespace) {
292 cout << '@';
293 }
294 cout << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000295 if (port != 0) {
296 cout << host << ":" << port;
297 }
298 cout << endl;
299
Roger Meier7e056e72011-07-17 07:28:28 +0000300 if (transport_type.compare("evhttp") == 0) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100301 event_base* base = event_base_new();
Roger Meier7e056e72011-07-17 07:28:28 +0000302 cout << "Libevent Version: " << event_get_version() << endl;
303 cout << "Libevent Method: " << event_base_get_method(base) << endl;
304#if LIBEVENT_VERSION_NUMBER >= 0x02000000
305 cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl;
306#endif
307
Roger Meier611f90c2011-12-11 22:08:51 +0000308 boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Roger Meier7e056e72011-07-17 07:28:28 +0000309
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100310 boost::shared_ptr<TAsyncChannel> channel(
311 new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
Roger Meier7e056e72011-07-17 07:28:28 +0000312 ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100313 client->testVoid(tcxx::bind(testVoid_clientReturn,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100314 base,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100315 tcxx::placeholders::_1));
Jake Farrell5d02b802014-01-07 21:42:01 -0500316
Roger Meier7e056e72011-07-17 07:28:28 +0000317 event_base_loop(base, 0);
318 return 0;
319 }
320
Roger Meierca142b02011-06-07 17:59:07 +0000321 ThriftTestClient testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000322
323 uint64_t time_min = 0;
324 uint64_t time_max = 0;
325 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000326
Mark Sleee8540632006-05-30 09:24:40 +0000327 int test = 0;
328 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000329
Mark Slee95771002006-06-07 06:53:25 +0000330 try {
Mark Sleea3302652006-10-25 19:03:32 +0000331 transport->open();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900332 } catch (TTransportException& ex) {
333 cout << "Connect failed: " << ex.what() << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900334 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000335 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000336
Mark Sleed788b2e2006-09-07 01:26:35 +0000337 /**
338 * CONNECT TEST
339 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100340 printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000341
342 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000343
Mark Sleee8540632006-05-30 09:24:40 +0000344 /**
345 * VOID TEST
346 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000347 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900348 cout << "testVoid()" << flush;
Mark Sleee129a2d2007-02-21 05:17:48 +0000349 testClient.testVoid();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900350 cout << " = void" << endl;
351 } catch (TTransportException&) {
352 // Stop here if transport got broken
353 throw;
354 } catch (exception& ex) {
355 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200356 return_code |= ERR_BASETYPES;
Mark Sleee129a2d2007-02-21 05:17:48 +0000357 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000358
Mark Sleee8540632006-05-30 09:24:40 +0000359 /**
360 * STRING TEST
361 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900362 cout << "testString(\"Test\")" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000363 string s;
364 testClient.testString(s, "Test");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900365 cout << " = " << s << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200366 if (s != "Test") {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900367 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200368 return_code |= ERR_BASETYPES;
369 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000370
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900371 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500372#ifdef _MSC_VER
373#pragma warning( push )
374#pragma warning( disable : 4566 )
375#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900376 string str(
377 "}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, "
378 "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, "
379 "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, "
380 "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, "
381 "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, "
382 "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, "
383 "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, "
384 "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, "
385 "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, "
386 "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, "
387 "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, "
388 "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, "
389 "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, "
390 "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa "
391 "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa "
392 "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪"
393 "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, "
394 "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, "
395 "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, "
396 "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple "
397 "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, "
398 "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, "
399 "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, "
400 "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, "
401 "Bân-lâm-gú, 粵語");
James E. King, III7edc8fa2017-01-20 10:11:41 -0500402#ifdef _MSC_VER
403#pragma warning( pop )
404#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900405 cout << "testString(" << str << ") = " << flush;
406 testClient.testString(s, str);
407 cout << s << endl;
408 if (s != str) {
409 cout.imbue(locale("en_US.UTF8"));
410 cout << "*** FAILED ***" << endl << "Expected string: " << str << " but got: " << s << endl << "CLEAR";
411 return_code |= ERR_BASETYPES;
412 }
413 } catch (TTransportException&) {
414 throw;
415 } catch (exception& ex) {
416 cout << "*** FAILED ***" << endl << ex.what() << endl;
417 return_code |= ERR_BASETYPES;
418 return return_code;
419 }
420 try {
421 string str(
422 "quote: \" backslash:"
423 " forwardslash-escaped: \\/ "
424 " backspace: \b formfeed: \f newline: \n return: \r tab: "
425 " now-all-of-them-together: \"\\\\/\b\n\r\t"
426 " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><"
427 " char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ ");
428 cout << "testString(" << str << ") = " << flush;
429 testClient.testString(s, str);
430 cout << s << endl;
431 if (s != str) {
432 cout.imbue(locale("en_US.UTF8"));
433 cout << "*** FAILED ***" << endl
434 << "Expected string: " << str << " but got: " << s << endl
435 << "CLEAR";
436 ;
437 return_code |= ERR_BASETYPES;
438 }
439 } catch (TTransportException&) {
440 throw;
441 } catch (exception& ex) {
442 cout << "*** FAILED ***" << endl << ex.what() << endl;
443 return_code |= ERR_BASETYPES;
444 return return_code;
445 }
446
Mark Sleee8540632006-05-30 09:24:40 +0000447 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900448 * BOOL TEST
449 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900450 cout << boolalpha;
451 BASETYPE_IDENTITY_TEST(testBool, true);
452 BASETYPE_IDENTITY_TEST(testBool, false);
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900453
454 /**
Mark Sleee8540632006-05-30 09:24:40 +0000455 * BYTE TEST
456 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900457 BASETYPE_IDENTITY_TEST(testByte, (int8_t)0);
458 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-1);
459 BASETYPE_IDENTITY_TEST(testByte, (int8_t)42);
460 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-42);
461 BASETYPE_IDENTITY_TEST(testByte, (int8_t)127);
462 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-128);
David Reiss0c90f6f2008-02-06 22:18:40 +0000463
Mark Sleee8540632006-05-30 09:24:40 +0000464 /**
465 * I32 TEST
466 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900467 BASETYPE_IDENTITY_TEST(testI32, 0);
468 BASETYPE_IDENTITY_TEST(testI32, -1);
469 BASETYPE_IDENTITY_TEST(testI32, 190000013);
470 BASETYPE_IDENTITY_TEST(testI32, -190000013);
471 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::max());
472 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::min());
Mark Sleee8540632006-05-30 09:24:40 +0000473
474 /**
Mark Sleee8540632006-05-30 09:24:40 +0000475 * I64 TEST
476 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900477 BASETYPE_IDENTITY_TEST(testI64, (int64_t)0);
478 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1);
479 BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL);
480 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500481 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32));
482 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32));
483 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32) + 1);
484 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32) - 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900485 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::max());
486 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::min());
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100487
Mark Sleec98d0502006-09-06 02:42:25 +0000488 /**
489 * DOUBLE TEST
490 */
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900491 // Comparing double values with plain equality because Thrift handles full precision of double
492 BASETYPE_IDENTITY_TEST(testDouble, 0.0);
493 BASETYPE_IDENTITY_TEST(testDouble, -1.0);
494 BASETYPE_IDENTITY_TEST(testDouble, -5.2098523);
495 BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500496 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32));
497 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32) + 1);
498 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 53) - 1);
499 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32));
500 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32) - 1);
501 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 53) + 1);
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900502
503 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500504 double expected = pow(static_cast<double>(10), 307);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900505 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900506 double actual = testClient.testDouble(expected);
507 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500508 if (expected - actual > pow(static_cast<double>(10), 292)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900509 cout << "*** FAILED ***" << endl
510 << "Expected: " << expected << " but got: " << actual << endl;
511 }
512 } catch (TTransportException&) {
513 throw;
514 } catch (exception& ex) {
515 cout << "*** FAILED ***" << endl << ex.what() << endl;
516 return_code |= ERR_BASETYPES;
517 }
518
519 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500520 double expected = pow(static_cast<double>(10), -292);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900521 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900522 double actual = testClient.testDouble(expected);
523 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500524 if (expected - actual > pow(static_cast<double>(10), -307)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900525 cout << "*** FAILED ***" << endl
526 << "Expected: " << expected << " but got: " << actual << endl;
527 }
528 } catch (TTransportException&) {
529 throw;
530 } catch (exception& ex) {
531 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200532 return_code |= ERR_BASETYPES;
533 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000534
Mark Sleee8540632006-05-30 09:24:40 +0000535 /**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100536 * BINARY TEST
537 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900538 cout << "testBinary(empty)" << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900539 try {
540 string bin_result;
541 testClient.testBinary(bin_result, string());
542 if (!bin_result.empty()) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900543 cout << endl << "*** FAILED ***" << endl;
544 cout << "invalid length: " << bin_result.size() << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900545 return_code |= ERR_BASETYPES;
546 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900547 } catch (TTransportException&) {
548 throw;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900549 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900550 cout << "*** FAILED ***" << endl << ex.what() << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900551 return_code |= ERR_BASETYPES;
552 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900553 cout << "testBinary([-128..127]) = {" << flush;
Cody P Schafer31295492016-09-09 15:50:26 -0400554 const signed char bin_data[256]
Jens Geyerd629ea02015-09-23 21:16:50 +0200555 = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
556 -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
557 -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
558 -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
559 -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
560 -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
561 -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
562 -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
563 -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
564 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
565 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
566 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
567 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
568 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
569 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
570 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
571 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
572 127};
573 try {
574 string bin_result;
Cody P Schafer31295492016-09-09 15:50:26 -0400575 testClient.testBinary(bin_result, string(reinterpret_cast<const char *>(bin_data), 256));
Jens Geyerd629ea02015-09-23 21:16:50 +0200576 if (bin_result.size() != 256) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900577 cout << endl << "*** FAILED ***" << endl;
578 cout << "invalid length: " << bin_result.size() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200579 return_code |= ERR_BASETYPES;
580 } else {
581 bool first = true;
582 bool failed = false;
583 for (int i = 0; i < 256; ++i) {
584 if (!first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900585 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200586 else
587 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900588 cout << static_cast<int>(bin_result[i]);
Jens Geyerd629ea02015-09-23 21:16:50 +0200589 if (!failed && bin_result[i] != i - 128) {
590 failed = true;
591 }
592 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900593 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200594 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900595 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200596 return_code |= ERR_BASETYPES;
597 }
598 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900599 } catch (TTransportException&) {
600 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200601 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900602 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200603 return_code |= ERR_BASETYPES;
604 }
605
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100606
607 /**
Mark Sleee8540632006-05-30 09:24:40 +0000608 * STRUCT TEST
609 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900610 cout << "testStruct({\"Zero\", 1, -3, -5})" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000611 Xtruct out;
612 out.string_thing = "Zero";
613 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000614 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000615 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000616 Xtruct in;
617 testClient.testStruct(in, out);
Roger Meier0e814802014-01-17 21:07:58 +0100618 printf(" = {\"%s\", %d, %d, %" PRId64 "}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000619 in.string_thing.c_str(),
620 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000621 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000622 in.i64_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200623 if (in != out) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900624 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200625 return_code |= ERR_STRUCTS;
626 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000627
Mark Sleee8540632006-05-30 09:24:40 +0000628 /**
629 * NESTED STRUCT TEST
630 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900631 cout << "testNest({1, {\"Zero\", 1, -3, -5}), 5}" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000632 Xtruct2 out2;
633 out2.byte_thing = 1;
634 out2.struct_thing = out;
635 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000636 Xtruct2 in2;
637 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000638 in = in2.struct_thing;
Roger Meier0e814802014-01-17 21:07:58 +0100639 printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000640 in2.byte_thing,
641 in.string_thing.c_str(),
642 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000643 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000644 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000645 in2.i32_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200646 if (in2 != out2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900647 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200648 return_code |= ERR_STRUCTS;
649 }
Mark Sleee8540632006-05-30 09:24:40 +0000650
651 /**
652 * MAP TEST
653 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100654 map<int32_t, int32_t> mapout;
Mark Sleee8540632006-05-30 09:24:40 +0000655 for (int32_t i = 0; i < 5; ++i) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100656 mapout.insert(make_pair(i, i - 10));
Mark Sleee8540632006-05-30 09:24:40 +0000657 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900658 cout << "testMap({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000659 map<int32_t, int32_t>::const_iterator m_iter;
660 bool first = true;
661 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
662 if (first) {
663 first = false;
664 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900665 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000666 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900667 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000668 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900669 cout << "})";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100670 map<int32_t, int32_t> mapin;
Mark Slee1921d202007-01-24 19:43:06 +0000671 testClient.testMap(mapin, mapout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900672 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000673 first = true;
674 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
675 if (first) {
676 first = false;
677 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900678 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000679 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900680 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000681 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900682 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200683 if (mapin != mapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900684 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200685 return_code |= ERR_CONTAINERS;
686 }
Roger Meier4fce9602012-05-04 06:22:09 +0000687
688 /**
689 * STRING MAP TEST
Roger Meier4fce9602012-05-04 06:22:09 +0000690 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900691 cout << "testStringMap({a => 2, b => blah, some => thing}) = {" << flush;
Jens Geyerd629ea02015-09-23 21:16:50 +0200692 map<string, string> smapin;
693 map<string, string> smapout;
694 smapin["a"] = "2";
695 smapin["b"] = "blah";
696 smapin["some"] = "thing";
697 try {
698 testClient.testStringMap(smapout, smapin);
699 first = true;
700 for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) {
701 if (first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900702 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200703 else
704 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900705 cout << it->first << " => " << it->second;
Jens Geyerd629ea02015-09-23 21:16:50 +0200706 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900707 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200708 if (smapin != smapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900709 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200710 return_code |= ERR_CONTAINERS;
711 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900712 } catch (TTransportException&) {
713 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200714 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900715 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200716 return_code |= ERR_CONTAINERS;
717 }
Mark Sleee8540632006-05-30 09:24:40 +0000718
719 /**
720 * SET TEST
721 */
722 set<int32_t> setout;
723 for (int32_t i = -2; i < 3; ++i) {
724 setout.insert(i);
725 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900726 cout << "testSet({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000727 set<int32_t>::const_iterator s_iter;
728 first = true;
729 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
730 if (first) {
731 first = false;
732 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900733 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000734 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900735 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000736 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900737 cout << "})";
Mark Slee1921d202007-01-24 19:43:06 +0000738 set<int32_t> setin;
739 testClient.testSet(setin, setout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900740 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000741 first = true;
742 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
743 if (first) {
744 first = false;
745 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900746 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000747 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900748 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000749 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900750 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200751 if (setin != setout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900752 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200753 return_code |= ERR_CONTAINERS;
754 }
Mark Sleee8540632006-05-30 09:24:40 +0000755
756 /**
757 * LIST TEST
758 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900759 cout << "testList(empty)" << flush;
760 try {
761 vector<int32_t> listout;
762 testClient.testList(listout, vector<int32_t>());
763 if (!listout.empty()) {
764 cout << "*** FAILED ***" << endl;
765 cout << "invalid length: " << listout.size() << endl;
766 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000767 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900768 } catch (TTransportException&) {
769 throw;
770 } catch (exception& ex) {
771 cout << "*** FAILED ***" << endl << ex.what() << endl;
772 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000773 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900774 try {
775 vector<int32_t> listout;
776 for (int32_t i = -2; i < 3; ++i) {
777 listout.push_back(i);
Mark Sleee8540632006-05-30 09:24:40 +0000778 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900779 cout << "testList({" << flush;
780 vector<int32_t>::const_iterator l_iter;
781 first = true;
782 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
783 if (first) {
784 first = false;
785 } else {
786 cout << ",";
787 }
788 cout << *l_iter;
789 }
790 cout << "})";
791 vector<int32_t> listin;
792 testClient.testList(listin, listout);
793 cout << " = {";
794 first = true;
795 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
796 if (first) {
797 first = false;
798 } else {
799 cout << ",";
800 }
801 cout << *l_iter;
802 }
803 cout << "}" << endl;
804 if (listin != listout) {
805 cout << "*** FAILED ***" << endl;
806 return_code |= ERR_CONTAINERS;
807 }
808 } catch (TTransportException&) {
809 throw;
810 } catch (exception& ex) {
811 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200812 return_code |= ERR_CONTAINERS;
813 }
Mark Sleee8540632006-05-30 09:24:40 +0000814
815 /**
816 * ENUM TEST
817 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900818 cout << "testEnum(ONE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000819 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900820 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200821 if (ret != Numberz::ONE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900822 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200823 return_code |= ERR_STRUCTS;
824 }
Mark Sleee8540632006-05-30 09:24:40 +0000825
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900826 cout << "testEnum(TWO)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000827 ret = testClient.testEnum(Numberz::TWO);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900828 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200829 if (ret != Numberz::TWO) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900830 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200831 return_code |= ERR_STRUCTS;
832 }
Mark Sleee8540632006-05-30 09:24:40 +0000833
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900834 cout << "testEnum(THREE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000835 ret = testClient.testEnum(Numberz::THREE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900836 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200837 if (ret != Numberz::THREE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900838 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200839 return_code |= ERR_STRUCTS;
840 }
Mark Sleee8540632006-05-30 09:24:40 +0000841
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900842 cout << "testEnum(FIVE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000843 ret = testClient.testEnum(Numberz::FIVE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900844 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200845 if (ret != Numberz::FIVE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900846 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200847 return_code |= ERR_STRUCTS;
848 }
Mark Sleee8540632006-05-30 09:24:40 +0000849
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900850 cout << "testEnum(EIGHT)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000851 ret = testClient.testEnum(Numberz::EIGHT);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900852 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200853 if (ret != Numberz::EIGHT) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900854 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200855 return_code |= ERR_STRUCTS;
856 }
Mark Sleee8540632006-05-30 09:24:40 +0000857
858 /**
859 * TYPEDEF TEST
860 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900861 cout << "testTypedef(309858235082523)" << flush;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000862 UserId uid = testClient.testTypedef(309858235082523LL);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900863 cout << " = " << uid << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200864 if (uid != 309858235082523LL) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900865 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200866 return_code |= ERR_STRUCTS;
867 }
Mark Sleee8540632006-05-30 09:24:40 +0000868
869 /**
870 * NESTED MAP TEST
871 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900872 cout << "testMapMap(1)" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000873 map<int32_t, map<int32_t, int32_t> > mm;
874 testClient.testMapMap(mm, 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900875 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000876 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
877 for (mi = mm.begin(); mi != mm.end(); ++mi) {
878 printf("%d => {", mi->first);
879 map<int32_t, int32_t>::const_iterator mi2;
880 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900881 cout << mi2->first << " => " << mi2->second;
Mark Sleee8540632006-05-30 09:24:40 +0000882 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900883 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000884 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900885 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200886 if (mm.size() != 2 ||
887 mm[-4][-4] != -4 ||
888 mm[-4][-3] != -3 ||
889 mm[-4][-2] != -2 ||
890 mm[-4][-1] != -1 ||
891 mm[4][4] != 4 ||
892 mm[4][3] != 3 ||
893 mm[4][2] != 2 ||
894 mm[4][1] != 1) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900895 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200896 return_code |= ERR_CONTAINERS;
897 }
Mark Sleee8540632006-05-30 09:24:40 +0000898
899 /**
900 * INSANITY TEST
901 */
Jens Geyerf4598682014-05-08 23:18:44 +0200902 if (!noinsane) {
903 Insanity insane;
Jens Geyerd629ea02015-09-23 21:16:50 +0200904 insane.userMap.insert(make_pair(Numberz::FIVE, 5));
905 insane.userMap.insert(make_pair(Numberz::EIGHT, 8));
Jens Geyerf4598682014-05-08 23:18:44 +0200906 Xtruct truck;
Jens Geyerd629ea02015-09-23 21:16:50 +0200907 truck.string_thing = "Goodbye4";
908 truck.byte_thing = 4;
909 truck.i32_thing = 4;
910 truck.i64_thing = 4;
911 Xtruct truck2;
912 truck2.string_thing = "Hello2";
913 truck2.byte_thing = 2;
914 truck2.i32_thing = 2;
915 truck2.i64_thing = 2;
Jens Geyerf4598682014-05-08 23:18:44 +0200916 insane.xtructs.push_back(truck);
Jens Geyerd629ea02015-09-23 21:16:50 +0200917 insane.xtructs.push_back(truck2);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900918 cout << "testInsanity()" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100919 map<UserId, map<Numberz::type, Insanity> > whoa;
Jens Geyerf4598682014-05-08 23:18:44 +0200920 testClient.testInsanity(whoa, insane);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900921 cout << " = {";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100922 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Jens Geyerf4598682014-05-08 23:18:44 +0200923 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
924 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100925 map<Numberz::type, Insanity>::const_iterator i2_iter;
926 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Jens Geyerf4598682014-05-08 23:18:44 +0200927 printf("%d => {", i2_iter->first);
928 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
929 map<Numberz::type, UserId>::const_iterator um;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900930 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200931 for (um = userMap.begin(); um != userMap.end(); ++um) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900932 cout << um->first << " => " << um->second;
Jens Geyerf4598682014-05-08 23:18:44 +0200933 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900934 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000935
Jens Geyerf4598682014-05-08 23:18:44 +0200936 vector<Xtruct> xtructs = i2_iter->second.xtructs;
937 vector<Xtruct>::const_iterator x;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900938 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200939 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
940 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
941 x->string_thing.c_str(),
942 (int)x->byte_thing,
943 x->i32_thing,
944 x->i64_thing);
945 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900946 cout << "}";
Mark Sleee8540632006-05-30 09:24:40 +0000947
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900948 cout << "}, ";
Jens Geyerf4598682014-05-08 23:18:44 +0200949 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900950 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000951 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900952 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200953 bool failed = false;
954 map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1));
955 if (whoa.size() != 2) {
956 failed = true;
957 }
958 if (it1 == whoa.end()) {
959 failed = true;
960 } else {
961 map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO);
962 if (it12 == it1->second.end() || it12->second != insane) {
963 failed = true;
964 }
965 map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE);
966 if (it13 == it1->second.end() || it13->second != insane) {
967 failed = true;
968 }
969 }
970 map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2));
971 if (it2 == whoa.end()) {
972 failed = true;
973 } else {
974 map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX);
975 if (it26 == it1->second.end() || it26->second != Insanity()) {
976 failed = true;
977 }
978 }
979 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900980 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200981 return_code |= ERR_STRUCTS;
982 }
Mark Sleee8540632006-05-30 09:24:40 +0000983 }
Jens Geyerd629ea02015-09-23 21:16:50 +0200984
985 /**
986 * MULTI TEST
987 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900988 cout << "testMulti()" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200989 try {
990 map<int16_t, string> mul_map;
991 Xtruct mul_result;
992 mul_map[1] = "blah";
993 mul_map[2] = "thing";
994 testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24));
995 Xtruct xxs;
996 xxs.string_thing = "Hello2";
997 xxs.byte_thing = 42;
998 xxs.i32_thing = 4242;
999 xxs.i64_thing = 424242;
1000 if (mul_result != xxs) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001001 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001002 return_code |= ERR_STRUCTS;
1003 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001004 } catch (TTransportException&) {
1005 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +02001006 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001007 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001008 return_code |= ERR_STRUCTS;
1009 }
1010
Marc Slemko71d4e472006-08-15 22:34:04 +00001011 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +00001012
Marc Slemkobf4fd192006-08-15 21:29:39 +00001013 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001014 cout << "testClient.testException(\"Xception\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001015 testClient.testException("Xception");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001016 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001017 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001018
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001019 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001020 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001021 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001022
Marc Slemkobf4fd192006-08-15 21:29:39 +00001023 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001024 cout << "testClient.testException(\"TException\") =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001025 testClient.testException("TException");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001026 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001027 return_code |= ERR_EXCEPTIONS;
Roger Meierf50df7f2012-05-02 22:49:55 +00001028
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001029 } catch (const TException&) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001030 cout << " Caught TException" << endl;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001031 }
Roger Meierf50df7f2012-05-02 22:49:55 +00001032
1033 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001034 cout << "testClient.testException(\"success\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001035 testClient.testException("success");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001036 cout << " void" << endl;
1037 } catch (exception & ex) { \
1038 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001039 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001040 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001041
Marc Slemko71d4e472006-08-15 22:34:04 +00001042 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +00001043
Marc Slemko71d4e472006-08-15 22:34:04 +00001044 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001045 cout << "testClient.testMultiException(\"Xception\", \"test 1\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001046 Xtruct result;
1047 testClient.testMultiException(result, "Xception", "test 1");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001048 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001049 return_code |= ERR_EXCEPTIONS;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001050 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001051 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
1052 }
1053
1054 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001055 cout << "testClient.testMultiException(\"Xception2\", \"test 2\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001056 Xtruct result;
1057 testClient.testMultiException(result, "Xception2", "test 2");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001058 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001059 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001060
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001061 } catch (Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001062 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001063 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001064
Marc Slemko71d4e472006-08-15 22:34:04 +00001065 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001066 cout << "testClient.testMultiException(\"success\", \"test 3\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001067 Xtruct result;
1068 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +00001069 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001070 } catch (exception & ex) { \
1071 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001072 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001073 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001074
David Reissc51986f2009-03-24 20:01:25 +00001075 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +00001076 {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001077 cout << "testClient.testOneway(1) =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001078 uint64_t startOneway = now();
1079 testClient.testOneway(1);
1080 uint64_t elapsed = now() - startOneway;
1081 if (elapsed > 200 * 1000) { // 0.2 seconds
Jens Geyerd629ea02015-09-23 21:16:50 +02001082 printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0);
1083 return_code |= ERR_BASETYPES;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001084 } else {
1085 printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
1086 }
David Reiss2ab6fe82008-02-18 02:11:44 +00001087 }
1088
David Reiss2845b522008-02-18 02:11:52 +00001089 /**
David Reissc51986f2009-03-24 20:01:25 +00001090 * redo a simple test after the oneway to make sure we aren't "off by one" --
1091 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +00001092 * fail since it will get the void confirmation rather than the correct
1093 * result. In this circumstance, the client will throw the exception:
1094 *
1095 * TApplicationException: Wrong method namea
1096 */
1097 /**
1098 * I32 TEST
1099 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001100 cout << "re-test testI32(-1)";
1101 int i32 = testClient.testI32(-1);
1102 cout << " = " << i32 << endl;
Roger Meier4fce9602012-05-04 06:22:09 +00001103 if (i32 != -1)
Jens Geyerd629ea02015-09-23 21:16:50 +02001104 return_code |= ERR_BASETYPES;
David Reiss2845b522008-02-18 02:11:52 +00001105
Marc Slemkobf4fd192006-08-15 21:29:39 +00001106 uint64_t stop = now();
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001107 uint64_t tot = stop - start;
Mark Sleed788b2e2006-09-07 01:26:35 +00001108
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001109 cout << "Total time: " << stop - start << " us" << endl;
David Reiss0c90f6f2008-02-06 22:18:40 +00001110
Mark Sleed788b2e2006-09-07 01:26:35 +00001111 time_tot += tot;
1112 if (time_min == 0 || tot < time_min) {
1113 time_min = tot;
1114 }
1115 if (tot > time_max) {
1116 time_max = tot;
1117 }
1118
Mark Sleea3302652006-10-25 19:03:32 +00001119 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +00001120 }
1121
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001122 cout << endl << "All tests done." << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001123
1124 uint64_t time_avg = time_tot / numTests;
1125
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001126 cout << "Min time: " << time_min << " us" << endl;
1127 cout << "Max time: " << time_max << " us" << endl;
1128 cout << "Avg time: " << time_avg << " us" << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001129
Jens Geyerd629ea02015-09-23 21:16:50 +02001130 return return_code;
Mark Sleee8540632006-05-30 09:24:40 +00001131}