blob: 6b2e7314d738106a802f647d9eb859d131fe1b42 [file] [log] [blame]
James E. King, III7edc8fa2017-01-20 10:11:41 -05001/*
David Reissea2cba82009-03-30 21:35:00 +00002 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +090020#include <limits>
21#include <locale>
22#include <ios>
Roger Meierca142b02011-06-07 17:59:07 +000023#include <iostream>
Sebastian Zenker39e505c2015-12-18 16:15:08 +010024#include <sstream>
Roger Meier49ff8b12012-04-13 09:12:31 +000025#include <thrift/protocol/TBinaryProtocol.h>
Roger Meier023192f2014-02-12 09:35:12 +010026#include <thrift/protocol/TCompactProtocol.h>
Dave Watson792db4e2015-01-16 11:22:01 -080027#include <thrift/protocol/THeaderProtocol.h>
Roger Meier49ff8b12012-04-13 09:12:31 +000028#include <thrift/protocol/TJSONProtocol.h>
29#include <thrift/transport/THttpClient.h>
30#include <thrift/transport/TTransportUtils.h>
31#include <thrift/transport/TSocket.h>
32#include <thrift/transport/TSSLSocket.h>
33#include <thrift/async/TEvhttpClientChannel.h>
34#include <thrift/server/TNonblockingServer.h> // <event.h>
Mark Sleee8540632006-05-30 09:24:40 +000035
James E. King, III7edc8fa2017-01-20 10:11:41 -050036#ifdef HAVE_STDINT_H
37#include <stdint.h>
38#endif
39#ifdef HAVE_INTTYPES_H
40#include <inttypes.h>
41#endif
42
Roger Meierca142b02011-06-07 17:59:07 +000043#include <boost/program_options.hpp>
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053044#include <boost/filesystem.hpp>
James E. King, III82ae9572017-08-05 12:23:54 -040045#include <thrift/stdcxx.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050046#if _WIN32
Konrad Grochowski16a23a62014-11-13 15:33:38 +010047#include <thrift/windows/TWinsockSingleton.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050048#endif
Roger Meierca142b02011-06-07 17:59:07 +000049
Marc Slemko6be374b2006-08-04 03:16:25 +000050#include "ThriftTest.h"
51
Marc Slemko6be374b2006-08-04 03:16:25 +000052using namespace std;
T Jake Lucianib5e62212009-01-31 22:36:20 +000053using namespace apache::thrift;
James E. King, III82ae9572017-08-05 12:23:54 -040054using namespace apache::thrift::async;
T Jake Lucianib5e62212009-01-31 22:36:20 +000055using namespace apache::thrift::protocol;
56using namespace apache::thrift::transport;
Marc Slemkobf4fd192006-08-15 21:29:39 +000057using namespace thrift::test;
Roger Meier7e056e72011-07-17 07:28:28 +000058
Mark Slee95771002006-06-07 06:53:25 +000059// Current time, microseconds since the epoch
Konrad Grochowski16a23a62014-11-13 15:33:38 +010060uint64_t now() {
Roger Meier5f9614c2010-11-21 16:59:05 +000061 int64_t ret;
Mark Slee95771002006-06-07 06:53:25 +000062 struct timeval tv;
David Reiss0c90f6f2008-02-06 22:18:40 +000063
Jake Farrell5d02b802014-01-07 21:42:01 -050064 THRIFT_GETTIMEOFDAY(&tv, NULL);
Mark Slee95771002006-06-07 06:53:25 +000065 ret = tv.tv_sec;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010066 ret = ret * 1000 * 1000 + tv.tv_usec;
Mark Slee95771002006-06-07 06:53:25 +000067 return ret;
68}
69
Sebastian Zenker39e505c2015-12-18 16:15:08 +010070static void testString_clientReturn(event_base* base,
71 int testNr,
Konrad Grochowski16a23a62014-11-13 15:33:38 +010072 ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000073 try {
74 string s;
75 client->recv_testString(s);
Sebastian Zenker39e505c2015-12-18 16:15:08 +010076 std::ostringstream os;
77 os << "test" << testNr;
78 const bool ok = (s == os.str());
79 cout << "testString: " << s << " " << ((ok) ? "ok" : "failed") << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000080 } 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
Sebastian Zenker39e505c2015-12-18 16:15:08 +010084 if (testNr == 9)
85 event_base_loopbreak(base); // end test
Roger Meier7e056e72011-07-17 07:28:28 +000086}
87
Sebastian Zenker39e505c2015-12-18 16:15:08 +010088static void testVoid_clientReturn(event_base* base, ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000089 try {
90 client->recv_testVoid();
91 cout << "testVoid" << endl;
92
Sebastian Zenker39e505c2015-12-18 16:15:08 +010093 for (int testNr = 0; testNr < 10; ++testNr) {
94 std::ostringstream os;
95 os << "test" << testNr;
James E. King, III82ae9572017-08-05 12:23:54 -040096 client->testString(stdcxx::bind(testString_clientReturn,
Sebastian Zenker39e505c2015-12-18 16:15:08 +010097 base,
98 testNr,
James E. King, III82ae9572017-08-05 12:23:54 -040099 stdcxx::placeholders::_1),
Sebastian Zenker39e505c2015-12-18 16:15:08 +0100100 os.str());
101 }
Roger Meier7e056e72011-07-17 07:28:28 +0000102 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500103 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +0000104 }
105}
106
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900107// Workaround for absense of C++11 "auto" keyword.
108template <typename T>
109bool print_eq(T expected, T actual) {
110 cout << "(" << actual << ")" << endl;
111 if (expected != actual) {
112 cout << "*** FAILED ***" << endl << "Expected: " << expected << " but got: " << actual << endl;
113 return false;
114 }
115 return true;
116}
117
118#define BASETYPE_IDENTITY_TEST(func, value) \
119 cout << #func "(" << value << ") = "; \
120 try { \
121 if (!print_eq(value, testClient.func(value))) \
122 return_code |= ERR_BASETYPES; \
123 } catch (TTransportException&) { \
124 throw; \
125 } catch (exception & ex) { \
126 cout << "*** FAILED ***" << endl << ex.what() << endl; \
127 return_code |= ERR_BASETYPES; \
128 }
129
Mark Sleee8540632006-05-30 09:24:40 +0000130int main(int argc, char** argv) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900131 cout.precision(19);
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900132 int ERR_BASETYPES = 1;
133 int ERR_STRUCTS = 2;
134 int ERR_CONTAINERS = 4;
135 int ERR_EXCEPTIONS = 8;
136 int ERR_UNKNOWN = 64;
137
James E. King, III06190872017-02-20 08:52:11 -0500138 string testDir = boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string();
139 string caPath = testDir + "/keys/CA.pem";
140 string certPath = testDir + "/keys/client.crt";
141 string keyPath = testDir + "/keys/client.key";
142
Jake Farrell5d02b802014-01-07 21:42:01 -0500143#if _WIN32
144 transport::TWinsockSingleton::create();
145#endif
Mark Sleee8540632006-05-30 09:24:40 +0000146 string host = "localhost";
147 int port = 9090;
148 int numTests = 1;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000149 bool ssl = false;
Roger Meierca142b02011-06-07 17:59:07 +0000150 string transport_type = "buffered";
151 string protocol_type = "binary";
152 string domain_socket = "";
pavlodd08f6e2015-10-08 16:43:56 -0400153 bool abstract_namespace = false;
Jens Geyerf4598682014-05-08 23:18:44 +0200154 bool noinsane = false;
Mark Sleee8540632006-05-30 09:24:40 +0000155
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900156 int return_code = 0;
157
Jake Farrell5d02b802014-01-07 21:42:01 -0500158 boost::program_options::options_description desc("Allowed options");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100159 desc.add_options()("help,h",
160 "produce help message")("host",
161 boost::program_options::value<string>(&host)
162 ->default_value(host),
163 "Host to connect")("port",
164 boost::program_options::value<int>(
165 &port)->default_value(port),
166 "Port number to connect")(
167 "domain-socket",
168 boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
169 "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")(
pavlodd08f6e2015-10-08 16:43:56 -0400170 "abstract-namespace",
171 "Look for the domain socket in the Abstract Namespace (no connection with filesystem pathnames)")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100172 "transport",
173 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
174 "Transport: buffered, framed, http, evhttp")(
175 "protocol",
176 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
Dave Watson792db4e2015-01-16 11:22:01 -0800177 "Protocol: binary, header, compact, json")("ssl", "Encrypted Transport using SSL")(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100178 "testloops,n",
179 boost::program_options::value<int>(&numTests)->default_value(numTests),
180 "Number of Tests")("noinsane", "Do not run insanity test");
Roger Meierca142b02011-06-07 17:59:07 +0000181
Jake Farrell5d02b802014-01-07 21:42:01 -0500182 boost::program_options::variables_map vm;
183 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
184 boost::program_options::notify(vm);
Roger Meierca142b02011-06-07 17:59:07 +0000185
186 if (vm.count("help")) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900187 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900188 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000189 }
Mark Sleea3302652006-10-25 19:03:32 +0000190
Jake Farrell5d02b802014-01-07 21:42:01 -0500191 try {
Roger Meierca142b02011-06-07 17:59:07 +0000192 if (!protocol_type.empty()) {
193 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100194 } else if (protocol_type == "compact") {
Dave Watson792db4e2015-01-16 11:22:01 -0800195 } else if (protocol_type == "header") {
Roger Meierca142b02011-06-07 17:59:07 +0000196 } else if (protocol_type == "json") {
197 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100198 throw invalid_argument("Unknown protocol type " + protocol_type);
Roger Meierca142b02011-06-07 17:59:07 +0000199 }
200 }
201
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100202 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000203 if (transport_type == "buffered") {
204 } else if (transport_type == "framed") {
205 } else if (transport_type == "http") {
Roger Meier7e056e72011-07-17 07:28:28 +0000206 } else if (transport_type == "evhttp") {
Roger Meierca142b02011-06-07 17:59:07 +0000207 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100208 throw invalid_argument("Unknown transport type " + transport_type);
Roger Meierca142b02011-06-07 17:59:07 +0000209 }
210 }
211
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900212 } catch (exception& e) {
Roger Meierca142b02011-06-07 17:59:07 +0000213 cerr << e.what() << endl;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900214 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900215 return ERR_UNKNOWN;
Roger Meierca142b02011-06-07 17:59:07 +0000216 }
217
218 if (vm.count("ssl")) {
219 ssl = true;
220 }
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530221
pavlodd08f6e2015-10-08 16:43:56 -0400222 if (vm.count("abstract-namespace")) {
223 abstract_namespace = true;
224 }
225
Jens Geyerf4598682014-05-08 23:18:44 +0200226 if (vm.count("noinsane")) {
227 noinsane = true;
228 }
Roger Meierca142b02011-06-07 17:59:07 +0000229
James E. King, III7f5a8c22017-04-04 09:36:38 -0400230 // THRIFT-4164: The factory MUST outlive any sockets it creates for correct behavior!
James E. King, III82ae9572017-08-05 12:23:54 -0400231 stdcxx::shared_ptr<TSSLSocketFactory> factory;
232 stdcxx::shared_ptr<TSocket> socket;
233 stdcxx::shared_ptr<TTransport> transport;
234 stdcxx::shared_ptr<TProtocol> protocol;
Roger Meierca142b02011-06-07 17:59:07 +0000235
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000236 if (ssl) {
James E. King, III06190872017-02-20 08:52:11 -0500237 cout << "Client Certificate File: " << certPath << endl;
238 cout << "Client Key File: " << keyPath << endl;
239 cout << "CA File: " << caPath << endl;
240
James E. King, III82ae9572017-08-05 12:23:54 -0400241 factory = stdcxx::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000242 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
James E. King, III06190872017-02-20 08:52:11 -0500243 factory->loadTrustedCertificates(caPath.c_str());
244 factory->loadCertificate(certPath.c_str());
245 factory->loadPrivateKey(keyPath.c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000246 factory->authenticate(true);
247 socket = factory->createSocket(host, port);
248 } else {
Roger Meierca142b02011-06-07 17:59:07 +0000249 if (domain_socket != "") {
pavlodd08f6e2015-10-08 16:43:56 -0400250 if (abstract_namespace) {
251 std::string abstract_socket("\0", 1);
252 abstract_socket += domain_socket;
James E. King, III82ae9572017-08-05 12:23:54 -0400253 socket = stdcxx::shared_ptr<TSocket>(new TSocket(abstract_socket));
pavlodd08f6e2015-10-08 16:43:56 -0400254 } else {
James E. King, III82ae9572017-08-05 12:23:54 -0400255 socket = stdcxx::shared_ptr<TSocket>(new TSocket(domain_socket));
pavlodd08f6e2015-10-08 16:43:56 -0400256 }
Roger Meierca142b02011-06-07 17:59:07 +0000257 port = 0;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100258 } else {
James E. King, III82ae9572017-08-05 12:23:54 -0400259 socket = stdcxx::shared_ptr<TSocket>(new TSocket(host, port));
Roger Meierca142b02011-06-07 17:59:07 +0000260 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000261 }
Mark Sleea3302652006-10-25 19:03:32 +0000262
Roger Meierca142b02011-06-07 17:59:07 +0000263 if (transport_type.compare("http") == 0) {
James E. King, III82ae9572017-08-05 12:23:54 -0400264 stdcxx::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service"));
Roger Meierca142b02011-06-07 17:59:07 +0000265 transport = httpSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100266 } else if (transport_type.compare("framed") == 0) {
James E. King, III82ae9572017-08-05 12:23:54 -0400267 stdcxx::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000268 transport = framedSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100269 } else {
James E. King, III82ae9572017-08-05 12:23:54 -0400270 stdcxx::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000271 transport = bufferedSocket;
272 }
273
Roger Meierca142b02011-06-07 17:59:07 +0000274 if (protocol_type.compare("json") == 0) {
James E. King, III82ae9572017-08-05 12:23:54 -0400275 stdcxx::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000276 protocol = jsonProtocol;
Roger Meier023192f2014-02-12 09:35:12 +0100277 } else if (protocol_type.compare("compact") == 0) {
James E. King, III82ae9572017-08-05 12:23:54 -0400278 stdcxx::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport));
Roger Meier023192f2014-02-12 09:35:12 +0100279 protocol = compactProtocol;
Dave Watson792db4e2015-01-16 11:22:01 -0800280 } else if (protocol_type == "header") {
James E. King, III82ae9572017-08-05 12:23:54 -0400281 stdcxx::shared_ptr<TProtocol> headerProtocol(new THeaderProtocol(transport));
Dave Watson792db4e2015-01-16 11:22:01 -0800282 protocol = headerProtocol;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100283 } else {
James E. King, III82ae9572017-08-05 12:23:54 -0400284 stdcxx::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport));
Roger Meierca142b02011-06-07 17:59:07 +0000285 protocol = binaryProtocol;
286 }
287
288 // Connection info
pavlodd08f6e2015-10-08 16:43:56 -0400289 cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: ";
290 if (abstract_namespace) {
291 cout << '@';
292 }
293 cout << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000294 if (port != 0) {
295 cout << host << ":" << port;
296 }
297 cout << endl;
298
Roger Meier7e056e72011-07-17 07:28:28 +0000299 if (transport_type.compare("evhttp") == 0) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100300 event_base* base = event_base_new();
Roger Meier7e056e72011-07-17 07:28:28 +0000301 cout << "Libevent Version: " << event_get_version() << endl;
302 cout << "Libevent Method: " << event_base_get_method(base) << endl;
303#if LIBEVENT_VERSION_NUMBER >= 0x02000000
304 cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl;
305#endif
306
James E. King, III82ae9572017-08-05 12:23:54 -0400307 stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Roger Meier7e056e72011-07-17 07:28:28 +0000308
James E. King, III82ae9572017-08-05 12:23:54 -0400309 stdcxx::shared_ptr<TAsyncChannel> channel(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100310 new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
Roger Meier7e056e72011-07-17 07:28:28 +0000311 ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
James E. King, III82ae9572017-08-05 12:23:54 -0400312 client->testVoid(stdcxx::bind(testVoid_clientReturn,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100313 base,
James E. King, III82ae9572017-08-05 12:23:54 -0400314 stdcxx::placeholders::_1));
Jake Farrell5d02b802014-01-07 21:42:01 -0500315
Roger Meier7e056e72011-07-17 07:28:28 +0000316 event_base_loop(base, 0);
317 return 0;
318 }
319
Roger Meierca142b02011-06-07 17:59:07 +0000320 ThriftTestClient testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000321
322 uint64_t time_min = 0;
323 uint64_t time_max = 0;
324 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000325
Mark Sleee8540632006-05-30 09:24:40 +0000326 int test = 0;
327 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000328
Mark Slee95771002006-06-07 06:53:25 +0000329 try {
Mark Sleea3302652006-10-25 19:03:32 +0000330 transport->open();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900331 } catch (TTransportException& ex) {
332 cout << "Connect failed: " << ex.what() << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900333 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000334 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000335
Mark Sleed788b2e2006-09-07 01:26:35 +0000336 /**
337 * CONNECT TEST
338 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100339 printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000340
341 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000342
Mark Sleee8540632006-05-30 09:24:40 +0000343 /**
344 * VOID TEST
345 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000346 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900347 cout << "testVoid()" << flush;
Mark Sleee129a2d2007-02-21 05:17:48 +0000348 testClient.testVoid();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900349 cout << " = void" << endl;
350 } catch (TTransportException&) {
351 // Stop here if transport got broken
352 throw;
353 } catch (exception& ex) {
354 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200355 return_code |= ERR_BASETYPES;
Mark Sleee129a2d2007-02-21 05:17:48 +0000356 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000357
Mark Sleee8540632006-05-30 09:24:40 +0000358 /**
359 * STRING TEST
360 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900361 cout << "testString(\"Test\")" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000362 string s;
363 testClient.testString(s, "Test");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900364 cout << " = " << s << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200365 if (s != "Test") {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900366 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200367 return_code |= ERR_BASETYPES;
368 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000369
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900370 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500371#ifdef _MSC_VER
372#pragma warning( push )
373#pragma warning( disable : 4566 )
374#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900375 string str(
376 "}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, "
377 "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, "
378 "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, "
379 "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, "
380 "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, "
381 "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, "
382 "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, "
383 "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, "
384 "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, "
385 "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, "
386 "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, "
387 "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, "
388 "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, "
389 "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa "
390 "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa "
391 "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪"
392 "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, "
393 "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, "
394 "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, "
395 "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple "
396 "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, "
397 "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, "
398 "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, "
399 "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, "
400 "Bân-lâm-gú, 粵語");
James E. King, III7edc8fa2017-01-20 10:11:41 -0500401#ifdef _MSC_VER
402#pragma warning( pop )
403#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900404 cout << "testString(" << str << ") = " << flush;
405 testClient.testString(s, str);
406 cout << s << endl;
407 if (s != str) {
408 cout.imbue(locale("en_US.UTF8"));
409 cout << "*** FAILED ***" << endl << "Expected string: " << str << " but got: " << s << endl << "CLEAR";
410 return_code |= ERR_BASETYPES;
411 }
412 } catch (TTransportException&) {
413 throw;
414 } catch (exception& ex) {
415 cout << "*** FAILED ***" << endl << ex.what() << endl;
416 return_code |= ERR_BASETYPES;
417 return return_code;
418 }
419 try {
420 string str(
421 "quote: \" backslash:"
422 " forwardslash-escaped: \\/ "
423 " backspace: \b formfeed: \f newline: \n return: \r tab: "
424 " now-all-of-them-together: \"\\\\/\b\n\r\t"
425 " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><"
426 " char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ ");
427 cout << "testString(" << str << ") = " << flush;
428 testClient.testString(s, str);
429 cout << s << endl;
430 if (s != str) {
431 cout.imbue(locale("en_US.UTF8"));
432 cout << "*** FAILED ***" << endl
433 << "Expected string: " << str << " but got: " << s << endl
434 << "CLEAR";
435 ;
436 return_code |= ERR_BASETYPES;
437 }
438 } catch (TTransportException&) {
439 throw;
440 } catch (exception& ex) {
441 cout << "*** FAILED ***" << endl << ex.what() << endl;
442 return_code |= ERR_BASETYPES;
443 return return_code;
444 }
445
Mark Sleee8540632006-05-30 09:24:40 +0000446 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900447 * BOOL TEST
448 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900449 cout << boolalpha;
450 BASETYPE_IDENTITY_TEST(testBool, true);
451 BASETYPE_IDENTITY_TEST(testBool, false);
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900452
453 /**
Mark Sleee8540632006-05-30 09:24:40 +0000454 * BYTE TEST
455 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900456 BASETYPE_IDENTITY_TEST(testByte, (int8_t)0);
457 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-1);
458 BASETYPE_IDENTITY_TEST(testByte, (int8_t)42);
459 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-42);
460 BASETYPE_IDENTITY_TEST(testByte, (int8_t)127);
461 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-128);
David Reiss0c90f6f2008-02-06 22:18:40 +0000462
Mark Sleee8540632006-05-30 09:24:40 +0000463 /**
464 * I32 TEST
465 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900466 BASETYPE_IDENTITY_TEST(testI32, 0);
467 BASETYPE_IDENTITY_TEST(testI32, -1);
468 BASETYPE_IDENTITY_TEST(testI32, 190000013);
469 BASETYPE_IDENTITY_TEST(testI32, -190000013);
470 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::max());
471 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::min());
Mark Sleee8540632006-05-30 09:24:40 +0000472
473 /**
Mark Sleee8540632006-05-30 09:24:40 +0000474 * I64 TEST
475 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900476 BASETYPE_IDENTITY_TEST(testI64, (int64_t)0);
477 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1);
478 BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL);
479 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500480 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32));
481 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32));
482 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32) + 1);
483 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32) - 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900484 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::max());
485 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::min());
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100486
Mark Sleec98d0502006-09-06 02:42:25 +0000487 /**
488 * DOUBLE TEST
489 */
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900490 // Comparing double values with plain equality because Thrift handles full precision of double
491 BASETYPE_IDENTITY_TEST(testDouble, 0.0);
492 BASETYPE_IDENTITY_TEST(testDouble, -1.0);
493 BASETYPE_IDENTITY_TEST(testDouble, -5.2098523);
494 BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500495 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32));
496 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32) + 1);
497 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 53) - 1);
498 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32));
499 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32) - 1);
500 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 53) + 1);
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900501
502 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500503 double expected = pow(static_cast<double>(10), 307);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900504 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900505 double actual = testClient.testDouble(expected);
506 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500507 if (expected - actual > pow(static_cast<double>(10), 292)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900508 cout << "*** FAILED ***" << endl
509 << "Expected: " << expected << " but got: " << actual << endl;
510 }
511 } catch (TTransportException&) {
512 throw;
513 } catch (exception& ex) {
514 cout << "*** FAILED ***" << endl << ex.what() << endl;
515 return_code |= ERR_BASETYPES;
516 }
517
518 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500519 double expected = pow(static_cast<double>(10), -292);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900520 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900521 double actual = testClient.testDouble(expected);
522 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500523 if (expected - actual > pow(static_cast<double>(10), -307)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900524 cout << "*** FAILED ***" << endl
525 << "Expected: " << expected << " but got: " << actual << endl;
526 }
527 } catch (TTransportException&) {
528 throw;
529 } catch (exception& ex) {
530 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200531 return_code |= ERR_BASETYPES;
532 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000533
Mark Sleee8540632006-05-30 09:24:40 +0000534 /**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100535 * BINARY TEST
536 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900537 cout << "testBinary(empty)" << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900538 try {
539 string bin_result;
540 testClient.testBinary(bin_result, string());
541 if (!bin_result.empty()) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900542 cout << endl << "*** FAILED ***" << endl;
543 cout << "invalid length: " << bin_result.size() << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900544 return_code |= ERR_BASETYPES;
545 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900546 } catch (TTransportException&) {
547 throw;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900548 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900549 cout << "*** FAILED ***" << endl << ex.what() << endl;
Nobuaki Sukegawadfb68962015-12-09 22:09:26 +0900550 return_code |= ERR_BASETYPES;
551 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900552 cout << "testBinary([-128..127]) = {" << flush;
Cody P Schafer31295492016-09-09 15:50:26 -0400553 const signed char bin_data[256]
Jens Geyerd629ea02015-09-23 21:16:50 +0200554 = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
555 -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
556 -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
557 -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
558 -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
559 -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
560 -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
561 -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
562 -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
563 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
564 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
565 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
566 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
567 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
568 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
569 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
570 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
571 127};
572 try {
573 string bin_result;
Cody P Schafer31295492016-09-09 15:50:26 -0400574 testClient.testBinary(bin_result, string(reinterpret_cast<const char *>(bin_data), 256));
Jens Geyerd629ea02015-09-23 21:16:50 +0200575 if (bin_result.size() != 256) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900576 cout << endl << "*** FAILED ***" << endl;
577 cout << "invalid length: " << bin_result.size() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200578 return_code |= ERR_BASETYPES;
579 } else {
580 bool first = true;
581 bool failed = false;
582 for (int i = 0; i < 256; ++i) {
583 if (!first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900584 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200585 else
586 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900587 cout << static_cast<int>(bin_result[i]);
Jens Geyerd629ea02015-09-23 21:16:50 +0200588 if (!failed && bin_result[i] != i - 128) {
589 failed = true;
590 }
591 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900592 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200593 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900594 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200595 return_code |= ERR_BASETYPES;
596 }
597 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900598 } catch (TTransportException&) {
599 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200600 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900601 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200602 return_code |= ERR_BASETYPES;
603 }
604
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100605
606 /**
Mark Sleee8540632006-05-30 09:24:40 +0000607 * STRUCT TEST
608 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900609 cout << "testStruct({\"Zero\", 1, -3, -5})" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000610 Xtruct out;
611 out.string_thing = "Zero";
612 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000613 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000614 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000615 Xtruct in;
616 testClient.testStruct(in, out);
Roger Meier0e814802014-01-17 21:07:58 +0100617 printf(" = {\"%s\", %d, %d, %" PRId64 "}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000618 in.string_thing.c_str(),
619 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000620 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000621 in.i64_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200622 if (in != out) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900623 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200624 return_code |= ERR_STRUCTS;
625 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000626
Mark Sleee8540632006-05-30 09:24:40 +0000627 /**
628 * NESTED STRUCT TEST
629 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900630 cout << "testNest({1, {\"Zero\", 1, -3, -5}), 5}" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000631 Xtruct2 out2;
632 out2.byte_thing = 1;
633 out2.struct_thing = out;
634 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000635 Xtruct2 in2;
636 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000637 in = in2.struct_thing;
Roger Meier0e814802014-01-17 21:07:58 +0100638 printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000639 in2.byte_thing,
640 in.string_thing.c_str(),
641 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000642 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000643 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000644 in2.i32_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200645 if (in2 != out2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900646 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200647 return_code |= ERR_STRUCTS;
648 }
Mark Sleee8540632006-05-30 09:24:40 +0000649
650 /**
651 * MAP TEST
652 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100653 map<int32_t, int32_t> mapout;
Mark Sleee8540632006-05-30 09:24:40 +0000654 for (int32_t i = 0; i < 5; ++i) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100655 mapout.insert(make_pair(i, i - 10));
Mark Sleee8540632006-05-30 09:24:40 +0000656 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900657 cout << "testMap({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000658 map<int32_t, int32_t>::const_iterator m_iter;
659 bool first = true;
660 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
661 if (first) {
662 first = false;
663 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900664 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000665 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900666 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000667 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900668 cout << "})";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100669 map<int32_t, int32_t> mapin;
Mark Slee1921d202007-01-24 19:43:06 +0000670 testClient.testMap(mapin, mapout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900671 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000672 first = true;
673 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
674 if (first) {
675 first = false;
676 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900677 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000678 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900679 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000680 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900681 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200682 if (mapin != mapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900683 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200684 return_code |= ERR_CONTAINERS;
685 }
Roger Meier4fce9602012-05-04 06:22:09 +0000686
687 /**
688 * STRING MAP TEST
Roger Meier4fce9602012-05-04 06:22:09 +0000689 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900690 cout << "testStringMap({a => 2, b => blah, some => thing}) = {" << flush;
Jens Geyerd629ea02015-09-23 21:16:50 +0200691 map<string, string> smapin;
692 map<string, string> smapout;
693 smapin["a"] = "2";
694 smapin["b"] = "blah";
695 smapin["some"] = "thing";
696 try {
697 testClient.testStringMap(smapout, smapin);
698 first = true;
699 for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) {
700 if (first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900701 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200702 else
703 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900704 cout << it->first << " => " << it->second;
Jens Geyerd629ea02015-09-23 21:16:50 +0200705 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900706 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200707 if (smapin != smapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900708 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200709 return_code |= ERR_CONTAINERS;
710 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900711 } catch (TTransportException&) {
712 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200713 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900714 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200715 return_code |= ERR_CONTAINERS;
716 }
Mark Sleee8540632006-05-30 09:24:40 +0000717
718 /**
719 * SET TEST
720 */
721 set<int32_t> setout;
722 for (int32_t i = -2; i < 3; ++i) {
723 setout.insert(i);
724 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900725 cout << "testSet({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000726 set<int32_t>::const_iterator s_iter;
727 first = true;
728 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
729 if (first) {
730 first = false;
731 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900732 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000733 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900734 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000735 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900736 cout << "})";
Mark Slee1921d202007-01-24 19:43:06 +0000737 set<int32_t> setin;
738 testClient.testSet(setin, setout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900739 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000740 first = true;
741 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
742 if (first) {
743 first = false;
744 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900745 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000746 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900747 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000748 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900749 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200750 if (setin != setout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900751 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200752 return_code |= ERR_CONTAINERS;
753 }
Mark Sleee8540632006-05-30 09:24:40 +0000754
755 /**
756 * LIST TEST
757 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900758 cout << "testList(empty)" << flush;
759 try {
760 vector<int32_t> listout;
761 testClient.testList(listout, vector<int32_t>());
762 if (!listout.empty()) {
763 cout << "*** FAILED ***" << endl;
764 cout << "invalid length: " << listout.size() << endl;
765 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000766 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900767 } catch (TTransportException&) {
768 throw;
769 } catch (exception& ex) {
770 cout << "*** FAILED ***" << endl << ex.what() << endl;
771 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000772 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900773 try {
774 vector<int32_t> listout;
775 for (int32_t i = -2; i < 3; ++i) {
776 listout.push_back(i);
Mark Sleee8540632006-05-30 09:24:40 +0000777 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900778 cout << "testList({" << flush;
779 vector<int32_t>::const_iterator l_iter;
780 first = true;
781 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
782 if (first) {
783 first = false;
784 } else {
785 cout << ",";
786 }
787 cout << *l_iter;
788 }
789 cout << "})";
790 vector<int32_t> listin;
791 testClient.testList(listin, listout);
792 cout << " = {";
793 first = true;
794 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
795 if (first) {
796 first = false;
797 } else {
798 cout << ",";
799 }
800 cout << *l_iter;
801 }
802 cout << "}" << endl;
803 if (listin != listout) {
804 cout << "*** FAILED ***" << endl;
805 return_code |= ERR_CONTAINERS;
806 }
807 } catch (TTransportException&) {
808 throw;
809 } catch (exception& ex) {
810 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200811 return_code |= ERR_CONTAINERS;
812 }
Mark Sleee8540632006-05-30 09:24:40 +0000813
814 /**
815 * ENUM TEST
816 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900817 cout << "testEnum(ONE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000818 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900819 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200820 if (ret != Numberz::ONE) {
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(TWO)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000826 ret = testClient.testEnum(Numberz::TWO);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900827 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200828 if (ret != Numberz::TWO) {
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(THREE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000834 ret = testClient.testEnum(Numberz::THREE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900835 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200836 if (ret != Numberz::THREE) {
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(FIVE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000842 ret = testClient.testEnum(Numberz::FIVE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900843 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200844 if (ret != Numberz::FIVE) {
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
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900849 cout << "testEnum(EIGHT)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000850 ret = testClient.testEnum(Numberz::EIGHT);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900851 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200852 if (ret != Numberz::EIGHT) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900853 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200854 return_code |= ERR_STRUCTS;
855 }
Mark Sleee8540632006-05-30 09:24:40 +0000856
857 /**
858 * TYPEDEF TEST
859 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900860 cout << "testTypedef(309858235082523)" << flush;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000861 UserId uid = testClient.testTypedef(309858235082523LL);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900862 cout << " = " << uid << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200863 if (uid != 309858235082523LL) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900864 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200865 return_code |= ERR_STRUCTS;
866 }
Mark Sleee8540632006-05-30 09:24:40 +0000867
868 /**
869 * NESTED MAP TEST
870 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900871 cout << "testMapMap(1)" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000872 map<int32_t, map<int32_t, int32_t> > mm;
873 testClient.testMapMap(mm, 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900874 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000875 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
876 for (mi = mm.begin(); mi != mm.end(); ++mi) {
877 printf("%d => {", mi->first);
878 map<int32_t, int32_t>::const_iterator mi2;
879 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900880 cout << mi2->first << " => " << mi2->second;
Mark Sleee8540632006-05-30 09:24:40 +0000881 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900882 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000883 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900884 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200885 if (mm.size() != 2 ||
886 mm[-4][-4] != -4 ||
887 mm[-4][-3] != -3 ||
888 mm[-4][-2] != -2 ||
889 mm[-4][-1] != -1 ||
890 mm[4][4] != 4 ||
891 mm[4][3] != 3 ||
892 mm[4][2] != 2 ||
893 mm[4][1] != 1) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900894 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200895 return_code |= ERR_CONTAINERS;
896 }
Mark Sleee8540632006-05-30 09:24:40 +0000897
898 /**
899 * INSANITY TEST
900 */
Jens Geyerf4598682014-05-08 23:18:44 +0200901 if (!noinsane) {
902 Insanity insane;
Jens Geyerd629ea02015-09-23 21:16:50 +0200903 insane.userMap.insert(make_pair(Numberz::FIVE, 5));
904 insane.userMap.insert(make_pair(Numberz::EIGHT, 8));
Jens Geyerf4598682014-05-08 23:18:44 +0200905 Xtruct truck;
Jens Geyerd629ea02015-09-23 21:16:50 +0200906 truck.string_thing = "Goodbye4";
907 truck.byte_thing = 4;
908 truck.i32_thing = 4;
909 truck.i64_thing = 4;
910 Xtruct truck2;
911 truck2.string_thing = "Hello2";
912 truck2.byte_thing = 2;
913 truck2.i32_thing = 2;
914 truck2.i64_thing = 2;
Jens Geyerf4598682014-05-08 23:18:44 +0200915 insane.xtructs.push_back(truck);
Jens Geyerd629ea02015-09-23 21:16:50 +0200916 insane.xtructs.push_back(truck2);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900917 cout << "testInsanity()" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100918 map<UserId, map<Numberz::type, Insanity> > whoa;
Jens Geyerf4598682014-05-08 23:18:44 +0200919 testClient.testInsanity(whoa, insane);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900920 cout << " = {";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100921 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Jens Geyerf4598682014-05-08 23:18:44 +0200922 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
923 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100924 map<Numberz::type, Insanity>::const_iterator i2_iter;
925 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Jens Geyerf4598682014-05-08 23:18:44 +0200926 printf("%d => {", i2_iter->first);
927 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
928 map<Numberz::type, UserId>::const_iterator um;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900929 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200930 for (um = userMap.begin(); um != userMap.end(); ++um) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900931 cout << um->first << " => " << um->second;
Jens Geyerf4598682014-05-08 23:18:44 +0200932 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900933 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000934
Jens Geyerf4598682014-05-08 23:18:44 +0200935 vector<Xtruct> xtructs = i2_iter->second.xtructs;
936 vector<Xtruct>::const_iterator x;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900937 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200938 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
939 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
940 x->string_thing.c_str(),
941 (int)x->byte_thing,
942 x->i32_thing,
943 x->i64_thing);
944 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900945 cout << "}";
Mark Sleee8540632006-05-30 09:24:40 +0000946
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900947 cout << "}, ";
Jens Geyerf4598682014-05-08 23:18:44 +0200948 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900949 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000950 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900951 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200952 bool failed = false;
953 map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1));
954 if (whoa.size() != 2) {
955 failed = true;
956 }
957 if (it1 == whoa.end()) {
958 failed = true;
959 } else {
960 map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO);
961 if (it12 == it1->second.end() || it12->second != insane) {
962 failed = true;
963 }
964 map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE);
965 if (it13 == it1->second.end() || it13->second != insane) {
966 failed = true;
967 }
968 }
969 map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2));
970 if (it2 == whoa.end()) {
971 failed = true;
972 } else {
973 map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX);
974 if (it26 == it1->second.end() || it26->second != Insanity()) {
975 failed = true;
976 }
977 }
978 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900979 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200980 return_code |= ERR_STRUCTS;
981 }
Mark Sleee8540632006-05-30 09:24:40 +0000982 }
Jens Geyerd629ea02015-09-23 21:16:50 +0200983
984 /**
985 * MULTI TEST
986 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900987 cout << "testMulti()" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200988 try {
989 map<int16_t, string> mul_map;
990 Xtruct mul_result;
991 mul_map[1] = "blah";
992 mul_map[2] = "thing";
993 testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24));
994 Xtruct xxs;
995 xxs.string_thing = "Hello2";
996 xxs.byte_thing = 42;
997 xxs.i32_thing = 4242;
998 xxs.i64_thing = 424242;
999 if (mul_result != xxs) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001000 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001001 return_code |= ERR_STRUCTS;
1002 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001003 } catch (TTransportException&) {
1004 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +02001005 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001006 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001007 return_code |= ERR_STRUCTS;
1008 }
1009
Marc Slemko71d4e472006-08-15 22:34:04 +00001010 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +00001011
Marc Slemkobf4fd192006-08-15 21:29:39 +00001012 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001013 cout << "testClient.testException(\"Xception\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001014 testClient.testException("Xception");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001015 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001016 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001017
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001018 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001019 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001020 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001021
Marc Slemkobf4fd192006-08-15 21:29:39 +00001022 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001023 cout << "testClient.testException(\"TException\") =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001024 testClient.testException("TException");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001025 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001026 return_code |= ERR_EXCEPTIONS;
Roger Meierf50df7f2012-05-02 22:49:55 +00001027
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001028 } catch (const TException&) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001029 cout << " Caught TException" << endl;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001030 }
Roger Meierf50df7f2012-05-02 22:49:55 +00001031
1032 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001033 cout << "testClient.testException(\"success\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001034 testClient.testException("success");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001035 cout << " void" << endl;
1036 } catch (exception & ex) { \
1037 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001038 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001039 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001040
Marc Slemko71d4e472006-08-15 22:34:04 +00001041 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +00001042
Marc Slemko71d4e472006-08-15 22:34:04 +00001043 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001044 cout << "testClient.testMultiException(\"Xception\", \"test 1\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001045 Xtruct result;
1046 testClient.testMultiException(result, "Xception", "test 1");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001047 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001048 return_code |= ERR_EXCEPTIONS;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001049 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001050 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
1051 }
1052
1053 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001054 cout << "testClient.testMultiException(\"Xception2\", \"test 2\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001055 Xtruct result;
1056 testClient.testMultiException(result, "Xception2", "test 2");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001057 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001058 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001059
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001060 } catch (Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001061 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001062 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001063
Marc Slemko71d4e472006-08-15 22:34:04 +00001064 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001065 cout << "testClient.testMultiException(\"success\", \"test 3\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001066 Xtruct result;
1067 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +00001068 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001069 } catch (exception & ex) { \
1070 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001071 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001072 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001073
David Reissc51986f2009-03-24 20:01:25 +00001074 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +00001075 {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001076 cout << "testClient.testOneway(1) =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001077 uint64_t startOneway = now();
1078 testClient.testOneway(1);
1079 uint64_t elapsed = now() - startOneway;
1080 if (elapsed > 200 * 1000) { // 0.2 seconds
Jens Geyerd629ea02015-09-23 21:16:50 +02001081 printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0);
1082 return_code |= ERR_BASETYPES;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001083 } else {
1084 printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
1085 }
David Reiss2ab6fe82008-02-18 02:11:44 +00001086 }
1087
David Reiss2845b522008-02-18 02:11:52 +00001088 /**
David Reissc51986f2009-03-24 20:01:25 +00001089 * redo a simple test after the oneway to make sure we aren't "off by one" --
1090 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +00001091 * fail since it will get the void confirmation rather than the correct
1092 * result. In this circumstance, the client will throw the exception:
1093 *
1094 * TApplicationException: Wrong method namea
1095 */
1096 /**
1097 * I32 TEST
1098 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001099 cout << "re-test testI32(-1)";
1100 int i32 = testClient.testI32(-1);
1101 cout << " = " << i32 << endl;
Roger Meier4fce9602012-05-04 06:22:09 +00001102 if (i32 != -1)
Jens Geyerd629ea02015-09-23 21:16:50 +02001103 return_code |= ERR_BASETYPES;
David Reiss2845b522008-02-18 02:11:52 +00001104
Marc Slemkobf4fd192006-08-15 21:29:39 +00001105 uint64_t stop = now();
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001106 uint64_t tot = stop - start;
Mark Sleed788b2e2006-09-07 01:26:35 +00001107
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001108 cout << "Total time: " << stop - start << " us" << endl;
David Reiss0c90f6f2008-02-06 22:18:40 +00001109
Mark Sleed788b2e2006-09-07 01:26:35 +00001110 time_tot += tot;
1111 if (time_min == 0 || tot < time_min) {
1112 time_min = tot;
1113 }
1114 if (tot > time_max) {
1115 time_max = tot;
1116 }
1117
Mark Sleea3302652006-10-25 19:03:32 +00001118 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +00001119 }
1120
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001121 cout << endl << "All tests done." << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001122
1123 uint64_t time_avg = time_tot / numTests;
1124
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001125 cout << "Min time: " << time_min << " us" << endl;
1126 cout << "Max time: " << time_max << " us" << endl;
1127 cout << "Avg time: " << time_avg << " us" << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001128
Jens Geyerd629ea02015-09-23 21:16:50 +02001129 return return_code;
Mark Sleee8540632006-05-30 09:24:40 +00001130}