blob: 5d06c568b7d41439b3a8fa159995f57a9922aaa8 [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>
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +090022#include <limits>
23#include <locale>
24#include <ios>
Roger Meierca142b02011-06-07 17:59:07 +000025#include <iostream>
Roger Meier49ff8b12012-04-13 09:12:31 +000026#include <thrift/protocol/TBinaryProtocol.h>
Roger Meier023192f2014-02-12 09:35:12 +010027#include <thrift/protocol/TCompactProtocol.h>
Dave Watson792db4e2015-01-16 11:22:01 -080028#include <thrift/protocol/THeaderProtocol.h>
Roger Meier49ff8b12012-04-13 09:12:31 +000029#include <thrift/protocol/TJSONProtocol.h>
30#include <thrift/transport/THttpClient.h>
31#include <thrift/transport/TTransportUtils.h>
32#include <thrift/transport/TSocket.h>
33#include <thrift/transport/TSSLSocket.h>
34#include <thrift/async/TEvhttpClientChannel.h>
35#include <thrift/server/TNonblockingServer.h> // <event.h>
Mark Sleee8540632006-05-30 09:24:40 +000036
Marc Slemko6be374b2006-08-04 03:16:25 +000037#include <boost/shared_ptr.hpp>
Roger Meierca142b02011-06-07 17:59:07 +000038#include <boost/program_options.hpp>
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053039#include <boost/filesystem.hpp>
Jake Farrell5d02b802014-01-07 21:42:01 -050040#include <thrift/cxxfunctional.h>
41#if _WIN32
Konrad Grochowski16a23a62014-11-13 15:33:38 +010042#include <thrift/windows/TWinsockSingleton.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050043#endif
Roger Meierca142b02011-06-07 17:59:07 +000044
Marc Slemko6be374b2006-08-04 03:16:25 +000045#include "ThriftTest.h"
46
Marc Slemko6be374b2006-08-04 03:16:25 +000047using namespace std;
T Jake Lucianib5e62212009-01-31 22:36:20 +000048using namespace apache::thrift;
49using namespace apache::thrift::protocol;
50using namespace apache::thrift::transport;
Marc Slemkobf4fd192006-08-15 21:29:39 +000051using namespace thrift::test;
Roger Meier7e056e72011-07-17 07:28:28 +000052using namespace apache::thrift::async;
53
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053054// Length of argv[0] - Length of script dir
55#define EXECUTABLE_FILE_NAME_LENGTH 19
56
Mark Slee95771002006-06-07 06:53:25 +000057// Current time, microseconds since the epoch
Konrad Grochowski16a23a62014-11-13 15:33:38 +010058uint64_t now() {
Roger Meier5f9614c2010-11-21 16:59:05 +000059 int64_t ret;
Mark Slee95771002006-06-07 06:53:25 +000060 struct timeval tv;
David Reiss0c90f6f2008-02-06 22:18:40 +000061
Jake Farrell5d02b802014-01-07 21:42:01 -050062 THRIFT_GETTIMEOFDAY(&tv, NULL);
Mark Slee95771002006-06-07 06:53:25 +000063 ret = tv.tv_sec;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010064 ret = ret * 1000 * 1000 + tv.tv_usec;
Mark Slee95771002006-06-07 06:53:25 +000065 return ret;
66}
67
Konrad Grochowski16a23a62014-11-13 15:33:38 +010068static void testString_clientReturn(const char* host,
69 int port,
70 event_base* base,
71 TProtocolFactory* protocolFactory,
72 ThriftTestCobClient* client) {
73 (void)host;
74 (void)port;
75 (void)protocolFactory;
Roger Meier7e056e72011-07-17 07:28:28 +000076 try {
77 string s;
78 client->recv_testString(s);
79 cout << "testString: " << s << endl;
80 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -050081 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000082 }
83
84 event_base_loopbreak(base); // end test
85}
86
Konrad Grochowski16a23a62014-11-13 15:33:38 +010087static void testVoid_clientReturn(const char* host,
88 int port,
89 event_base* base,
90 TProtocolFactory* protocolFactory,
91 ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000092 try {
93 client->recv_testVoid();
94 cout << "testVoid" << endl;
95
96 // next test
97 delete client;
Roger Meier611f90c2011-12-11 22:08:51 +000098 boost::shared_ptr<TAsyncChannel> channel(new TEvhttpClientChannel(host, "/", host, port, base));
Roger Meier7e056e72011-07-17 07:28:28 +000099 client = new ThriftTestCobClient(channel, protocolFactory);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100100 client->testString(tcxx::bind(testString_clientReturn,
101 host,
102 port,
103 base,
104 protocolFactory,
105 tcxx::placeholders::_1),
106 "Test");
Roger Meier7e056e72011-07-17 07:28:28 +0000107 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500108 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +0000109 }
110}
111
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900112// Workaround for absense of C++11 "auto" keyword.
113template <typename T>
114bool print_eq(T expected, T actual) {
115 cout << "(" << actual << ")" << endl;
116 if (expected != actual) {
117 cout << "*** FAILED ***" << endl << "Expected: " << expected << " but got: " << actual << endl;
118 return false;
119 }
120 return true;
121}
122
123#define BASETYPE_IDENTITY_TEST(func, value) \
124 cout << #func "(" << value << ") = "; \
125 try { \
126 if (!print_eq(value, testClient.func(value))) \
127 return_code |= ERR_BASETYPES; \
128 } catch (TTransportException&) { \
129 throw; \
130 } catch (exception & ex) { \
131 cout << "*** FAILED ***" << endl << ex.what() << endl; \
132 return_code |= ERR_BASETYPES; \
133 }
134
Mark Sleee8540632006-05-30 09:24:40 +0000135int main(int argc, char** argv) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900136 cout.precision(19);
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900137 int ERR_BASETYPES = 1;
138 int ERR_STRUCTS = 2;
139 int ERR_CONTAINERS = 4;
140 int ERR_EXCEPTIONS = 8;
141 int ERR_UNKNOWN = 64;
142
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530143 string file_path = boost::filesystem::system_complete(argv[0]).string();
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100144 string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH);
Jake Farrell5d02b802014-01-07 21:42:01 -0500145#if _WIN32
146 transport::TWinsockSingleton::create();
147#endif
Mark Sleee8540632006-05-30 09:24:40 +0000148 string host = "localhost";
149 int port = 9090;
150 int numTests = 1;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000151 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000152 string transport_type = "buffered";
153 string protocol_type = "binary";
154 string domain_socket = "";
pavlodd08f6e2015-10-08 16:43:56 -0400155 bool abstract_namespace = false;
Jens Geyerf4598682014-05-08 23:18:44 +0200156 bool noinsane = false;
Mark Sleee8540632006-05-30 09:24:40 +0000157
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900158 int return_code = 0;
159
Jake Farrell5d02b802014-01-07 21:42:01 -0500160 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100161 desc.add_options()("help,h",
162 "produce help message")("host",
163 boost::program_options::value<string>(&host)
164 ->default_value(host),
165 "Host to connect")("port",
166 boost::program_options::value<int>(
167 &port)->default_value(port),
168 "Port number to connect")(
169 "domain-socket",
170 boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
171 "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")(
pavlodd08f6e2015-10-08 16:43:56 -0400172 "abstract-namespace",
173 "Look for the domain socket in the Abstract Namespace (no connection with filesystem pathnames)")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100174 "transport",
175 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
176 "Transport: buffered, framed, http, evhttp")(
177 "protocol",
178 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
Dave Watson792db4e2015-01-16 11:22:01 -0800179 "Protocol: binary, header, compact, json")("ssl", "Encrypted Transport using SSL")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100180 "testloops,n",
181 boost::program_options::value<int>(&numTests)->default_value(numTests),
182 "Number of Tests")("noinsane", "Do not run insanity test");
Roger Meierca142b02011-06-07 17:59:07 +0000183
Jake Farrell5d02b802014-01-07 21:42:01 -0500184 boost::program_options::variables_map vm;
185 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
186 boost::program_options::notify(vm);
Roger Meierca142b02011-06-07 17:59:07 +0000187
188 if (vm.count("help")) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900189 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900190 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000191 }
Mark Sleea3302652006-10-25 19:03:32 +0000192
Jake Farrell5d02b802014-01-07 21:42:01 -0500193 try {
Roger Meierca142b02011-06-07 17:59:07 +0000194 if (!protocol_type.empty()) {
195 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100196 } else if (protocol_type == "compact") {
Dave Watson792db4e2015-01-16 11:22:01 -0800197 } else if (protocol_type == "header") {
Roger Meierca142b02011-06-07 17:59:07 +0000198 } else if (protocol_type == "json") {
199 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100200 throw invalid_argument("Unknown protocol type " + protocol_type);
Roger Meierca142b02011-06-07 17:59:07 +0000201 }
202 }
203
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100204 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000205 if (transport_type == "buffered") {
206 } else if (transport_type == "framed") {
207 } else if (transport_type == "http") {
Roger Meier7e056e72011-07-17 07:28:28 +0000208 } else if (transport_type == "evhttp") {
Roger Meierca142b02011-06-07 17:59:07 +0000209 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100210 throw invalid_argument("Unknown transport type " + transport_type);
Roger Meierca142b02011-06-07 17:59:07 +0000211 }
212 }
213
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900214 } catch (exception& e) {
Roger Meierca142b02011-06-07 17:59:07 +0000215 cerr << e.what() << endl;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900216 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900217 return ERR_UNKNOWN;
Roger Meierca142b02011-06-07 17:59:07 +0000218 }
219
220 if (vm.count("ssl")) {
221 ssl = true;
222 }
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530223
pavlodd08f6e2015-10-08 16:43:56 -0400224 if (vm.count("abstract-namespace")) {
225 abstract_namespace = true;
226 }
227
Jens Geyerf4598682014-05-08 23:18:44 +0200228 if (vm.count("noinsane")) {
229 noinsane = true;
230 }
Roger Meierca142b02011-06-07 17:59:07 +0000231
Roger Meier611f90c2011-12-11 22:08:51 +0000232 boost::shared_ptr<TTransport> transport;
233 boost::shared_ptr<TProtocol> protocol;
Roger Meierca142b02011-06-07 17:59:07 +0000234
Roger Meier611f90c2011-12-11 22:08:51 +0000235 boost::shared_ptr<TSocket> socket;
236 boost::shared_ptr<TSSLSocketFactory> factory;
Roger Meierca142b02011-06-07 17:59:07 +0000237
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000238 if (ssl) {
Roger Meier611f90c2011-12-11 22:08:51 +0000239 factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000240 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530241 factory->loadTrustedCertificates((dir_path + "../keys/CA.pem").c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000242 factory->authenticate(true);
243 socket = factory->createSocket(host, port);
244 } else {
Roger Meierca142b02011-06-07 17:59:07 +0000245 if (domain_socket != "") {
pavlodd08f6e2015-10-08 16:43:56 -0400246 if (abstract_namespace) {
247 std::string abstract_socket("\0", 1);
248 abstract_socket += domain_socket;
249 socket = boost::shared_ptr<TSocket>(new TSocket(abstract_socket));
250 } else {
251 socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket));
252 }
Roger Meierca142b02011-06-07 17:59:07 +0000253 port = 0;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100254 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000255 socket = boost::shared_ptr<TSocket>(new TSocket(host, port));
Roger Meierca142b02011-06-07 17:59:07 +0000256 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000257 }
Mark Sleea3302652006-10-25 19:03:32 +0000258
Roger Meierca142b02011-06-07 17:59:07 +0000259 if (transport_type.compare("http") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000260 boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service"));
Roger Meierca142b02011-06-07 17:59:07 +0000261 transport = httpSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100262 } else if (transport_type.compare("framed") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000263 boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000264 transport = framedSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100265 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000266 boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000267 transport = bufferedSocket;
268 }
269
Roger Meierca142b02011-06-07 17:59:07 +0000270 if (protocol_type.compare("json") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000271 boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000272 protocol = jsonProtocol;
Roger Meier023192f2014-02-12 09:35:12 +0100273 } else if (protocol_type.compare("compact") == 0) {
274 boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport));
275 protocol = compactProtocol;
Dave Watson792db4e2015-01-16 11:22:01 -0800276 } else if (protocol_type == "header") {
277 boost::shared_ptr<TProtocol> headerProtocol(new THeaderProtocol(transport));
278 protocol = headerProtocol;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100279 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000280 boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000281 protocol = binaryProtocol;
282 }
283
284 // Connection info
pavlodd08f6e2015-10-08 16:43:56 -0400285 cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: ";
286 if (abstract_namespace) {
287 cout << '@';
288 }
289 cout << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000290 if (port != 0) {
291 cout << host << ":" << port;
292 }
293 cout << endl;
294
Roger Meier7e056e72011-07-17 07:28:28 +0000295 if (transport_type.compare("evhttp") == 0) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100296 event_base* base = event_base_new();
Roger Meier7e056e72011-07-17 07:28:28 +0000297 cout << "Libevent Version: " << event_get_version() << endl;
298 cout << "Libevent Method: " << event_base_get_method(base) << endl;
299#if LIBEVENT_VERSION_NUMBER >= 0x02000000
300 cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl;
301#endif
302
Roger Meier611f90c2011-12-11 22:08:51 +0000303 boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Roger Meier7e056e72011-07-17 07:28:28 +0000304
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100305 boost::shared_ptr<TAsyncChannel> channel(
306 new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
Roger Meier7e056e72011-07-17 07:28:28 +0000307 ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100308 client->testVoid(tcxx::bind(testVoid_clientReturn,
309 host.c_str(),
310 port,
311 base,
312 protocolFactory.get(),
313 tcxx::placeholders::_1));
Jake Farrell5d02b802014-01-07 21:42:01 -0500314
Roger Meier7e056e72011-07-17 07:28:28 +0000315 event_base_loop(base, 0);
316 return 0;
317 }
318
Roger Meierca142b02011-06-07 17:59:07 +0000319 ThriftTestClient testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000320
321 uint64_t time_min = 0;
322 uint64_t time_max = 0;
323 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000324
Mark Sleee8540632006-05-30 09:24:40 +0000325 int test = 0;
326 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000327
Mark Slee95771002006-06-07 06:53:25 +0000328 try {
Mark Sleea3302652006-10-25 19:03:32 +0000329 transport->open();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900330 } catch (TTransportException& ex) {
331 cout << "Connect failed: " << ex.what() << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900332 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000333 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000334
Mark Sleed788b2e2006-09-07 01:26:35 +0000335 /**
336 * CONNECT TEST
337 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100338 printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000339
340 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000341
Mark Sleee8540632006-05-30 09:24:40 +0000342 /**
343 * VOID TEST
344 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000345 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900346 cout << "testVoid()" << flush;
Mark Sleee129a2d2007-02-21 05:17:48 +0000347 testClient.testVoid();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900348 cout << " = void" << endl;
349 } catch (TTransportException&) {
350 // Stop here if transport got broken
351 throw;
352 } catch (exception& ex) {
353 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200354 return_code |= ERR_BASETYPES;
Mark Sleee129a2d2007-02-21 05:17:48 +0000355 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000356
Mark Sleee8540632006-05-30 09:24:40 +0000357 /**
358 * STRING TEST
359 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900360 cout << "testString(\"Test\")" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000361 string s;
362 testClient.testString(s, "Test");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900363 cout << " = " << s << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200364 if (s != "Test") {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900365 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200366 return_code |= ERR_BASETYPES;
367 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000368
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900369 try {
370 string str(
371 "}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, "
372 "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, "
373 "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, "
374 "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, "
375 "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, "
376 "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, "
377 "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, "
378 "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, "
379 "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, "
380 "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, "
381 "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, "
382 "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, "
383 "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, "
384 "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa "
385 "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa "
386 "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪"
387 "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, "
388 "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, "
389 "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, "
390 "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple "
391 "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, "
392 "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, "
393 "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, "
394 "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, "
395 "Bân-lâm-gú, 粵語");
396 cout << "testString(" << str << ") = " << flush;
397 testClient.testString(s, str);
398 cout << s << endl;
399 if (s != str) {
400 cout.imbue(locale("en_US.UTF8"));
401 cout << "*** FAILED ***" << endl << "Expected string: " << str << " but got: " << s << endl << "CLEAR";
402 return_code |= ERR_BASETYPES;
403 }
404 } catch (TTransportException&) {
405 throw;
406 } catch (exception& ex) {
407 cout << "*** FAILED ***" << endl << ex.what() << endl;
408 return_code |= ERR_BASETYPES;
409 return return_code;
410 }
411 try {
412 string str(
413 "quote: \" backslash:"
414 " forwardslash-escaped: \\/ "
415 " backspace: \b formfeed: \f newline: \n return: \r tab: "
416 " now-all-of-them-together: \"\\\\/\b\n\r\t"
417 " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><"
418 " char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ ");
419 cout << "testString(" << str << ") = " << flush;
420 testClient.testString(s, str);
421 cout << s << endl;
422 if (s != str) {
423 cout.imbue(locale("en_US.UTF8"));
424 cout << "*** FAILED ***" << endl
425 << "Expected string: " << str << " but got: " << s << endl
426 << "CLEAR";
427 ;
428 return_code |= ERR_BASETYPES;
429 }
430 } catch (TTransportException&) {
431 throw;
432 } catch (exception& ex) {
433 cout << "*** FAILED ***" << endl << ex.what() << endl;
434 return_code |= ERR_BASETYPES;
435 return return_code;
436 }
437
Mark Sleee8540632006-05-30 09:24:40 +0000438 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900439 * BOOL TEST
440 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900441 cout << boolalpha;
442 BASETYPE_IDENTITY_TEST(testBool, true);
443 BASETYPE_IDENTITY_TEST(testBool, false);
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900444
445 /**
Mark Sleee8540632006-05-30 09:24:40 +0000446 * BYTE TEST
447 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900448 BASETYPE_IDENTITY_TEST(testByte, (int8_t)0);
449 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-1);
450 BASETYPE_IDENTITY_TEST(testByte, (int8_t)42);
451 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-42);
452 BASETYPE_IDENTITY_TEST(testByte, (int8_t)127);
453 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-128);
David Reiss0c90f6f2008-02-06 22:18:40 +0000454
Mark Sleee8540632006-05-30 09:24:40 +0000455 /**
456 * I32 TEST
457 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900458 BASETYPE_IDENTITY_TEST(testI32, 0);
459 BASETYPE_IDENTITY_TEST(testI32, -1);
460 BASETYPE_IDENTITY_TEST(testI32, 190000013);
461 BASETYPE_IDENTITY_TEST(testI32, -190000013);
462 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::max());
463 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::min());
Mark Sleee8540632006-05-30 09:24:40 +0000464
465 /**
Mark Sleee8540632006-05-30 09:24:40 +0000466 * I64 TEST
467 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900468 BASETYPE_IDENTITY_TEST(testI64, (int64_t)0);
469 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1);
470 BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL);
471 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL);
472 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(2LL, 32));
473 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(2LL, 32));
474 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(2LL, 32) + 1);
475 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(2LL, 32) - 1);
476 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::max());
477 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::min());
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100478
Mark Sleec98d0502006-09-06 02:42:25 +0000479 /**
480 * DOUBLE TEST
481 */
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900482 // Comparing double values with plain equality because Thrift handles full precision of double
483 BASETYPE_IDENTITY_TEST(testDouble, 0.0);
484 BASETYPE_IDENTITY_TEST(testDouble, -1.0);
485 BASETYPE_IDENTITY_TEST(testDouble, -5.2098523);
486 BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279);
487 BASETYPE_IDENTITY_TEST(testDouble, pow(2, 32));
488 BASETYPE_IDENTITY_TEST(testDouble, pow(2, 32) + 1);
489 BASETYPE_IDENTITY_TEST(testDouble, pow(2, 53) - 1);
490 BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 32));
491 BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 32) - 1);
492 BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 53) + 1);
493
494 try {
495 double expected = pow(10, 307);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900496 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900497 double actual = testClient.testDouble(expected);
498 cout << "(" << actual << ")" << endl;
499 if (expected - actual > pow(10, 292)) {
500 cout << "*** FAILED ***" << endl
501 << "Expected: " << expected << " but got: " << actual << endl;
502 }
503 } catch (TTransportException&) {
504 throw;
505 } catch (exception& ex) {
506 cout << "*** FAILED ***" << endl << ex.what() << endl;
507 return_code |= ERR_BASETYPES;
508 }
509
510 try {
511 double expected = pow(10, -292);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900512 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900513 double actual = testClient.testDouble(expected);
514 cout << "(" << actual << ")" << endl;
515 if (expected - actual > pow(10, -307)) {
516 cout << "*** FAILED ***" << endl
517 << "Expected: " << expected << " but got: " << actual << endl;
518 }
519 } catch (TTransportException&) {
520 throw;
521 } catch (exception& ex) {
522 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200523 return_code |= ERR_BASETYPES;
524 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000525
Mark Sleee8540632006-05-30 09:24:40 +0000526 /**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100527 * BINARY TEST
528 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900529 cout << "testBinary(empty)" << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900530 try {
531 string bin_result;
532 testClient.testBinary(bin_result, string());
533 if (!bin_result.empty()) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900534 cout << endl << "*** FAILED ***" << endl;
535 cout << "invalid length: " << bin_result.size() << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900536 return_code |= ERR_BASETYPES;
537 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900538 } catch (TTransportException&) {
539 throw;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900540 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900541 cout << "*** FAILED ***" << endl << ex.what() << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900542 return_code |= ERR_BASETYPES;
543 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900544 cout << "testBinary([-128..127]) = {" << flush;
Jens Geyerd629ea02015-09-23 21:16:50 +0200545 const char bin_data[256]
546 = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
547 -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
548 -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
549 -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
550 -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
551 -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
552 -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
553 -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
554 -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
555 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
556 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
557 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
558 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
559 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
560 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
561 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
562 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
563 127};
564 try {
565 string bin_result;
566 testClient.testBinary(bin_result, string(bin_data, 256));
567 if (bin_result.size() != 256) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900568 cout << endl << "*** FAILED ***" << endl;
569 cout << "invalid length: " << bin_result.size() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200570 return_code |= ERR_BASETYPES;
571 } else {
572 bool first = true;
573 bool failed = false;
574 for (int i = 0; i < 256; ++i) {
575 if (!first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900576 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200577 else
578 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900579 cout << static_cast<int>(bin_result[i]);
Jens Geyerd629ea02015-09-23 21:16:50 +0200580 if (!failed && bin_result[i] != i - 128) {
581 failed = true;
582 }
583 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900584 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200585 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900586 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200587 return_code |= ERR_BASETYPES;
588 }
589 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900590 } catch (TTransportException&) {
591 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200592 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900593 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200594 return_code |= ERR_BASETYPES;
595 }
596
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100597
598 /**
Mark Sleee8540632006-05-30 09:24:40 +0000599 * STRUCT TEST
600 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900601 cout << "testStruct({\"Zero\", 1, -3, -5})" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000602 Xtruct out;
603 out.string_thing = "Zero";
604 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000605 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000606 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000607 Xtruct in;
608 testClient.testStruct(in, out);
Roger Meier0e814802014-01-17 21:07:58 +0100609 printf(" = {\"%s\", %d, %d, %" PRId64 "}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000610 in.string_thing.c_str(),
611 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000612 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000613 in.i64_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200614 if (in != out) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900615 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200616 return_code |= ERR_STRUCTS;
617 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000618
Mark Sleee8540632006-05-30 09:24:40 +0000619 /**
620 * NESTED STRUCT TEST
621 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900622 cout << "testNest({1, {\"Zero\", 1, -3, -5}), 5}" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000623 Xtruct2 out2;
624 out2.byte_thing = 1;
625 out2.struct_thing = out;
626 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000627 Xtruct2 in2;
628 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000629 in = in2.struct_thing;
Roger Meier0e814802014-01-17 21:07:58 +0100630 printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000631 in2.byte_thing,
632 in.string_thing.c_str(),
633 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000634 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000635 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000636 in2.i32_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200637 if (in2 != out2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900638 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200639 return_code |= ERR_STRUCTS;
640 }
Mark Sleee8540632006-05-30 09:24:40 +0000641
642 /**
643 * MAP TEST
644 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100645 map<int32_t, int32_t> mapout;
Mark Sleee8540632006-05-30 09:24:40 +0000646 for (int32_t i = 0; i < 5; ++i) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100647 mapout.insert(make_pair(i, i - 10));
Mark Sleee8540632006-05-30 09:24:40 +0000648 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900649 cout << "testMap({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000650 map<int32_t, int32_t>::const_iterator m_iter;
651 bool first = true;
652 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
653 if (first) {
654 first = false;
655 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900656 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000657 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900658 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000659 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900660 cout << "})";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100661 map<int32_t, int32_t> mapin;
Mark Slee1921d202007-01-24 19:43:06 +0000662 testClient.testMap(mapin, mapout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900663 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000664 first = true;
665 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
666 if (first) {
667 first = false;
668 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900669 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000670 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900671 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000672 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900673 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200674 if (mapin != mapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900675 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200676 return_code |= ERR_CONTAINERS;
677 }
Roger Meier4fce9602012-05-04 06:22:09 +0000678
679 /**
680 * STRING MAP TEST
Roger Meier4fce9602012-05-04 06:22:09 +0000681 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900682 cout << "testStringMap({a => 2, b => blah, some => thing}) = {" << flush;
Jens Geyerd629ea02015-09-23 21:16:50 +0200683 map<string, string> smapin;
684 map<string, string> smapout;
685 smapin["a"] = "2";
686 smapin["b"] = "blah";
687 smapin["some"] = "thing";
688 try {
689 testClient.testStringMap(smapout, smapin);
690 first = true;
691 for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) {
692 if (first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900693 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200694 else
695 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900696 cout << it->first << " => " << it->second;
Jens Geyerd629ea02015-09-23 21:16:50 +0200697 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900698 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200699 if (smapin != smapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900700 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200701 return_code |= ERR_CONTAINERS;
702 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900703 } catch (TTransportException&) {
704 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200705 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900706 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200707 return_code |= ERR_CONTAINERS;
708 }
Mark Sleee8540632006-05-30 09:24:40 +0000709
710 /**
711 * SET TEST
712 */
713 set<int32_t> setout;
714 for (int32_t i = -2; i < 3; ++i) {
715 setout.insert(i);
716 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900717 cout << "testSet({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000718 set<int32_t>::const_iterator s_iter;
719 first = true;
720 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
721 if (first) {
722 first = false;
723 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900724 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000725 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900726 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000727 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900728 cout << "})";
Mark Slee1921d202007-01-24 19:43:06 +0000729 set<int32_t> setin;
730 testClient.testSet(setin, setout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900731 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000732 first = true;
733 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
734 if (first) {
735 first = false;
736 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900737 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000738 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900739 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000740 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900741 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200742 if (setin != setout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900743 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200744 return_code |= ERR_CONTAINERS;
745 }
Mark Sleee8540632006-05-30 09:24:40 +0000746
747 /**
748 * LIST TEST
749 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900750 cout << "testList(empty)" << flush;
751 try {
752 vector<int32_t> listout;
753 testClient.testList(listout, vector<int32_t>());
754 if (!listout.empty()) {
755 cout << "*** FAILED ***" << endl;
756 cout << "invalid length: " << listout.size() << endl;
757 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000758 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900759 } catch (TTransportException&) {
760 throw;
761 } catch (exception& ex) {
762 cout << "*** FAILED ***" << endl << ex.what() << endl;
763 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000764 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900765 try {
766 vector<int32_t> listout;
767 for (int32_t i = -2; i < 3; ++i) {
768 listout.push_back(i);
Mark Sleee8540632006-05-30 09:24:40 +0000769 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900770 cout << "testList({" << flush;
771 vector<int32_t>::const_iterator l_iter;
772 first = true;
773 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
774 if (first) {
775 first = false;
776 } else {
777 cout << ",";
778 }
779 cout << *l_iter;
780 }
781 cout << "})";
782 vector<int32_t> listin;
783 testClient.testList(listin, listout);
784 cout << " = {";
785 first = true;
786 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
787 if (first) {
788 first = false;
789 } else {
790 cout << ",";
791 }
792 cout << *l_iter;
793 }
794 cout << "}" << endl;
795 if (listin != listout) {
796 cout << "*** FAILED ***" << endl;
797 return_code |= ERR_CONTAINERS;
798 }
799 } catch (TTransportException&) {
800 throw;
801 } catch (exception& ex) {
802 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200803 return_code |= ERR_CONTAINERS;
804 }
Mark Sleee8540632006-05-30 09:24:40 +0000805
806 /**
807 * ENUM TEST
808 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900809 cout << "testEnum(ONE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000810 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900811 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200812 if (ret != Numberz::ONE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900813 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200814 return_code |= ERR_STRUCTS;
815 }
Mark Sleee8540632006-05-30 09:24:40 +0000816
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900817 cout << "testEnum(TWO)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000818 ret = testClient.testEnum(Numberz::TWO);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900819 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200820 if (ret != Numberz::TWO) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900821 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200822 return_code |= ERR_STRUCTS;
823 }
Mark Sleee8540632006-05-30 09:24:40 +0000824
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900825 cout << "testEnum(THREE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000826 ret = testClient.testEnum(Numberz::THREE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900827 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200828 if (ret != Numberz::THREE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900829 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200830 return_code |= ERR_STRUCTS;
831 }
Mark Sleee8540632006-05-30 09:24:40 +0000832
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900833 cout << "testEnum(FIVE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000834 ret = testClient.testEnum(Numberz::FIVE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900835 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200836 if (ret != Numberz::FIVE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900837 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200838 return_code |= ERR_STRUCTS;
839 }
Mark Sleee8540632006-05-30 09:24:40 +0000840
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900841 cout << "testEnum(EIGHT)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000842 ret = testClient.testEnum(Numberz::EIGHT);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900843 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200844 if (ret != Numberz::EIGHT) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900845 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200846 return_code |= ERR_STRUCTS;
847 }
Mark Sleee8540632006-05-30 09:24:40 +0000848
849 /**
850 * TYPEDEF TEST
851 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900852 cout << "testTypedef(309858235082523)" << flush;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000853 UserId uid = testClient.testTypedef(309858235082523LL);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900854 cout << " = " << uid << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200855 if (uid != 309858235082523LL) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900856 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200857 return_code |= ERR_STRUCTS;
858 }
Mark Sleee8540632006-05-30 09:24:40 +0000859
860 /**
861 * NESTED MAP TEST
862 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900863 cout << "testMapMap(1)" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000864 map<int32_t, map<int32_t, int32_t> > mm;
865 testClient.testMapMap(mm, 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900866 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000867 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
868 for (mi = mm.begin(); mi != mm.end(); ++mi) {
869 printf("%d => {", mi->first);
870 map<int32_t, int32_t>::const_iterator mi2;
871 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900872 cout << mi2->first << " => " << mi2->second;
Mark Sleee8540632006-05-30 09:24:40 +0000873 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900874 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000875 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900876 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200877 if (mm.size() != 2 ||
878 mm[-4][-4] != -4 ||
879 mm[-4][-3] != -3 ||
880 mm[-4][-2] != -2 ||
881 mm[-4][-1] != -1 ||
882 mm[4][4] != 4 ||
883 mm[4][3] != 3 ||
884 mm[4][2] != 2 ||
885 mm[4][1] != 1) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900886 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200887 return_code |= ERR_CONTAINERS;
888 }
Mark Sleee8540632006-05-30 09:24:40 +0000889
890 /**
891 * INSANITY TEST
892 */
Jens Geyerf4598682014-05-08 23:18:44 +0200893 if (!noinsane) {
894 Insanity insane;
Jens Geyerd629ea02015-09-23 21:16:50 +0200895 insane.userMap.insert(make_pair(Numberz::FIVE, 5));
896 insane.userMap.insert(make_pair(Numberz::EIGHT, 8));
Jens Geyerf4598682014-05-08 23:18:44 +0200897 Xtruct truck;
Jens Geyerd629ea02015-09-23 21:16:50 +0200898 truck.string_thing = "Goodbye4";
899 truck.byte_thing = 4;
900 truck.i32_thing = 4;
901 truck.i64_thing = 4;
902 Xtruct truck2;
903 truck2.string_thing = "Hello2";
904 truck2.byte_thing = 2;
905 truck2.i32_thing = 2;
906 truck2.i64_thing = 2;
Jens Geyerf4598682014-05-08 23:18:44 +0200907 insane.xtructs.push_back(truck);
Jens Geyerd629ea02015-09-23 21:16:50 +0200908 insane.xtructs.push_back(truck2);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900909 cout << "testInsanity()" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100910 map<UserId, map<Numberz::type, Insanity> > whoa;
Jens Geyerf4598682014-05-08 23:18:44 +0200911 testClient.testInsanity(whoa, insane);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900912 cout << " = {";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100913 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Jens Geyerf4598682014-05-08 23:18:44 +0200914 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
915 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100916 map<Numberz::type, Insanity>::const_iterator i2_iter;
917 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Jens Geyerf4598682014-05-08 23:18:44 +0200918 printf("%d => {", i2_iter->first);
919 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
920 map<Numberz::type, UserId>::const_iterator um;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900921 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200922 for (um = userMap.begin(); um != userMap.end(); ++um) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900923 cout << um->first << " => " << um->second;
Jens Geyerf4598682014-05-08 23:18:44 +0200924 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900925 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000926
Jens Geyerf4598682014-05-08 23:18:44 +0200927 vector<Xtruct> xtructs = i2_iter->second.xtructs;
928 vector<Xtruct>::const_iterator x;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900929 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200930 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
931 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
932 x->string_thing.c_str(),
933 (int)x->byte_thing,
934 x->i32_thing,
935 x->i64_thing);
936 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900937 cout << "}";
Mark Sleee8540632006-05-30 09:24:40 +0000938
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900939 cout << "}, ";
Jens Geyerf4598682014-05-08 23:18:44 +0200940 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900941 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000942 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900943 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200944 bool failed = false;
945 map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1));
946 if (whoa.size() != 2) {
947 failed = true;
948 }
949 if (it1 == whoa.end()) {
950 failed = true;
951 } else {
952 map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO);
953 if (it12 == it1->second.end() || it12->second != insane) {
954 failed = true;
955 }
956 map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE);
957 if (it13 == it1->second.end() || it13->second != insane) {
958 failed = true;
959 }
960 }
961 map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2));
962 if (it2 == whoa.end()) {
963 failed = true;
964 } else {
965 map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX);
966 if (it26 == it1->second.end() || it26->second != Insanity()) {
967 failed = true;
968 }
969 }
970 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900971 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200972 return_code |= ERR_STRUCTS;
973 }
Mark Sleee8540632006-05-30 09:24:40 +0000974 }
Jens Geyerd629ea02015-09-23 21:16:50 +0200975
976 /**
977 * MULTI TEST
978 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900979 cout << "testMulti()" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200980 try {
981 map<int16_t, string> mul_map;
982 Xtruct mul_result;
983 mul_map[1] = "blah";
984 mul_map[2] = "thing";
985 testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24));
986 Xtruct xxs;
987 xxs.string_thing = "Hello2";
988 xxs.byte_thing = 42;
989 xxs.i32_thing = 4242;
990 xxs.i64_thing = 424242;
991 if (mul_result != xxs) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900992 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200993 return_code |= ERR_STRUCTS;
994 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900995 } catch (TTransportException&) {
996 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200997 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900998 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200999 return_code |= ERR_STRUCTS;
1000 }
1001
Marc Slemko71d4e472006-08-15 22:34:04 +00001002 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +00001003
Marc Slemkobf4fd192006-08-15 21:29:39 +00001004 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001005 cout << "testClient.testException(\"Xception\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001006 testClient.testException("Xception");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001007 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001008 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001009
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001010 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001011 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001012 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001013
Marc Slemkobf4fd192006-08-15 21:29:39 +00001014 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001015 cout << "testClient.testException(\"TException\") =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001016 testClient.testException("TException");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001017 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001018 return_code |= ERR_EXCEPTIONS;
Roger Meierf50df7f2012-05-02 22:49:55 +00001019
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001020 } catch (const TException&) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001021 cout << " Caught TException" << endl;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001022 }
Roger Meierf50df7f2012-05-02 22:49:55 +00001023
1024 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001025 cout << "testClient.testException(\"success\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001026 testClient.testException("success");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001027 cout << " void" << endl;
1028 } catch (exception & ex) { \
1029 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001030 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001031 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001032
Marc Slemko71d4e472006-08-15 22:34:04 +00001033 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +00001034
Marc Slemko71d4e472006-08-15 22:34:04 +00001035 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001036 cout << "testClient.testMultiException(\"Xception\", \"test 1\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001037 Xtruct result;
1038 testClient.testMultiException(result, "Xception", "test 1");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001039 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001040 return_code |= ERR_EXCEPTIONS;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001041 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001042 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
1043 }
1044
1045 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001046 cout << "testClient.testMultiException(\"Xception2\", \"test 2\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001047 Xtruct result;
1048 testClient.testMultiException(result, "Xception2", "test 2");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001049 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001050 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001051
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001052 } catch (Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001053 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001054 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001055
Marc Slemko71d4e472006-08-15 22:34:04 +00001056 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001057 cout << "testClient.testMultiException(\"success\", \"test 3\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001058 Xtruct result;
1059 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +00001060 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001061 } catch (exception & ex) { \
1062 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001063 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001064 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001065
David Reissc51986f2009-03-24 20:01:25 +00001066 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +00001067 {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001068 cout << "testClient.testOneway(1) =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001069 uint64_t startOneway = now();
1070 testClient.testOneway(1);
1071 uint64_t elapsed = now() - startOneway;
1072 if (elapsed > 200 * 1000) { // 0.2 seconds
Jens Geyerd629ea02015-09-23 21:16:50 +02001073 printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0);
1074 return_code |= ERR_BASETYPES;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001075 } else {
1076 printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
1077 }
David Reiss2ab6fe82008-02-18 02:11:44 +00001078 }
1079
David Reiss2845b522008-02-18 02:11:52 +00001080 /**
David Reissc51986f2009-03-24 20:01:25 +00001081 * redo a simple test after the oneway to make sure we aren't "off by one" --
1082 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +00001083 * fail since it will get the void confirmation rather than the correct
1084 * result. In this circumstance, the client will throw the exception:
1085 *
1086 * TApplicationException: Wrong method namea
1087 */
1088 /**
1089 * I32 TEST
1090 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001091 cout << "re-test testI32(-1)";
1092 int i32 = testClient.testI32(-1);
1093 cout << " = " << i32 << endl;
Roger Meier4fce9602012-05-04 06:22:09 +00001094 if (i32 != -1)
Jens Geyerd629ea02015-09-23 21:16:50 +02001095 return_code |= ERR_BASETYPES;
David Reiss2845b522008-02-18 02:11:52 +00001096
Marc Slemkobf4fd192006-08-15 21:29:39 +00001097 uint64_t stop = now();
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001098 uint64_t tot = stop - start;
Mark Sleed788b2e2006-09-07 01:26:35 +00001099
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001100 cout << "Total time: " << stop - start << " us" << endl;
David Reiss0c90f6f2008-02-06 22:18:40 +00001101
Mark Sleed788b2e2006-09-07 01:26:35 +00001102 time_tot += tot;
1103 if (time_min == 0 || tot < time_min) {
1104 time_min = tot;
1105 }
1106 if (tot > time_max) {
1107 time_max = tot;
1108 }
1109
Mark Sleea3302652006-10-25 19:03:32 +00001110 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +00001111 }
1112
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001113 cout << endl << "All tests done." << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001114
1115 uint64_t time_avg = time_tot / numTests;
1116
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001117 cout << "Min time: " << time_min << " us" << endl;
1118 cout << "Max time: " << time_max << " us" << endl;
1119 cout << "Avg time: " << time_avg << " us" << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001120
Jens Geyerd629ea02015-09-23 21:16:50 +02001121 return return_code;
Mark Sleee8540632006-05-30 09:24:40 +00001122}