blob: 7c425a97baddfd2831e36866bf1ab3bc8896ab66 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
2 * 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
Roger Meierd3b9dca2011-06-24 14:01:10 +000020#define __STDC_FORMAT_MACROS
21#include <inttypes.h>
22
Roger Meierca142b02011-06-07 17:59:07 +000023#include <iostream>
Roger Meier49ff8b12012-04-13 09:12:31 +000024#include <thrift/protocol/TBinaryProtocol.h>
Roger Meier023192f2014-02-12 09:35:12 +010025#include <thrift/protocol/TCompactProtocol.h>
Roger Meier49ff8b12012-04-13 09:12:31 +000026#include <thrift/protocol/TJSONProtocol.h>
27#include <thrift/transport/THttpClient.h>
28#include <thrift/transport/TTransportUtils.h>
29#include <thrift/transport/TSocket.h>
30#include <thrift/transport/TSSLSocket.h>
31#include <thrift/async/TEvhttpClientChannel.h>
32#include <thrift/server/TNonblockingServer.h> // <event.h>
Mark Sleee8540632006-05-30 09:24:40 +000033
Marc Slemko6be374b2006-08-04 03:16:25 +000034#include <boost/shared_ptr.hpp>
Roger Meierca142b02011-06-07 17:59:07 +000035#include <boost/program_options.hpp>
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053036#include <boost/filesystem.hpp>
Jake Farrell5d02b802014-01-07 21:42:01 -050037#include <thrift/cxxfunctional.h>
38#if _WIN32
Konrad Grochowski16a23a62014-11-13 15:33:38 +010039#include <thrift/windows/TWinsockSingleton.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050040#endif
Roger Meierca142b02011-06-07 17:59:07 +000041
Marc Slemko6be374b2006-08-04 03:16:25 +000042#include "ThriftTest.h"
43
Marc Slemko6be374b2006-08-04 03:16:25 +000044using namespace std;
T Jake Lucianib5e62212009-01-31 22:36:20 +000045using namespace apache::thrift;
46using namespace apache::thrift::protocol;
47using namespace apache::thrift::transport;
Marc Slemkobf4fd192006-08-15 21:29:39 +000048using namespace thrift::test;
Roger Meier7e056e72011-07-17 07:28:28 +000049using namespace apache::thrift::async;
50
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053051// Length of argv[0] - Length of script dir
52#define EXECUTABLE_FILE_NAME_LENGTH 19
53
Mark Slee95771002006-06-07 06:53:25 +000054// Current time, microseconds since the epoch
Konrad Grochowski16a23a62014-11-13 15:33:38 +010055uint64_t now() {
Roger Meier5f9614c2010-11-21 16:59:05 +000056 int64_t ret;
Mark Slee95771002006-06-07 06:53:25 +000057 struct timeval tv;
David Reiss0c90f6f2008-02-06 22:18:40 +000058
Jake Farrell5d02b802014-01-07 21:42:01 -050059 THRIFT_GETTIMEOFDAY(&tv, NULL);
Mark Slee95771002006-06-07 06:53:25 +000060 ret = tv.tv_sec;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010061 ret = ret * 1000 * 1000 + tv.tv_usec;
Mark Slee95771002006-06-07 06:53:25 +000062 return ret;
63}
64
Konrad Grochowski16a23a62014-11-13 15:33:38 +010065static void testString_clientReturn(const char* host,
66 int port,
67 event_base* base,
68 TProtocolFactory* protocolFactory,
69 ThriftTestCobClient* client) {
70 (void)host;
71 (void)port;
72 (void)protocolFactory;
Roger Meier7e056e72011-07-17 07:28:28 +000073 try {
74 string s;
75 client->recv_testString(s);
76 cout << "testString: " << s << endl;
77 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -050078 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000079 }
80
81 event_base_loopbreak(base); // end test
82}
83
Konrad Grochowski16a23a62014-11-13 15:33:38 +010084static void testVoid_clientReturn(const char* host,
85 int port,
86 event_base* base,
87 TProtocolFactory* protocolFactory,
88 ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000089 try {
90 client->recv_testVoid();
91 cout << "testVoid" << endl;
92
93 // next test
94 delete client;
Roger Meier611f90c2011-12-11 22:08:51 +000095 boost::shared_ptr<TAsyncChannel> channel(new TEvhttpClientChannel(host, "/", host, port, base));
Roger Meier7e056e72011-07-17 07:28:28 +000096 client = new ThriftTestCobClient(channel, protocolFactory);
Konrad Grochowski16a23a62014-11-13 15:33:38 +010097 client->testString(tcxx::bind(testString_clientReturn,
98 host,
99 port,
100 base,
101 protocolFactory,
102 tcxx::placeholders::_1),
103 "Test");
Roger Meier7e056e72011-07-17 07:28:28 +0000104 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500105 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +0000106 }
107}
108
Mark Sleee8540632006-05-30 09:24:40 +0000109int main(int argc, char** argv) {
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530110 string file_path = boost::filesystem::system_complete(argv[0]).string();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100111 string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH);
Jake Farrell5d02b802014-01-07 21:42:01 -0500112#if _WIN32
113 transport::TWinsockSingleton::create();
114#endif
Mark Sleee8540632006-05-30 09:24:40 +0000115 string host = "localhost";
116 int port = 9090;
117 int numTests = 1;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000118 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000119 string transport_type = "buffered";
120 string protocol_type = "binary";
121 string domain_socket = "";
Jens Geyerf4598682014-05-08 23:18:44 +0200122 bool noinsane = false;
Mark Sleee8540632006-05-30 09:24:40 +0000123
Jake Farrell5d02b802014-01-07 21:42:01 -0500124 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100125 desc.add_options()("help,h",
126 "produce help message")("host",
127 boost::program_options::value<string>(&host)
128 ->default_value(host),
129 "Host to connect")("port",
130 boost::program_options::value<int>(
131 &port)->default_value(port),
132 "Port number to connect")(
133 "domain-socket",
134 boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
135 "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")(
136 "transport",
137 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
138 "Transport: buffered, framed, http, evhttp")(
139 "protocol",
140 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
141 "Protocol: binary, compact, json")("ssl", "Encrypted Transport using SSL")(
142 "testloops,n",
143 boost::program_options::value<int>(&numTests)->default_value(numTests),
144 "Number of Tests")("noinsane", "Do not run insanity test");
Roger Meierca142b02011-06-07 17:59:07 +0000145
Jake Farrell5d02b802014-01-07 21:42:01 -0500146 boost::program_options::variables_map vm;
147 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
148 boost::program_options::notify(vm);
Roger Meierca142b02011-06-07 17:59:07 +0000149
150 if (vm.count("help")) {
151 cout << desc << "\n";
152 return 1;
Mark Sleee8540632006-05-30 09:24:40 +0000153 }
Mark Sleea3302652006-10-25 19:03:32 +0000154
Jake Farrell5d02b802014-01-07 21:42:01 -0500155 try {
Roger Meierca142b02011-06-07 17:59:07 +0000156 if (!protocol_type.empty()) {
157 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100158 } else if (protocol_type == "compact") {
Roger Meierca142b02011-06-07 17:59:07 +0000159 } else if (protocol_type == "json") {
160 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100161 throw invalid_argument("Unknown protocol type " + protocol_type);
Roger Meierca142b02011-06-07 17:59:07 +0000162 }
163 }
164
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100165 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000166 if (transport_type == "buffered") {
167 } else if (transport_type == "framed") {
168 } else if (transport_type == "http") {
Roger Meier7e056e72011-07-17 07:28:28 +0000169 } else if (transport_type == "evhttp") {
Roger Meierca142b02011-06-07 17:59:07 +0000170 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100171 throw invalid_argument("Unknown transport type " + transport_type);
Roger Meierca142b02011-06-07 17:59:07 +0000172 }
173 }
174
175 } catch (std::exception& e) {
176 cerr << e.what() << endl;
177 cout << desc << "\n";
178 return 1;
179 }
180
181 if (vm.count("ssl")) {
182 ssl = true;
183 }
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530184
Jens Geyerf4598682014-05-08 23:18:44 +0200185 if (vm.count("noinsane")) {
186 noinsane = true;
187 }
Roger Meierca142b02011-06-07 17:59:07 +0000188
Roger Meier611f90c2011-12-11 22:08:51 +0000189 boost::shared_ptr<TTransport> transport;
190 boost::shared_ptr<TProtocol> protocol;
Roger Meierca142b02011-06-07 17:59:07 +0000191
Roger Meier611f90c2011-12-11 22:08:51 +0000192 boost::shared_ptr<TSocket> socket;
193 boost::shared_ptr<TSSLSocketFactory> factory;
Roger Meierca142b02011-06-07 17:59:07 +0000194
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000195 if (ssl) {
Roger Meier611f90c2011-12-11 22:08:51 +0000196 factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000197 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530198 factory->loadTrustedCertificates((dir_path + "../keys/CA.pem").c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000199 factory->authenticate(true);
200 socket = factory->createSocket(host, port);
201 } else {
Roger Meierca142b02011-06-07 17:59:07 +0000202 if (domain_socket != "") {
Roger Meier611f90c2011-12-11 22:08:51 +0000203 socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket));
Roger Meierca142b02011-06-07 17:59:07 +0000204 port = 0;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100205 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000206 socket = boost::shared_ptr<TSocket>(new TSocket(host, port));
Roger Meierca142b02011-06-07 17:59:07 +0000207 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000208 }
Mark Sleea3302652006-10-25 19:03:32 +0000209
Roger Meierca142b02011-06-07 17:59:07 +0000210 if (transport_type.compare("http") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000211 boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service"));
Roger Meierca142b02011-06-07 17:59:07 +0000212 transport = httpSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100213 } else if (transport_type.compare("framed") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000214 boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000215 transport = framedSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100216 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000217 boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000218 transport = bufferedSocket;
219 }
220
Roger Meierca142b02011-06-07 17:59:07 +0000221 if (protocol_type.compare("json") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000222 boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000223 protocol = jsonProtocol;
Roger Meier023192f2014-02-12 09:35:12 +0100224 } else if (protocol_type.compare("compact") == 0) {
225 boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport));
226 protocol = compactProtocol;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100227 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000228 boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000229 protocol = binaryProtocol;
230 }
231
232 // Connection info
233 cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: " << domain_socket;
234 if (port != 0) {
235 cout << host << ":" << port;
236 }
237 cout << endl;
238
Roger Meier7e056e72011-07-17 07:28:28 +0000239 if (transport_type.compare("evhttp") == 0) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100240 event_base* base = event_base_new();
Roger Meier7e056e72011-07-17 07:28:28 +0000241 cout << "Libevent Version: " << event_get_version() << endl;
242 cout << "Libevent Method: " << event_base_get_method(base) << endl;
243#if LIBEVENT_VERSION_NUMBER >= 0x02000000
244 cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl;
245#endif
246
Roger Meier611f90c2011-12-11 22:08:51 +0000247 boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Roger Meier7e056e72011-07-17 07:28:28 +0000248
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100249 boost::shared_ptr<TAsyncChannel> channel(
250 new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
Roger Meier7e056e72011-07-17 07:28:28 +0000251 ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100252 client->testVoid(tcxx::bind(testVoid_clientReturn,
253 host.c_str(),
254 port,
255 base,
256 protocolFactory.get(),
257 tcxx::placeholders::_1));
Jake Farrell5d02b802014-01-07 21:42:01 -0500258
Roger Meier7e056e72011-07-17 07:28:28 +0000259 event_base_loop(base, 0);
260 return 0;
261 }
262
Roger Meierca142b02011-06-07 17:59:07 +0000263 ThriftTestClient testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000264
265 uint64_t time_min = 0;
266 uint64_t time_max = 0;
267 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000268
Jens Geyerd629ea02015-09-23 21:16:50 +0200269 int return_code = 0;
270 int ERR_BASETYPES = 1;
271 int ERR_STRUCTS = 2;
272 int ERR_CONTAINERS = 4;
273 int ERR_EXCEPTIONS = 8;
274
Mark Sleee8540632006-05-30 09:24:40 +0000275 int test = 0;
276 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000277
Mark Slee95771002006-06-07 06:53:25 +0000278 try {
Mark Sleea3302652006-10-25 19:03:32 +0000279 transport->open();
Mark Slee95771002006-06-07 06:53:25 +0000280 } catch (TTransportException& ttx) {
Mark Sleeb9ff32a2006-11-16 01:00:24 +0000281 printf("Connect failed: %s\n", ttx.what());
Roger Meier5b1e3c72011-12-08 13:20:12 +0000282 return 1;
Mark Sleee8540632006-05-30 09:24:40 +0000283 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000284
Mark Sleed788b2e2006-09-07 01:26:35 +0000285 /**
286 * CONNECT TEST
287 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100288 printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000289
290 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000291
Mark Sleee8540632006-05-30 09:24:40 +0000292 /**
293 * VOID TEST
294 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000295 try {
296 printf("testVoid()");
297 testClient.testVoid();
298 printf(" = void\n");
Roger Meier4fce9602012-05-04 06:22:09 +0000299 } catch (TApplicationException& tax) {
Jens Geyerd629ea02015-09-23 21:16:50 +0200300 printf("*** FAILED ***\n");
Mark Sleee129a2d2007-02-21 05:17:48 +0000301 printf("%s\n", tax.what());
Jens Geyerd629ea02015-09-23 21:16:50 +0200302 return_code |= ERR_BASETYPES;
Mark Sleee129a2d2007-02-21 05:17:48 +0000303 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000304
Mark Sleee8540632006-05-30 09:24:40 +0000305 /**
306 * STRING TEST
307 */
308 printf("testString(\"Test\")");
Mark Slee1921d202007-01-24 19:43:06 +0000309 string s;
310 testClient.testString(s, "Test");
Mark Sleee8540632006-05-30 09:24:40 +0000311 printf(" = \"%s\"\n", s.c_str());
Jens Geyerd629ea02015-09-23 21:16:50 +0200312 if (s != "Test") {
313 printf("*** FAILED ***\n");
314 return_code |= ERR_BASETYPES;
315 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000316
Mark Sleee8540632006-05-30 09:24:40 +0000317 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900318 * BOOL TEST
319 */
320 printf("testBool(true)");
321 bool bl = testClient.testBool(true);
322 printf(" = %s\n", bl ? "true" : "false");
Jens Geyerd629ea02015-09-23 21:16:50 +0200323 if (bl != true) {
324 printf("*** FAILED ***\n");
325 return_code |= ERR_BASETYPES;
326 }
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900327
328 printf("testBool(false)");
329 bl = testClient.testBool(false);
330 printf(" = %s\n", bl ? "true" : "false");
Jens Geyerd629ea02015-09-23 21:16:50 +0200331 if (bl != false) {
332 printf("*** FAILED ***\n");
333 return_code |= ERR_BASETYPES;
334 }
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900335
336 /**
Mark Sleee8540632006-05-30 09:24:40 +0000337 * BYTE TEST
338 */
339 printf("testByte(1)");
340 uint8_t u8 = testClient.testByte(1);
341 printf(" = %d\n", (int)u8);
Jens Geyerd629ea02015-09-23 21:16:50 +0200342 if (u8 != 1) {
343 printf("*** FAILED ***\n");
344 return_code |= ERR_BASETYPES;
345 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000346
Mark Sleee8540632006-05-30 09:24:40 +0000347 /**
348 * I32 TEST
349 */
350 printf("testI32(-1)");
351 int32_t i32 = testClient.testI32(-1);
352 printf(" = %d\n", i32);
Jens Geyerd629ea02015-09-23 21:16:50 +0200353 if (i32 != -1) {
354 printf("*** FAILED ***\n");
355 return_code |= ERR_BASETYPES;
356 }
Mark Sleee8540632006-05-30 09:24:40 +0000357
358 /**
Mark Sleee8540632006-05-30 09:24:40 +0000359 * I64 TEST
360 */
361 printf("testI64(-34359738368)");
Marc Slemkobf4fd192006-08-15 21:29:39 +0000362 int64_t i64 = testClient.testI64(-34359738368LL);
Roger Meier0e814802014-01-17 21:07:58 +0100363 printf(" = %" PRId64 "\n", i64);
Jens Geyerd629ea02015-09-23 21:16:50 +0200364 if (i64 != -34359738368LL) {
365 printf("*** FAILED ***\n");
366 return_code |= ERR_BASETYPES;
367 }
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100368
Mark Sleec98d0502006-09-06 02:42:25 +0000369 /**
370 * DOUBLE TEST
371 */
372 printf("testDouble(-5.2098523)");
373 double dub = testClient.testDouble(-5.2098523);
Roger Meiera8cef6e2011-07-17 18:55:59 +0000374 printf(" = %f\n", dub);
Jens Geyerd629ea02015-09-23 21:16:50 +0200375 if ((dub - (-5.2098523)) > 0.001) {
376 printf("*** FAILED ***\n");
377 return_code |= ERR_BASETYPES;
378 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000379
Mark Sleee8540632006-05-30 09:24:40 +0000380 /**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100381 * BINARY TEST
382 */
Jens Geyerd629ea02015-09-23 21:16:50 +0200383 printf("testBinary([-128..127]) = {");
384 const char bin_data[256]
385 = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
386 -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
387 -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
388 -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
389 -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
390 -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
391 -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
392 -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
393 -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
394 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
395 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
396 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
397 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
398 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
399 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
400 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
401 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
402 127};
403 try {
404 string bin_result;
405 testClient.testBinary(bin_result, string(bin_data, 256));
406 if (bin_result.size() != 256) {
407 printf("}\n*** FAILED ***\n");
408 printf("invalid length: %lu\n", bin_result.size());
409 return_code |= ERR_BASETYPES;
410 } else {
411 bool first = true;
412 bool failed = false;
413 for (int i = 0; i < 256; ++i) {
414 if (!first)
415 printf(" ,");
416 else
417 first = false;
418 printf("%d", bin_result[i]);
419 if (!failed && bin_result[i] != i - 128) {
420 failed = true;
421 }
422 }
423 printf("}\n");
424 if (failed) {
425 printf("*** FAILED ***\n");
426 return_code |= ERR_BASETYPES;
427 }
428 }
429 } catch (exception& ex) {
430 printf("}\n*** FAILED ***\n");
431 printf("%s\n", ex.what());
432 return_code |= ERR_BASETYPES;
433 }
434
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100435
436 /**
Mark Sleee8540632006-05-30 09:24:40 +0000437 * STRUCT TEST
438 */
Mark Slee6e536442006-06-30 18:28:50 +0000439 printf("testStruct({\"Zero\", 1, -3, -5})");
Mark Sleee8540632006-05-30 09:24:40 +0000440 Xtruct out;
441 out.string_thing = "Zero";
442 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000443 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000444 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000445 Xtruct in;
446 testClient.testStruct(in, out);
Roger Meier0e814802014-01-17 21:07:58 +0100447 printf(" = {\"%s\", %d, %d, %" PRId64 "}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000448 in.string_thing.c_str(),
449 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000450 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000451 in.i64_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200452 if (in != out) {
453 printf("*** FAILED ***\n");
454 return_code |= ERR_STRUCTS;
455 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000456
Mark Sleee8540632006-05-30 09:24:40 +0000457 /**
458 * NESTED STRUCT TEST
459 */
Mark Slee6e536442006-06-30 18:28:50 +0000460 printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
Mark Sleee8540632006-05-30 09:24:40 +0000461 Xtruct2 out2;
462 out2.byte_thing = 1;
463 out2.struct_thing = out;
464 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000465 Xtruct2 in2;
466 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000467 in = in2.struct_thing;
Roger Meier0e814802014-01-17 21:07:58 +0100468 printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000469 in2.byte_thing,
470 in.string_thing.c_str(),
471 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000472 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000473 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000474 in2.i32_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200475 if (in2 != out2) {
476 printf("*** FAILED ***\n");
477 return_code |= ERR_STRUCTS;
478 }
Mark Sleee8540632006-05-30 09:24:40 +0000479
480 /**
481 * MAP TEST
482 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100483 map<int32_t, int32_t> mapout;
Mark Sleee8540632006-05-30 09:24:40 +0000484 for (int32_t i = 0; i < 5; ++i) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100485 mapout.insert(make_pair(i, i - 10));
Mark Sleee8540632006-05-30 09:24:40 +0000486 }
487 printf("testMap({");
488 map<int32_t, int32_t>::const_iterator m_iter;
489 bool first = true;
490 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
491 if (first) {
492 first = false;
493 } else {
494 printf(", ");
495 }
496 printf("%d => %d", m_iter->first, m_iter->second);
497 }
498 printf("})");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100499 map<int32_t, int32_t> mapin;
Mark Slee1921d202007-01-24 19:43:06 +0000500 testClient.testMap(mapin, mapout);
Mark Sleee8540632006-05-30 09:24:40 +0000501 printf(" = {");
502 first = true;
503 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
504 if (first) {
505 first = false;
506 } else {
507 printf(", ");
508 }
509 printf("%d => %d", m_iter->first, m_iter->second);
510 }
511 printf("}\n");
Jens Geyerd629ea02015-09-23 21:16:50 +0200512 if (mapin != mapout) {
513 printf("*** FAILED ***\n");
514 return_code |= ERR_CONTAINERS;
515 }
Roger Meier4fce9602012-05-04 06:22:09 +0000516
517 /**
518 * STRING MAP TEST
Roger Meier4fce9602012-05-04 06:22:09 +0000519 */
Jens Geyerd629ea02015-09-23 21:16:50 +0200520 printf("testStringMap({a => 2, b => blah, some => thing}) = {");
521 map<string, string> smapin;
522 map<string, string> smapout;
523 smapin["a"] = "2";
524 smapin["b"] = "blah";
525 smapin["some"] = "thing";
526 try {
527 testClient.testStringMap(smapout, smapin);
528 first = true;
529 for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) {
530 if (first)
531 printf(",");
532 else
533 first = false;
534 printf("%s => %s", it->first.c_str(), it->second.c_str());
535 }
536 printf("}\n");
537 if (smapin != smapout) {
538 printf("*** FAILED ***\n");
539 return_code |= ERR_CONTAINERS;
540 }
541 } catch (exception& ex) {
542 printf("}\n*** FAILED ***\n");
543 printf("%s\n", ex.what());
544 return_code |= ERR_CONTAINERS;
545 }
Mark Sleee8540632006-05-30 09:24:40 +0000546
547 /**
548 * SET TEST
549 */
550 set<int32_t> setout;
551 for (int32_t i = -2; i < 3; ++i) {
552 setout.insert(i);
553 }
554 printf("testSet({");
555 set<int32_t>::const_iterator s_iter;
556 first = true;
557 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
558 if (first) {
559 first = false;
560 } else {
561 printf(", ");
562 }
563 printf("%d", *s_iter);
564 }
565 printf("})");
Mark Slee1921d202007-01-24 19:43:06 +0000566 set<int32_t> setin;
567 testClient.testSet(setin, setout);
Mark Sleee8540632006-05-30 09:24:40 +0000568 printf(" = {");
569 first = true;
570 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
571 if (first) {
572 first = false;
573 } else {
574 printf(", ");
575 }
576 printf("%d", *s_iter);
577 }
578 printf("}\n");
Jens Geyerd629ea02015-09-23 21:16:50 +0200579 if (setin != setout) {
580 printf("*** FAILED ***\n");
581 return_code |= ERR_CONTAINERS;
582 }
Mark Sleee8540632006-05-30 09:24:40 +0000583
584 /**
585 * LIST TEST
586 */
Mark Sleeb9acf982006-10-10 01:57:32 +0000587 vector<int32_t> listout;
Mark Sleee8540632006-05-30 09:24:40 +0000588 for (int32_t i = -2; i < 3; ++i) {
589 listout.push_back(i);
590 }
591 printf("testList({");
Mark Sleeb9acf982006-10-10 01:57:32 +0000592 vector<int32_t>::const_iterator l_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000593 first = true;
594 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
595 if (first) {
596 first = false;
597 } else {
598 printf(", ");
599 }
600 printf("%d", *l_iter);
601 }
602 printf("})");
Mark Slee1921d202007-01-24 19:43:06 +0000603 vector<int32_t> listin;
604 testClient.testList(listin, listout);
Mark Sleee8540632006-05-30 09:24:40 +0000605 printf(" = {");
606 first = true;
607 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
608 if (first) {
609 first = false;
610 } else {
611 printf(", ");
612 }
613 printf("%d", *l_iter);
614 }
615 printf("}\n");
Jens Geyerd629ea02015-09-23 21:16:50 +0200616 if (listin != listout) {
617 printf("*** FAILED ***\n");
618 return_code |= ERR_CONTAINERS;
619 }
Mark Sleee8540632006-05-30 09:24:40 +0000620
621 /**
622 * ENUM TEST
623 */
624 printf("testEnum(ONE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000625 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Mark Sleee8540632006-05-30 09:24:40 +0000626 printf(" = %d\n", ret);
Jens Geyerd629ea02015-09-23 21:16:50 +0200627 if (ret != Numberz::ONE) {
628 printf("*** FAILED ***\n");
629 return_code |= ERR_STRUCTS;
630 }
Mark Sleee8540632006-05-30 09:24:40 +0000631
632 printf("testEnum(TWO)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000633 ret = testClient.testEnum(Numberz::TWO);
Mark Sleee8540632006-05-30 09:24:40 +0000634 printf(" = %d\n", ret);
Jens Geyerd629ea02015-09-23 21:16:50 +0200635 if (ret != Numberz::TWO) {
636 printf("*** FAILED ***\n");
637 return_code |= ERR_STRUCTS;
638 }
Mark Sleee8540632006-05-30 09:24:40 +0000639
640 printf("testEnum(THREE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000641 ret = testClient.testEnum(Numberz::THREE);
Mark Sleee8540632006-05-30 09:24:40 +0000642 printf(" = %d\n", ret);
Jens Geyerd629ea02015-09-23 21:16:50 +0200643 if (ret != Numberz::THREE) {
644 printf("*** FAILED ***\n");
645 return_code |= ERR_STRUCTS;
646 }
Mark Sleee8540632006-05-30 09:24:40 +0000647
648 printf("testEnum(FIVE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000649 ret = testClient.testEnum(Numberz::FIVE);
Mark Sleee8540632006-05-30 09:24:40 +0000650 printf(" = %d\n", ret);
Jens Geyerd629ea02015-09-23 21:16:50 +0200651 if (ret != Numberz::FIVE) {
652 printf("*** FAILED ***\n");
653 return_code |= ERR_STRUCTS;
654 }
Mark Sleee8540632006-05-30 09:24:40 +0000655
656 printf("testEnum(EIGHT)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000657 ret = testClient.testEnum(Numberz::EIGHT);
Mark Sleee8540632006-05-30 09:24:40 +0000658 printf(" = %d\n", ret);
Jens Geyerd629ea02015-09-23 21:16:50 +0200659 if (ret != Numberz::EIGHT) {
660 printf("*** FAILED ***\n");
661 return_code |= ERR_STRUCTS;
662 }
Mark Sleee8540632006-05-30 09:24:40 +0000663
664 /**
665 * TYPEDEF TEST
666 */
667 printf("testTypedef(309858235082523)");
Marc Slemkobf4fd192006-08-15 21:29:39 +0000668 UserId uid = testClient.testTypedef(309858235082523LL);
Roger Meier0e814802014-01-17 21:07:58 +0100669 printf(" = %" PRId64 "\n", uid);
Jens Geyerd629ea02015-09-23 21:16:50 +0200670 if (uid != 309858235082523LL) {
671 printf("*** FAILED ***\n");
672 return_code |= ERR_STRUCTS;
673 }
Mark Sleee8540632006-05-30 09:24:40 +0000674
675 /**
676 * NESTED MAP TEST
677 */
678 printf("testMapMap(1)");
Mark Slee1921d202007-01-24 19:43:06 +0000679 map<int32_t, map<int32_t, int32_t> > mm;
680 testClient.testMapMap(mm, 1);
Mark Sleee8540632006-05-30 09:24:40 +0000681 printf(" = {");
682 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
683 for (mi = mm.begin(); mi != mm.end(); ++mi) {
684 printf("%d => {", mi->first);
685 map<int32_t, int32_t>::const_iterator mi2;
686 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
687 printf("%d => %d, ", mi2->first, mi2->second);
688 }
689 printf("}, ");
690 }
691 printf("}\n");
Jens Geyerd629ea02015-09-23 21:16:50 +0200692 if (mm.size() != 2 ||
693 mm[-4][-4] != -4 ||
694 mm[-4][-3] != -3 ||
695 mm[-4][-2] != -2 ||
696 mm[-4][-1] != -1 ||
697 mm[4][4] != 4 ||
698 mm[4][3] != 3 ||
699 mm[4][2] != 2 ||
700 mm[4][1] != 1) {
701 printf("*** FAILED ***\n");
702 return_code |= ERR_CONTAINERS;
703 }
Mark Sleee8540632006-05-30 09:24:40 +0000704
705 /**
706 * INSANITY TEST
707 */
Jens Geyerf4598682014-05-08 23:18:44 +0200708 if (!noinsane) {
709 Insanity insane;
Jens Geyerd629ea02015-09-23 21:16:50 +0200710 insane.userMap.insert(make_pair(Numberz::FIVE, 5));
711 insane.userMap.insert(make_pair(Numberz::EIGHT, 8));
Jens Geyerf4598682014-05-08 23:18:44 +0200712 Xtruct truck;
Jens Geyerd629ea02015-09-23 21:16:50 +0200713 truck.string_thing = "Goodbye4";
714 truck.byte_thing = 4;
715 truck.i32_thing = 4;
716 truck.i64_thing = 4;
717 Xtruct truck2;
718 truck2.string_thing = "Hello2";
719 truck2.byte_thing = 2;
720 truck2.i32_thing = 2;
721 truck2.i64_thing = 2;
Jens Geyerf4598682014-05-08 23:18:44 +0200722 insane.xtructs.push_back(truck);
Jens Geyerd629ea02015-09-23 21:16:50 +0200723 insane.xtructs.push_back(truck2);
Jens Geyerf4598682014-05-08 23:18:44 +0200724 printf("testInsanity()");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100725 map<UserId, map<Numberz::type, Insanity> > whoa;
Jens Geyerf4598682014-05-08 23:18:44 +0200726 testClient.testInsanity(whoa, insane);
727 printf(" = {");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100728 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Jens Geyerf4598682014-05-08 23:18:44 +0200729 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
730 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100731 map<Numberz::type, Insanity>::const_iterator i2_iter;
732 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Jens Geyerf4598682014-05-08 23:18:44 +0200733 printf("%d => {", i2_iter->first);
734 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
735 map<Numberz::type, UserId>::const_iterator um;
736 printf("{");
737 for (um = userMap.begin(); um != userMap.end(); ++um) {
738 printf("%d => %" PRId64 ", ", um->first, um->second);
739 }
740 printf("}, ");
Mark Sleee8540632006-05-30 09:24:40 +0000741
Jens Geyerf4598682014-05-08 23:18:44 +0200742 vector<Xtruct> xtructs = i2_iter->second.xtructs;
743 vector<Xtruct>::const_iterator x;
744 printf("{");
745 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
746 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
747 x->string_thing.c_str(),
748 (int)x->byte_thing,
749 x->i32_thing,
750 x->i64_thing);
751 }
752 printf("}");
Mark Sleee8540632006-05-30 09:24:40 +0000753
Jens Geyerf4598682014-05-08 23:18:44 +0200754 printf("}, ");
755 }
Mark Sleee8540632006-05-30 09:24:40 +0000756 printf("}, ");
757 }
Jens Geyerf4598682014-05-08 23:18:44 +0200758 printf("}\n");
Jens Geyerd629ea02015-09-23 21:16:50 +0200759 bool failed = false;
760 map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1));
761 if (whoa.size() != 2) {
762 failed = true;
763 }
764 if (it1 == whoa.end()) {
765 failed = true;
766 } else {
767 map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO);
768 if (it12 == it1->second.end() || it12->second != insane) {
769 failed = true;
770 }
771 map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE);
772 if (it13 == it1->second.end() || it13->second != insane) {
773 failed = true;
774 }
775 }
776 map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2));
777 if (it2 == whoa.end()) {
778 failed = true;
779 } else {
780 map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX);
781 if (it26 == it1->second.end() || it26->second != Insanity()) {
782 failed = true;
783 }
784 }
785 if (failed) {
786 printf("*** FAILED ***\n");
787 return_code |= ERR_STRUCTS;
788 }
Mark Sleee8540632006-05-30 09:24:40 +0000789 }
Jens Geyerd629ea02015-09-23 21:16:50 +0200790
791 /**
792 * MULTI TEST
793 */
794 printf("testMulti()\n");
795 try {
796 map<int16_t, string> mul_map;
797 Xtruct mul_result;
798 mul_map[1] = "blah";
799 mul_map[2] = "thing";
800 testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24));
801 Xtruct xxs;
802 xxs.string_thing = "Hello2";
803 xxs.byte_thing = 42;
804 xxs.i32_thing = 4242;
805 xxs.i64_thing = 424242;
806 if (mul_result != xxs) {
807 printf("*** FAILED ***\n");
808 return_code |= ERR_STRUCTS;
809 }
810 } catch (exception& ex) {
811 printf("*** FAILED ***\n");
812 return_code |= ERR_STRUCTS;
813 }
814
Marc Slemko71d4e472006-08-15 22:34:04 +0000815 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +0000816
Marc Slemkobf4fd192006-08-15 21:29:39 +0000817 try {
Marc Slemko71d4e472006-08-15 22:34:04 +0000818 printf("testClient.testException(\"Xception\") =>");
819 testClient.testException("Xception");
Jens Geyerd629ea02015-09-23 21:16:50 +0200820 printf(" void\n*** FAILED ***\n");
821 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +0000822
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100823 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000824 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000825 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000826
Marc Slemkobf4fd192006-08-15 21:29:39 +0000827 try {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100828 printf("testClient.testException(\"TException\") =>");
829 testClient.testException("TException");
Jens Geyerd629ea02015-09-23 21:16:50 +0200830 printf(" void\n*** FAILED ***\n");
831 return_code |= ERR_EXCEPTIONS;
Roger Meierf50df7f2012-05-02 22:49:55 +0000832
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100833 } catch (const TException&) {
834 printf(" Caught TException\n");
835 }
Roger Meierf50df7f2012-05-02 22:49:55 +0000836
837 try {
Marc Slemko71d4e472006-08-15 22:34:04 +0000838 printf("testClient.testException(\"success\") =>");
839 testClient.testException("success");
840 printf(" void\n");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100841 } catch (...) {
Jens Geyerd629ea02015-09-23 21:16:50 +0200842 printf(" exception\n*** FAILED ***\n");
843 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +0000844 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000845
Marc Slemko71d4e472006-08-15 22:34:04 +0000846 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +0000847
Marc Slemko71d4e472006-08-15 22:34:04 +0000848 try {
849 printf("testClient.testMultiException(\"Xception\", \"test 1\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000850 Xtruct result;
851 testClient.testMultiException(result, "Xception", "test 1");
Jens Geyerd629ea02015-09-23 21:16:50 +0200852 printf(" result\n*** FAILED ***\n");
853 return_code |= ERR_EXCEPTIONS;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100854 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000855 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
856 }
857
858 try {
859 printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000860 Xtruct result;
861 testClient.testMultiException(result, "Xception2", "test 2");
Jens Geyerd629ea02015-09-23 21:16:50 +0200862 printf(" result\n*** FAILED ***\n");
863 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +0000864
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100865 } catch (Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000866 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000867 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000868
Marc Slemko71d4e472006-08-15 22:34:04 +0000869 try {
870 printf("testClient.testMultiException(\"success\", \"test 3\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000871 Xtruct result;
872 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +0000873 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100874 } catch (...) {
Jens Geyerd629ea02015-09-23 21:16:50 +0200875 printf(" exception\n*** FAILED ***\n");
876 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +0000877 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000878
David Reissc51986f2009-03-24 20:01:25 +0000879 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +0000880 {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100881 printf("testClient.testOneway(1) =>");
882 uint64_t startOneway = now();
883 testClient.testOneway(1);
884 uint64_t elapsed = now() - startOneway;
885 if (elapsed > 200 * 1000) { // 0.2 seconds
Jens Geyerd629ea02015-09-23 21:16:50 +0200886 printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0);
887 return_code |= ERR_BASETYPES;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100888 } else {
889 printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
890 }
David Reiss2ab6fe82008-02-18 02:11:44 +0000891 }
892
David Reiss2845b522008-02-18 02:11:52 +0000893 /**
David Reissc51986f2009-03-24 20:01:25 +0000894 * redo a simple test after the oneway to make sure we aren't "off by one" --
895 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +0000896 * fail since it will get the void confirmation rather than the correct
897 * result. In this circumstance, the client will throw the exception:
898 *
899 * TApplicationException: Wrong method namea
900 */
901 /**
902 * I32 TEST
903 */
904 printf("re-test testI32(-1)");
905 i32 = testClient.testI32(-1);
906 printf(" = %d\n", i32);
Roger Meier4fce9602012-05-04 06:22:09 +0000907 if (i32 != -1)
Jens Geyerd629ea02015-09-23 21:16:50 +0200908 return_code |= ERR_BASETYPES;
David Reiss2845b522008-02-18 02:11:52 +0000909
Marc Slemkobf4fd192006-08-15 21:29:39 +0000910 uint64_t stop = now();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100911 uint64_t tot = stop - start;
Mark Sleed788b2e2006-09-07 01:26:35 +0000912
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100913 printf("Total time: %" PRIu64 " us\n", stop - start);
David Reiss0c90f6f2008-02-06 22:18:40 +0000914
Mark Sleed788b2e2006-09-07 01:26:35 +0000915 time_tot += tot;
916 if (time_min == 0 || tot < time_min) {
917 time_min = tot;
918 }
919 if (tot > time_max) {
920 time_max = tot;
921 }
922
Mark Sleea3302652006-10-25 19:03:32 +0000923 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +0000924 }
925
Mark Sleee8540632006-05-30 09:24:40 +0000926 printf("\nAll tests done.\n");
Mark Sleed788b2e2006-09-07 01:26:35 +0000927
928 uint64_t time_avg = time_tot / numTests;
929
Roger Meier0e814802014-01-17 21:07:58 +0100930 printf("Min time: %" PRIu64 " us\n", time_min);
931 printf("Max time: %" PRIu64 " us\n", time_max);
932 printf("Avg time: %" PRIu64 " us\n", time_avg);
Mark Sleed788b2e2006-09-07 01:26:35 +0000933
Jens Geyerd629ea02015-09-23 21:16:50 +0200934 return return_code;
Mark Sleee8540632006-05-30 09:24:40 +0000935}