blob: e709899487e1ba845c7b28c6723655c314173b86 [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) {
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900110 int ERR_BASETYPES = 1;
111 int ERR_STRUCTS = 2;
112 int ERR_CONTAINERS = 4;
113 int ERR_EXCEPTIONS = 8;
114 int ERR_UNKNOWN = 64;
115
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530116 string file_path = boost::filesystem::system_complete(argv[0]).string();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100117 string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH);
Jake Farrell5d02b802014-01-07 21:42:01 -0500118#if _WIN32
119 transport::TWinsockSingleton::create();
120#endif
Mark Sleee8540632006-05-30 09:24:40 +0000121 string host = "localhost";
122 int port = 9090;
123 int numTests = 1;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000124 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000125 string transport_type = "buffered";
126 string protocol_type = "binary";
127 string domain_socket = "";
Jens Geyerf4598682014-05-08 23:18:44 +0200128 bool noinsane = false;
Mark Sleee8540632006-05-30 09:24:40 +0000129
Jake Farrell5d02b802014-01-07 21:42:01 -0500130 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100131 desc.add_options()("help,h",
132 "produce help message")("host",
133 boost::program_options::value<string>(&host)
134 ->default_value(host),
135 "Host to connect")("port",
136 boost::program_options::value<int>(
137 &port)->default_value(port),
138 "Port number to connect")(
139 "domain-socket",
140 boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
141 "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")(
142 "transport",
143 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
144 "Transport: buffered, framed, http, evhttp")(
145 "protocol",
146 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
147 "Protocol: binary, compact, json")("ssl", "Encrypted Transport using SSL")(
148 "testloops,n",
149 boost::program_options::value<int>(&numTests)->default_value(numTests),
150 "Number of Tests")("noinsane", "Do not run insanity test");
Roger Meierca142b02011-06-07 17:59:07 +0000151
Jake Farrell5d02b802014-01-07 21:42:01 -0500152 boost::program_options::variables_map vm;
153 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
154 boost::program_options::notify(vm);
Roger Meierca142b02011-06-07 17:59:07 +0000155
156 if (vm.count("help")) {
157 cout << desc << "\n";
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900158 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000159 }
Mark Sleea3302652006-10-25 19:03:32 +0000160
Jake Farrell5d02b802014-01-07 21:42:01 -0500161 try {
Roger Meierca142b02011-06-07 17:59:07 +0000162 if (!protocol_type.empty()) {
163 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100164 } else if (protocol_type == "compact") {
Roger Meierca142b02011-06-07 17:59:07 +0000165 } else if (protocol_type == "json") {
166 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100167 throw invalid_argument("Unknown protocol type " + protocol_type);
Roger Meierca142b02011-06-07 17:59:07 +0000168 }
169 }
170
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100171 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000172 if (transport_type == "buffered") {
173 } else if (transport_type == "framed") {
174 } else if (transport_type == "http") {
Roger Meier7e056e72011-07-17 07:28:28 +0000175 } else if (transport_type == "evhttp") {
Roger Meierca142b02011-06-07 17:59:07 +0000176 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100177 throw invalid_argument("Unknown transport type " + transport_type);
Roger Meierca142b02011-06-07 17:59:07 +0000178 }
179 }
180
181 } catch (std::exception& e) {
182 cerr << e.what() << endl;
183 cout << desc << "\n";
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900184 return ERR_UNKNOWN;
Roger Meierca142b02011-06-07 17:59:07 +0000185 }
186
187 if (vm.count("ssl")) {
188 ssl = true;
189 }
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530190
Jens Geyerf4598682014-05-08 23:18:44 +0200191 if (vm.count("noinsane")) {
192 noinsane = true;
193 }
Roger Meierca142b02011-06-07 17:59:07 +0000194
Roger Meier611f90c2011-12-11 22:08:51 +0000195 boost::shared_ptr<TTransport> transport;
196 boost::shared_ptr<TProtocol> protocol;
Roger Meierca142b02011-06-07 17:59:07 +0000197
Roger Meier611f90c2011-12-11 22:08:51 +0000198 boost::shared_ptr<TSocket> socket;
199 boost::shared_ptr<TSSLSocketFactory> factory;
Roger Meierca142b02011-06-07 17:59:07 +0000200
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000201 if (ssl) {
Roger Meier611f90c2011-12-11 22:08:51 +0000202 factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000203 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530204 factory->loadTrustedCertificates((dir_path + "../keys/CA.pem").c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000205 factory->authenticate(true);
206 socket = factory->createSocket(host, port);
207 } else {
Roger Meierca142b02011-06-07 17:59:07 +0000208 if (domain_socket != "") {
Roger Meier611f90c2011-12-11 22:08:51 +0000209 socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket));
Roger Meierca142b02011-06-07 17:59:07 +0000210 port = 0;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100211 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000212 socket = boost::shared_ptr<TSocket>(new TSocket(host, port));
Roger Meierca142b02011-06-07 17:59:07 +0000213 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000214 }
Mark Sleea3302652006-10-25 19:03:32 +0000215
Roger Meierca142b02011-06-07 17:59:07 +0000216 if (transport_type.compare("http") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000217 boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service"));
Roger Meierca142b02011-06-07 17:59:07 +0000218 transport = httpSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100219 } else if (transport_type.compare("framed") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000220 boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000221 transport = framedSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100222 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000223 boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000224 transport = bufferedSocket;
225 }
226
Roger Meierca142b02011-06-07 17:59:07 +0000227 if (protocol_type.compare("json") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000228 boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000229 protocol = jsonProtocol;
Roger Meier023192f2014-02-12 09:35:12 +0100230 } else if (protocol_type.compare("compact") == 0) {
231 boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport));
232 protocol = compactProtocol;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100233 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000234 boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000235 protocol = binaryProtocol;
236 }
237
238 // Connection info
239 cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: " << domain_socket;
240 if (port != 0) {
241 cout << host << ":" << port;
242 }
243 cout << endl;
244
Roger Meier7e056e72011-07-17 07:28:28 +0000245 if (transport_type.compare("evhttp") == 0) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100246 event_base* base = event_base_new();
Roger Meier7e056e72011-07-17 07:28:28 +0000247 cout << "Libevent Version: " << event_get_version() << endl;
248 cout << "Libevent Method: " << event_base_get_method(base) << endl;
249#if LIBEVENT_VERSION_NUMBER >= 0x02000000
250 cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl;
251#endif
252
Roger Meier611f90c2011-12-11 22:08:51 +0000253 boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Roger Meier7e056e72011-07-17 07:28:28 +0000254
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100255 boost::shared_ptr<TAsyncChannel> channel(
256 new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
Roger Meier7e056e72011-07-17 07:28:28 +0000257 ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100258 client->testVoid(tcxx::bind(testVoid_clientReturn,
259 host.c_str(),
260 port,
261 base,
262 protocolFactory.get(),
263 tcxx::placeholders::_1));
Jake Farrell5d02b802014-01-07 21:42:01 -0500264
Roger Meier7e056e72011-07-17 07:28:28 +0000265 event_base_loop(base, 0);
266 return 0;
267 }
268
Roger Meierca142b02011-06-07 17:59:07 +0000269 ThriftTestClient testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000270
271 uint64_t time_min = 0;
272 uint64_t time_max = 0;
273 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000274
Jens Geyerd629ea02015-09-23 21:16:50 +0200275 int return_code = 0;
Jens Geyerd629ea02015-09-23 21:16:50 +0200276
Mark Sleee8540632006-05-30 09:24:40 +0000277 int test = 0;
278 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000279
Mark Slee95771002006-06-07 06:53:25 +0000280 try {
Mark Sleea3302652006-10-25 19:03:32 +0000281 transport->open();
Mark Slee95771002006-06-07 06:53:25 +0000282 } catch (TTransportException& ttx) {
Mark Sleeb9ff32a2006-11-16 01:00:24 +0000283 printf("Connect failed: %s\n", ttx.what());
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900284 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000285 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000286
Mark Sleed788b2e2006-09-07 01:26:35 +0000287 /**
288 * CONNECT TEST
289 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100290 printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000291
292 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000293
Mark Sleee8540632006-05-30 09:24:40 +0000294 /**
295 * VOID TEST
296 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000297 try {
298 printf("testVoid()");
299 testClient.testVoid();
300 printf(" = void\n");
Roger Meier4fce9602012-05-04 06:22:09 +0000301 } catch (TApplicationException& tax) {
Jens Geyerd629ea02015-09-23 21:16:50 +0200302 printf("*** FAILED ***\n");
Mark Sleee129a2d2007-02-21 05:17:48 +0000303 printf("%s\n", tax.what());
Jens Geyerd629ea02015-09-23 21:16:50 +0200304 return_code |= ERR_BASETYPES;
Mark Sleee129a2d2007-02-21 05:17:48 +0000305 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000306
Mark Sleee8540632006-05-30 09:24:40 +0000307 /**
308 * STRING TEST
309 */
310 printf("testString(\"Test\")");
Mark Slee1921d202007-01-24 19:43:06 +0000311 string s;
312 testClient.testString(s, "Test");
Mark Sleee8540632006-05-30 09:24:40 +0000313 printf(" = \"%s\"\n", s.c_str());
Jens Geyerd629ea02015-09-23 21:16:50 +0200314 if (s != "Test") {
315 printf("*** FAILED ***\n");
316 return_code |= ERR_BASETYPES;
317 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000318
Mark Sleee8540632006-05-30 09:24:40 +0000319 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900320 * BOOL TEST
321 */
322 printf("testBool(true)");
323 bool bl = testClient.testBool(true);
324 printf(" = %s\n", bl ? "true" : "false");
Jens Geyerd629ea02015-09-23 21:16:50 +0200325 if (bl != true) {
326 printf("*** FAILED ***\n");
327 return_code |= ERR_BASETYPES;
328 }
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900329
330 printf("testBool(false)");
331 bl = testClient.testBool(false);
332 printf(" = %s\n", bl ? "true" : "false");
Jens Geyerd629ea02015-09-23 21:16:50 +0200333 if (bl != false) {
334 printf("*** FAILED ***\n");
335 return_code |= ERR_BASETYPES;
336 }
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900337
338 /**
Mark Sleee8540632006-05-30 09:24:40 +0000339 * BYTE TEST
340 */
341 printf("testByte(1)");
342 uint8_t u8 = testClient.testByte(1);
343 printf(" = %d\n", (int)u8);
Jens Geyerd629ea02015-09-23 21:16:50 +0200344 if (u8 != 1) {
345 printf("*** FAILED ***\n");
346 return_code |= ERR_BASETYPES;
347 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000348
Mark Sleee8540632006-05-30 09:24:40 +0000349 /**
350 * I32 TEST
351 */
352 printf("testI32(-1)");
353 int32_t i32 = testClient.testI32(-1);
354 printf(" = %d\n", i32);
Jens Geyerd629ea02015-09-23 21:16:50 +0200355 if (i32 != -1) {
356 printf("*** FAILED ***\n");
357 return_code |= ERR_BASETYPES;
358 }
Mark Sleee8540632006-05-30 09:24:40 +0000359
360 /**
Mark Sleee8540632006-05-30 09:24:40 +0000361 * I64 TEST
362 */
363 printf("testI64(-34359738368)");
Marc Slemkobf4fd192006-08-15 21:29:39 +0000364 int64_t i64 = testClient.testI64(-34359738368LL);
Roger Meier0e814802014-01-17 21:07:58 +0100365 printf(" = %" PRId64 "\n", i64);
Jens Geyerd629ea02015-09-23 21:16:50 +0200366 if (i64 != -34359738368LL) {
367 printf("*** FAILED ***\n");
368 return_code |= ERR_BASETYPES;
369 }
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100370
Mark Sleec98d0502006-09-06 02:42:25 +0000371 /**
372 * DOUBLE TEST
373 */
374 printf("testDouble(-5.2098523)");
375 double dub = testClient.testDouble(-5.2098523);
Roger Meiera8cef6e2011-07-17 18:55:59 +0000376 printf(" = %f\n", dub);
Jens Geyerd629ea02015-09-23 21:16:50 +0200377 if ((dub - (-5.2098523)) > 0.001) {
378 printf("*** FAILED ***\n");
379 return_code |= ERR_BASETYPES;
380 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000381
Mark Sleee8540632006-05-30 09:24:40 +0000382 /**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100383 * BINARY TEST
384 */
Jens Geyerd629ea02015-09-23 21:16:50 +0200385 printf("testBinary([-128..127]) = {");
386 const char bin_data[256]
387 = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
388 -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
389 -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
390 -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
391 -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
392 -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
393 -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
394 -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
395 -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
396 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
397 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
398 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
399 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
400 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
401 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
402 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
403 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
404 127};
405 try {
406 string bin_result;
407 testClient.testBinary(bin_result, string(bin_data, 256));
408 if (bin_result.size() != 256) {
409 printf("}\n*** FAILED ***\n");
410 printf("invalid length: %lu\n", bin_result.size());
411 return_code |= ERR_BASETYPES;
412 } else {
413 bool first = true;
414 bool failed = false;
415 for (int i = 0; i < 256; ++i) {
416 if (!first)
417 printf(" ,");
418 else
419 first = false;
420 printf("%d", bin_result[i]);
421 if (!failed && bin_result[i] != i - 128) {
422 failed = true;
423 }
424 }
425 printf("}\n");
426 if (failed) {
427 printf("*** FAILED ***\n");
428 return_code |= ERR_BASETYPES;
429 }
430 }
431 } catch (exception& ex) {
432 printf("}\n*** FAILED ***\n");
433 printf("%s\n", ex.what());
434 return_code |= ERR_BASETYPES;
435 }
436
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100437
438 /**
Mark Sleee8540632006-05-30 09:24:40 +0000439 * STRUCT TEST
440 */
Mark Slee6e536442006-06-30 18:28:50 +0000441 printf("testStruct({\"Zero\", 1, -3, -5})");
Mark Sleee8540632006-05-30 09:24:40 +0000442 Xtruct out;
443 out.string_thing = "Zero";
444 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000445 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000446 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000447 Xtruct in;
448 testClient.testStruct(in, out);
Roger Meier0e814802014-01-17 21:07:58 +0100449 printf(" = {\"%s\", %d, %d, %" PRId64 "}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000450 in.string_thing.c_str(),
451 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000452 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000453 in.i64_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200454 if (in != out) {
455 printf("*** FAILED ***\n");
456 return_code |= ERR_STRUCTS;
457 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000458
Mark Sleee8540632006-05-30 09:24:40 +0000459 /**
460 * NESTED STRUCT TEST
461 */
Mark Slee6e536442006-06-30 18:28:50 +0000462 printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
Mark Sleee8540632006-05-30 09:24:40 +0000463 Xtruct2 out2;
464 out2.byte_thing = 1;
465 out2.struct_thing = out;
466 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000467 Xtruct2 in2;
468 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000469 in = in2.struct_thing;
Roger Meier0e814802014-01-17 21:07:58 +0100470 printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000471 in2.byte_thing,
472 in.string_thing.c_str(),
473 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000474 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000475 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000476 in2.i32_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200477 if (in2 != out2) {
478 printf("*** FAILED ***\n");
479 return_code |= ERR_STRUCTS;
480 }
Mark Sleee8540632006-05-30 09:24:40 +0000481
482 /**
483 * MAP TEST
484 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100485 map<int32_t, int32_t> mapout;
Mark Sleee8540632006-05-30 09:24:40 +0000486 for (int32_t i = 0; i < 5; ++i) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100487 mapout.insert(make_pair(i, i - 10));
Mark Sleee8540632006-05-30 09:24:40 +0000488 }
489 printf("testMap({");
490 map<int32_t, int32_t>::const_iterator m_iter;
491 bool first = true;
492 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
493 if (first) {
494 first = false;
495 } else {
496 printf(", ");
497 }
498 printf("%d => %d", m_iter->first, m_iter->second);
499 }
500 printf("})");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100501 map<int32_t, int32_t> mapin;
Mark Slee1921d202007-01-24 19:43:06 +0000502 testClient.testMap(mapin, mapout);
Mark Sleee8540632006-05-30 09:24:40 +0000503 printf(" = {");
504 first = true;
505 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
506 if (first) {
507 first = false;
508 } else {
509 printf(", ");
510 }
511 printf("%d => %d", m_iter->first, m_iter->second);
512 }
513 printf("}\n");
Jens Geyerd629ea02015-09-23 21:16:50 +0200514 if (mapin != mapout) {
515 printf("*** FAILED ***\n");
516 return_code |= ERR_CONTAINERS;
517 }
Roger Meier4fce9602012-05-04 06:22:09 +0000518
519 /**
520 * STRING MAP TEST
Roger Meier4fce9602012-05-04 06:22:09 +0000521 */
Jens Geyerd629ea02015-09-23 21:16:50 +0200522 printf("testStringMap({a => 2, b => blah, some => thing}) = {");
523 map<string, string> smapin;
524 map<string, string> smapout;
525 smapin["a"] = "2";
526 smapin["b"] = "blah";
527 smapin["some"] = "thing";
528 try {
529 testClient.testStringMap(smapout, smapin);
530 first = true;
531 for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) {
532 if (first)
533 printf(",");
534 else
535 first = false;
536 printf("%s => %s", it->first.c_str(), it->second.c_str());
537 }
538 printf("}\n");
539 if (smapin != smapout) {
540 printf("*** FAILED ***\n");
541 return_code |= ERR_CONTAINERS;
542 }
543 } catch (exception& ex) {
544 printf("}\n*** FAILED ***\n");
545 printf("%s\n", ex.what());
546 return_code |= ERR_CONTAINERS;
547 }
Mark Sleee8540632006-05-30 09:24:40 +0000548
549 /**
550 * SET TEST
551 */
552 set<int32_t> setout;
553 for (int32_t i = -2; i < 3; ++i) {
554 setout.insert(i);
555 }
556 printf("testSet({");
557 set<int32_t>::const_iterator s_iter;
558 first = true;
559 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
560 if (first) {
561 first = false;
562 } else {
563 printf(", ");
564 }
565 printf("%d", *s_iter);
566 }
567 printf("})");
Mark Slee1921d202007-01-24 19:43:06 +0000568 set<int32_t> setin;
569 testClient.testSet(setin, setout);
Mark Sleee8540632006-05-30 09:24:40 +0000570 printf(" = {");
571 first = true;
572 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
573 if (first) {
574 first = false;
575 } else {
576 printf(", ");
577 }
578 printf("%d", *s_iter);
579 }
580 printf("}\n");
Jens Geyerd629ea02015-09-23 21:16:50 +0200581 if (setin != setout) {
582 printf("*** FAILED ***\n");
583 return_code |= ERR_CONTAINERS;
584 }
Mark Sleee8540632006-05-30 09:24:40 +0000585
586 /**
587 * LIST TEST
588 */
Mark Sleeb9acf982006-10-10 01:57:32 +0000589 vector<int32_t> listout;
Mark Sleee8540632006-05-30 09:24:40 +0000590 for (int32_t i = -2; i < 3; ++i) {
591 listout.push_back(i);
592 }
593 printf("testList({");
Mark Sleeb9acf982006-10-10 01:57:32 +0000594 vector<int32_t>::const_iterator l_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000595 first = true;
596 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
597 if (first) {
598 first = false;
599 } else {
600 printf(", ");
601 }
602 printf("%d", *l_iter);
603 }
604 printf("})");
Mark Slee1921d202007-01-24 19:43:06 +0000605 vector<int32_t> listin;
606 testClient.testList(listin, listout);
Mark Sleee8540632006-05-30 09:24:40 +0000607 printf(" = {");
608 first = true;
609 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
610 if (first) {
611 first = false;
612 } else {
613 printf(", ");
614 }
615 printf("%d", *l_iter);
616 }
617 printf("}\n");
Jens Geyerd629ea02015-09-23 21:16:50 +0200618 if (listin != listout) {
619 printf("*** FAILED ***\n");
620 return_code |= ERR_CONTAINERS;
621 }
Mark Sleee8540632006-05-30 09:24:40 +0000622
623 /**
624 * ENUM TEST
625 */
626 printf("testEnum(ONE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000627 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Mark Sleee8540632006-05-30 09:24:40 +0000628 printf(" = %d\n", ret);
Jens Geyerd629ea02015-09-23 21:16:50 +0200629 if (ret != Numberz::ONE) {
630 printf("*** FAILED ***\n");
631 return_code |= ERR_STRUCTS;
632 }
Mark Sleee8540632006-05-30 09:24:40 +0000633
634 printf("testEnum(TWO)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000635 ret = testClient.testEnum(Numberz::TWO);
Mark Sleee8540632006-05-30 09:24:40 +0000636 printf(" = %d\n", ret);
Jens Geyerd629ea02015-09-23 21:16:50 +0200637 if (ret != Numberz::TWO) {
638 printf("*** FAILED ***\n");
639 return_code |= ERR_STRUCTS;
640 }
Mark Sleee8540632006-05-30 09:24:40 +0000641
642 printf("testEnum(THREE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000643 ret = testClient.testEnum(Numberz::THREE);
Mark Sleee8540632006-05-30 09:24:40 +0000644 printf(" = %d\n", ret);
Jens Geyerd629ea02015-09-23 21:16:50 +0200645 if (ret != Numberz::THREE) {
646 printf("*** FAILED ***\n");
647 return_code |= ERR_STRUCTS;
648 }
Mark Sleee8540632006-05-30 09:24:40 +0000649
650 printf("testEnum(FIVE)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000651 ret = testClient.testEnum(Numberz::FIVE);
Mark Sleee8540632006-05-30 09:24:40 +0000652 printf(" = %d\n", ret);
Jens Geyerd629ea02015-09-23 21:16:50 +0200653 if (ret != Numberz::FIVE) {
654 printf("*** FAILED ***\n");
655 return_code |= ERR_STRUCTS;
656 }
Mark Sleee8540632006-05-30 09:24:40 +0000657
658 printf("testEnum(EIGHT)");
Bryan Duxbury833ae492010-09-27 17:26:02 +0000659 ret = testClient.testEnum(Numberz::EIGHT);
Mark Sleee8540632006-05-30 09:24:40 +0000660 printf(" = %d\n", ret);
Jens Geyerd629ea02015-09-23 21:16:50 +0200661 if (ret != Numberz::EIGHT) {
662 printf("*** FAILED ***\n");
663 return_code |= ERR_STRUCTS;
664 }
Mark Sleee8540632006-05-30 09:24:40 +0000665
666 /**
667 * TYPEDEF TEST
668 */
669 printf("testTypedef(309858235082523)");
Marc Slemkobf4fd192006-08-15 21:29:39 +0000670 UserId uid = testClient.testTypedef(309858235082523LL);
Roger Meier0e814802014-01-17 21:07:58 +0100671 printf(" = %" PRId64 "\n", uid);
Jens Geyerd629ea02015-09-23 21:16:50 +0200672 if (uid != 309858235082523LL) {
673 printf("*** FAILED ***\n");
674 return_code |= ERR_STRUCTS;
675 }
Mark Sleee8540632006-05-30 09:24:40 +0000676
677 /**
678 * NESTED MAP TEST
679 */
680 printf("testMapMap(1)");
Mark Slee1921d202007-01-24 19:43:06 +0000681 map<int32_t, map<int32_t, int32_t> > mm;
682 testClient.testMapMap(mm, 1);
Mark Sleee8540632006-05-30 09:24:40 +0000683 printf(" = {");
684 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
685 for (mi = mm.begin(); mi != mm.end(); ++mi) {
686 printf("%d => {", mi->first);
687 map<int32_t, int32_t>::const_iterator mi2;
688 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
689 printf("%d => %d, ", mi2->first, mi2->second);
690 }
691 printf("}, ");
692 }
693 printf("}\n");
Jens Geyerd629ea02015-09-23 21:16:50 +0200694 if (mm.size() != 2 ||
695 mm[-4][-4] != -4 ||
696 mm[-4][-3] != -3 ||
697 mm[-4][-2] != -2 ||
698 mm[-4][-1] != -1 ||
699 mm[4][4] != 4 ||
700 mm[4][3] != 3 ||
701 mm[4][2] != 2 ||
702 mm[4][1] != 1) {
703 printf("*** FAILED ***\n");
704 return_code |= ERR_CONTAINERS;
705 }
Mark Sleee8540632006-05-30 09:24:40 +0000706
707 /**
708 * INSANITY TEST
709 */
Jens Geyerf4598682014-05-08 23:18:44 +0200710 if (!noinsane) {
711 Insanity insane;
Jens Geyerd629ea02015-09-23 21:16:50 +0200712 insane.userMap.insert(make_pair(Numberz::FIVE, 5));
713 insane.userMap.insert(make_pair(Numberz::EIGHT, 8));
Jens Geyerf4598682014-05-08 23:18:44 +0200714 Xtruct truck;
Jens Geyerd629ea02015-09-23 21:16:50 +0200715 truck.string_thing = "Goodbye4";
716 truck.byte_thing = 4;
717 truck.i32_thing = 4;
718 truck.i64_thing = 4;
719 Xtruct truck2;
720 truck2.string_thing = "Hello2";
721 truck2.byte_thing = 2;
722 truck2.i32_thing = 2;
723 truck2.i64_thing = 2;
Jens Geyerf4598682014-05-08 23:18:44 +0200724 insane.xtructs.push_back(truck);
Jens Geyerd629ea02015-09-23 21:16:50 +0200725 insane.xtructs.push_back(truck2);
Jens Geyerf4598682014-05-08 23:18:44 +0200726 printf("testInsanity()");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100727 map<UserId, map<Numberz::type, Insanity> > whoa;
Jens Geyerf4598682014-05-08 23:18:44 +0200728 testClient.testInsanity(whoa, insane);
729 printf(" = {");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100730 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Jens Geyerf4598682014-05-08 23:18:44 +0200731 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
732 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100733 map<Numberz::type, Insanity>::const_iterator i2_iter;
734 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Jens Geyerf4598682014-05-08 23:18:44 +0200735 printf("%d => {", i2_iter->first);
736 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
737 map<Numberz::type, UserId>::const_iterator um;
738 printf("{");
739 for (um = userMap.begin(); um != userMap.end(); ++um) {
740 printf("%d => %" PRId64 ", ", um->first, um->second);
741 }
742 printf("}, ");
Mark Sleee8540632006-05-30 09:24:40 +0000743
Jens Geyerf4598682014-05-08 23:18:44 +0200744 vector<Xtruct> xtructs = i2_iter->second.xtructs;
745 vector<Xtruct>::const_iterator x;
746 printf("{");
747 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
748 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
749 x->string_thing.c_str(),
750 (int)x->byte_thing,
751 x->i32_thing,
752 x->i64_thing);
753 }
754 printf("}");
Mark Sleee8540632006-05-30 09:24:40 +0000755
Jens Geyerf4598682014-05-08 23:18:44 +0200756 printf("}, ");
757 }
Mark Sleee8540632006-05-30 09:24:40 +0000758 printf("}, ");
759 }
Jens Geyerf4598682014-05-08 23:18:44 +0200760 printf("}\n");
Jens Geyerd629ea02015-09-23 21:16:50 +0200761 bool failed = false;
762 map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1));
763 if (whoa.size() != 2) {
764 failed = true;
765 }
766 if (it1 == whoa.end()) {
767 failed = true;
768 } else {
769 map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO);
770 if (it12 == it1->second.end() || it12->second != insane) {
771 failed = true;
772 }
773 map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE);
774 if (it13 == it1->second.end() || it13->second != insane) {
775 failed = true;
776 }
777 }
778 map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2));
779 if (it2 == whoa.end()) {
780 failed = true;
781 } else {
782 map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX);
783 if (it26 == it1->second.end() || it26->second != Insanity()) {
784 failed = true;
785 }
786 }
787 if (failed) {
788 printf("*** FAILED ***\n");
789 return_code |= ERR_STRUCTS;
790 }
Mark Sleee8540632006-05-30 09:24:40 +0000791 }
Jens Geyerd629ea02015-09-23 21:16:50 +0200792
793 /**
794 * MULTI TEST
795 */
796 printf("testMulti()\n");
797 try {
798 map<int16_t, string> mul_map;
799 Xtruct mul_result;
800 mul_map[1] = "blah";
801 mul_map[2] = "thing";
802 testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24));
803 Xtruct xxs;
804 xxs.string_thing = "Hello2";
805 xxs.byte_thing = 42;
806 xxs.i32_thing = 4242;
807 xxs.i64_thing = 424242;
808 if (mul_result != xxs) {
809 printf("*** FAILED ***\n");
810 return_code |= ERR_STRUCTS;
811 }
812 } catch (exception& ex) {
813 printf("*** FAILED ***\n");
814 return_code |= ERR_STRUCTS;
815 }
816
Marc Slemko71d4e472006-08-15 22:34:04 +0000817 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +0000818
Marc Slemkobf4fd192006-08-15 21:29:39 +0000819 try {
Marc Slemko71d4e472006-08-15 22:34:04 +0000820 printf("testClient.testException(\"Xception\") =>");
821 testClient.testException("Xception");
Jens Geyerd629ea02015-09-23 21:16:50 +0200822 printf(" void\n*** FAILED ***\n");
823 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +0000824
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100825 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000826 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000827 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000828
Marc Slemkobf4fd192006-08-15 21:29:39 +0000829 try {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100830 printf("testClient.testException(\"TException\") =>");
831 testClient.testException("TException");
Jens Geyerd629ea02015-09-23 21:16:50 +0200832 printf(" void\n*** FAILED ***\n");
833 return_code |= ERR_EXCEPTIONS;
Roger Meierf50df7f2012-05-02 22:49:55 +0000834
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100835 } catch (const TException&) {
836 printf(" Caught TException\n");
837 }
Roger Meierf50df7f2012-05-02 22:49:55 +0000838
839 try {
Marc Slemko71d4e472006-08-15 22:34:04 +0000840 printf("testClient.testException(\"success\") =>");
841 testClient.testException("success");
842 printf(" void\n");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100843 } catch (...) {
Jens Geyerd629ea02015-09-23 21:16:50 +0200844 printf(" exception\n*** FAILED ***\n");
845 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +0000846 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000847
Marc Slemko71d4e472006-08-15 22:34:04 +0000848 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +0000849
Marc Slemko71d4e472006-08-15 22:34:04 +0000850 try {
851 printf("testClient.testMultiException(\"Xception\", \"test 1\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000852 Xtruct result;
853 testClient.testMultiException(result, "Xception", "test 1");
Jens Geyerd629ea02015-09-23 21:16:50 +0200854 printf(" result\n*** FAILED ***\n");
855 return_code |= ERR_EXCEPTIONS;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100856 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000857 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
858 }
859
860 try {
861 printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000862 Xtruct result;
863 testClient.testMultiException(result, "Xception2", "test 2");
Jens Geyerd629ea02015-09-23 21:16:50 +0200864 printf(" result\n*** FAILED ***\n");
865 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +0000866
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100867 } catch (Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000868 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000869 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000870
Marc Slemko71d4e472006-08-15 22:34:04 +0000871 try {
872 printf("testClient.testMultiException(\"success\", \"test 3\") =>");
Mark Slee1921d202007-01-24 19:43:06 +0000873 Xtruct result;
874 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +0000875 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100876 } catch (...) {
Jens Geyerd629ea02015-09-23 21:16:50 +0200877 printf(" exception\n*** FAILED ***\n");
878 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +0000879 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000880
David Reissc51986f2009-03-24 20:01:25 +0000881 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +0000882 {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100883 printf("testClient.testOneway(1) =>");
884 uint64_t startOneway = now();
885 testClient.testOneway(1);
886 uint64_t elapsed = now() - startOneway;
887 if (elapsed > 200 * 1000) { // 0.2 seconds
Jens Geyerd629ea02015-09-23 21:16:50 +0200888 printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0);
889 return_code |= ERR_BASETYPES;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100890 } else {
891 printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
892 }
David Reiss2ab6fe82008-02-18 02:11:44 +0000893 }
894
David Reiss2845b522008-02-18 02:11:52 +0000895 /**
David Reissc51986f2009-03-24 20:01:25 +0000896 * redo a simple test after the oneway to make sure we aren't "off by one" --
897 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +0000898 * fail since it will get the void confirmation rather than the correct
899 * result. In this circumstance, the client will throw the exception:
900 *
901 * TApplicationException: Wrong method namea
902 */
903 /**
904 * I32 TEST
905 */
906 printf("re-test testI32(-1)");
907 i32 = testClient.testI32(-1);
908 printf(" = %d\n", i32);
Roger Meier4fce9602012-05-04 06:22:09 +0000909 if (i32 != -1)
Jens Geyerd629ea02015-09-23 21:16:50 +0200910 return_code |= ERR_BASETYPES;
David Reiss2845b522008-02-18 02:11:52 +0000911
Marc Slemkobf4fd192006-08-15 21:29:39 +0000912 uint64_t stop = now();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100913 uint64_t tot = stop - start;
Mark Sleed788b2e2006-09-07 01:26:35 +0000914
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100915 printf("Total time: %" PRIu64 " us\n", stop - start);
David Reiss0c90f6f2008-02-06 22:18:40 +0000916
Mark Sleed788b2e2006-09-07 01:26:35 +0000917 time_tot += tot;
918 if (time_min == 0 || tot < time_min) {
919 time_min = tot;
920 }
921 if (tot > time_max) {
922 time_max = tot;
923 }
924
Mark Sleea3302652006-10-25 19:03:32 +0000925 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +0000926 }
927
Mark Sleee8540632006-05-30 09:24:40 +0000928 printf("\nAll tests done.\n");
Mark Sleed788b2e2006-09-07 01:26:35 +0000929
930 uint64_t time_avg = time_tot / numTests;
931
Roger Meier0e814802014-01-17 21:07:58 +0100932 printf("Min time: %" PRIu64 " us\n", time_min);
933 printf("Max time: %" PRIu64 " us\n", time_max);
934 printf("Avg time: %" PRIu64 " us\n", time_avg);
Mark Sleed788b2e2006-09-07 01:26:35 +0000935
Jens Geyerd629ea02015-09-23 21:16:50 +0200936 return return_code;
Mark Sleee8540632006-05-30 09:24:40 +0000937}