blob: bbe196249cc65b3d2b79f87c8ac13f7572c7b46b [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>
Sebastian Zenker39e505c2015-12-18 16:15:08 +010026#include <sstream>
Roger Meier49ff8b12012-04-13 09:12:31 +000027#include <thrift/protocol/TBinaryProtocol.h>
Roger Meier023192f2014-02-12 09:35:12 +010028#include <thrift/protocol/TCompactProtocol.h>
Dave Watson792db4e2015-01-16 11:22:01 -080029#include <thrift/protocol/THeaderProtocol.h>
Roger Meier49ff8b12012-04-13 09:12:31 +000030#include <thrift/protocol/TJSONProtocol.h>
31#include <thrift/transport/THttpClient.h>
32#include <thrift/transport/TTransportUtils.h>
33#include <thrift/transport/TSocket.h>
34#include <thrift/transport/TSSLSocket.h>
35#include <thrift/async/TEvhttpClientChannel.h>
36#include <thrift/server/TNonblockingServer.h> // <event.h>
Mark Sleee8540632006-05-30 09:24:40 +000037
Marc Slemko6be374b2006-08-04 03:16:25 +000038#include <boost/shared_ptr.hpp>
Roger Meierca142b02011-06-07 17:59:07 +000039#include <boost/program_options.hpp>
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053040#include <boost/filesystem.hpp>
Jake Farrell5d02b802014-01-07 21:42:01 -050041#include <thrift/cxxfunctional.h>
42#if _WIN32
Konrad Grochowski16a23a62014-11-13 15:33:38 +010043#include <thrift/windows/TWinsockSingleton.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050044#endif
Roger Meierca142b02011-06-07 17:59:07 +000045
Marc Slemko6be374b2006-08-04 03:16:25 +000046#include "ThriftTest.h"
47
Marc Slemko6be374b2006-08-04 03:16:25 +000048using namespace std;
T Jake Lucianib5e62212009-01-31 22:36:20 +000049using namespace apache::thrift;
50using namespace apache::thrift::protocol;
51using namespace apache::thrift::transport;
Marc Slemkobf4fd192006-08-15 21:29:39 +000052using namespace thrift::test;
Roger Meier7e056e72011-07-17 07:28:28 +000053using namespace apache::thrift::async;
54
Mark Slee95771002006-06-07 06:53:25 +000055// Current time, microseconds since the epoch
Konrad Grochowski16a23a62014-11-13 15:33:38 +010056uint64_t now() {
Roger Meier5f9614c2010-11-21 16:59:05 +000057 int64_t ret;
Mark Slee95771002006-06-07 06:53:25 +000058 struct timeval tv;
David Reiss0c90f6f2008-02-06 22:18:40 +000059
Jake Farrell5d02b802014-01-07 21:42:01 -050060 THRIFT_GETTIMEOFDAY(&tv, NULL);
Mark Slee95771002006-06-07 06:53:25 +000061 ret = tv.tv_sec;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010062 ret = ret * 1000 * 1000 + tv.tv_usec;
Mark Slee95771002006-06-07 06:53:25 +000063 return ret;
64}
65
Sebastian Zenker39e505c2015-12-18 16:15:08 +010066static void testString_clientReturn(event_base* base,
67 int testNr,
Konrad Grochowski16a23a62014-11-13 15:33:38 +010068 ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000069 try {
70 string s;
71 client->recv_testString(s);
Sebastian Zenker39e505c2015-12-18 16:15:08 +010072 std::ostringstream os;
73 os << "test" << testNr;
74 const bool ok = (s == os.str());
75 cout << "testString: " << s << " " << ((ok) ? "ok" : "failed") << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000076 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -050077 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000078 }
79
Sebastian Zenker39e505c2015-12-18 16:15:08 +010080 if (testNr == 9)
81 event_base_loopbreak(base); // end test
Roger Meier7e056e72011-07-17 07:28:28 +000082}
83
Sebastian Zenker39e505c2015-12-18 16:15:08 +010084static void testVoid_clientReturn(event_base* base, ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000085 try {
86 client->recv_testVoid();
87 cout << "testVoid" << endl;
88
Sebastian Zenker39e505c2015-12-18 16:15:08 +010089 for (int testNr = 0; testNr < 10; ++testNr) {
90 std::ostringstream os;
91 os << "test" << testNr;
92 client->testString(tcxx::bind(testString_clientReturn,
93 base,
94 testNr,
95 tcxx::placeholders::_1),
96 os.str());
97 }
Roger Meier7e056e72011-07-17 07:28:28 +000098 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -050099 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +0000100 }
101}
102
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900103// Workaround for absense of C++11 "auto" keyword.
104template <typename T>
105bool print_eq(T expected, T actual) {
106 cout << "(" << actual << ")" << endl;
107 if (expected != actual) {
108 cout << "*** FAILED ***" << endl << "Expected: " << expected << " but got: " << actual << endl;
109 return false;
110 }
111 return true;
112}
113
114#define BASETYPE_IDENTITY_TEST(func, value) \
115 cout << #func "(" << value << ") = "; \
116 try { \
117 if (!print_eq(value, testClient.func(value))) \
118 return_code |= ERR_BASETYPES; \
119 } catch (TTransportException&) { \
120 throw; \
121 } catch (exception & ex) { \
122 cout << "*** FAILED ***" << endl << ex.what() << endl; \
123 return_code |= ERR_BASETYPES; \
124 }
125
Mark Sleee8540632006-05-30 09:24:40 +0000126int main(int argc, char** argv) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900127 cout.precision(19);
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900128 int ERR_BASETYPES = 1;
129 int ERR_STRUCTS = 2;
130 int ERR_CONTAINERS = 4;
131 int ERR_EXCEPTIONS = 8;
132 int ERR_UNKNOWN = 64;
133
Nobuaki Sukegawac8744082016-03-09 19:55:56 +0900134 string testDir = boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string();
135 string pemPath = testDir + "/keys/CA.pem";
Jake Farrell5d02b802014-01-07 21:42:01 -0500136#if _WIN32
137 transport::TWinsockSingleton::create();
138#endif
Mark Sleee8540632006-05-30 09:24:40 +0000139 string host = "localhost";
140 int port = 9090;
141 int numTests = 1;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000142 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000143 string transport_type = "buffered";
144 string protocol_type = "binary";
145 string domain_socket = "";
pavlodd08f6e2015-10-08 16:43:56 -0400146 bool abstract_namespace = false;
Jens Geyerf4598682014-05-08 23:18:44 +0200147 bool noinsane = false;
Mark Sleee8540632006-05-30 09:24:40 +0000148
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900149 int return_code = 0;
150
Jake Farrell5d02b802014-01-07 21:42:01 -0500151 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100152 desc.add_options()("help,h",
153 "produce help message")("host",
154 boost::program_options::value<string>(&host)
155 ->default_value(host),
156 "Host to connect")("port",
157 boost::program_options::value<int>(
158 &port)->default_value(port),
159 "Port number to connect")(
160 "domain-socket",
161 boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
162 "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")(
pavlodd08f6e2015-10-08 16:43:56 -0400163 "abstract-namespace",
164 "Look for the domain socket in the Abstract Namespace (no connection with filesystem pathnames)")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100165 "transport",
166 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
167 "Transport: buffered, framed, http, evhttp")(
168 "protocol",
169 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
Dave Watson792db4e2015-01-16 11:22:01 -0800170 "Protocol: binary, header, compact, json")("ssl", "Encrypted Transport using SSL")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100171 "testloops,n",
172 boost::program_options::value<int>(&numTests)->default_value(numTests),
173 "Number of Tests")("noinsane", "Do not run insanity test");
Roger Meierca142b02011-06-07 17:59:07 +0000174
Jake Farrell5d02b802014-01-07 21:42:01 -0500175 boost::program_options::variables_map vm;
176 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
177 boost::program_options::notify(vm);
Roger Meierca142b02011-06-07 17:59:07 +0000178
179 if (vm.count("help")) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900180 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900181 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000182 }
Mark Sleea3302652006-10-25 19:03:32 +0000183
Jake Farrell5d02b802014-01-07 21:42:01 -0500184 try {
Roger Meierca142b02011-06-07 17:59:07 +0000185 if (!protocol_type.empty()) {
186 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100187 } else if (protocol_type == "compact") {
Dave Watson792db4e2015-01-16 11:22:01 -0800188 } else if (protocol_type == "header") {
Roger Meierca142b02011-06-07 17:59:07 +0000189 } else if (protocol_type == "json") {
190 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100191 throw invalid_argument("Unknown protocol type " + protocol_type);
Roger Meierca142b02011-06-07 17:59:07 +0000192 }
193 }
194
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100195 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000196 if (transport_type == "buffered") {
197 } else if (transport_type == "framed") {
198 } else if (transport_type == "http") {
Roger Meier7e056e72011-07-17 07:28:28 +0000199 } else if (transport_type == "evhttp") {
Roger Meierca142b02011-06-07 17:59:07 +0000200 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100201 throw invalid_argument("Unknown transport type " + transport_type);
Roger Meierca142b02011-06-07 17:59:07 +0000202 }
203 }
204
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900205 } catch (exception& e) {
Roger Meierca142b02011-06-07 17:59:07 +0000206 cerr << e.what() << endl;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900207 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900208 return ERR_UNKNOWN;
Roger Meierca142b02011-06-07 17:59:07 +0000209 }
210
211 if (vm.count("ssl")) {
212 ssl = true;
213 }
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530214
pavlodd08f6e2015-10-08 16:43:56 -0400215 if (vm.count("abstract-namespace")) {
216 abstract_namespace = true;
217 }
218
Jens Geyerf4598682014-05-08 23:18:44 +0200219 if (vm.count("noinsane")) {
220 noinsane = true;
221 }
Roger Meierca142b02011-06-07 17:59:07 +0000222
Roger Meier611f90c2011-12-11 22:08:51 +0000223 boost::shared_ptr<TTransport> transport;
224 boost::shared_ptr<TProtocol> protocol;
Roger Meierca142b02011-06-07 17:59:07 +0000225
Roger Meier611f90c2011-12-11 22:08:51 +0000226 boost::shared_ptr<TSocket> socket;
227 boost::shared_ptr<TSSLSocketFactory> factory;
Roger Meierca142b02011-06-07 17:59:07 +0000228
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000229 if (ssl) {
Roger Meier611f90c2011-12-11 22:08:51 +0000230 factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000231 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Nobuaki Sukegawac8744082016-03-09 19:55:56 +0900232 factory->loadTrustedCertificates(pemPath.c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000233 factory->authenticate(true);
234 socket = factory->createSocket(host, port);
235 } else {
Roger Meierca142b02011-06-07 17:59:07 +0000236 if (domain_socket != "") {
pavlodd08f6e2015-10-08 16:43:56 -0400237 if (abstract_namespace) {
238 std::string abstract_socket("\0", 1);
239 abstract_socket += domain_socket;
240 socket = boost::shared_ptr<TSocket>(new TSocket(abstract_socket));
241 } else {
242 socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket));
243 }
Roger Meierca142b02011-06-07 17:59:07 +0000244 port = 0;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100245 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000246 socket = boost::shared_ptr<TSocket>(new TSocket(host, port));
Roger Meierca142b02011-06-07 17:59:07 +0000247 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000248 }
Mark Sleea3302652006-10-25 19:03:32 +0000249
Roger Meierca142b02011-06-07 17:59:07 +0000250 if (transport_type.compare("http") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000251 boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service"));
Roger Meierca142b02011-06-07 17:59:07 +0000252 transport = httpSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100253 } else if (transport_type.compare("framed") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000254 boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000255 transport = framedSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100256 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000257 boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000258 transport = bufferedSocket;
259 }
260
Roger Meierca142b02011-06-07 17:59:07 +0000261 if (protocol_type.compare("json") == 0) {
Roger Meier611f90c2011-12-11 22:08:51 +0000262 boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000263 protocol = jsonProtocol;
Roger Meier023192f2014-02-12 09:35:12 +0100264 } else if (protocol_type.compare("compact") == 0) {
265 boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport));
266 protocol = compactProtocol;
Dave Watson792db4e2015-01-16 11:22:01 -0800267 } else if (protocol_type == "header") {
268 boost::shared_ptr<TProtocol> headerProtocol(new THeaderProtocol(transport));
269 protocol = headerProtocol;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100270 } else {
Roger Meier611f90c2011-12-11 22:08:51 +0000271 boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000272 protocol = binaryProtocol;
273 }
274
275 // Connection info
pavlodd08f6e2015-10-08 16:43:56 -0400276 cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: ";
277 if (abstract_namespace) {
278 cout << '@';
279 }
280 cout << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000281 if (port != 0) {
282 cout << host << ":" << port;
283 }
284 cout << endl;
285
Roger Meier7e056e72011-07-17 07:28:28 +0000286 if (transport_type.compare("evhttp") == 0) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100287 event_base* base = event_base_new();
Roger Meier7e056e72011-07-17 07:28:28 +0000288 cout << "Libevent Version: " << event_get_version() << endl;
289 cout << "Libevent Method: " << event_base_get_method(base) << endl;
290#if LIBEVENT_VERSION_NUMBER >= 0x02000000
291 cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl;
292#endif
293
Roger Meier611f90c2011-12-11 22:08:51 +0000294 boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Roger Meier7e056e72011-07-17 07:28:28 +0000295
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100296 boost::shared_ptr<TAsyncChannel> channel(
297 new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
Roger Meier7e056e72011-07-17 07:28:28 +0000298 ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100299 client->testVoid(tcxx::bind(testVoid_clientReturn,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100300 base,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100301 tcxx::placeholders::_1));
Jake Farrell5d02b802014-01-07 21:42:01 -0500302
Roger Meier7e056e72011-07-17 07:28:28 +0000303 event_base_loop(base, 0);
304 return 0;
305 }
306
Roger Meierca142b02011-06-07 17:59:07 +0000307 ThriftTestClient testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000308
309 uint64_t time_min = 0;
310 uint64_t time_max = 0;
311 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000312
Mark Sleee8540632006-05-30 09:24:40 +0000313 int test = 0;
314 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000315
Mark Slee95771002006-06-07 06:53:25 +0000316 try {
Mark Sleea3302652006-10-25 19:03:32 +0000317 transport->open();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900318 } catch (TTransportException& ex) {
319 cout << "Connect failed: " << ex.what() << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900320 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000321 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000322
Mark Sleed788b2e2006-09-07 01:26:35 +0000323 /**
324 * CONNECT TEST
325 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100326 printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000327
328 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000329
Mark Sleee8540632006-05-30 09:24:40 +0000330 /**
331 * VOID TEST
332 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000333 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900334 cout << "testVoid()" << flush;
Mark Sleee129a2d2007-02-21 05:17:48 +0000335 testClient.testVoid();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900336 cout << " = void" << endl;
337 } catch (TTransportException&) {
338 // Stop here if transport got broken
339 throw;
340 } catch (exception& ex) {
341 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200342 return_code |= ERR_BASETYPES;
Mark Sleee129a2d2007-02-21 05:17:48 +0000343 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000344
Mark Sleee8540632006-05-30 09:24:40 +0000345 /**
346 * STRING TEST
347 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900348 cout << "testString(\"Test\")" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000349 string s;
350 testClient.testString(s, "Test");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900351 cout << " = " << s << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200352 if (s != "Test") {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900353 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200354 return_code |= ERR_BASETYPES;
355 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000356
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900357 try {
358 string str(
359 "}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, "
360 "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, "
361 "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, "
362 "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, "
363 "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, "
364 "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, "
365 "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, "
366 "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, "
367 "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, "
368 "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, "
369 "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, "
370 "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, "
371 "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, "
372 "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa "
373 "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa "
374 "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪"
375 "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, "
376 "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, "
377 "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, "
378 "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple "
379 "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, "
380 "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, "
381 "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, "
382 "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, "
383 "Bân-lâm-gú, 粵語");
384 cout << "testString(" << str << ") = " << flush;
385 testClient.testString(s, str);
386 cout << s << endl;
387 if (s != str) {
388 cout.imbue(locale("en_US.UTF8"));
389 cout << "*** FAILED ***" << endl << "Expected string: " << str << " but got: " << s << endl << "CLEAR";
390 return_code |= ERR_BASETYPES;
391 }
392 } catch (TTransportException&) {
393 throw;
394 } catch (exception& ex) {
395 cout << "*** FAILED ***" << endl << ex.what() << endl;
396 return_code |= ERR_BASETYPES;
397 return return_code;
398 }
399 try {
400 string str(
401 "quote: \" backslash:"
402 " forwardslash-escaped: \\/ "
403 " backspace: \b formfeed: \f newline: \n return: \r tab: "
404 " now-all-of-them-together: \"\\\\/\b\n\r\t"
405 " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><"
406 " char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ ");
407 cout << "testString(" << str << ") = " << flush;
408 testClient.testString(s, str);
409 cout << s << endl;
410 if (s != str) {
411 cout.imbue(locale("en_US.UTF8"));
412 cout << "*** FAILED ***" << endl
413 << "Expected string: " << str << " but got: " << s << endl
414 << "CLEAR";
415 ;
416 return_code |= ERR_BASETYPES;
417 }
418 } catch (TTransportException&) {
419 throw;
420 } catch (exception& ex) {
421 cout << "*** FAILED ***" << endl << ex.what() << endl;
422 return_code |= ERR_BASETYPES;
423 return return_code;
424 }
425
Mark Sleee8540632006-05-30 09:24:40 +0000426 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900427 * BOOL TEST
428 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900429 cout << boolalpha;
430 BASETYPE_IDENTITY_TEST(testBool, true);
431 BASETYPE_IDENTITY_TEST(testBool, false);
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900432
433 /**
Mark Sleee8540632006-05-30 09:24:40 +0000434 * BYTE TEST
435 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900436 BASETYPE_IDENTITY_TEST(testByte, (int8_t)0);
437 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-1);
438 BASETYPE_IDENTITY_TEST(testByte, (int8_t)42);
439 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-42);
440 BASETYPE_IDENTITY_TEST(testByte, (int8_t)127);
441 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-128);
David Reiss0c90f6f2008-02-06 22:18:40 +0000442
Mark Sleee8540632006-05-30 09:24:40 +0000443 /**
444 * I32 TEST
445 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900446 BASETYPE_IDENTITY_TEST(testI32, 0);
447 BASETYPE_IDENTITY_TEST(testI32, -1);
448 BASETYPE_IDENTITY_TEST(testI32, 190000013);
449 BASETYPE_IDENTITY_TEST(testI32, -190000013);
450 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::max());
451 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::min());
Mark Sleee8540632006-05-30 09:24:40 +0000452
453 /**
Mark Sleee8540632006-05-30 09:24:40 +0000454 * I64 TEST
455 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900456 BASETYPE_IDENTITY_TEST(testI64, (int64_t)0);
457 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1);
458 BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL);
459 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL);
460 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(2LL, 32));
461 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(2LL, 32));
462 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(2LL, 32) + 1);
463 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(2LL, 32) - 1);
464 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::max());
465 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::min());
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100466
Mark Sleec98d0502006-09-06 02:42:25 +0000467 /**
468 * DOUBLE TEST
469 */
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900470 // Comparing double values with plain equality because Thrift handles full precision of double
471 BASETYPE_IDENTITY_TEST(testDouble, 0.0);
472 BASETYPE_IDENTITY_TEST(testDouble, -1.0);
473 BASETYPE_IDENTITY_TEST(testDouble, -5.2098523);
474 BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279);
475 BASETYPE_IDENTITY_TEST(testDouble, pow(2, 32));
476 BASETYPE_IDENTITY_TEST(testDouble, pow(2, 32) + 1);
477 BASETYPE_IDENTITY_TEST(testDouble, pow(2, 53) - 1);
478 BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 32));
479 BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 32) - 1);
480 BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 53) + 1);
481
482 try {
483 double expected = pow(10, 307);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900484 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900485 double actual = testClient.testDouble(expected);
486 cout << "(" << actual << ")" << endl;
487 if (expected - actual > pow(10, 292)) {
488 cout << "*** FAILED ***" << endl
489 << "Expected: " << expected << " but got: " << actual << endl;
490 }
491 } catch (TTransportException&) {
492 throw;
493 } catch (exception& ex) {
494 cout << "*** FAILED ***" << endl << ex.what() << endl;
495 return_code |= ERR_BASETYPES;
496 }
497
498 try {
499 double expected = pow(10, -292);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900500 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900501 double actual = testClient.testDouble(expected);
502 cout << "(" << actual << ")" << endl;
503 if (expected - actual > pow(10, -307)) {
504 cout << "*** FAILED ***" << endl
505 << "Expected: " << expected << " but got: " << actual << endl;
506 }
507 } catch (TTransportException&) {
508 throw;
509 } catch (exception& ex) {
510 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200511 return_code |= ERR_BASETYPES;
512 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000513
Mark Sleee8540632006-05-30 09:24:40 +0000514 /**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100515 * BINARY TEST
516 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900517 cout << "testBinary(empty)" << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900518 try {
519 string bin_result;
520 testClient.testBinary(bin_result, string());
521 if (!bin_result.empty()) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900522 cout << endl << "*** FAILED ***" << endl;
523 cout << "invalid length: " << bin_result.size() << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900524 return_code |= ERR_BASETYPES;
525 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900526 } catch (TTransportException&) {
527 throw;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900528 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900529 cout << "*** FAILED ***" << endl << ex.what() << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900530 return_code |= ERR_BASETYPES;
531 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900532 cout << "testBinary([-128..127]) = {" << flush;
Jens Geyerd629ea02015-09-23 21:16:50 +0200533 const char bin_data[256]
534 = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
535 -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
536 -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
537 -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
538 -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
539 -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
540 -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
541 -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
542 -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
543 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
544 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
545 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
546 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
547 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
548 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
549 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
550 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
551 127};
552 try {
553 string bin_result;
554 testClient.testBinary(bin_result, string(bin_data, 256));
555 if (bin_result.size() != 256) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900556 cout << endl << "*** FAILED ***" << endl;
557 cout << "invalid length: " << bin_result.size() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200558 return_code |= ERR_BASETYPES;
559 } else {
560 bool first = true;
561 bool failed = false;
562 for (int i = 0; i < 256; ++i) {
563 if (!first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900564 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200565 else
566 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900567 cout << static_cast<int>(bin_result[i]);
Jens Geyerd629ea02015-09-23 21:16:50 +0200568 if (!failed && bin_result[i] != i - 128) {
569 failed = true;
570 }
571 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900572 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200573 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900574 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200575 return_code |= ERR_BASETYPES;
576 }
577 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900578 } catch (TTransportException&) {
579 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200580 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900581 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200582 return_code |= ERR_BASETYPES;
583 }
584
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100585
586 /**
Mark Sleee8540632006-05-30 09:24:40 +0000587 * STRUCT TEST
588 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900589 cout << "testStruct({\"Zero\", 1, -3, -5})" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000590 Xtruct out;
591 out.string_thing = "Zero";
592 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000593 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000594 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000595 Xtruct in;
596 testClient.testStruct(in, out);
Roger Meier0e814802014-01-17 21:07:58 +0100597 printf(" = {\"%s\", %d, %d, %" PRId64 "}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000598 in.string_thing.c_str(),
599 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000600 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000601 in.i64_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200602 if (in != out) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900603 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200604 return_code |= ERR_STRUCTS;
605 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000606
Mark Sleee8540632006-05-30 09:24:40 +0000607 /**
608 * NESTED STRUCT TEST
609 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900610 cout << "testNest({1, {\"Zero\", 1, -3, -5}), 5}" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000611 Xtruct2 out2;
612 out2.byte_thing = 1;
613 out2.struct_thing = out;
614 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000615 Xtruct2 in2;
616 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000617 in = in2.struct_thing;
Roger Meier0e814802014-01-17 21:07:58 +0100618 printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000619 in2.byte_thing,
620 in.string_thing.c_str(),
621 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000622 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000623 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000624 in2.i32_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200625 if (in2 != out2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900626 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200627 return_code |= ERR_STRUCTS;
628 }
Mark Sleee8540632006-05-30 09:24:40 +0000629
630 /**
631 * MAP TEST
632 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100633 map<int32_t, int32_t> mapout;
Mark Sleee8540632006-05-30 09:24:40 +0000634 for (int32_t i = 0; i < 5; ++i) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100635 mapout.insert(make_pair(i, i - 10));
Mark Sleee8540632006-05-30 09:24:40 +0000636 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900637 cout << "testMap({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000638 map<int32_t, int32_t>::const_iterator m_iter;
639 bool first = true;
640 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
641 if (first) {
642 first = false;
643 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900644 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000645 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900646 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000647 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900648 cout << "})";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100649 map<int32_t, int32_t> mapin;
Mark Slee1921d202007-01-24 19:43:06 +0000650 testClient.testMap(mapin, mapout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900651 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000652 first = true;
653 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
654 if (first) {
655 first = false;
656 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900657 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000658 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900659 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000660 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900661 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200662 if (mapin != mapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900663 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200664 return_code |= ERR_CONTAINERS;
665 }
Roger Meier4fce9602012-05-04 06:22:09 +0000666
667 /**
668 * STRING MAP TEST
Roger Meier4fce9602012-05-04 06:22:09 +0000669 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900670 cout << "testStringMap({a => 2, b => blah, some => thing}) = {" << flush;
Jens Geyerd629ea02015-09-23 21:16:50 +0200671 map<string, string> smapin;
672 map<string, string> smapout;
673 smapin["a"] = "2";
674 smapin["b"] = "blah";
675 smapin["some"] = "thing";
676 try {
677 testClient.testStringMap(smapout, smapin);
678 first = true;
679 for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) {
680 if (first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900681 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200682 else
683 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900684 cout << it->first << " => " << it->second;
Jens Geyerd629ea02015-09-23 21:16:50 +0200685 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900686 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200687 if (smapin != smapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900688 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200689 return_code |= ERR_CONTAINERS;
690 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900691 } catch (TTransportException&) {
692 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200693 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900694 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200695 return_code |= ERR_CONTAINERS;
696 }
Mark Sleee8540632006-05-30 09:24:40 +0000697
698 /**
699 * SET TEST
700 */
701 set<int32_t> setout;
702 for (int32_t i = -2; i < 3; ++i) {
703 setout.insert(i);
704 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900705 cout << "testSet({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000706 set<int32_t>::const_iterator s_iter;
707 first = true;
708 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
709 if (first) {
710 first = false;
711 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900712 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000713 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900714 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000715 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900716 cout << "})";
Mark Slee1921d202007-01-24 19:43:06 +0000717 set<int32_t> setin;
718 testClient.testSet(setin, setout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900719 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000720 first = true;
721 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
722 if (first) {
723 first = false;
724 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900725 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000726 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900727 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000728 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900729 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200730 if (setin != setout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900731 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200732 return_code |= ERR_CONTAINERS;
733 }
Mark Sleee8540632006-05-30 09:24:40 +0000734
735 /**
736 * LIST TEST
737 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900738 cout << "testList(empty)" << flush;
739 try {
740 vector<int32_t> listout;
741 testClient.testList(listout, vector<int32_t>());
742 if (!listout.empty()) {
743 cout << "*** FAILED ***" << endl;
744 cout << "invalid length: " << listout.size() << endl;
745 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000746 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900747 } catch (TTransportException&) {
748 throw;
749 } catch (exception& ex) {
750 cout << "*** FAILED ***" << endl << ex.what() << endl;
751 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000752 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900753 try {
754 vector<int32_t> listout;
755 for (int32_t i = -2; i < 3; ++i) {
756 listout.push_back(i);
Mark Sleee8540632006-05-30 09:24:40 +0000757 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900758 cout << "testList({" << flush;
759 vector<int32_t>::const_iterator l_iter;
760 first = true;
761 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
762 if (first) {
763 first = false;
764 } else {
765 cout << ",";
766 }
767 cout << *l_iter;
768 }
769 cout << "})";
770 vector<int32_t> listin;
771 testClient.testList(listin, listout);
772 cout << " = {";
773 first = true;
774 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
775 if (first) {
776 first = false;
777 } else {
778 cout << ",";
779 }
780 cout << *l_iter;
781 }
782 cout << "}" << endl;
783 if (listin != listout) {
784 cout << "*** FAILED ***" << endl;
785 return_code |= ERR_CONTAINERS;
786 }
787 } catch (TTransportException&) {
788 throw;
789 } catch (exception& ex) {
790 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200791 return_code |= ERR_CONTAINERS;
792 }
Mark Sleee8540632006-05-30 09:24:40 +0000793
794 /**
795 * ENUM TEST
796 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900797 cout << "testEnum(ONE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000798 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900799 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200800 if (ret != Numberz::ONE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900801 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200802 return_code |= ERR_STRUCTS;
803 }
Mark Sleee8540632006-05-30 09:24:40 +0000804
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900805 cout << "testEnum(TWO)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000806 ret = testClient.testEnum(Numberz::TWO);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900807 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200808 if (ret != Numberz::TWO) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900809 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200810 return_code |= ERR_STRUCTS;
811 }
Mark Sleee8540632006-05-30 09:24:40 +0000812
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900813 cout << "testEnum(THREE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000814 ret = testClient.testEnum(Numberz::THREE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900815 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200816 if (ret != Numberz::THREE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900817 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200818 return_code |= ERR_STRUCTS;
819 }
Mark Sleee8540632006-05-30 09:24:40 +0000820
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900821 cout << "testEnum(FIVE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000822 ret = testClient.testEnum(Numberz::FIVE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900823 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200824 if (ret != Numberz::FIVE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900825 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200826 return_code |= ERR_STRUCTS;
827 }
Mark Sleee8540632006-05-30 09:24:40 +0000828
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900829 cout << "testEnum(EIGHT)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000830 ret = testClient.testEnum(Numberz::EIGHT);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900831 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200832 if (ret != Numberz::EIGHT) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900833 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200834 return_code |= ERR_STRUCTS;
835 }
Mark Sleee8540632006-05-30 09:24:40 +0000836
837 /**
838 * TYPEDEF TEST
839 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900840 cout << "testTypedef(309858235082523)" << flush;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000841 UserId uid = testClient.testTypedef(309858235082523LL);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900842 cout << " = " << uid << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200843 if (uid != 309858235082523LL) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900844 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200845 return_code |= ERR_STRUCTS;
846 }
Mark Sleee8540632006-05-30 09:24:40 +0000847
848 /**
849 * NESTED MAP TEST
850 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900851 cout << "testMapMap(1)" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000852 map<int32_t, map<int32_t, int32_t> > mm;
853 testClient.testMapMap(mm, 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900854 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000855 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
856 for (mi = mm.begin(); mi != mm.end(); ++mi) {
857 printf("%d => {", mi->first);
858 map<int32_t, int32_t>::const_iterator mi2;
859 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900860 cout << mi2->first << " => " << mi2->second;
Mark Sleee8540632006-05-30 09:24:40 +0000861 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900862 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000863 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900864 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200865 if (mm.size() != 2 ||
866 mm[-4][-4] != -4 ||
867 mm[-4][-3] != -3 ||
868 mm[-4][-2] != -2 ||
869 mm[-4][-1] != -1 ||
870 mm[4][4] != 4 ||
871 mm[4][3] != 3 ||
872 mm[4][2] != 2 ||
873 mm[4][1] != 1) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900874 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200875 return_code |= ERR_CONTAINERS;
876 }
Mark Sleee8540632006-05-30 09:24:40 +0000877
878 /**
879 * INSANITY TEST
880 */
Jens Geyerf4598682014-05-08 23:18:44 +0200881 if (!noinsane) {
882 Insanity insane;
Jens Geyerd629ea02015-09-23 21:16:50 +0200883 insane.userMap.insert(make_pair(Numberz::FIVE, 5));
884 insane.userMap.insert(make_pair(Numberz::EIGHT, 8));
Jens Geyerf4598682014-05-08 23:18:44 +0200885 Xtruct truck;
Jens Geyerd629ea02015-09-23 21:16:50 +0200886 truck.string_thing = "Goodbye4";
887 truck.byte_thing = 4;
888 truck.i32_thing = 4;
889 truck.i64_thing = 4;
890 Xtruct truck2;
891 truck2.string_thing = "Hello2";
892 truck2.byte_thing = 2;
893 truck2.i32_thing = 2;
894 truck2.i64_thing = 2;
Jens Geyerf4598682014-05-08 23:18:44 +0200895 insane.xtructs.push_back(truck);
Jens Geyerd629ea02015-09-23 21:16:50 +0200896 insane.xtructs.push_back(truck2);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900897 cout << "testInsanity()" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100898 map<UserId, map<Numberz::type, Insanity> > whoa;
Jens Geyerf4598682014-05-08 23:18:44 +0200899 testClient.testInsanity(whoa, insane);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900900 cout << " = {";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100901 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Jens Geyerf4598682014-05-08 23:18:44 +0200902 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
903 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100904 map<Numberz::type, Insanity>::const_iterator i2_iter;
905 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Jens Geyerf4598682014-05-08 23:18:44 +0200906 printf("%d => {", i2_iter->first);
907 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
908 map<Numberz::type, UserId>::const_iterator um;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900909 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200910 for (um = userMap.begin(); um != userMap.end(); ++um) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900911 cout << um->first << " => " << um->second;
Jens Geyerf4598682014-05-08 23:18:44 +0200912 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900913 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000914
Jens Geyerf4598682014-05-08 23:18:44 +0200915 vector<Xtruct> xtructs = i2_iter->second.xtructs;
916 vector<Xtruct>::const_iterator x;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900917 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200918 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
919 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
920 x->string_thing.c_str(),
921 (int)x->byte_thing,
922 x->i32_thing,
923 x->i64_thing);
924 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900925 cout << "}";
Mark Sleee8540632006-05-30 09:24:40 +0000926
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900927 cout << "}, ";
Jens Geyerf4598682014-05-08 23:18:44 +0200928 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900929 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000930 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900931 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200932 bool failed = false;
933 map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1));
934 if (whoa.size() != 2) {
935 failed = true;
936 }
937 if (it1 == whoa.end()) {
938 failed = true;
939 } else {
940 map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO);
941 if (it12 == it1->second.end() || it12->second != insane) {
942 failed = true;
943 }
944 map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE);
945 if (it13 == it1->second.end() || it13->second != insane) {
946 failed = true;
947 }
948 }
949 map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2));
950 if (it2 == whoa.end()) {
951 failed = true;
952 } else {
953 map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX);
954 if (it26 == it1->second.end() || it26->second != Insanity()) {
955 failed = true;
956 }
957 }
958 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900959 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200960 return_code |= ERR_STRUCTS;
961 }
Mark Sleee8540632006-05-30 09:24:40 +0000962 }
Jens Geyerd629ea02015-09-23 21:16:50 +0200963
964 /**
965 * MULTI TEST
966 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900967 cout << "testMulti()" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200968 try {
969 map<int16_t, string> mul_map;
970 Xtruct mul_result;
971 mul_map[1] = "blah";
972 mul_map[2] = "thing";
973 testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24));
974 Xtruct xxs;
975 xxs.string_thing = "Hello2";
976 xxs.byte_thing = 42;
977 xxs.i32_thing = 4242;
978 xxs.i64_thing = 424242;
979 if (mul_result != xxs) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900980 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200981 return_code |= ERR_STRUCTS;
982 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900983 } catch (TTransportException&) {
984 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200985 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900986 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200987 return_code |= ERR_STRUCTS;
988 }
989
Marc Slemko71d4e472006-08-15 22:34:04 +0000990 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +0000991
Marc Slemkobf4fd192006-08-15 21:29:39 +0000992 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900993 cout << "testClient.testException(\"Xception\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +0000994 testClient.testException("Xception");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900995 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200996 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +0000997
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100998 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000999 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001000 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001001
Marc Slemkobf4fd192006-08-15 21:29:39 +00001002 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001003 cout << "testClient.testException(\"TException\") =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001004 testClient.testException("TException");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001005 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001006 return_code |= ERR_EXCEPTIONS;
Roger Meierf50df7f2012-05-02 22:49:55 +00001007
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001008 } catch (const TException&) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001009 cout << " Caught TException" << endl;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001010 }
Roger Meierf50df7f2012-05-02 22:49:55 +00001011
1012 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001013 cout << "testClient.testException(\"success\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001014 testClient.testException("success");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001015 cout << " void" << endl;
1016 } catch (exception & ex) { \
1017 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001018 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001019 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001020
Marc Slemko71d4e472006-08-15 22:34:04 +00001021 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +00001022
Marc Slemko71d4e472006-08-15 22:34:04 +00001023 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001024 cout << "testClient.testMultiException(\"Xception\", \"test 1\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001025 Xtruct result;
1026 testClient.testMultiException(result, "Xception", "test 1");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001027 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001028 return_code |= ERR_EXCEPTIONS;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001029 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001030 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
1031 }
1032
1033 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001034 cout << "testClient.testMultiException(\"Xception2\", \"test 2\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001035 Xtruct result;
1036 testClient.testMultiException(result, "Xception2", "test 2");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001037 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001038 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001039
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001040 } catch (Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001041 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001042 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001043
Marc Slemko71d4e472006-08-15 22:34:04 +00001044 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001045 cout << "testClient.testMultiException(\"success\", \"test 3\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001046 Xtruct result;
1047 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +00001048 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001049 } catch (exception & ex) { \
1050 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001051 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001052 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001053
David Reissc51986f2009-03-24 20:01:25 +00001054 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +00001055 {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001056 cout << "testClient.testOneway(1) =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001057 uint64_t startOneway = now();
1058 testClient.testOneway(1);
1059 uint64_t elapsed = now() - startOneway;
1060 if (elapsed > 200 * 1000) { // 0.2 seconds
Jens Geyerd629ea02015-09-23 21:16:50 +02001061 printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0);
1062 return_code |= ERR_BASETYPES;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001063 } else {
1064 printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
1065 }
David Reiss2ab6fe82008-02-18 02:11:44 +00001066 }
1067
David Reiss2845b522008-02-18 02:11:52 +00001068 /**
David Reissc51986f2009-03-24 20:01:25 +00001069 * redo a simple test after the oneway to make sure we aren't "off by one" --
1070 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +00001071 * fail since it will get the void confirmation rather than the correct
1072 * result. In this circumstance, the client will throw the exception:
1073 *
1074 * TApplicationException: Wrong method namea
1075 */
1076 /**
1077 * I32 TEST
1078 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001079 cout << "re-test testI32(-1)";
1080 int i32 = testClient.testI32(-1);
1081 cout << " = " << i32 << endl;
Roger Meier4fce9602012-05-04 06:22:09 +00001082 if (i32 != -1)
Jens Geyerd629ea02015-09-23 21:16:50 +02001083 return_code |= ERR_BASETYPES;
David Reiss2845b522008-02-18 02:11:52 +00001084
Marc Slemkobf4fd192006-08-15 21:29:39 +00001085 uint64_t stop = now();
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001086 uint64_t tot = stop - start;
Mark Sleed788b2e2006-09-07 01:26:35 +00001087
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001088 cout << "Total time: " << stop - start << " us" << endl;
David Reiss0c90f6f2008-02-06 22:18:40 +00001089
Mark Sleed788b2e2006-09-07 01:26:35 +00001090 time_tot += tot;
1091 if (time_min == 0 || tot < time_min) {
1092 time_min = tot;
1093 }
1094 if (tot > time_max) {
1095 time_max = tot;
1096 }
1097
Mark Sleea3302652006-10-25 19:03:32 +00001098 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +00001099 }
1100
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001101 cout << endl << "All tests done." << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001102
1103 uint64_t time_avg = time_tot / numTests;
1104
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001105 cout << "Min time: " << time_min << " us" << endl;
1106 cout << "Max time: " << time_max << " us" << endl;
1107 cout << "Avg time: " << time_avg << " us" << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001108
Jens Geyerd629ea02015-09-23 21:16:50 +02001109 return return_code;
Mark Sleee8540632006-05-30 09:24:40 +00001110}