blob: 89f3fd13c35a1e332a87e0ecbfa6378af023b8bd [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>
Jake Farrell5d02b802014-01-07 21:42:01 -050049#if _WIN32
Konrad Grochowski16a23a62014-11-13 15:33:38 +010050#include <thrift/windows/TWinsockSingleton.h>
Jake Farrell5d02b802014-01-07 21:42:01 -050051#endif
Roger Meierca142b02011-06-07 17:59:07 +000052
James E. King, III58402ff2017-11-17 14:41:46 -050053#include "SecondService.h"
Marc Slemko6be374b2006-08-04 03:16:25 +000054#include "ThriftTest.h"
55
Marc Slemko6be374b2006-08-04 03:16:25 +000056using namespace std;
T Jake Lucianib5e62212009-01-31 22:36:20 +000057using namespace apache::thrift;
James E. King, III82ae9572017-08-05 12:23:54 -040058using namespace apache::thrift::async;
T Jake Lucianib5e62212009-01-31 22:36:20 +000059using namespace apache::thrift::protocol;
60using namespace apache::thrift::transport;
Marc Slemkobf4fd192006-08-15 21:29:39 +000061using namespace thrift::test;
Roger Meier7e056e72011-07-17 07:28:28 +000062
Mark Slee95771002006-06-07 06:53:25 +000063// Current time, microseconds since the epoch
Konrad Grochowski16a23a62014-11-13 15:33:38 +010064uint64_t now() {
Roger Meier5f9614c2010-11-21 16:59:05 +000065 int64_t ret;
Mark Slee95771002006-06-07 06:53:25 +000066 struct timeval tv;
David Reiss0c90f6f2008-02-06 22:18:40 +000067
Jake Farrell5d02b802014-01-07 21:42:01 -050068 THRIFT_GETTIMEOFDAY(&tv, NULL);
Mark Slee95771002006-06-07 06:53:25 +000069 ret = tv.tv_sec;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010070 ret = ret * 1000 * 1000 + tv.tv_usec;
Mark Slee95771002006-06-07 06:53:25 +000071 return ret;
72}
73
Sebastian Zenker39e505c2015-12-18 16:15:08 +010074static void testString_clientReturn(event_base* base,
75 int testNr,
Konrad Grochowski16a23a62014-11-13 15:33:38 +010076 ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000077 try {
78 string s;
79 client->recv_testString(s);
Sebastian Zenker39e505c2015-12-18 16:15:08 +010080 std::ostringstream os;
81 os << "test" << testNr;
82 const bool ok = (s == os.str());
83 cout << "testString: " << s << " " << ((ok) ? "ok" : "failed") << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000084 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -050085 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +000086 }
87
Sebastian Zenker39e505c2015-12-18 16:15:08 +010088 if (testNr == 9)
89 event_base_loopbreak(base); // end test
Roger Meier7e056e72011-07-17 07:28:28 +000090}
91
Sebastian Zenker39e505c2015-12-18 16:15:08 +010092static void testVoid_clientReturn(event_base* base, ThriftTestCobClient* client) {
Roger Meier7e056e72011-07-17 07:28:28 +000093 try {
94 client->recv_testVoid();
95 cout << "testVoid" << endl;
96
Sebastian Zenker39e505c2015-12-18 16:15:08 +010097 for (int testNr = 0; testNr < 10; ++testNr) {
98 std::ostringstream os;
99 os << "test" << testNr;
cyy316723a2019-01-05 16:35:14 +0800100 client->testString(std::bind(testString_clientReturn,
Sebastian Zenker39e505c2015-12-18 16:15:08 +0100101 base,
102 testNr,
cyy316723a2019-01-05 16:35:14 +0800103 std::placeholders::_1),
Sebastian Zenker39e505c2015-12-18 16:15:08 +0100104 os.str());
105 }
Roger Meier7e056e72011-07-17 07:28:28 +0000106 } catch (TException& exn) {
Jake Farrell5d02b802014-01-07 21:42:01 -0500107 cout << "Error: " << exn.what() << endl;
Roger Meier7e056e72011-07-17 07:28:28 +0000108 }
109}
110
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900111// Workaround for absense of C++11 "auto" keyword.
112template <typename T>
113bool print_eq(T expected, T actual) {
114 cout << "(" << actual << ")" << endl;
115 if (expected != actual) {
116 cout << "*** FAILED ***" << endl << "Expected: " << expected << " but got: " << actual << endl;
117 return false;
118 }
119 return true;
120}
121
122#define BASETYPE_IDENTITY_TEST(func, value) \
123 cout << #func "(" << value << ") = "; \
124 try { \
125 if (!print_eq(value, testClient.func(value))) \
126 return_code |= ERR_BASETYPES; \
127 } catch (TTransportException&) { \
128 throw; \
129 } catch (exception & ex) { \
130 cout << "*** FAILED ***" << endl << ex.what() << endl; \
131 return_code |= ERR_BASETYPES; \
132 }
133
James E. King, III39eaae62017-11-19 20:17:33 -0500134int binary_test(ThriftTestClient& testClient, string::size_type siz);
135
136BOOST_CONSTEXPR_OR_CONST int ERR_BASETYPES = 1;
137BOOST_CONSTEXPR_OR_CONST int ERR_STRUCTS = 2;
138BOOST_CONSTEXPR_OR_CONST int ERR_CONTAINERS = 4;
139BOOST_CONSTEXPR_OR_CONST int ERR_EXCEPTIONS = 8;
140BOOST_CONSTEXPR_OR_CONST int ERR_UNKNOWN = 64;
141
Mark Sleee8540632006-05-30 09:24:40 +0000142int main(int argc, char** argv) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900143 cout.precision(19);
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900144
James E. King, III06190872017-02-20 08:52:11 -0500145 string testDir = boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string();
146 string caPath = testDir + "/keys/CA.pem";
147 string certPath = testDir + "/keys/client.crt";
148 string keyPath = testDir + "/keys/client.key";
149
Jake Farrell5d02b802014-01-07 21:42:01 -0500150#if _WIN32
151 transport::TWinsockSingleton::create();
152#endif
Mark Sleee8540632006-05-30 09:24:40 +0000153 string host = "localhost";
154 int port = 9090;
155 int numTests = 1;
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000156 bool ssl = false;
James E. King IIIb2b767e2018-09-15 20:32:04 +0000157 bool zlib = false;
Roger Meierca142b02011-06-07 17:59:07 +0000158 string transport_type = "buffered";
159 string protocol_type = "binary";
160 string domain_socket = "";
pavlodd08f6e2015-10-08 16:43:56 -0400161 bool abstract_namespace = false;
Jens Geyerf4598682014-05-08 23:18:44 +0200162 bool noinsane = false;
Mark Sleee8540632006-05-30 09:24:40 +0000163
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900164 int return_code = 0;
165
Jake Farrell5d02b802014-01-07 21:42:01 -0500166 boost::program_options::options_description desc("Allowed options");
James E. King, III58402ff2017-11-17 14:41:46 -0500167 desc.add_options()
168 ("help,h", "produce help message")
James E. King, III39eaae62017-11-19 20:17:33 -0500169 ("host",
170 boost::program_options::value<string>(&host)->default_value(host),
James E. King, III58402ff2017-11-17 14:41:46 -0500171 "Host to connect")
James E. King, III39eaae62017-11-19 20:17:33 -0500172 ("port",
173 boost::program_options::value<int>(&port)->default_value(port),
James E. King, III58402ff2017-11-17 14:41:46 -0500174 "Port number to connect")
James E. King, III39eaae62017-11-19 20:17:33 -0500175 ("domain-socket",
James E. King, III58402ff2017-11-17 14:41:46 -0500176 boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
177 "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")
178 ("abstract-namespace",
179 "Look for the domain socket in the Abstract Namespace"
180 " (no connection with filesystem pathnames)")
181 ("transport",
182 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
James E. King IIIb2b767e2018-09-15 20:32:04 +0000183 "Transport: buffered, framed, http, evhttp, zlib")
James E. King, III58402ff2017-11-17 14:41:46 -0500184 ("protocol",
185 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
186 "Protocol: binary, compact, header, json, multi, multic, multih, multij")
James E. King, III39eaae62017-11-19 20:17:33 -0500187 ("ssl",
James E. King, III58402ff2017-11-17 14:41:46 -0500188 "Encrypted Transport using SSL")
James E. King IIIb2b767e2018-09-15 20:32:04 +0000189 ("zlib",
190 "Wrap Transport with Zlib")
James E. King, III58402ff2017-11-17 14:41:46 -0500191 ("testloops,n",
192 boost::program_options::value<int>(&numTests)->default_value(numTests),
193 "Number of Tests")
194 ("noinsane",
195 "Do not run insanity test");
Roger Meierca142b02011-06-07 17:59:07 +0000196
Jake Farrell5d02b802014-01-07 21:42:01 -0500197 boost::program_options::variables_map vm;
198 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
199 boost::program_options::notify(vm);
Roger Meierca142b02011-06-07 17:59:07 +0000200
201 if (vm.count("help")) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900202 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900203 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000204 }
Mark Sleea3302652006-10-25 19:03:32 +0000205
Jake Farrell5d02b802014-01-07 21:42:01 -0500206 try {
Roger Meierca142b02011-06-07 17:59:07 +0000207 if (!protocol_type.empty()) {
208 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100209 } else if (protocol_type == "compact") {
Dave Watson792db4e2015-01-16 11:22:01 -0800210 } else if (protocol_type == "header") {
Roger Meierca142b02011-06-07 17:59:07 +0000211 } else if (protocol_type == "json") {
James E. King, III58402ff2017-11-17 14:41:46 -0500212 } else if (protocol_type == "multi") {
213 } else if (protocol_type == "multic") {
214 } else if (protocol_type == "multih") {
215 } else if (protocol_type == "multij") {
Roger Meierca142b02011-06-07 17:59:07 +0000216 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100217 throw invalid_argument("Unknown protocol type " + protocol_type);
Roger Meierca142b02011-06-07 17:59:07 +0000218 }
219 }
220
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100221 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000222 if (transport_type == "buffered") {
223 } else if (transport_type == "framed") {
224 } else if (transport_type == "http") {
Roger Meier7e056e72011-07-17 07:28:28 +0000225 } else if (transport_type == "evhttp") {
James E. King IIIb2b767e2018-09-15 20:32:04 +0000226 } else if (transport_type == "zlib") {
227 // crosstest will pass zlib as a transport and as a flag right now..
Roger Meierca142b02011-06-07 17:59:07 +0000228 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100229 throw invalid_argument("Unknown transport type " + transport_type);
Roger Meierca142b02011-06-07 17:59:07 +0000230 }
231 }
232
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900233 } catch (exception& e) {
Roger Meierca142b02011-06-07 17:59:07 +0000234 cerr << e.what() << endl;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900235 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900236 return ERR_UNKNOWN;
Roger Meierca142b02011-06-07 17:59:07 +0000237 }
238
239 if (vm.count("ssl")) {
240 ssl = true;
241 }
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530242
James E. King IIIb2b767e2018-09-15 20:32:04 +0000243 if (vm.count("zlib")) {
244 zlib = true;
245 }
246
pavlodd08f6e2015-10-08 16:43:56 -0400247 if (vm.count("abstract-namespace")) {
248 abstract_namespace = true;
249 }
250
Jens Geyerf4598682014-05-08 23:18:44 +0200251 if (vm.count("noinsane")) {
252 noinsane = true;
253 }
Roger Meierca142b02011-06-07 17:59:07 +0000254
James E. King, III7f5a8c22017-04-04 09:36:38 -0400255 // THRIFT-4164: The factory MUST outlive any sockets it creates for correct behavior!
cyy316723a2019-01-05 16:35:14 +0800256 std::shared_ptr<TSSLSocketFactory> factory;
257 std::shared_ptr<TSocket> socket;
258 std::shared_ptr<TTransport> transport;
259 std::shared_ptr<TProtocol> protocol;
260 std::shared_ptr<TProtocol> protocol2; // SecondService for multiplexed
Roger Meierca142b02011-06-07 17:59:07 +0000261
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000262 if (ssl) {
James E. King, III06190872017-02-20 08:52:11 -0500263 cout << "Client Certificate File: " << certPath << endl;
264 cout << "Client Key File: " << keyPath << endl;
265 cout << "CA File: " << caPath << endl;
266
cyy316723a2019-01-05 16:35:14 +0800267 factory = std::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000268 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
James E. King, III06190872017-02-20 08:52:11 -0500269 factory->loadTrustedCertificates(caPath.c_str());
270 factory->loadCertificate(certPath.c_str());
271 factory->loadPrivateKey(keyPath.c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000272 factory->authenticate(true);
273 socket = factory->createSocket(host, port);
274 } else {
Roger Meierca142b02011-06-07 17:59:07 +0000275 if (domain_socket != "") {
pavlodd08f6e2015-10-08 16:43:56 -0400276 if (abstract_namespace) {
277 std::string abstract_socket("\0", 1);
278 abstract_socket += domain_socket;
cyy316723a2019-01-05 16:35:14 +0800279 socket = std::shared_ptr<TSocket>(new TSocket(abstract_socket));
pavlodd08f6e2015-10-08 16:43:56 -0400280 } else {
cyy316723a2019-01-05 16:35:14 +0800281 socket = std::shared_ptr<TSocket>(new TSocket(domain_socket));
pavlodd08f6e2015-10-08 16:43:56 -0400282 }
Roger Meierca142b02011-06-07 17:59:07 +0000283 port = 0;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100284 } else {
cyy316723a2019-01-05 16:35:14 +0800285 socket = std::shared_ptr<TSocket>(new TSocket(host, port));
Roger Meierca142b02011-06-07 17:59:07 +0000286 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000287 }
Mark Sleea3302652006-10-25 19:03:32 +0000288
Roger Meierca142b02011-06-07 17:59:07 +0000289 if (transport_type.compare("http") == 0) {
cyy316723a2019-01-05 16:35:14 +0800290 transport = std::make_shared<THttpClient>(socket, host, "/service");
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100291 } else if (transport_type.compare("framed") == 0) {
cyy316723a2019-01-05 16:35:14 +0800292 transport = std::make_shared<TFramedTransport>(socket);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100293 } else {
cyy316723a2019-01-05 16:35:14 +0800294 transport = std::make_shared<TBufferedTransport>(socket);
James E. King IIIb2b767e2018-09-15 20:32:04 +0000295 }
296
297 if (zlib) {
cyy316723a2019-01-05 16:35:14 +0800298 transport = std::make_shared<TZlibTransport>(transport);
Mark Sleea3302652006-10-25 19:03:32 +0000299 }
300
James E. King, III58402ff2017-11-17 14:41:46 -0500301 if (protocol_type == "json" || protocol_type == "multij") {
cyy316723a2019-01-05 16:35:14 +0800302 protocol = std::make_shared<TJSONProtocol>(transport);
James E. King, III58402ff2017-11-17 14:41:46 -0500303 } else if (protocol_type == "compact" || protocol_type == "multic") {
cyy316723a2019-01-05 16:35:14 +0800304 protocol = std::make_shared<TCompactProtocol>(transport);
James E. King, III58402ff2017-11-17 14:41:46 -0500305 } else if (protocol_type == "header" || protocol_type == "multih") {
cyy316723a2019-01-05 16:35:14 +0800306 protocol = std::make_shared<THeaderProtocol>(transport);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100307 } else {
cyy316723a2019-01-05 16:35:14 +0800308 protocol = std::make_shared<TBinaryProtocol>(transport);
James E. King, III58402ff2017-11-17 14:41:46 -0500309 }
310
311 if (boost::starts_with(protocol_type, "multi")) {
cyy316723a2019-01-05 16:35:14 +0800312 protocol2 = std::make_shared<TMultiplexedProtocol>(protocol, "SecondService");
James E. King, III39eaae62017-11-19 20:17:33 -0500313 // we don't need access to the original protocol any more, so...
cyy316723a2019-01-05 16:35:14 +0800314 protocol = std::make_shared<TMultiplexedProtocol>(protocol, "ThriftTest");
Roger Meierca142b02011-06-07 17:59:07 +0000315 }
316
317 // Connection info
pavlodd08f6e2015-10-08 16:43:56 -0400318 cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: ";
319 if (abstract_namespace) {
320 cout << '@';
321 }
322 cout << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000323 if (port != 0) {
324 cout << host << ":" << port;
325 }
326 cout << endl;
327
Roger Meier7e056e72011-07-17 07:28:28 +0000328 if (transport_type.compare("evhttp") == 0) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100329 event_base* base = event_base_new();
Roger Meier7e056e72011-07-17 07:28:28 +0000330 cout << "Libevent Version: " << event_get_version() << endl;
331 cout << "Libevent Method: " << event_base_get_method(base) << endl;
332#if LIBEVENT_VERSION_NUMBER >= 0x02000000
333 cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl;
334#endif
335
cyy316723a2019-01-05 16:35:14 +0800336 std::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Roger Meier7e056e72011-07-17 07:28:28 +0000337
cyy316723a2019-01-05 16:35:14 +0800338 std::shared_ptr<TAsyncChannel> channel(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100339 new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
Roger Meier7e056e72011-07-17 07:28:28 +0000340 ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
cyy316723a2019-01-05 16:35:14 +0800341 client->testVoid(std::bind(testVoid_clientReturn,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100342 base,
cyy316723a2019-01-05 16:35:14 +0800343 std::placeholders::_1));
Jake Farrell5d02b802014-01-07 21:42:01 -0500344
Roger Meier7e056e72011-07-17 07:28:28 +0000345 event_base_loop(base, 0);
346 return 0;
347 }
348
Roger Meierca142b02011-06-07 17:59:07 +0000349 ThriftTestClient testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000350
351 uint64_t time_min = 0;
352 uint64_t time_max = 0;
353 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000354
Mark Sleee8540632006-05-30 09:24:40 +0000355 int test = 0;
356 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000357
Mark Slee95771002006-06-07 06:53:25 +0000358 try {
Mark Sleea3302652006-10-25 19:03:32 +0000359 transport->open();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900360 } catch (TTransportException& ex) {
361 cout << "Connect failed: " << ex.what() << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900362 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000363 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000364
Mark Sleed788b2e2006-09-07 01:26:35 +0000365 /**
366 * CONNECT TEST
367 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100368 printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000369
370 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000371
Mark Sleee8540632006-05-30 09:24:40 +0000372 /**
373 * VOID TEST
374 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000375 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900376 cout << "testVoid()" << flush;
Mark Sleee129a2d2007-02-21 05:17:48 +0000377 testClient.testVoid();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900378 cout << " = void" << endl;
379 } catch (TTransportException&) {
380 // Stop here if transport got broken
381 throw;
382 } catch (exception& ex) {
383 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200384 return_code |= ERR_BASETYPES;
Mark Sleee129a2d2007-02-21 05:17:48 +0000385 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000386
Mark Sleee8540632006-05-30 09:24:40 +0000387 /**
388 * STRING TEST
389 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900390 cout << "testString(\"Test\")" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000391 string s;
392 testClient.testString(s, "Test");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900393 cout << " = " << s << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200394 if (s != "Test") {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900395 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200396 return_code |= ERR_BASETYPES;
397 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000398
James E. King, III58402ff2017-11-17 14:41:46 -0500399 //
400 // Multiplexed protocol - call another service method
401 // in the middle of the ThriftTest
402 //
403 if (boost::starts_with(protocol_type, "multi")) {
James E. King, III39eaae62017-11-19 20:17:33 -0500404 SecondServiceClient ssc(protocol2);
405 // transport is already open...
406
James E. King, III58402ff2017-11-17 14:41:46 -0500407 try {
408 cout << "secondService.secondTestString(\"foo\") => " << flush;
James E. King, III39eaae62017-11-19 20:17:33 -0500409 std::string result;
410 ssc.secondtestString(result, "foo");
411 cout << "{" << result << "}" << endl;
412 } catch (std::exception& e) {
413 cout << " *** FAILED *** " << e.what() << endl;
414 return_code |= ERR_EXCEPTIONS;
415 }
James E. King, III58402ff2017-11-17 14:41:46 -0500416 }
417
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900418 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500419#ifdef _MSC_VER
420#pragma warning( push )
421#pragma warning( disable : 4566 )
422#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900423 string str(
424 "}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, "
425 "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, "
426 "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, "
427 "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, "
428 "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, "
429 "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, "
430 "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, "
431 "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, "
432 "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, "
433 "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, "
434 "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, "
435 "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, "
436 "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, "
437 "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa "
438 "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa "
439 "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪"
440 "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, "
441 "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, "
442 "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, "
443 "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple "
444 "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, "
445 "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, "
446 "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, "
447 "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, "
448 "Bân-lâm-gú, 粵語");
James E. King, III7edc8fa2017-01-20 10:11:41 -0500449#ifdef _MSC_VER
450#pragma warning( pop )
451#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900452 cout << "testString(" << str << ") = " << flush;
453 testClient.testString(s, str);
454 cout << s << endl;
455 if (s != str) {
456 cout.imbue(locale("en_US.UTF8"));
457 cout << "*** FAILED ***" << endl << "Expected string: " << str << " but got: " << s << endl << "CLEAR";
458 return_code |= ERR_BASETYPES;
459 }
460 } catch (TTransportException&) {
461 throw;
462 } catch (exception& ex) {
463 cout << "*** FAILED ***" << endl << ex.what() << endl;
464 return_code |= ERR_BASETYPES;
465 return return_code;
466 }
467 try {
468 string str(
469 "quote: \" backslash:"
470 " forwardslash-escaped: \\/ "
471 " backspace: \b formfeed: \f newline: \n return: \r tab: "
472 " now-all-of-them-together: \"\\\\/\b\n\r\t"
473 " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><"
474 " char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ ");
475 cout << "testString(" << str << ") = " << flush;
476 testClient.testString(s, str);
477 cout << s << endl;
478 if (s != str) {
479 cout.imbue(locale("en_US.UTF8"));
480 cout << "*** FAILED ***" << endl
481 << "Expected string: " << str << " but got: " << s << endl
482 << "CLEAR";
483 ;
484 return_code |= ERR_BASETYPES;
485 }
486 } catch (TTransportException&) {
487 throw;
488 } catch (exception& ex) {
489 cout << "*** FAILED ***" << endl << ex.what() << endl;
490 return_code |= ERR_BASETYPES;
491 return return_code;
492 }
493
Mark Sleee8540632006-05-30 09:24:40 +0000494 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900495 * BOOL TEST
496 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900497 cout << boolalpha;
498 BASETYPE_IDENTITY_TEST(testBool, true);
499 BASETYPE_IDENTITY_TEST(testBool, false);
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900500
501 /**
Mark Sleee8540632006-05-30 09:24:40 +0000502 * BYTE TEST
503 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900504 BASETYPE_IDENTITY_TEST(testByte, (int8_t)0);
505 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-1);
506 BASETYPE_IDENTITY_TEST(testByte, (int8_t)42);
507 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-42);
508 BASETYPE_IDENTITY_TEST(testByte, (int8_t)127);
509 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-128);
David Reiss0c90f6f2008-02-06 22:18:40 +0000510
Mark Sleee8540632006-05-30 09:24:40 +0000511 /**
512 * I32 TEST
513 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900514 BASETYPE_IDENTITY_TEST(testI32, 0);
515 BASETYPE_IDENTITY_TEST(testI32, -1);
516 BASETYPE_IDENTITY_TEST(testI32, 190000013);
517 BASETYPE_IDENTITY_TEST(testI32, -190000013);
James E. King III9b75e4f2018-12-17 16:21:14 -0500518 BASETYPE_IDENTITY_TEST(testI32, (numeric_limits<int32_t>::max)());
519 BASETYPE_IDENTITY_TEST(testI32, (numeric_limits<int32_t>::min)());
Mark Sleee8540632006-05-30 09:24:40 +0000520
521 /**
Mark Sleee8540632006-05-30 09:24:40 +0000522 * I64 TEST
523 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900524 BASETYPE_IDENTITY_TEST(testI64, (int64_t)0);
525 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1);
526 BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL);
527 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500528 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32));
529 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) + 1);
531 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32) - 1);
James E. King III9b75e4f2018-12-17 16:21:14 -0500532 BASETYPE_IDENTITY_TEST(testI64, (numeric_limits<int64_t>::max)());
533 BASETYPE_IDENTITY_TEST(testI64, (numeric_limits<int64_t>::min)());
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100534
Mark Sleec98d0502006-09-06 02:42:25 +0000535 /**
536 * DOUBLE TEST
537 */
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900538 // Comparing double values with plain equality because Thrift handles full precision of double
539 BASETYPE_IDENTITY_TEST(testDouble, 0.0);
540 BASETYPE_IDENTITY_TEST(testDouble, -1.0);
541 BASETYPE_IDENTITY_TEST(testDouble, -5.2098523);
542 BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500543 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32));
544 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32) + 1);
545 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 53) - 1);
546 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32));
547 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32) - 1);
548 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 53) + 1);
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900549
550 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500551 double expected = pow(static_cast<double>(10), 307);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900552 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900553 double actual = testClient.testDouble(expected);
554 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500555 if (expected - actual > pow(static_cast<double>(10), 292)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900556 cout << "*** FAILED ***" << endl
557 << "Expected: " << expected << " but got: " << actual << endl;
558 }
559 } catch (TTransportException&) {
560 throw;
561 } catch (exception& ex) {
562 cout << "*** FAILED ***" << endl << ex.what() << endl;
563 return_code |= ERR_BASETYPES;
564 }
565
566 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500567 double expected = pow(static_cast<double>(10), -292);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900568 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900569 double actual = testClient.testDouble(expected);
570 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500571 if (expected - actual > pow(static_cast<double>(10), -307)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900572 cout << "*** FAILED ***" << endl
573 << "Expected: " << expected << " but got: " << actual << endl;
574 }
575 } catch (TTransportException&) {
576 throw;
577 } catch (exception& ex) {
578 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200579 return_code |= ERR_BASETYPES;
580 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000581
Mark Sleee8540632006-05-30 09:24:40 +0000582 /**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100583 * BINARY TEST
584 */
James E. King, III39eaae62017-11-19 20:17:33 -0500585 for (string::size_type i = 0; i < 131073 && !return_code; ) {
586 return_code |= binary_test(testClient, i);
587 if (i > 0) { i *= 2; } else { ++i; }
Jens Geyerd629ea02015-09-23 21:16:50 +0200588 }
589
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100590
591 /**
Mark Sleee8540632006-05-30 09:24:40 +0000592 * STRUCT TEST
593 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900594 cout << "testStruct({\"Zero\", 1, -3, -5})" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000595 Xtruct out;
596 out.string_thing = "Zero";
597 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000598 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000599 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000600 Xtruct in;
601 testClient.testStruct(in, out);
Roger Meier0e814802014-01-17 21:07:58 +0100602 printf(" = {\"%s\", %d, %d, %" PRId64 "}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000603 in.string_thing.c_str(),
604 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000605 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000606 in.i64_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200607 if (in != out) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900608 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200609 return_code |= ERR_STRUCTS;
610 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000611
Mark Sleee8540632006-05-30 09:24:40 +0000612 /**
613 * NESTED STRUCT TEST
614 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900615 cout << "testNest({1, {\"Zero\", 1, -3, -5}), 5}" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000616 Xtruct2 out2;
617 out2.byte_thing = 1;
618 out2.struct_thing = out;
619 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000620 Xtruct2 in2;
621 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000622 in = in2.struct_thing;
Roger Meier0e814802014-01-17 21:07:58 +0100623 printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000624 in2.byte_thing,
625 in.string_thing.c_str(),
626 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000627 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000628 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000629 in2.i32_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200630 if (in2 != out2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900631 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200632 return_code |= ERR_STRUCTS;
633 }
Mark Sleee8540632006-05-30 09:24:40 +0000634
635 /**
636 * MAP TEST
637 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100638 map<int32_t, int32_t> mapout;
Mark Sleee8540632006-05-30 09:24:40 +0000639 for (int32_t i = 0; i < 5; ++i) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100640 mapout.insert(make_pair(i, i - 10));
Mark Sleee8540632006-05-30 09:24:40 +0000641 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900642 cout << "testMap({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000643 map<int32_t, int32_t>::const_iterator m_iter;
644 bool first = true;
645 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
646 if (first) {
647 first = false;
648 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900649 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000650 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900651 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000652 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900653 cout << "})";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100654 map<int32_t, int32_t> mapin;
Mark Slee1921d202007-01-24 19:43:06 +0000655 testClient.testMap(mapin, mapout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900656 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000657 first = true;
658 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
659 if (first) {
660 first = false;
661 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900662 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000663 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900664 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000665 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900666 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200667 if (mapin != mapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900668 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200669 return_code |= ERR_CONTAINERS;
670 }
Roger Meier4fce9602012-05-04 06:22:09 +0000671
672 /**
673 * STRING MAP TEST
Roger Meier4fce9602012-05-04 06:22:09 +0000674 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900675 cout << "testStringMap({a => 2, b => blah, some => thing}) = {" << flush;
Jens Geyerd629ea02015-09-23 21:16:50 +0200676 map<string, string> smapin;
677 map<string, string> smapout;
678 smapin["a"] = "2";
679 smapin["b"] = "blah";
680 smapin["some"] = "thing";
681 try {
682 testClient.testStringMap(smapout, smapin);
683 first = true;
684 for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) {
685 if (first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900686 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200687 else
688 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900689 cout << it->first << " => " << it->second;
Jens Geyerd629ea02015-09-23 21:16:50 +0200690 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900691 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200692 if (smapin != smapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900693 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200694 return_code |= ERR_CONTAINERS;
695 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900696 } catch (TTransportException&) {
697 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200698 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900699 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200700 return_code |= ERR_CONTAINERS;
701 }
Mark Sleee8540632006-05-30 09:24:40 +0000702
703 /**
704 * SET TEST
705 */
706 set<int32_t> setout;
707 for (int32_t i = -2; i < 3; ++i) {
708 setout.insert(i);
709 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900710 cout << "testSet({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000711 set<int32_t>::const_iterator s_iter;
712 first = true;
713 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
714 if (first) {
715 first = false;
716 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900717 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000718 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900719 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000720 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900721 cout << "})";
Mark Slee1921d202007-01-24 19:43:06 +0000722 set<int32_t> setin;
723 testClient.testSet(setin, setout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900724 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000725 first = true;
726 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
727 if (first) {
728 first = false;
729 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900730 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000731 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900732 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000733 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900734 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200735 if (setin != setout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900736 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200737 return_code |= ERR_CONTAINERS;
738 }
Mark Sleee8540632006-05-30 09:24:40 +0000739
740 /**
741 * LIST TEST
742 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900743 cout << "testList(empty)" << flush;
744 try {
745 vector<int32_t> listout;
746 testClient.testList(listout, vector<int32_t>());
747 if (!listout.empty()) {
748 cout << "*** FAILED ***" << endl;
749 cout << "invalid length: " << listout.size() << endl;
750 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000751 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900752 } catch (TTransportException&) {
753 throw;
754 } catch (exception& ex) {
755 cout << "*** FAILED ***" << endl << ex.what() << endl;
756 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000757 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900758 try {
759 vector<int32_t> listout;
760 for (int32_t i = -2; i < 3; ++i) {
761 listout.push_back(i);
Mark Sleee8540632006-05-30 09:24:40 +0000762 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900763 cout << "testList({" << flush;
764 vector<int32_t>::const_iterator l_iter;
765 first = true;
766 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
767 if (first) {
768 first = false;
769 } else {
770 cout << ",";
771 }
772 cout << *l_iter;
773 }
774 cout << "})";
775 vector<int32_t> listin;
776 testClient.testList(listin, listout);
777 cout << " = {";
778 first = true;
779 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
780 if (first) {
781 first = false;
782 } else {
783 cout << ",";
784 }
785 cout << *l_iter;
786 }
787 cout << "}" << endl;
788 if (listin != listout) {
789 cout << "*** FAILED ***" << endl;
790 return_code |= ERR_CONTAINERS;
791 }
792 } catch (TTransportException&) {
793 throw;
794 } catch (exception& ex) {
795 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200796 return_code |= ERR_CONTAINERS;
797 }
Mark Sleee8540632006-05-30 09:24:40 +0000798
799 /**
800 * ENUM TEST
801 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900802 cout << "testEnum(ONE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000803 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900804 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200805 if (ret != Numberz::ONE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900806 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200807 return_code |= ERR_STRUCTS;
808 }
Mark Sleee8540632006-05-30 09:24:40 +0000809
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900810 cout << "testEnum(TWO)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000811 ret = testClient.testEnum(Numberz::TWO);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900812 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200813 if (ret != Numberz::TWO) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900814 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200815 return_code |= ERR_STRUCTS;
816 }
Mark Sleee8540632006-05-30 09:24:40 +0000817
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900818 cout << "testEnum(THREE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000819 ret = testClient.testEnum(Numberz::THREE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900820 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200821 if (ret != Numberz::THREE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900822 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200823 return_code |= ERR_STRUCTS;
824 }
Mark Sleee8540632006-05-30 09:24:40 +0000825
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900826 cout << "testEnum(FIVE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000827 ret = testClient.testEnum(Numberz::FIVE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900828 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200829 if (ret != Numberz::FIVE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900830 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200831 return_code |= ERR_STRUCTS;
832 }
Mark Sleee8540632006-05-30 09:24:40 +0000833
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900834 cout << "testEnum(EIGHT)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000835 ret = testClient.testEnum(Numberz::EIGHT);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900836 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200837 if (ret != Numberz::EIGHT) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900838 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200839 return_code |= ERR_STRUCTS;
840 }
Mark Sleee8540632006-05-30 09:24:40 +0000841
842 /**
843 * TYPEDEF TEST
844 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900845 cout << "testTypedef(309858235082523)" << flush;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000846 UserId uid = testClient.testTypedef(309858235082523LL);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900847 cout << " = " << uid << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200848 if (uid != 309858235082523LL) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900849 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200850 return_code |= ERR_STRUCTS;
851 }
Mark Sleee8540632006-05-30 09:24:40 +0000852
853 /**
854 * NESTED MAP TEST
855 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900856 cout << "testMapMap(1)" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000857 map<int32_t, map<int32_t, int32_t> > mm;
858 testClient.testMapMap(mm, 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900859 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000860 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
861 for (mi = mm.begin(); mi != mm.end(); ++mi) {
862 printf("%d => {", mi->first);
863 map<int32_t, int32_t>::const_iterator mi2;
864 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900865 cout << mi2->first << " => " << mi2->second;
Mark Sleee8540632006-05-30 09:24:40 +0000866 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900867 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000868 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900869 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200870 if (mm.size() != 2 ||
871 mm[-4][-4] != -4 ||
872 mm[-4][-3] != -3 ||
873 mm[-4][-2] != -2 ||
874 mm[-4][-1] != -1 ||
875 mm[4][4] != 4 ||
876 mm[4][3] != 3 ||
877 mm[4][2] != 2 ||
878 mm[4][1] != 1) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900879 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200880 return_code |= ERR_CONTAINERS;
881 }
Mark Sleee8540632006-05-30 09:24:40 +0000882
883 /**
884 * INSANITY TEST
885 */
Jens Geyerf4598682014-05-08 23:18:44 +0200886 if (!noinsane) {
887 Insanity insane;
Jens Geyerd629ea02015-09-23 21:16:50 +0200888 insane.userMap.insert(make_pair(Numberz::FIVE, 5));
889 insane.userMap.insert(make_pair(Numberz::EIGHT, 8));
Jens Geyerf4598682014-05-08 23:18:44 +0200890 Xtruct truck;
Jens Geyerd629ea02015-09-23 21:16:50 +0200891 truck.string_thing = "Goodbye4";
892 truck.byte_thing = 4;
893 truck.i32_thing = 4;
894 truck.i64_thing = 4;
895 Xtruct truck2;
896 truck2.string_thing = "Hello2";
897 truck2.byte_thing = 2;
898 truck2.i32_thing = 2;
899 truck2.i64_thing = 2;
Jens Geyerf4598682014-05-08 23:18:44 +0200900 insane.xtructs.push_back(truck);
Jens Geyerd629ea02015-09-23 21:16:50 +0200901 insane.xtructs.push_back(truck2);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900902 cout << "testInsanity()" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100903 map<UserId, map<Numberz::type, Insanity> > whoa;
Jens Geyerf4598682014-05-08 23:18:44 +0200904 testClient.testInsanity(whoa, insane);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900905 cout << " = {";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100906 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Jens Geyerf4598682014-05-08 23:18:44 +0200907 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
908 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100909 map<Numberz::type, Insanity>::const_iterator i2_iter;
910 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Jens Geyerf4598682014-05-08 23:18:44 +0200911 printf("%d => {", i2_iter->first);
912 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
913 map<Numberz::type, UserId>::const_iterator um;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900914 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200915 for (um = userMap.begin(); um != userMap.end(); ++um) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900916 cout << um->first << " => " << um->second;
Jens Geyerf4598682014-05-08 23:18:44 +0200917 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900918 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000919
Jens Geyerf4598682014-05-08 23:18:44 +0200920 vector<Xtruct> xtructs = i2_iter->second.xtructs;
921 vector<Xtruct>::const_iterator x;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900922 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200923 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
924 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
925 x->string_thing.c_str(),
926 (int)x->byte_thing,
927 x->i32_thing,
928 x->i64_thing);
929 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900930 cout << "}";
Mark Sleee8540632006-05-30 09:24:40 +0000931
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900932 cout << "}, ";
Jens Geyerf4598682014-05-08 23:18:44 +0200933 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900934 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000935 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900936 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200937 bool failed = false;
938 map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1));
939 if (whoa.size() != 2) {
940 failed = true;
941 }
942 if (it1 == whoa.end()) {
943 failed = true;
944 } else {
945 map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO);
946 if (it12 == it1->second.end() || it12->second != insane) {
947 failed = true;
948 }
949 map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE);
950 if (it13 == it1->second.end() || it13->second != insane) {
951 failed = true;
952 }
953 }
954 map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2));
955 if (it2 == whoa.end()) {
956 failed = true;
957 } else {
958 map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX);
James E. King IIIf5f430d2018-06-08 03:37:55 +0000959 if (it26 == it2->second.end() || it26->second != Insanity()) {
Jens Geyerd629ea02015-09-23 21:16:50 +0200960 failed = true;
961 }
962 }
963 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900964 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200965 return_code |= ERR_STRUCTS;
966 }
Mark Sleee8540632006-05-30 09:24:40 +0000967 }
Jens Geyerd629ea02015-09-23 21:16:50 +0200968
969 /**
970 * MULTI TEST
971 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900972 cout << "testMulti()" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200973 try {
974 map<int16_t, string> mul_map;
975 Xtruct mul_result;
976 mul_map[1] = "blah";
977 mul_map[2] = "thing";
978 testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24));
979 Xtruct xxs;
980 xxs.string_thing = "Hello2";
981 xxs.byte_thing = 42;
982 xxs.i32_thing = 4242;
983 xxs.i64_thing = 424242;
984 if (mul_result != xxs) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900985 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200986 return_code |= ERR_STRUCTS;
987 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900988 } catch (TTransportException&) {
989 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200990 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900991 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200992 return_code |= ERR_STRUCTS;
993 }
994
Marc Slemko71d4e472006-08-15 22:34:04 +0000995 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +0000996
Marc Slemkobf4fd192006-08-15 21:29:39 +0000997 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900998 cout << "testClient.testException(\"Xception\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +0000999 testClient.testException("Xception");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001000 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001001 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001002
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001003 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001004 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001005 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001006
Marc Slemkobf4fd192006-08-15 21:29:39 +00001007 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001008 cout << "testClient.testException(\"TException\") =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001009 testClient.testException("TException");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001010 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001011 return_code |= ERR_EXCEPTIONS;
Roger Meierf50df7f2012-05-02 22:49:55 +00001012
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001013 } catch (const TException&) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001014 cout << " Caught TException" << endl;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001015 }
Roger Meierf50df7f2012-05-02 22:49:55 +00001016
1017 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001018 cout << "testClient.testException(\"success\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001019 testClient.testException("success");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001020 cout << " void" << endl;
1021 } catch (exception & ex) { \
1022 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001023 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001024 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001025
Marc Slemko71d4e472006-08-15 22:34:04 +00001026 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +00001027
Marc Slemko71d4e472006-08-15 22:34:04 +00001028 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001029 cout << "testClient.testMultiException(\"Xception\", \"test 1\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001030 Xtruct result;
1031 testClient.testMultiException(result, "Xception", "test 1");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001032 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001033 return_code |= ERR_EXCEPTIONS;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001034 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001035 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
1036 }
1037
1038 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001039 cout << "testClient.testMultiException(\"Xception2\", \"test 2\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001040 Xtruct result;
1041 testClient.testMultiException(result, "Xception2", "test 2");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001042 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001043 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +00001044
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001045 } catch (Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001046 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001047 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001048
Marc Slemko71d4e472006-08-15 22:34:04 +00001049 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001050 cout << "testClient.testMultiException(\"success\", \"test 3\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001051 Xtruct result;
1052 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +00001053 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001054 } catch (exception & ex) { \
1055 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001056 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001057 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001058
David Reissc51986f2009-03-24 20:01:25 +00001059 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +00001060 {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001061 cout << "testClient.testOneway(1) =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001062 uint64_t startOneway = now();
1063 testClient.testOneway(1);
1064 uint64_t elapsed = now() - startOneway;
1065 if (elapsed > 200 * 1000) { // 0.2 seconds
Jens Geyerd629ea02015-09-23 21:16:50 +02001066 printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0);
1067 return_code |= ERR_BASETYPES;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001068 } else {
1069 printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
1070 }
David Reiss2ab6fe82008-02-18 02:11:44 +00001071 }
1072
David Reiss2845b522008-02-18 02:11:52 +00001073 /**
David Reissc51986f2009-03-24 20:01:25 +00001074 * redo a simple test after the oneway to make sure we aren't "off by one" --
1075 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +00001076 * fail since it will get the void confirmation rather than the correct
1077 * result. In this circumstance, the client will throw the exception:
1078 *
1079 * TApplicationException: Wrong method namea
1080 */
1081 /**
1082 * I32 TEST
1083 */
James E. King, III58402ff2017-11-17 14:41:46 -05001084 cout << "re-test testI32(-1)" << flush;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001085 int i32 = testClient.testI32(-1);
1086 cout << " = " << i32 << endl;
Roger Meier4fce9602012-05-04 06:22:09 +00001087 if (i32 != -1)
Jens Geyerd629ea02015-09-23 21:16:50 +02001088 return_code |= ERR_BASETYPES;
David Reiss2845b522008-02-18 02:11:52 +00001089
James E. King, III58402ff2017-11-17 14:41:46 -05001090 cout << endl << "All tests done." << endl << flush;
James E. King, III39eaae62017-11-19 20:17:33 -05001091
Marc Slemkobf4fd192006-08-15 21:29:39 +00001092 uint64_t stop = now();
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001093 uint64_t tot = stop - start;
Mark Sleed788b2e2006-09-07 01:26:35 +00001094
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001095 cout << "Total time: " << stop - start << " us" << endl;
David Reiss0c90f6f2008-02-06 22:18:40 +00001096
Mark Sleed788b2e2006-09-07 01:26:35 +00001097 time_tot += tot;
1098 if (time_min == 0 || tot < time_min) {
1099 time_min = tot;
1100 }
1101 if (tot > time_max) {
1102 time_max = tot;
1103 }
1104
James E. King, III58402ff2017-11-17 14:41:46 -05001105 cout << flush;
Mark Sleea3302652006-10-25 19:03:32 +00001106 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +00001107 }
1108
Mark Sleed788b2e2006-09-07 01:26:35 +00001109
1110 uint64_t time_avg = time_tot / numTests;
1111
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001112 cout << "Min time: " << time_min << " us" << endl;
1113 cout << "Max time: " << time_max << " us" << endl;
1114 cout << "Avg time: " << time_avg << " us" << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001115
Jens Geyerd629ea02015-09-23 21:16:50 +02001116 return return_code;
Mark Sleee8540632006-05-30 09:24:40 +00001117}
James E. King, III39eaae62017-11-19 20:17:33 -05001118
1119void binary_fill(std::string& str, string::size_type siz)
1120{
1121 static const signed char bin_data[256]
1122 = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
1123 -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
1124 -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
1125 -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
1126 -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
1127 -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
1128 -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
1129 -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
1130 -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
1131 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
1132 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
1133 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
1134 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
1135 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
1136 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
1137 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
1138 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
1139 127};
1140
1141 str.resize(siz);
1142 char *ptr = &str[0];
1143 string::size_type pos = 0;
1144 for (string::size_type i = 0; i < siz; ++i)
1145 {
1146 if (pos == 255) { pos = 0; } else { ++pos; }
1147 *ptr++ = bin_data[pos];
1148 }
1149}
1150
1151int binary_test(ThriftTestClient& testClient, string::size_type siz)
1152{
1153 string bin_request;
1154 string bin_result;
1155
1156 cout << "testBinary(siz = " << siz << ")" << endl;
1157 binary_fill(bin_request, siz);
1158 try {
1159 testClient.testBinary(bin_result, bin_request);
1160
1161 if (bin_request.size() != bin_result.size()) {
1162 cout << "*** FAILED: request size " << bin_request.size() << "; result size " << bin_result.size() << endl;
1163 return ERR_BASETYPES;
1164 }
1165
1166 for (string::size_type i = 0; i < siz; ++i) {
1167 if (bin_request.at(i) != bin_result.at(i)) {
1168 cout << "*** FAILED: at position " << i << " request[i] is h" << hex << bin_request.at(i) << " result[i] is h" << hex << bin_result.at(i) << endl;
1169 return ERR_BASETYPES;
1170 }
1171 }
1172 } catch (TTransportException&) {
1173 throw;
1174 } catch (exception& ex) {
1175 cout << "*** FAILED ***" << endl << ex.what() << endl;
1176 return ERR_BASETYPES;
1177 }
1178
1179 return 0;
1180}