blob: ca213260e55eb16f4a05d4439e3e1e5415b80583 [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>
James E. King, III58402ff2017-11-17 14:41:46 -050029#include <thrift/protocol/TMultiplexedProtocol.h>
Roger Meier49ff8b12012-04-13 09:12:31 +000030#include <thrift/transport/THttpClient.h>
31#include <thrift/transport/TTransportUtils.h>
32#include <thrift/transport/TSocket.h>
33#include <thrift/transport/TSSLSocket.h>
James E. King IIIb2b767e2018-09-15 20:32:04 +000034#include <thrift/transport/TZlibTransport.h>
Roger Meier49ff8b12012-04-13 09:12:31 +000035#include <thrift/async/TEvhttpClientChannel.h>
36#include <thrift/server/TNonblockingServer.h> // <event.h>
Mark Sleee8540632006-05-30 09:24:40 +000037
James E. King, III7edc8fa2017-01-20 10:11:41 -050038#ifdef HAVE_STDINT_H
39#include <stdint.h>
40#endif
41#ifdef HAVE_INTTYPES_H
42#include <inttypes.h>
43#endif
44
James E. King, III58402ff2017-11-17 14:41:46 -050045#include <boost/algorithm/string.hpp>
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053046#include <boost/filesystem.hpp>
James E. King, III58402ff2017-11-17 14:41:46 -050047#include <boost/program_options.hpp>
James E. King, III39eaae62017-11-19 20:17:33 -050048#include <boost/random/random_device.hpp>
James E. King, III82ae9572017-08-05 12:23:54 -040049#include <thrift/stdcxx.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050050#if _WIN32
Konrad Grochowski16a23a62014-11-13 15:33:38 +010051#include <thrift/windows/TWinsockSingleton.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050052#endif
Roger Meierca142b02011-06-07 17:59:07 +000053
James E. King, III58402ff2017-11-17 14:41:46 -050054#include "SecondService.h"
Marc Slemko6be374b2006-08-04 03:16:25 +000055#include "ThriftTest.h"
56
Marc Slemko6be374b2006-08-04 03:16:25 +000057using namespace std;
T Jake Lucianib5e62212009-01-31 22:36:20 +000058using namespace apache::thrift;
James E. King, III82ae9572017-08-05 12:23:54 -040059using namespace apache::thrift::async;
T Jake Lucianib5e62212009-01-31 22:36:20 +000060using namespace apache::thrift::protocol;
61using namespace apache::thrift::transport;
Marc Slemkobf4fd192006-08-15 21:29:39 +000062using namespace thrift::test;
Roger Meier7e056e72011-07-17 07:28:28 +000063
Mark Slee95771002006-06-07 06:53:25 +000064// Current time, microseconds since the epoch
Konrad Grochowski16a23a62014-11-13 15:33:38 +010065uint64_t now() {
Roger Meier5f9614c2010-11-21 16:59:05 +000066 int64_t ret;
Mark Slee95771002006-06-07 06:53:25 +000067 struct timeval tv;
David Reiss0c90f6f2008-02-06 22:18:40 +000068
Jake Farrell5d02b802014-01-07 21:42:01 -050069 THRIFT_GETTIMEOFDAY(&tv, NULL);
Mark Slee95771002006-06-07 06:53:25 +000070 ret = tv.tv_sec;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010071 ret = ret * 1000 * 1000 + tv.tv_usec;
Mark Slee95771002006-06-07 06:53:25 +000072 return ret;
73}
74
Sebastian Zenker39e505c2015-12-18 16:15:08 +010075static void testString_clientReturn(event_base* base,
76 int testNr,
Konrad Grochowski16a23a62014-11-13 15:33:38 +010077 ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000078 try {
79 string s;
80 client->recv_testString(s);
Sebastian Zenker39e505c2015-12-18 16:15:08 +010081 std::ostringstream os;
82 os << "test" << testNr;
83 const bool ok = (s == os.str());
84 cout << "testString: " << s << " " << ((ok) ? "ok" : "failed") << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000085 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -050086 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000087 }
88
Sebastian Zenker39e505c2015-12-18 16:15:08 +010089 if (testNr == 9)
90 event_base_loopbreak(base); // end test
Roger Meier7e056e72011-07-17 07:28:28 +000091}
92
Sebastian Zenker39e505c2015-12-18 16:15:08 +010093static void testVoid_clientReturn(event_base* base, ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000094 try {
95 client->recv_testVoid();
96 cout << "testVoid" << endl;
97
Sebastian Zenker39e505c2015-12-18 16:15:08 +010098 for (int testNr = 0; testNr < 10; ++testNr) {
99 std::ostringstream os;
100 os << "test" << testNr;
James E. King, III82ae9572017-08-05 12:23:54 -0400101 client->testString(stdcxx::bind(testString_clientReturn,
Sebastian Zenker39e505c2015-12-18 16:15:08 +0100102 base,
103 testNr,
James E. King, III82ae9572017-08-05 12:23:54 -0400104 stdcxx::placeholders::_1),
Sebastian Zenker39e505c2015-12-18 16:15:08 +0100105 os.str());
106 }
Roger Meier7e056e72011-07-17 07:28:28 +0000107 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500108 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +0000109 }
110}
111
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900112// Workaround for absense of C++11 "auto" keyword.
113template <typename T>
114bool print_eq(T expected, T actual) {
115 cout << "(" << actual << ")" << endl;
116 if (expected != actual) {
117 cout << "*** FAILED ***" << endl << "Expected: " << expected << " but got: " << actual << endl;
118 return false;
119 }
120 return true;
121}
122
123#define BASETYPE_IDENTITY_TEST(func, value) \
124 cout << #func "(" << value << ") = "; \
125 try { \
126 if (!print_eq(value, testClient.func(value))) \
127 return_code |= ERR_BASETYPES; \
128 } catch (TTransportException&) { \
129 throw; \
130 } catch (exception & ex) { \
131 cout << "*** FAILED ***" << endl << ex.what() << endl; \
132 return_code |= ERR_BASETYPES; \
133 }
134
James E. King, III39eaae62017-11-19 20:17:33 -0500135int binary_test(ThriftTestClient& testClient, string::size_type siz);
136
137BOOST_CONSTEXPR_OR_CONST int ERR_BASETYPES = 1;
138BOOST_CONSTEXPR_OR_CONST int ERR_STRUCTS = 2;
139BOOST_CONSTEXPR_OR_CONST int ERR_CONTAINERS = 4;
140BOOST_CONSTEXPR_OR_CONST int ERR_EXCEPTIONS = 8;
141BOOST_CONSTEXPR_OR_CONST int ERR_UNKNOWN = 64;
142
Mark Sleee8540632006-05-30 09:24:40 +0000143int main(int argc, char** argv) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900144 cout.precision(19);
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900145
James E. King, III06190872017-02-20 08:52:11 -0500146 string testDir = boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string();
147 string caPath = testDir + "/keys/CA.pem";
148 string certPath = testDir + "/keys/client.crt";
149 string keyPath = testDir + "/keys/client.key";
150
Jake Farrell5d02b802014-01-07 21:42:01 -0500151#if _WIN32
152 transport::TWinsockSingleton::create();
153#endif
Mark Sleee8540632006-05-30 09:24:40 +0000154 string host = "localhost";
155 int port = 9090;
156 int numTests = 1;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000157 bool ssl = false;
James E. King IIIb2b767e2018-09-15 20:32:04 +0000158 bool zlib = false;
Roger Meierca142b02011-06-07 17:59:07 +0000159 string transport_type = "buffered";
160 string protocol_type = "binary";
161 string domain_socket = "";
pavlodd08f6e2015-10-08 16:43:56 -0400162 bool abstract_namespace = false;
Jens Geyerf4598682014-05-08 23:18:44 +0200163 bool noinsane = false;
Mark Sleee8540632006-05-30 09:24:40 +0000164
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900165 int return_code = 0;
166
Jake Farrell5d02b802014-01-07 21:42:01 -0500167 boost::program_options::options_description desc("Allowed options");
James E. King, III58402ff2017-11-17 14:41:46 -0500168 desc.add_options()
169 ("help,h", "produce help message")
James E. King, III39eaae62017-11-19 20:17:33 -0500170 ("host",
171 boost::program_options::value<string>(&host)->default_value(host),
James E. King, III58402ff2017-11-17 14:41:46 -0500172 "Host to connect")
James E. King, III39eaae62017-11-19 20:17:33 -0500173 ("port",
174 boost::program_options::value<int>(&port)->default_value(port),
James E. King, III58402ff2017-11-17 14:41:46 -0500175 "Port number to connect")
James E. King, III39eaae62017-11-19 20:17:33 -0500176 ("domain-socket",
James E. King, III58402ff2017-11-17 14:41:46 -0500177 boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
178 "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")
179 ("abstract-namespace",
180 "Look for the domain socket in the Abstract Namespace"
181 " (no connection with filesystem pathnames)")
182 ("transport",
183 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
James E. King IIIb2b767e2018-09-15 20:32:04 +0000184 "Transport: buffered, framed, http, evhttp, zlib")
James E. King, III58402ff2017-11-17 14:41:46 -0500185 ("protocol",
186 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
187 "Protocol: binary, compact, header, json, multi, multic, multih, multij")
James E. King, III39eaae62017-11-19 20:17:33 -0500188 ("ssl",
James E. King, III58402ff2017-11-17 14:41:46 -0500189 "Encrypted Transport using SSL")
James E. King IIIb2b767e2018-09-15 20:32:04 +0000190 ("zlib",
191 "Wrap Transport with Zlib")
James E. King, III58402ff2017-11-17 14:41:46 -0500192 ("testloops,n",
193 boost::program_options::value<int>(&numTests)->default_value(numTests),
194 "Number of Tests")
195 ("noinsane",
196 "Do not run insanity test");
Roger Meierca142b02011-06-07 17:59:07 +0000197
Jake Farrell5d02b802014-01-07 21:42:01 -0500198 boost::program_options::variables_map vm;
199 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
200 boost::program_options::notify(vm);
Roger Meierca142b02011-06-07 17:59:07 +0000201
202 if (vm.count("help")) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900203 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900204 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000205 }
Mark Sleea3302652006-10-25 19:03:32 +0000206
Jake Farrell5d02b802014-01-07 21:42:01 -0500207 try {
Roger Meierca142b02011-06-07 17:59:07 +0000208 if (!protocol_type.empty()) {
209 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100210 } else if (protocol_type == "compact") {
Dave Watson792db4e2015-01-16 11:22:01 -0800211 } else if (protocol_type == "header") {
Roger Meierca142b02011-06-07 17:59:07 +0000212 } else if (protocol_type == "json") {
James E. King, III58402ff2017-11-17 14:41:46 -0500213 } else if (protocol_type == "multi") {
214 } else if (protocol_type == "multic") {
215 } else if (protocol_type == "multih") {
216 } else if (protocol_type == "multij") {
Roger Meierca142b02011-06-07 17:59:07 +0000217 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100218 throw invalid_argument("Unknown protocol type " + protocol_type);
Roger Meierca142b02011-06-07 17:59:07 +0000219 }
220 }
221
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100222 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000223 if (transport_type == "buffered") {
224 } else if (transport_type == "framed") {
225 } else if (transport_type == "http") {
Roger Meier7e056e72011-07-17 07:28:28 +0000226 } else if (transport_type == "evhttp") {
James E. King IIIb2b767e2018-09-15 20:32:04 +0000227 } else if (transport_type == "zlib") {
228 // crosstest will pass zlib as a transport and as a flag right now..
Roger Meierca142b02011-06-07 17:59:07 +0000229 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100230 throw invalid_argument("Unknown transport type " + transport_type);
Roger Meierca142b02011-06-07 17:59:07 +0000231 }
232 }
233
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900234 } catch (exception& e) {
Roger Meierca142b02011-06-07 17:59:07 +0000235 cerr << e.what() << endl;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900236 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900237 return ERR_UNKNOWN;
Roger Meierca142b02011-06-07 17:59:07 +0000238 }
239
240 if (vm.count("ssl")) {
241 ssl = true;
242 }
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530243
James E. King IIIb2b767e2018-09-15 20:32:04 +0000244 if (vm.count("zlib")) {
245 zlib = true;
246 }
247
pavlodd08f6e2015-10-08 16:43:56 -0400248 if (vm.count("abstract-namespace")) {
249 abstract_namespace = true;
250 }
251
Jens Geyerf4598682014-05-08 23:18:44 +0200252 if (vm.count("noinsane")) {
253 noinsane = true;
254 }
Roger Meierca142b02011-06-07 17:59:07 +0000255
James E. King, III7f5a8c22017-04-04 09:36:38 -0400256 // THRIFT-4164: The factory MUST outlive any sockets it creates for correct behavior!
James E. King, III82ae9572017-08-05 12:23:54 -0400257 stdcxx::shared_ptr<TSSLSocketFactory> factory;
258 stdcxx::shared_ptr<TSocket> socket;
259 stdcxx::shared_ptr<TTransport> transport;
260 stdcxx::shared_ptr<TProtocol> protocol;
James E. King, III39eaae62017-11-19 20:17:33 -0500261 stdcxx::shared_ptr<TProtocol> protocol2; // SecondService for multiplexed
Roger Meierca142b02011-06-07 17:59:07 +0000262
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000263 if (ssl) {
James E. King, III06190872017-02-20 08:52:11 -0500264 cout << "Client Certificate File: " << certPath << endl;
265 cout << "Client Key File: " << keyPath << endl;
266 cout << "CA File: " << caPath << endl;
267
James E. King, III82ae9572017-08-05 12:23:54 -0400268 factory = stdcxx::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000269 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
James E. King, III06190872017-02-20 08:52:11 -0500270 factory->loadTrustedCertificates(caPath.c_str());
271 factory->loadCertificate(certPath.c_str());
272 factory->loadPrivateKey(keyPath.c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000273 factory->authenticate(true);
274 socket = factory->createSocket(host, port);
275 } else {
Roger Meierca142b02011-06-07 17:59:07 +0000276 if (domain_socket != "") {
pavlodd08f6e2015-10-08 16:43:56 -0400277 if (abstract_namespace) {
278 std::string abstract_socket("\0", 1);
279 abstract_socket += domain_socket;
James E. King, III82ae9572017-08-05 12:23:54 -0400280 socket = stdcxx::shared_ptr<TSocket>(new TSocket(abstract_socket));
pavlodd08f6e2015-10-08 16:43:56 -0400281 } else {
James E. King, III82ae9572017-08-05 12:23:54 -0400282 socket = stdcxx::shared_ptr<TSocket>(new TSocket(domain_socket));
pavlodd08f6e2015-10-08 16:43:56 -0400283 }
Roger Meierca142b02011-06-07 17:59:07 +0000284 port = 0;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100285 } else {
James E. King, III82ae9572017-08-05 12:23:54 -0400286 socket = stdcxx::shared_ptr<TSocket>(new TSocket(host, port));
Roger Meierca142b02011-06-07 17:59:07 +0000287 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000288 }
Mark Sleea3302652006-10-25 19:03:32 +0000289
Roger Meierca142b02011-06-07 17:59:07 +0000290 if (transport_type.compare("http") == 0) {
James E. King IIIb2b767e2018-09-15 20:32:04 +0000291 transport = stdcxx::make_shared<THttpClient>(socket, host, "/service");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100292 } else if (transport_type.compare("framed") == 0) {
James E. King IIIb2b767e2018-09-15 20:32:04 +0000293 transport = stdcxx::make_shared<TFramedTransport>(socket);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100294 } else {
James E. King IIIb2b767e2018-09-15 20:32:04 +0000295 transport = stdcxx::make_shared<TBufferedTransport>(socket);
296 }
297
298 if (zlib) {
299 transport = stdcxx::make_shared<TZlibTransport>(transport);
Mark Sleea3302652006-10-25 19:03:32 +0000300 }
301
James E. King, III58402ff2017-11-17 14:41:46 -0500302 if (protocol_type == "json" || protocol_type == "multij") {
303 protocol = stdcxx::make_shared<TJSONProtocol>(transport);
304 } else if (protocol_type == "compact" || protocol_type == "multic") {
305 protocol = stdcxx::make_shared<TCompactProtocol>(transport);
306 } else if (protocol_type == "header" || protocol_type == "multih") {
307 protocol = stdcxx::make_shared<THeaderProtocol>(transport);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100308 } else {
James E. King, III58402ff2017-11-17 14:41:46 -0500309 protocol = stdcxx::make_shared<TBinaryProtocol>(transport);
310 }
311
312 if (boost::starts_with(protocol_type, "multi")) {
James E. King, III39eaae62017-11-19 20:17:33 -0500313 protocol2 = stdcxx::make_shared<TMultiplexedProtocol>(protocol, "SecondService");
314 // we don't need access to the original protocol any more, so...
315 protocol = stdcxx::make_shared<TMultiplexedProtocol>(protocol, "ThriftTest");
Roger Meierca142b02011-06-07 17:59:07 +0000316 }
317
318 // Connection info
pavlodd08f6e2015-10-08 16:43:56 -0400319 cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: ";
320 if (abstract_namespace) {
321 cout << '@';
322 }
323 cout << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000324 if (port != 0) {
325 cout << host << ":" << port;
326 }
327 cout << endl;
328
Roger Meier7e056e72011-07-17 07:28:28 +0000329 if (transport_type.compare("evhttp") == 0) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100330 event_base* base = event_base_new();
Roger Meier7e056e72011-07-17 07:28:28 +0000331 cout << "Libevent Version: " << event_get_version() << endl;
332 cout << "Libevent Method: " << event_base_get_method(base) << endl;
333#if LIBEVENT_VERSION_NUMBER >= 0x02000000
334 cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl;
335#endif
336
James E. King, III82ae9572017-08-05 12:23:54 -0400337 stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Roger Meier7e056e72011-07-17 07:28:28 +0000338
James E. King, III82ae9572017-08-05 12:23:54 -0400339 stdcxx::shared_ptr<TAsyncChannel> channel(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100340 new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
Roger Meier7e056e72011-07-17 07:28:28 +0000341 ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
James E. King, III82ae9572017-08-05 12:23:54 -0400342 client->testVoid(stdcxx::bind(testVoid_clientReturn,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100343 base,
James E. King, III82ae9572017-08-05 12:23:54 -0400344 stdcxx::placeholders::_1));
Jake Farrell5d02b802014-01-07 21:42:01 -0500345
Roger Meier7e056e72011-07-17 07:28:28 +0000346 event_base_loop(base, 0);
347 return 0;
348 }
349
Roger Meierca142b02011-06-07 17:59:07 +0000350 ThriftTestClient testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000351
352 uint64_t time_min = 0;
353 uint64_t time_max = 0;
354 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000355
Mark Sleee8540632006-05-30 09:24:40 +0000356 int test = 0;
357 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000358
Mark Slee95771002006-06-07 06:53:25 +0000359 try {
Mark Sleea3302652006-10-25 19:03:32 +0000360 transport->open();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900361 } catch (TTransportException& ex) {
362 cout << "Connect failed: " << ex.what() << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900363 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000364 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000365
Mark Sleed788b2e2006-09-07 01:26:35 +0000366 /**
367 * CONNECT TEST
368 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100369 printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000370
371 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000372
Mark Sleee8540632006-05-30 09:24:40 +0000373 /**
374 * VOID TEST
375 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000376 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900377 cout << "testVoid()" << flush;
Mark Sleee129a2d2007-02-21 05:17:48 +0000378 testClient.testVoid();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900379 cout << " = void" << endl;
380 } catch (TTransportException&) {
381 // Stop here if transport got broken
382 throw;
383 } catch (exception& ex) {
384 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200385 return_code |= ERR_BASETYPES;
Mark Sleee129a2d2007-02-21 05:17:48 +0000386 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000387
Mark Sleee8540632006-05-30 09:24:40 +0000388 /**
389 * STRING TEST
390 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900391 cout << "testString(\"Test\")" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000392 string s;
393 testClient.testString(s, "Test");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900394 cout << " = " << s << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200395 if (s != "Test") {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900396 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200397 return_code |= ERR_BASETYPES;
398 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000399
James E. King, III58402ff2017-11-17 14:41:46 -0500400 //
401 // Multiplexed protocol - call another service method
402 // in the middle of the ThriftTest
403 //
404 if (boost::starts_with(protocol_type, "multi")) {
James E. King, III39eaae62017-11-19 20:17:33 -0500405 SecondServiceClient ssc(protocol2);
406 // transport is already open...
407
James E. King, III58402ff2017-11-17 14:41:46 -0500408 try {
409 cout << "secondService.secondTestString(\"foo\") => " << flush;
James E. King, III39eaae62017-11-19 20:17:33 -0500410 std::string result;
411 ssc.secondtestString(result, "foo");
412 cout << "{" << result << "}" << endl;
413 } catch (std::exception& e) {
414 cout << " *** FAILED *** " << e.what() << endl;
415 return_code |= ERR_EXCEPTIONS;
416 }
James E. King, III58402ff2017-11-17 14:41:46 -0500417 }
418
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900419 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500420#ifdef _MSC_VER
421#pragma warning( push )
422#pragma warning( disable : 4566 )
423#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900424 string str(
425 "}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, "
426 "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, "
427 "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, "
428 "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, "
429 "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, "
430 "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, "
431 "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, "
432 "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, "
433 "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, "
434 "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, "
435 "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, "
436 "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, "
437 "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, "
438 "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa "
439 "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa "
440 "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪"
441 "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, "
442 "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, "
443 "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, "
444 "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple "
445 "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, "
446 "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, "
447 "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, "
448 "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, "
449 "Bân-lâm-gú, 粵語");
James E. King, III7edc8fa2017-01-20 10:11:41 -0500450#ifdef _MSC_VER
451#pragma warning( pop )
452#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900453 cout << "testString(" << str << ") = " << flush;
454 testClient.testString(s, str);
455 cout << s << endl;
456 if (s != str) {
457 cout.imbue(locale("en_US.UTF8"));
458 cout << "*** FAILED ***" << endl << "Expected string: " << str << " but got: " << s << endl << "CLEAR";
459 return_code |= ERR_BASETYPES;
460 }
461 } catch (TTransportException&) {
462 throw;
463 } catch (exception& ex) {
464 cout << "*** FAILED ***" << endl << ex.what() << endl;
465 return_code |= ERR_BASETYPES;
466 return return_code;
467 }
468 try {
469 string str(
470 "quote: \" backslash:"
471 " forwardslash-escaped: \\/ "
472 " backspace: \b formfeed: \f newline: \n return: \r tab: "
473 " now-all-of-them-together: \"\\\\/\b\n\r\t"
474 " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><"
475 " char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ ");
476 cout << "testString(" << str << ") = " << flush;
477 testClient.testString(s, str);
478 cout << s << endl;
479 if (s != str) {
480 cout.imbue(locale("en_US.UTF8"));
481 cout << "*** FAILED ***" << endl
482 << "Expected string: " << str << " but got: " << s << endl
483 << "CLEAR";
484 ;
485 return_code |= ERR_BASETYPES;
486 }
487 } catch (TTransportException&) {
488 throw;
489 } catch (exception& ex) {
490 cout << "*** FAILED ***" << endl << ex.what() << endl;
491 return_code |= ERR_BASETYPES;
492 return return_code;
493 }
494
Mark Sleee8540632006-05-30 09:24:40 +0000495 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900496 * BOOL TEST
497 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900498 cout << boolalpha;
499 BASETYPE_IDENTITY_TEST(testBool, true);
500 BASETYPE_IDENTITY_TEST(testBool, false);
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900501
502 /**
Mark Sleee8540632006-05-30 09:24:40 +0000503 * BYTE TEST
504 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900505 BASETYPE_IDENTITY_TEST(testByte, (int8_t)0);
506 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-1);
507 BASETYPE_IDENTITY_TEST(testByte, (int8_t)42);
508 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-42);
509 BASETYPE_IDENTITY_TEST(testByte, (int8_t)127);
510 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-128);
David Reiss0c90f6f2008-02-06 22:18:40 +0000511
Mark Sleee8540632006-05-30 09:24:40 +0000512 /**
513 * I32 TEST
514 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900515 BASETYPE_IDENTITY_TEST(testI32, 0);
516 BASETYPE_IDENTITY_TEST(testI32, -1);
517 BASETYPE_IDENTITY_TEST(testI32, 190000013);
518 BASETYPE_IDENTITY_TEST(testI32, -190000013);
James E. King III9b75e4f2018-12-17 16:21:14 -0500519 BASETYPE_IDENTITY_TEST(testI32, (numeric_limits<int32_t>::max)());
520 BASETYPE_IDENTITY_TEST(testI32, (numeric_limits<int32_t>::min)());
Mark Sleee8540632006-05-30 09:24:40 +0000521
522 /**
Mark Sleee8540632006-05-30 09:24:40 +0000523 * I64 TEST
524 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900525 BASETYPE_IDENTITY_TEST(testI64, (int64_t)0);
526 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1);
527 BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL);
528 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500529 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32));
530 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32));
531 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32) + 1);
532 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32) - 1);
James E. King III9b75e4f2018-12-17 16:21:14 -0500533 BASETYPE_IDENTITY_TEST(testI64, (numeric_limits<int64_t>::max)());
534 BASETYPE_IDENTITY_TEST(testI64, (numeric_limits<int64_t>::min)());
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100535
Mark Sleec98d0502006-09-06 02:42:25 +0000536 /**
537 * DOUBLE TEST
538 */
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900539 // Comparing double values with plain equality because Thrift handles full precision of double
540 BASETYPE_IDENTITY_TEST(testDouble, 0.0);
541 BASETYPE_IDENTITY_TEST(testDouble, -1.0);
542 BASETYPE_IDENTITY_TEST(testDouble, -5.2098523);
543 BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500544 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32));
545 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32) + 1);
546 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 53) - 1);
547 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32));
548 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32) - 1);
549 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 53) + 1);
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900550
551 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500552 double expected = pow(static_cast<double>(10), 307);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900553 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900554 double actual = testClient.testDouble(expected);
555 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500556 if (expected - actual > pow(static_cast<double>(10), 292)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900557 cout << "*** FAILED ***" << endl
558 << "Expected: " << expected << " but got: " << actual << endl;
559 }
560 } catch (TTransportException&) {
561 throw;
562 } catch (exception& ex) {
563 cout << "*** FAILED ***" << endl << ex.what() << endl;
564 return_code |= ERR_BASETYPES;
565 }
566
567 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500568 double expected = pow(static_cast<double>(10), -292);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900569 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900570 double actual = testClient.testDouble(expected);
571 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500572 if (expected - actual > pow(static_cast<double>(10), -307)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900573 cout << "*** FAILED ***" << endl
574 << "Expected: " << expected << " but got: " << actual << endl;
575 }
576 } catch (TTransportException&) {
577 throw;
578 } catch (exception& ex) {
579 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200580 return_code |= ERR_BASETYPES;
581 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000582
Mark Sleee8540632006-05-30 09:24:40 +0000583 /**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100584 * BINARY TEST
585 */
James E. King, III39eaae62017-11-19 20:17:33 -0500586 for (string::size_type i = 0; i < 131073 && !return_code; ) {
587 return_code |= binary_test(testClient, i);
588 if (i > 0) { i *= 2; } else { ++i; }
Jens Geyerd629ea02015-09-23 21:16:50 +0200589 }
590
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100591
592 /**
Mark Sleee8540632006-05-30 09:24:40 +0000593 * STRUCT TEST
594 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900595 cout << "testStruct({\"Zero\", 1, -3, -5})" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000596 Xtruct out;
597 out.string_thing = "Zero";
598 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000599 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000600 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000601 Xtruct in;
602 testClient.testStruct(in, out);
Roger Meier0e814802014-01-17 21:07:58 +0100603 printf(" = {\"%s\", %d, %d, %" PRId64 "}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000604 in.string_thing.c_str(),
605 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000606 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000607 in.i64_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200608 if (in != out) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900609 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200610 return_code |= ERR_STRUCTS;
611 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000612
Mark Sleee8540632006-05-30 09:24:40 +0000613 /**
614 * NESTED STRUCT TEST
615 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900616 cout << "testNest({1, {\"Zero\", 1, -3, -5}), 5}" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000617 Xtruct2 out2;
618 out2.byte_thing = 1;
619 out2.struct_thing = out;
620 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000621 Xtruct2 in2;
622 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000623 in = in2.struct_thing;
Roger Meier0e814802014-01-17 21:07:58 +0100624 printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000625 in2.byte_thing,
626 in.string_thing.c_str(),
627 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000628 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000629 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000630 in2.i32_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200631 if (in2 != out2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900632 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200633 return_code |= ERR_STRUCTS;
634 }
Mark Sleee8540632006-05-30 09:24:40 +0000635
636 /**
637 * MAP TEST
638 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100639 map<int32_t, int32_t> mapout;
Mark Sleee8540632006-05-30 09:24:40 +0000640 for (int32_t i = 0; i < 5; ++i) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100641 mapout.insert(make_pair(i, i - 10));
Mark Sleee8540632006-05-30 09:24:40 +0000642 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900643 cout << "testMap({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000644 map<int32_t, int32_t>::const_iterator m_iter;
645 bool first = true;
646 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
647 if (first) {
648 first = false;
649 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900650 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000651 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900652 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000653 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900654 cout << "})";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100655 map<int32_t, int32_t> mapin;
Mark Slee1921d202007-01-24 19:43:06 +0000656 testClient.testMap(mapin, mapout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900657 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000658 first = true;
659 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
660 if (first) {
661 first = false;
662 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900663 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000664 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900665 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000666 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900667 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200668 if (mapin != mapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900669 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200670 return_code |= ERR_CONTAINERS;
671 }
Roger Meier4fce9602012-05-04 06:22:09 +0000672
673 /**
674 * STRING MAP TEST
Roger Meier4fce9602012-05-04 06:22:09 +0000675 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900676 cout << "testStringMap({a => 2, b => blah, some => thing}) = {" << flush;
Jens Geyerd629ea02015-09-23 21:16:50 +0200677 map<string, string> smapin;
678 map<string, string> smapout;
679 smapin["a"] = "2";
680 smapin["b"] = "blah";
681 smapin["some"] = "thing";
682 try {
683 testClient.testStringMap(smapout, smapin);
684 first = true;
685 for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) {
686 if (first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900687 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200688 else
689 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900690 cout << it->first << " => " << it->second;
Jens Geyerd629ea02015-09-23 21:16:50 +0200691 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900692 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200693 if (smapin != smapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900694 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200695 return_code |= ERR_CONTAINERS;
696 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900697 } catch (TTransportException&) {
698 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200699 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900700 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200701 return_code |= ERR_CONTAINERS;
702 }
Mark Sleee8540632006-05-30 09:24:40 +0000703
704 /**
705 * SET TEST
706 */
707 set<int32_t> setout;
708 for (int32_t i = -2; i < 3; ++i) {
709 setout.insert(i);
710 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900711 cout << "testSet({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000712 set<int32_t>::const_iterator s_iter;
713 first = true;
714 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
715 if (first) {
716 first = false;
717 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900718 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000719 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900720 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000721 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900722 cout << "})";
Mark Slee1921d202007-01-24 19:43:06 +0000723 set<int32_t> setin;
724 testClient.testSet(setin, setout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900725 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000726 first = true;
727 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
728 if (first) {
729 first = false;
730 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900731 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000732 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900733 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000734 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900735 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200736 if (setin != setout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900737 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200738 return_code |= ERR_CONTAINERS;
739 }
Mark Sleee8540632006-05-30 09:24:40 +0000740
741 /**
742 * LIST TEST
743 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900744 cout << "testList(empty)" << flush;
745 try {
746 vector<int32_t> listout;
747 testClient.testList(listout, vector<int32_t>());
748 if (!listout.empty()) {
749 cout << "*** FAILED ***" << endl;
750 cout << "invalid length: " << listout.size() << endl;
751 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000752 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900753 } catch (TTransportException&) {
754 throw;
755 } catch (exception& ex) {
756 cout << "*** FAILED ***" << endl << ex.what() << endl;
757 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000758 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900759 try {
760 vector<int32_t> listout;
761 for (int32_t i = -2; i < 3; ++i) {
762 listout.push_back(i);
Mark Sleee8540632006-05-30 09:24:40 +0000763 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900764 cout << "testList({" << flush;
765 vector<int32_t>::const_iterator l_iter;
766 first = true;
767 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
768 if (first) {
769 first = false;
770 } else {
771 cout << ",";
772 }
773 cout << *l_iter;
774 }
775 cout << "})";
776 vector<int32_t> listin;
777 testClient.testList(listin, listout);
778 cout << " = {";
779 first = true;
780 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
781 if (first) {
782 first = false;
783 } else {
784 cout << ",";
785 }
786 cout << *l_iter;
787 }
788 cout << "}" << endl;
789 if (listin != listout) {
790 cout << "*** FAILED ***" << endl;
791 return_code |= ERR_CONTAINERS;
792 }
793 } catch (TTransportException&) {
794 throw;
795 } catch (exception& ex) {
796 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200797 return_code |= ERR_CONTAINERS;
798 }
Mark Sleee8540632006-05-30 09:24:40 +0000799
800 /**
801 * ENUM TEST
802 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900803 cout << "testEnum(ONE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000804 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900805 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200806 if (ret != Numberz::ONE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900807 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200808 return_code |= ERR_STRUCTS;
809 }
Mark Sleee8540632006-05-30 09:24:40 +0000810
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900811 cout << "testEnum(TWO)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000812 ret = testClient.testEnum(Numberz::TWO);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900813 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200814 if (ret != Numberz::TWO) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900815 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200816 return_code |= ERR_STRUCTS;
817 }
Mark Sleee8540632006-05-30 09:24:40 +0000818
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900819 cout << "testEnum(THREE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000820 ret = testClient.testEnum(Numberz::THREE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900821 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200822 if (ret != Numberz::THREE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900823 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200824 return_code |= ERR_STRUCTS;
825 }
Mark Sleee8540632006-05-30 09:24:40 +0000826
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900827 cout << "testEnum(FIVE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000828 ret = testClient.testEnum(Numberz::FIVE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900829 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200830 if (ret != Numberz::FIVE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900831 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200832 return_code |= ERR_STRUCTS;
833 }
Mark Sleee8540632006-05-30 09:24:40 +0000834
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900835 cout << "testEnum(EIGHT)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000836 ret = testClient.testEnum(Numberz::EIGHT);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900837 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200838 if (ret != Numberz::EIGHT) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900839 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200840 return_code |= ERR_STRUCTS;
841 }
Mark Sleee8540632006-05-30 09:24:40 +0000842
843 /**
844 * TYPEDEF TEST
845 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900846 cout << "testTypedef(309858235082523)" << flush;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000847 UserId uid = testClient.testTypedef(309858235082523LL);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900848 cout << " = " << uid << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200849 if (uid != 309858235082523LL) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900850 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200851 return_code |= ERR_STRUCTS;
852 }
Mark Sleee8540632006-05-30 09:24:40 +0000853
854 /**
855 * NESTED MAP TEST
856 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900857 cout << "testMapMap(1)" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000858 map<int32_t, map<int32_t, int32_t> > mm;
859 testClient.testMapMap(mm, 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900860 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000861 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
862 for (mi = mm.begin(); mi != mm.end(); ++mi) {
863 printf("%d => {", mi->first);
864 map<int32_t, int32_t>::const_iterator mi2;
865 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900866 cout << mi2->first << " => " << mi2->second;
Mark Sleee8540632006-05-30 09:24:40 +0000867 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900868 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000869 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900870 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200871 if (mm.size() != 2 ||
872 mm[-4][-4] != -4 ||
873 mm[-4][-3] != -3 ||
874 mm[-4][-2] != -2 ||
875 mm[-4][-1] != -1 ||
876 mm[4][4] != 4 ||
877 mm[4][3] != 3 ||
878 mm[4][2] != 2 ||
879 mm[4][1] != 1) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900880 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200881 return_code |= ERR_CONTAINERS;
882 }
Mark Sleee8540632006-05-30 09:24:40 +0000883
884 /**
885 * INSANITY TEST
886 */
Jens Geyerf4598682014-05-08 23:18:44 +0200887 if (!noinsane) {
888 Insanity insane;
Jens Geyerd629ea02015-09-23 21:16:50 +0200889 insane.userMap.insert(make_pair(Numberz::FIVE, 5));
890 insane.userMap.insert(make_pair(Numberz::EIGHT, 8));
Jens Geyerf4598682014-05-08 23:18:44 +0200891 Xtruct truck;
Jens Geyerd629ea02015-09-23 21:16:50 +0200892 truck.string_thing = "Goodbye4";
893 truck.byte_thing = 4;
894 truck.i32_thing = 4;
895 truck.i64_thing = 4;
896 Xtruct truck2;
897 truck2.string_thing = "Hello2";
898 truck2.byte_thing = 2;
899 truck2.i32_thing = 2;
900 truck2.i64_thing = 2;
Jens Geyerf4598682014-05-08 23:18:44 +0200901 insane.xtructs.push_back(truck);
Jens Geyerd629ea02015-09-23 21:16:50 +0200902 insane.xtructs.push_back(truck2);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900903 cout << "testInsanity()" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100904 map<UserId, map<Numberz::type, Insanity> > whoa;
Jens Geyerf4598682014-05-08 23:18:44 +0200905 testClient.testInsanity(whoa, insane);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900906 cout << " = {";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100907 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Jens Geyerf4598682014-05-08 23:18:44 +0200908 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
909 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100910 map<Numberz::type, Insanity>::const_iterator i2_iter;
911 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Jens Geyerf4598682014-05-08 23:18:44 +0200912 printf("%d => {", i2_iter->first);
913 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
914 map<Numberz::type, UserId>::const_iterator um;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900915 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200916 for (um = userMap.begin(); um != userMap.end(); ++um) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900917 cout << um->first << " => " << um->second;
Jens Geyerf4598682014-05-08 23:18:44 +0200918 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900919 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000920
Jens Geyerf4598682014-05-08 23:18:44 +0200921 vector<Xtruct> xtructs = i2_iter->second.xtructs;
922 vector<Xtruct>::const_iterator x;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900923 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200924 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
925 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
926 x->string_thing.c_str(),
927 (int)x->byte_thing,
928 x->i32_thing,
929 x->i64_thing);
930 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900931 cout << "}";
Mark Sleee8540632006-05-30 09:24:40 +0000932
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900933 cout << "}, ";
Jens Geyerf4598682014-05-08 23:18:44 +0200934 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900935 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000936 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900937 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200938 bool failed = false;
939 map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1));
940 if (whoa.size() != 2) {
941 failed = true;
942 }
943 if (it1 == whoa.end()) {
944 failed = true;
945 } else {
946 map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO);
947 if (it12 == it1->second.end() || it12->second != insane) {
948 failed = true;
949 }
950 map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE);
951 if (it13 == it1->second.end() || it13->second != insane) {
952 failed = true;
953 }
954 }
955 map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2));
956 if (it2 == whoa.end()) {
957 failed = true;
958 } else {
959 map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX);
James E. King IIIf5f430d2018-06-08 03:37:55 +0000960 if (it26 == it2->second.end() || it26->second != Insanity()) {
Jens Geyerd629ea02015-09-23 21:16:50 +0200961 failed = true;
962 }
963 }
964 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900965 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200966 return_code |= ERR_STRUCTS;
967 }
Mark Sleee8540632006-05-30 09:24:40 +0000968 }
Jens Geyerd629ea02015-09-23 21:16:50 +0200969
970 /**
971 * MULTI TEST
972 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900973 cout << "testMulti()" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200974 try {
975 map<int16_t, string> mul_map;
976 Xtruct mul_result;
977 mul_map[1] = "blah";
978 mul_map[2] = "thing";
979 testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24));
980 Xtruct xxs;
981 xxs.string_thing = "Hello2";
982 xxs.byte_thing = 42;
983 xxs.i32_thing = 4242;
984 xxs.i64_thing = 424242;
985 if (mul_result != xxs) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900986 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200987 return_code |= ERR_STRUCTS;
988 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900989 } catch (TTransportException&) {
990 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200991 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900992 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200993 return_code |= ERR_STRUCTS;
994 }
995
Marc Slemko71d4e472006-08-15 22:34:04 +0000996 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +0000997
Marc Slemkobf4fd192006-08-15 21:29:39 +0000998 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900999 cout << "testClient.testException(\"Xception\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001000 testClient.testException("Xception");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001001 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001002 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001003
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001004 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001005 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001006 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001007
Marc Slemkobf4fd192006-08-15 21:29:39 +00001008 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001009 cout << "testClient.testException(\"TException\") =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001010 testClient.testException("TException");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001011 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001012 return_code |= ERR_EXCEPTIONS;
Roger Meierf50df7f2012-05-02 22:49:55 +00001013
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001014 } catch (const TException&) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001015 cout << " Caught TException" << endl;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001016 }
Roger Meierf50df7f2012-05-02 22:49:55 +00001017
1018 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001019 cout << "testClient.testException(\"success\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001020 testClient.testException("success");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001021 cout << " void" << endl;
1022 } catch (exception & ex) { \
1023 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001024 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001025 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001026
Marc Slemko71d4e472006-08-15 22:34:04 +00001027 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +00001028
Marc Slemko71d4e472006-08-15 22:34:04 +00001029 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001030 cout << "testClient.testMultiException(\"Xception\", \"test 1\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001031 Xtruct result;
1032 testClient.testMultiException(result, "Xception", "test 1");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001033 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001034 return_code |= ERR_EXCEPTIONS;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001035 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001036 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
1037 }
1038
1039 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001040 cout << "testClient.testMultiException(\"Xception2\", \"test 2\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001041 Xtruct result;
1042 testClient.testMultiException(result, "Xception2", "test 2");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001043 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001044 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001045
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001046 } catch (Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001047 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001048 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001049
Marc Slemko71d4e472006-08-15 22:34:04 +00001050 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001051 cout << "testClient.testMultiException(\"success\", \"test 3\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001052 Xtruct result;
1053 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +00001054 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001055 } catch (exception & ex) { \
1056 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001057 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001058 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001059
David Reissc51986f2009-03-24 20:01:25 +00001060 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +00001061 {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001062 cout << "testClient.testOneway(1) =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001063 uint64_t startOneway = now();
1064 testClient.testOneway(1);
1065 uint64_t elapsed = now() - startOneway;
1066 if (elapsed > 200 * 1000) { // 0.2 seconds
Jens Geyerd629ea02015-09-23 21:16:50 +02001067 printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0);
1068 return_code |= ERR_BASETYPES;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001069 } else {
1070 printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
1071 }
David Reiss2ab6fe82008-02-18 02:11:44 +00001072 }
1073
David Reiss2845b522008-02-18 02:11:52 +00001074 /**
David Reissc51986f2009-03-24 20:01:25 +00001075 * redo a simple test after the oneway to make sure we aren't "off by one" --
1076 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +00001077 * fail since it will get the void confirmation rather than the correct
1078 * result. In this circumstance, the client will throw the exception:
1079 *
1080 * TApplicationException: Wrong method namea
1081 */
1082 /**
1083 * I32 TEST
1084 */
James E. King, III58402ff2017-11-17 14:41:46 -05001085 cout << "re-test testI32(-1)" << flush;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001086 int i32 = testClient.testI32(-1);
1087 cout << " = " << i32 << endl;
Roger Meier4fce9602012-05-04 06:22:09 +00001088 if (i32 != -1)
Jens Geyerd629ea02015-09-23 21:16:50 +02001089 return_code |= ERR_BASETYPES;
David Reiss2845b522008-02-18 02:11:52 +00001090
James E. King, III58402ff2017-11-17 14:41:46 -05001091 cout << endl << "All tests done." << endl << flush;
James E. King, III39eaae62017-11-19 20:17:33 -05001092
Marc Slemkobf4fd192006-08-15 21:29:39 +00001093 uint64_t stop = now();
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001094 uint64_t tot = stop - start;
Mark Sleed788b2e2006-09-07 01:26:35 +00001095
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001096 cout << "Total time: " << stop - start << " us" << endl;
David Reiss0c90f6f2008-02-06 22:18:40 +00001097
Mark Sleed788b2e2006-09-07 01:26:35 +00001098 time_tot += tot;
1099 if (time_min == 0 || tot < time_min) {
1100 time_min = tot;
1101 }
1102 if (tot > time_max) {
1103 time_max = tot;
1104 }
1105
James E. King, III58402ff2017-11-17 14:41:46 -05001106 cout << flush;
Mark Sleea3302652006-10-25 19:03:32 +00001107 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +00001108 }
1109
Mark Sleed788b2e2006-09-07 01:26:35 +00001110
1111 uint64_t time_avg = time_tot / numTests;
1112
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001113 cout << "Min time: " << time_min << " us" << endl;
1114 cout << "Max time: " << time_max << " us" << endl;
1115 cout << "Avg time: " << time_avg << " us" << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001116
Jens Geyerd629ea02015-09-23 21:16:50 +02001117 return return_code;
Mark Sleee8540632006-05-30 09:24:40 +00001118}
James E. King, III39eaae62017-11-19 20:17:33 -05001119
1120void binary_fill(std::string& str, string::size_type siz)
1121{
1122 static const signed char bin_data[256]
1123 = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
1124 -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
1125 -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
1126 -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
1127 -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
1128 -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
1129 -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
1130 -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
1131 -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
1132 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
1133 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
1134 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
1135 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
1136 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
1137 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
1138 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
1139 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
1140 127};
1141
1142 str.resize(siz);
1143 char *ptr = &str[0];
1144 string::size_type pos = 0;
1145 for (string::size_type i = 0; i < siz; ++i)
1146 {
1147 if (pos == 255) { pos = 0; } else { ++pos; }
1148 *ptr++ = bin_data[pos];
1149 }
1150}
1151
1152int binary_test(ThriftTestClient& testClient, string::size_type siz)
1153{
1154 string bin_request;
1155 string bin_result;
1156
1157 cout << "testBinary(siz = " << siz << ")" << endl;
1158 binary_fill(bin_request, siz);
1159 try {
1160 testClient.testBinary(bin_result, bin_request);
1161
1162 if (bin_request.size() != bin_result.size()) {
1163 cout << "*** FAILED: request size " << bin_request.size() << "; result size " << bin_result.size() << endl;
1164 return ERR_BASETYPES;
1165 }
1166
1167 for (string::size_type i = 0; i < siz; ++i) {
1168 if (bin_request.at(i) != bin_result.at(i)) {
1169 cout << "*** FAILED: at position " << i << " request[i] is h" << hex << bin_request.at(i) << " result[i] is h" << hex << bin_result.at(i) << endl;
1170 return ERR_BASETYPES;
1171 }
1172 }
1173 } catch (TTransportException&) {
1174 throw;
1175 } catch (exception& ex) {
1176 cout << "*** FAILED ***" << endl << ex.what() << endl;
1177 return ERR_BASETYPES;
1178 }
1179
1180 return 0;
1181}