blob: 87bb0283ab5eb5a6dacfe9fd232a5561a913df01 [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>
34#include <thrift/async/TEvhttpClientChannel.h>
35#include <thrift/server/TNonblockingServer.h> // <event.h>
Mark Sleee8540632006-05-30 09:24:40 +000036
James E. King, III7edc8fa2017-01-20 10:11:41 -050037#ifdef HAVE_STDINT_H
38#include <stdint.h>
39#endif
40#ifdef HAVE_INTTYPES_H
41#include <inttypes.h>
42#endif
43
James E. King, III58402ff2017-11-17 14:41:46 -050044#include <boost/algorithm/string.hpp>
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +053045#include <boost/filesystem.hpp>
James E. King, III58402ff2017-11-17 14:41:46 -050046#include <boost/program_options.hpp>
James E. King, III39eaae62017-11-19 20:17:33 -050047#include <boost/random/random_device.hpp>
James E. King, III82ae9572017-08-05 12:23:54 -040048#include <thrift/stdcxx.h>
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;
James E. King, III82ae9572017-08-05 12:23:54 -0400100 client->testString(stdcxx::bind(testString_clientReturn,
Sebastian Zenker39e505c2015-12-18 16:15:08 +0100101 base,
102 testNr,
James E. King, III82ae9572017-08-05 12:23:54 -0400103 stdcxx::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;
Roger Meierca142b02011-06-07 17:59:07 +0000157 string transport_type = "buffered";
158 string protocol_type = "binary";
159 string domain_socket = "";
pavlodd08f6e2015-10-08 16:43:56 -0400160 bool abstract_namespace = false;
Jens Geyerf4598682014-05-08 23:18:44 +0200161 bool noinsane = false;
Mark Sleee8540632006-05-30 09:24:40 +0000162
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900163 int return_code = 0;
164
Jake Farrell5d02b802014-01-07 21:42:01 -0500165 boost::program_options::options_description desc("Allowed options");
James E. King, III58402ff2017-11-17 14:41:46 -0500166 desc.add_options()
167 ("help,h", "produce help message")
James E. King, III39eaae62017-11-19 20:17:33 -0500168 ("host",
169 boost::program_options::value<string>(&host)->default_value(host),
James E. King, III58402ff2017-11-17 14:41:46 -0500170 "Host to connect")
James E. King, III39eaae62017-11-19 20:17:33 -0500171 ("port",
172 boost::program_options::value<int>(&port)->default_value(port),
James E. King, III58402ff2017-11-17 14:41:46 -0500173 "Port number to connect")
James E. King, III39eaae62017-11-19 20:17:33 -0500174 ("domain-socket",
James E. King, III58402ff2017-11-17 14:41:46 -0500175 boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
176 "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")
177 ("abstract-namespace",
178 "Look for the domain socket in the Abstract Namespace"
179 " (no connection with filesystem pathnames)")
180 ("transport",
181 boost::program_options::value<string>(&transport_type)->default_value(transport_type),
182 "Transport: buffered, framed, http, evhttp")
183 ("protocol",
184 boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
185 "Protocol: binary, compact, header, json, multi, multic, multih, multij")
James E. King, III39eaae62017-11-19 20:17:33 -0500186 ("ssl",
James E. King, III58402ff2017-11-17 14:41:46 -0500187 "Encrypted Transport using SSL")
188 ("testloops,n",
189 boost::program_options::value<int>(&numTests)->default_value(numTests),
190 "Number of Tests")
191 ("noinsane",
192 "Do not run insanity test");
Roger Meierca142b02011-06-07 17:59:07 +0000193
Jake Farrell5d02b802014-01-07 21:42:01 -0500194 boost::program_options::variables_map vm;
195 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
196 boost::program_options::notify(vm);
Roger Meierca142b02011-06-07 17:59:07 +0000197
198 if (vm.count("help")) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900199 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900200 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000201 }
Mark Sleea3302652006-10-25 19:03:32 +0000202
Jake Farrell5d02b802014-01-07 21:42:01 -0500203 try {
Roger Meierca142b02011-06-07 17:59:07 +0000204 if (!protocol_type.empty()) {
205 if (protocol_type == "binary") {
Roger Meier284101c2014-03-11 21:20:35 +0100206 } else if (protocol_type == "compact") {
Dave Watson792db4e2015-01-16 11:22:01 -0800207 } else if (protocol_type == "header") {
Roger Meierca142b02011-06-07 17:59:07 +0000208 } else if (protocol_type == "json") {
James E. King, III58402ff2017-11-17 14:41:46 -0500209 } else if (protocol_type == "multi") {
210 } else if (protocol_type == "multic") {
211 } else if (protocol_type == "multih") {
212 } else if (protocol_type == "multij") {
Roger Meierca142b02011-06-07 17:59:07 +0000213 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100214 throw invalid_argument("Unknown protocol type " + protocol_type);
Roger Meierca142b02011-06-07 17:59:07 +0000215 }
216 }
217
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100218 if (!transport_type.empty()) {
Roger Meierca142b02011-06-07 17:59:07 +0000219 if (transport_type == "buffered") {
220 } else if (transport_type == "framed") {
221 } else if (transport_type == "http") {
Roger Meier7e056e72011-07-17 07:28:28 +0000222 } else if (transport_type == "evhttp") {
Roger Meierca142b02011-06-07 17:59:07 +0000223 } else {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100224 throw invalid_argument("Unknown transport type " + transport_type);
Roger Meierca142b02011-06-07 17:59:07 +0000225 }
226 }
227
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900228 } catch (exception& e) {
Roger Meierca142b02011-06-07 17:59:07 +0000229 cerr << e.what() << endl;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900230 cout << desc << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900231 return ERR_UNKNOWN;
Roger Meierca142b02011-06-07 17:59:07 +0000232 }
233
234 if (vm.count("ssl")) {
235 ssl = true;
236 }
cdwijayarathnaa07ec0b2014-08-09 17:45:56 +0530237
pavlodd08f6e2015-10-08 16:43:56 -0400238 if (vm.count("abstract-namespace")) {
239 abstract_namespace = true;
240 }
241
Jens Geyerf4598682014-05-08 23:18:44 +0200242 if (vm.count("noinsane")) {
243 noinsane = true;
244 }
Roger Meierca142b02011-06-07 17:59:07 +0000245
James E. King, III7f5a8c22017-04-04 09:36:38 -0400246 // THRIFT-4164: The factory MUST outlive any sockets it creates for correct behavior!
James E. King, III82ae9572017-08-05 12:23:54 -0400247 stdcxx::shared_ptr<TSSLSocketFactory> factory;
248 stdcxx::shared_ptr<TSocket> socket;
249 stdcxx::shared_ptr<TTransport> transport;
250 stdcxx::shared_ptr<TProtocol> protocol;
James E. King, III39eaae62017-11-19 20:17:33 -0500251 stdcxx::shared_ptr<TProtocol> protocol2; // SecondService for multiplexed
Roger Meierca142b02011-06-07 17:59:07 +0000252
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000253 if (ssl) {
James E. King, III06190872017-02-20 08:52:11 -0500254 cout << "Client Certificate File: " << certPath << endl;
255 cout << "Client Key File: " << keyPath << endl;
256 cout << "CA File: " << caPath << endl;
257
James E. King, III82ae9572017-08-05 12:23:54 -0400258 factory = stdcxx::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000259 factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
James E. King, III06190872017-02-20 08:52:11 -0500260 factory->loadTrustedCertificates(caPath.c_str());
261 factory->loadCertificate(certPath.c_str());
262 factory->loadPrivateKey(keyPath.c_str());
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000263 factory->authenticate(true);
264 socket = factory->createSocket(host, port);
265 } else {
Roger Meierca142b02011-06-07 17:59:07 +0000266 if (domain_socket != "") {
pavlodd08f6e2015-10-08 16:43:56 -0400267 if (abstract_namespace) {
268 std::string abstract_socket("\0", 1);
269 abstract_socket += domain_socket;
James E. King, III82ae9572017-08-05 12:23:54 -0400270 socket = stdcxx::shared_ptr<TSocket>(new TSocket(abstract_socket));
pavlodd08f6e2015-10-08 16:43:56 -0400271 } else {
James E. King, III82ae9572017-08-05 12:23:54 -0400272 socket = stdcxx::shared_ptr<TSocket>(new TSocket(domain_socket));
pavlodd08f6e2015-10-08 16:43:56 -0400273 }
Roger Meierca142b02011-06-07 17:59:07 +0000274 port = 0;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100275 } else {
James E. King, III82ae9572017-08-05 12:23:54 -0400276 socket = stdcxx::shared_ptr<TSocket>(new TSocket(host, port));
Roger Meierca142b02011-06-07 17:59:07 +0000277 }
Bryan Duxburycd9aea12011-02-22 18:12:06 +0000278 }
Mark Sleea3302652006-10-25 19:03:32 +0000279
Roger Meierca142b02011-06-07 17:59:07 +0000280 if (transport_type.compare("http") == 0) {
James E. King, III82ae9572017-08-05 12:23:54 -0400281 stdcxx::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service"));
Roger Meierca142b02011-06-07 17:59:07 +0000282 transport = httpSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100283 } else if (transport_type.compare("framed") == 0) {
James E. King, III82ae9572017-08-05 12:23:54 -0400284 stdcxx::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000285 transport = framedSocket;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100286 } else {
James E. King, III82ae9572017-08-05 12:23:54 -0400287 stdcxx::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
Mark Sleea3302652006-10-25 19:03:32 +0000288 transport = bufferedSocket;
289 }
290
James E. King, III58402ff2017-11-17 14:41:46 -0500291 if (protocol_type == "json" || protocol_type == "multij") {
292 protocol = stdcxx::make_shared<TJSONProtocol>(transport);
293 } else if (protocol_type == "compact" || protocol_type == "multic") {
294 protocol = stdcxx::make_shared<TCompactProtocol>(transport);
295 } else if (protocol_type == "header" || protocol_type == "multih") {
296 protocol = stdcxx::make_shared<THeaderProtocol>(transport);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100297 } else {
James E. King, III58402ff2017-11-17 14:41:46 -0500298 protocol = stdcxx::make_shared<TBinaryProtocol>(transport);
299 }
300
301 if (boost::starts_with(protocol_type, "multi")) {
James E. King, III39eaae62017-11-19 20:17:33 -0500302 protocol2 = stdcxx::make_shared<TMultiplexedProtocol>(protocol, "SecondService");
303 // we don't need access to the original protocol any more, so...
304 protocol = stdcxx::make_shared<TMultiplexedProtocol>(protocol, "ThriftTest");
Roger Meierca142b02011-06-07 17:59:07 +0000305 }
306
307 // Connection info
pavlodd08f6e2015-10-08 16:43:56 -0400308 cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: ";
309 if (abstract_namespace) {
310 cout << '@';
311 }
312 cout << domain_socket;
Roger Meierca142b02011-06-07 17:59:07 +0000313 if (port != 0) {
314 cout << host << ":" << port;
315 }
316 cout << endl;
317
Roger Meier7e056e72011-07-17 07:28:28 +0000318 if (transport_type.compare("evhttp") == 0) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100319 event_base* base = event_base_new();
Roger Meier7e056e72011-07-17 07:28:28 +0000320 cout << "Libevent Version: " << event_get_version() << endl;
321 cout << "Libevent Method: " << event_base_get_method(base) << endl;
322#if LIBEVENT_VERSION_NUMBER >= 0x02000000
323 cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl;
324#endif
325
James E. King, III82ae9572017-08-05 12:23:54 -0400326 stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
Roger Meier7e056e72011-07-17 07:28:28 +0000327
James E. King, III82ae9572017-08-05 12:23:54 -0400328 stdcxx::shared_ptr<TAsyncChannel> channel(
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100329 new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base));
Roger Meier7e056e72011-07-17 07:28:28 +0000330 ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get());
James E. King, III82ae9572017-08-05 12:23:54 -0400331 client->testVoid(stdcxx::bind(testVoid_clientReturn,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100332 base,
James E. King, III82ae9572017-08-05 12:23:54 -0400333 stdcxx::placeholders::_1));
Jake Farrell5d02b802014-01-07 21:42:01 -0500334
Roger Meier7e056e72011-07-17 07:28:28 +0000335 event_base_loop(base, 0);
336 return 0;
337 }
338
Roger Meierca142b02011-06-07 17:59:07 +0000339 ThriftTestClient testClient(protocol);
Mark Sleed788b2e2006-09-07 01:26:35 +0000340
341 uint64_t time_min = 0;
342 uint64_t time_max = 0;
343 uint64_t time_tot = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000344
Mark Sleee8540632006-05-30 09:24:40 +0000345 int test = 0;
346 for (test = 0; test < numTests; ++test) {
Mark Slee95771002006-06-07 06:53:25 +0000347
Mark Slee95771002006-06-07 06:53:25 +0000348 try {
Mark Sleea3302652006-10-25 19:03:32 +0000349 transport->open();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900350 } catch (TTransportException& ex) {
351 cout << "Connect failed: " << ex.what() << endl;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900352 return ERR_UNKNOWN;
Mark Sleee8540632006-05-30 09:24:40 +0000353 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000354
Mark Sleed788b2e2006-09-07 01:26:35 +0000355 /**
356 * CONNECT TEST
357 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100358 printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port);
Mark Slee95771002006-06-07 06:53:25 +0000359
360 uint64_t start = now();
David Reiss0c90f6f2008-02-06 22:18:40 +0000361
Mark Sleee8540632006-05-30 09:24:40 +0000362 /**
363 * VOID TEST
364 */
Mark Sleee129a2d2007-02-21 05:17:48 +0000365 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900366 cout << "testVoid()" << flush;
Mark Sleee129a2d2007-02-21 05:17:48 +0000367 testClient.testVoid();
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900368 cout << " = void" << endl;
369 } catch (TTransportException&) {
370 // Stop here if transport got broken
371 throw;
372 } catch (exception& ex) {
373 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200374 return_code |= ERR_BASETYPES;
Mark Sleee129a2d2007-02-21 05:17:48 +0000375 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000376
Mark Sleee8540632006-05-30 09:24:40 +0000377 /**
378 * STRING TEST
379 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900380 cout << "testString(\"Test\")" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000381 string s;
382 testClient.testString(s, "Test");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900383 cout << " = " << s << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200384 if (s != "Test") {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900385 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200386 return_code |= ERR_BASETYPES;
387 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000388
James E. King, III58402ff2017-11-17 14:41:46 -0500389 //
390 // Multiplexed protocol - call another service method
391 // in the middle of the ThriftTest
392 //
393 if (boost::starts_with(protocol_type, "multi")) {
James E. King, III39eaae62017-11-19 20:17:33 -0500394 SecondServiceClient ssc(protocol2);
395 // transport is already open...
396
James E. King, III58402ff2017-11-17 14:41:46 -0500397 try {
398 cout << "secondService.secondTestString(\"foo\") => " << flush;
James E. King, III39eaae62017-11-19 20:17:33 -0500399 std::string result;
400 ssc.secondtestString(result, "foo");
401 cout << "{" << result << "}" << endl;
402 } catch (std::exception& e) {
403 cout << " *** FAILED *** " << e.what() << endl;
404 return_code |= ERR_EXCEPTIONS;
405 }
James E. King, III58402ff2017-11-17 14:41:46 -0500406 }
407
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900408 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500409#ifdef _MSC_VER
410#pragma warning( push )
411#pragma warning( disable : 4566 )
412#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900413 string str(
414 "}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, "
415 "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, "
416 "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, "
417 "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, "
418 "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, "
419 "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, "
420 "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, "
421 "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, "
422 "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, "
423 "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, "
424 "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, "
425 "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, "
426 "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, "
427 "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa "
428 "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa "
429 "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪"
430 "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, "
431 "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, "
432 "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, "
433 "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple "
434 "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, "
435 "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, "
436 "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, "
437 "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, "
438 "Bân-lâm-gú, 粵語");
James E. King, III7edc8fa2017-01-20 10:11:41 -0500439#ifdef _MSC_VER
440#pragma warning( pop )
441#endif
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900442 cout << "testString(" << str << ") = " << flush;
443 testClient.testString(s, str);
444 cout << s << endl;
445 if (s != str) {
446 cout.imbue(locale("en_US.UTF8"));
447 cout << "*** FAILED ***" << endl << "Expected string: " << str << " but got: " << s << endl << "CLEAR";
448 return_code |= ERR_BASETYPES;
449 }
450 } catch (TTransportException&) {
451 throw;
452 } catch (exception& ex) {
453 cout << "*** FAILED ***" << endl << ex.what() << endl;
454 return_code |= ERR_BASETYPES;
455 return return_code;
456 }
457 try {
458 string str(
459 "quote: \" backslash:"
460 " forwardslash-escaped: \\/ "
461 " backspace: \b formfeed: \f newline: \n return: \r tab: "
462 " now-all-of-them-together: \"\\\\/\b\n\r\t"
463 " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><"
464 " char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ ");
465 cout << "testString(" << str << ") = " << flush;
466 testClient.testString(s, str);
467 cout << s << endl;
468 if (s != str) {
469 cout.imbue(locale("en_US.UTF8"));
470 cout << "*** FAILED ***" << endl
471 << "Expected string: " << str << " but got: " << s << endl
472 << "CLEAR";
473 ;
474 return_code |= ERR_BASETYPES;
475 }
476 } catch (TTransportException&) {
477 throw;
478 } catch (exception& ex) {
479 cout << "*** FAILED ***" << endl << ex.what() << endl;
480 return_code |= ERR_BASETYPES;
481 return return_code;
482 }
483
Mark Sleee8540632006-05-30 09:24:40 +0000484 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900485 * BOOL TEST
486 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900487 cout << boolalpha;
488 BASETYPE_IDENTITY_TEST(testBool, true);
489 BASETYPE_IDENTITY_TEST(testBool, false);
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900490
491 /**
Mark Sleee8540632006-05-30 09:24:40 +0000492 * BYTE TEST
493 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900494 BASETYPE_IDENTITY_TEST(testByte, (int8_t)0);
495 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-1);
496 BASETYPE_IDENTITY_TEST(testByte, (int8_t)42);
497 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-42);
498 BASETYPE_IDENTITY_TEST(testByte, (int8_t)127);
499 BASETYPE_IDENTITY_TEST(testByte, (int8_t)-128);
David Reiss0c90f6f2008-02-06 22:18:40 +0000500
Mark Sleee8540632006-05-30 09:24:40 +0000501 /**
502 * I32 TEST
503 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900504 BASETYPE_IDENTITY_TEST(testI32, 0);
505 BASETYPE_IDENTITY_TEST(testI32, -1);
506 BASETYPE_IDENTITY_TEST(testI32, 190000013);
507 BASETYPE_IDENTITY_TEST(testI32, -190000013);
508 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::max());
509 BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::min());
Mark Sleee8540632006-05-30 09:24:40 +0000510
511 /**
Mark Sleee8540632006-05-30 09:24:40 +0000512 * I64 TEST
513 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900514 BASETYPE_IDENTITY_TEST(testI64, (int64_t)0);
515 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1);
516 BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL);
517 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500518 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32));
519 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32));
520 BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32) + 1);
521 BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32) - 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900522 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::max());
523 BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::min());
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100524
Mark Sleec98d0502006-09-06 02:42:25 +0000525 /**
526 * DOUBLE TEST
527 */
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900528 // Comparing double values with plain equality because Thrift handles full precision of double
529 BASETYPE_IDENTITY_TEST(testDouble, 0.0);
530 BASETYPE_IDENTITY_TEST(testDouble, -1.0);
531 BASETYPE_IDENTITY_TEST(testDouble, -5.2098523);
532 BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279);
James E. King, III7edc8fa2017-01-20 10:11:41 -0500533 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32));
534 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32) + 1);
535 BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 53) - 1);
536 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32));
537 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32) - 1);
538 BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 53) + 1);
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900539
540 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500541 double expected = pow(static_cast<double>(10), 307);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900542 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900543 double actual = testClient.testDouble(expected);
544 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500545 if (expected - actual > pow(static_cast<double>(10), 292)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900546 cout << "*** FAILED ***" << endl
547 << "Expected: " << expected << " but got: " << actual << endl;
548 }
549 } catch (TTransportException&) {
550 throw;
551 } catch (exception& ex) {
552 cout << "*** FAILED ***" << endl << ex.what() << endl;
553 return_code |= ERR_BASETYPES;
554 }
555
556 try {
James E. King, III7edc8fa2017-01-20 10:11:41 -0500557 double expected = pow(static_cast<double>(10), -292);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900558 cout << "testDouble(" << expected << ") = " << flush;
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900559 double actual = testClient.testDouble(expected);
560 cout << "(" << actual << ")" << endl;
James E. King, III7edc8fa2017-01-20 10:11:41 -0500561 if (expected - actual > pow(static_cast<double>(10), -307)) {
Nobuaki Sukegawa228b3282015-10-10 03:11:49 +0900562 cout << "*** FAILED ***" << endl
563 << "Expected: " << expected << " but got: " << actual << endl;
564 }
565 } catch (TTransportException&) {
566 throw;
567 } catch (exception& ex) {
568 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200569 return_code |= ERR_BASETYPES;
570 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000571
Mark Sleee8540632006-05-30 09:24:40 +0000572 /**
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100573 * BINARY TEST
574 */
James E. King, III39eaae62017-11-19 20:17:33 -0500575 for (string::size_type i = 0; i < 131073 && !return_code; ) {
576 return_code |= binary_test(testClient, i);
577 if (i > 0) { i *= 2; } else { ++i; }
Jens Geyerd629ea02015-09-23 21:16:50 +0200578 }
579
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100580
581 /**
Mark Sleee8540632006-05-30 09:24:40 +0000582 * STRUCT TEST
583 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900584 cout << "testStruct({\"Zero\", 1, -3, -5})" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000585 Xtruct out;
586 out.string_thing = "Zero";
587 out.byte_thing = 1;
Mark Sleee8540632006-05-30 09:24:40 +0000588 out.i32_thing = -3;
Mark Sleee8540632006-05-30 09:24:40 +0000589 out.i64_thing = -5;
Mark Slee1921d202007-01-24 19:43:06 +0000590 Xtruct in;
591 testClient.testStruct(in, out);
Roger Meier0e814802014-01-17 21:07:58 +0100592 printf(" = {\"%s\", %d, %d, %" PRId64 "}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000593 in.string_thing.c_str(),
594 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000595 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000596 in.i64_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200597 if (in != out) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900598 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200599 return_code |= ERR_STRUCTS;
600 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000601
Mark Sleee8540632006-05-30 09:24:40 +0000602 /**
603 * NESTED STRUCT TEST
604 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900605 cout << "testNest({1, {\"Zero\", 1, -3, -5}), 5}" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000606 Xtruct2 out2;
607 out2.byte_thing = 1;
608 out2.struct_thing = out;
609 out2.i32_thing = 5;
Mark Slee1921d202007-01-24 19:43:06 +0000610 Xtruct2 in2;
611 testClient.testNest(in2, out2);
Mark Sleee8540632006-05-30 09:24:40 +0000612 in = in2.struct_thing;
Roger Meier0e814802014-01-17 21:07:58 +0100613 printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
Mark Sleee8540632006-05-30 09:24:40 +0000614 in2.byte_thing,
615 in.string_thing.c_str(),
616 (int)in.byte_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000617 in.i32_thing,
Mark Sleee8540632006-05-30 09:24:40 +0000618 in.i64_thing,
David Reiss0c90f6f2008-02-06 22:18:40 +0000619 in2.i32_thing);
Jens Geyerd629ea02015-09-23 21:16:50 +0200620 if (in2 != out2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900621 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200622 return_code |= ERR_STRUCTS;
623 }
Mark Sleee8540632006-05-30 09:24:40 +0000624
625 /**
626 * MAP TEST
627 */
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100628 map<int32_t, int32_t> mapout;
Mark Sleee8540632006-05-30 09:24:40 +0000629 for (int32_t i = 0; i < 5; ++i) {
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100630 mapout.insert(make_pair(i, i - 10));
Mark Sleee8540632006-05-30 09:24:40 +0000631 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900632 cout << "testMap({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000633 map<int32_t, int32_t>::const_iterator m_iter;
634 bool first = true;
635 for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) {
636 if (first) {
637 first = false;
638 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900639 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000640 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900641 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000642 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900643 cout << "})";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100644 map<int32_t, int32_t> mapin;
Mark Slee1921d202007-01-24 19:43:06 +0000645 testClient.testMap(mapin, mapout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900646 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000647 first = true;
648 for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) {
649 if (first) {
650 first = false;
651 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900652 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000653 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900654 cout << m_iter->first << " => " << m_iter->second;
Mark Sleee8540632006-05-30 09:24:40 +0000655 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900656 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200657 if (mapin != mapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900658 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200659 return_code |= ERR_CONTAINERS;
660 }
Roger Meier4fce9602012-05-04 06:22:09 +0000661
662 /**
663 * STRING MAP TEST
Roger Meier4fce9602012-05-04 06:22:09 +0000664 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900665 cout << "testStringMap({a => 2, b => blah, some => thing}) = {" << flush;
Jens Geyerd629ea02015-09-23 21:16:50 +0200666 map<string, string> smapin;
667 map<string, string> smapout;
668 smapin["a"] = "2";
669 smapin["b"] = "blah";
670 smapin["some"] = "thing";
671 try {
672 testClient.testStringMap(smapout, smapin);
673 first = true;
674 for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) {
675 if (first)
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900676 cout << ",";
Jens Geyerd629ea02015-09-23 21:16:50 +0200677 else
678 first = false;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900679 cout << it->first << " => " << it->second;
Jens Geyerd629ea02015-09-23 21:16:50 +0200680 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900681 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200682 if (smapin != smapout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900683 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200684 return_code |= ERR_CONTAINERS;
685 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900686 } catch (TTransportException&) {
687 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200688 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900689 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200690 return_code |= ERR_CONTAINERS;
691 }
Mark Sleee8540632006-05-30 09:24:40 +0000692
693 /**
694 * SET TEST
695 */
696 set<int32_t> setout;
697 for (int32_t i = -2; i < 3; ++i) {
698 setout.insert(i);
699 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900700 cout << "testSet({" << flush;
Mark Sleee8540632006-05-30 09:24:40 +0000701 set<int32_t>::const_iterator s_iter;
702 first = true;
703 for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) {
704 if (first) {
705 first = false;
706 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900707 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000708 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900709 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000710 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900711 cout << "})";
Mark Slee1921d202007-01-24 19:43:06 +0000712 set<int32_t> setin;
713 testClient.testSet(setin, setout);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900714 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000715 first = true;
716 for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) {
717 if (first) {
718 first = false;
719 } else {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900720 cout << ",";
Mark Sleee8540632006-05-30 09:24:40 +0000721 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900722 cout << *s_iter;
Mark Sleee8540632006-05-30 09:24:40 +0000723 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900724 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200725 if (setin != setout) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900726 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200727 return_code |= ERR_CONTAINERS;
728 }
Mark Sleee8540632006-05-30 09:24:40 +0000729
730 /**
731 * LIST TEST
732 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900733 cout << "testList(empty)" << flush;
734 try {
735 vector<int32_t> listout;
736 testClient.testList(listout, vector<int32_t>());
737 if (!listout.empty()) {
738 cout << "*** FAILED ***" << endl;
739 cout << "invalid length: " << listout.size() << endl;
740 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000741 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900742 } catch (TTransportException&) {
743 throw;
744 } catch (exception& ex) {
745 cout << "*** FAILED ***" << endl << ex.what() << endl;
746 return_code |= ERR_CONTAINERS;
Mark Sleee8540632006-05-30 09:24:40 +0000747 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900748 try {
749 vector<int32_t> listout;
750 for (int32_t i = -2; i < 3; ++i) {
751 listout.push_back(i);
Mark Sleee8540632006-05-30 09:24:40 +0000752 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900753 cout << "testList({" << flush;
754 vector<int32_t>::const_iterator l_iter;
755 first = true;
756 for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) {
757 if (first) {
758 first = false;
759 } else {
760 cout << ",";
761 }
762 cout << *l_iter;
763 }
764 cout << "})";
765 vector<int32_t> listin;
766 testClient.testList(listin, listout);
767 cout << " = {";
768 first = true;
769 for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) {
770 if (first) {
771 first = false;
772 } else {
773 cout << ",";
774 }
775 cout << *l_iter;
776 }
777 cout << "}" << endl;
778 if (listin != listout) {
779 cout << "*** FAILED ***" << endl;
780 return_code |= ERR_CONTAINERS;
781 }
782 } catch (TTransportException&) {
783 throw;
784 } catch (exception& ex) {
785 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200786 return_code |= ERR_CONTAINERS;
787 }
Mark Sleee8540632006-05-30 09:24:40 +0000788
789 /**
790 * ENUM TEST
791 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900792 cout << "testEnum(ONE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000793 Numberz::type ret = testClient.testEnum(Numberz::ONE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900794 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200795 if (ret != Numberz::ONE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900796 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200797 return_code |= ERR_STRUCTS;
798 }
Mark Sleee8540632006-05-30 09:24:40 +0000799
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900800 cout << "testEnum(TWO)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000801 ret = testClient.testEnum(Numberz::TWO);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900802 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200803 if (ret != Numberz::TWO) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900804 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200805 return_code |= ERR_STRUCTS;
806 }
Mark Sleee8540632006-05-30 09:24:40 +0000807
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900808 cout << "testEnum(THREE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000809 ret = testClient.testEnum(Numberz::THREE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900810 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200811 if (ret != Numberz::THREE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900812 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200813 return_code |= ERR_STRUCTS;
814 }
Mark Sleee8540632006-05-30 09:24:40 +0000815
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900816 cout << "testEnum(FIVE)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000817 ret = testClient.testEnum(Numberz::FIVE);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900818 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200819 if (ret != Numberz::FIVE) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900820 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200821 return_code |= ERR_STRUCTS;
822 }
Mark Sleee8540632006-05-30 09:24:40 +0000823
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900824 cout << "testEnum(EIGHT)" << flush;
Bryan Duxbury833ae492010-09-27 17:26:02 +0000825 ret = testClient.testEnum(Numberz::EIGHT);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900826 cout << " = " << ret << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200827 if (ret != Numberz::EIGHT) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900828 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200829 return_code |= ERR_STRUCTS;
830 }
Mark Sleee8540632006-05-30 09:24:40 +0000831
832 /**
833 * TYPEDEF TEST
834 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900835 cout << "testTypedef(309858235082523)" << flush;
Marc Slemkobf4fd192006-08-15 21:29:39 +0000836 UserId uid = testClient.testTypedef(309858235082523LL);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900837 cout << " = " << uid << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200838 if (uid != 309858235082523LL) {
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 * NESTED MAP TEST
845 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900846 cout << "testMapMap(1)" << flush;
Mark Slee1921d202007-01-24 19:43:06 +0000847 map<int32_t, map<int32_t, int32_t> > mm;
848 testClient.testMapMap(mm, 1);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900849 cout << " = {";
Mark Sleee8540632006-05-30 09:24:40 +0000850 map<int32_t, map<int32_t, int32_t> >::const_iterator mi;
851 for (mi = mm.begin(); mi != mm.end(); ++mi) {
852 printf("%d => {", mi->first);
853 map<int32_t, int32_t>::const_iterator mi2;
854 for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900855 cout << mi2->first << " => " << mi2->second;
Mark Sleee8540632006-05-30 09:24:40 +0000856 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900857 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000858 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900859 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200860 if (mm.size() != 2 ||
861 mm[-4][-4] != -4 ||
862 mm[-4][-3] != -3 ||
863 mm[-4][-2] != -2 ||
864 mm[-4][-1] != -1 ||
865 mm[4][4] != 4 ||
866 mm[4][3] != 3 ||
867 mm[4][2] != 2 ||
868 mm[4][1] != 1) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900869 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200870 return_code |= ERR_CONTAINERS;
871 }
Mark Sleee8540632006-05-30 09:24:40 +0000872
873 /**
874 * INSANITY TEST
875 */
Jens Geyerf4598682014-05-08 23:18:44 +0200876 if (!noinsane) {
877 Insanity insane;
Jens Geyerd629ea02015-09-23 21:16:50 +0200878 insane.userMap.insert(make_pair(Numberz::FIVE, 5));
879 insane.userMap.insert(make_pair(Numberz::EIGHT, 8));
Jens Geyerf4598682014-05-08 23:18:44 +0200880 Xtruct truck;
Jens Geyerd629ea02015-09-23 21:16:50 +0200881 truck.string_thing = "Goodbye4";
882 truck.byte_thing = 4;
883 truck.i32_thing = 4;
884 truck.i64_thing = 4;
885 Xtruct truck2;
886 truck2.string_thing = "Hello2";
887 truck2.byte_thing = 2;
888 truck2.i32_thing = 2;
889 truck2.i64_thing = 2;
Jens Geyerf4598682014-05-08 23:18:44 +0200890 insane.xtructs.push_back(truck);
Jens Geyerd629ea02015-09-23 21:16:50 +0200891 insane.xtructs.push_back(truck2);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900892 cout << "testInsanity()" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100893 map<UserId, map<Numberz::type, Insanity> > whoa;
Jens Geyerf4598682014-05-08 23:18:44 +0200894 testClient.testInsanity(whoa, insane);
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900895 cout << " = {";
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100896 map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
Jens Geyerf4598682014-05-08 23:18:44 +0200897 for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
898 printf("%" PRId64 " => {", i_iter->first);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100899 map<Numberz::type, Insanity>::const_iterator i2_iter;
900 for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
Jens Geyerf4598682014-05-08 23:18:44 +0200901 printf("%d => {", i2_iter->first);
902 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
903 map<Numberz::type, UserId>::const_iterator um;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900904 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200905 for (um = userMap.begin(); um != userMap.end(); ++um) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900906 cout << um->first << " => " << um->second;
Jens Geyerf4598682014-05-08 23:18:44 +0200907 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900908 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000909
Jens Geyerf4598682014-05-08 23:18:44 +0200910 vector<Xtruct> xtructs = i2_iter->second.xtructs;
911 vector<Xtruct>::const_iterator x;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900912 cout << "{";
Jens Geyerf4598682014-05-08 23:18:44 +0200913 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
914 printf("{\"%s\", %d, %d, %" PRId64 "}, ",
915 x->string_thing.c_str(),
916 (int)x->byte_thing,
917 x->i32_thing,
918 x->i64_thing);
919 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900920 cout << "}";
Mark Sleee8540632006-05-30 09:24:40 +0000921
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900922 cout << "}, ";
Jens Geyerf4598682014-05-08 23:18:44 +0200923 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900924 cout << "}, ";
Mark Sleee8540632006-05-30 09:24:40 +0000925 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900926 cout << "}" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200927 bool failed = false;
928 map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1));
929 if (whoa.size() != 2) {
930 failed = true;
931 }
932 if (it1 == whoa.end()) {
933 failed = true;
934 } else {
935 map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO);
936 if (it12 == it1->second.end() || it12->second != insane) {
937 failed = true;
938 }
939 map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE);
940 if (it13 == it1->second.end() || it13->second != insane) {
941 failed = true;
942 }
943 }
944 map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2));
945 if (it2 == whoa.end()) {
946 failed = true;
947 } else {
948 map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX);
James E. King IIIf5f430d2018-06-08 03:37:55 +0000949 if (it26 == it2->second.end() || it26->second != Insanity()) {
Jens Geyerd629ea02015-09-23 21:16:50 +0200950 failed = true;
951 }
952 }
953 if (failed) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900954 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200955 return_code |= ERR_STRUCTS;
956 }
Mark Sleee8540632006-05-30 09:24:40 +0000957 }
Jens Geyerd629ea02015-09-23 21:16:50 +0200958
959 /**
960 * MULTI TEST
961 */
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900962 cout << "testMulti()" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200963 try {
964 map<int16_t, string> mul_map;
965 Xtruct mul_result;
966 mul_map[1] = "blah";
967 mul_map[2] = "thing";
968 testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24));
969 Xtruct xxs;
970 xxs.string_thing = "Hello2";
971 xxs.byte_thing = 42;
972 xxs.i32_thing = 4242;
973 xxs.i64_thing = 424242;
974 if (mul_result != xxs) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900975 cout << "*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200976 return_code |= ERR_STRUCTS;
977 }
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900978 } catch (TTransportException&) {
979 throw;
Jens Geyerd629ea02015-09-23 21:16:50 +0200980 } catch (exception& ex) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900981 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200982 return_code |= ERR_STRUCTS;
983 }
984
Marc Slemko71d4e472006-08-15 22:34:04 +0000985 /* test exception */
Mark Slee95771002006-06-07 06:53:25 +0000986
Marc Slemkobf4fd192006-08-15 21:29:39 +0000987 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900988 cout << "testClient.testException(\"Xception\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +0000989 testClient.testException("Xception");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900990 cout << " void\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +0200991 return_code |= ERR_EXCEPTIONS;
David Reiss0c90f6f2008-02-06 22:18:40 +0000992
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100993 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +0000994 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +0000995 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000996
Marc Slemkobf4fd192006-08-15 21:29:39 +0000997 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +0900998 cout << "testClient.testException(\"TException\") =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100999 testClient.testException("TException");
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;
Roger Meierf50df7f2012-05-02 22:49:55 +00001002
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001003 } catch (const TException&) {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001004 cout << " Caught TException" << endl;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001005 }
Roger Meierf50df7f2012-05-02 22:49:55 +00001006
1007 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001008 cout << "testClient.testException(\"success\") =>" << flush;
Marc Slemko71d4e472006-08-15 22:34:04 +00001009 testClient.testException("success");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001010 cout << " void" << endl;
1011 } catch (exception & ex) { \
1012 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001013 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001014 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001015
Marc Slemko71d4e472006-08-15 22:34:04 +00001016 /* test multi exception */
David Reiss0c90f6f2008-02-06 22:18:40 +00001017
Marc Slemko71d4e472006-08-15 22:34:04 +00001018 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001019 cout << "testClient.testMultiException(\"Xception\", \"test 1\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001020 Xtruct result;
1021 testClient.testMultiException(result, "Xception", "test 1");
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001022 cout << " result\n*** FAILED ***" << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001023 return_code |= ERR_EXCEPTIONS;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001024 } catch (Xception& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001025 printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
1026 }
1027
1028 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001029 cout << "testClient.testMultiException(\"Xception2\", \"test 2\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001030 Xtruct result;
1031 testClient.testMultiException(result, "Xception2", "test 2");
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;
David Reiss0c90f6f2008-02-06 22:18:40 +00001034
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001035 } catch (Xception2& e) {
Marc Slemko71d4e472006-08-15 22:34:04 +00001036 printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
Marc Slemkobf4fd192006-08-15 21:29:39 +00001037 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001038
Marc Slemko71d4e472006-08-15 22:34:04 +00001039 try {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001040 cout << "testClient.testMultiException(\"success\", \"test 3\") =>" << flush;
Mark Slee1921d202007-01-24 19:43:06 +00001041 Xtruct result;
1042 testClient.testMultiException(result, "success", "test 3");
Marc Slemko71d4e472006-08-15 22:34:04 +00001043 printf(" {{\"%s\"}}\n", result.string_thing.c_str());
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001044 } catch (exception & ex) { \
1045 cout << "*** FAILED ***" << endl << ex.what() << endl;
Jens Geyerd629ea02015-09-23 21:16:50 +02001046 return_code |= ERR_EXCEPTIONS;
Marc Slemko71d4e472006-08-15 22:34:04 +00001047 }
David Reiss0c90f6f2008-02-06 22:18:40 +00001048
David Reissc51986f2009-03-24 20:01:25 +00001049 /* test oneway void */
David Reiss2ab6fe82008-02-18 02:11:44 +00001050 {
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001051 cout << "testClient.testOneway(1) =>" << flush;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001052 uint64_t startOneway = now();
1053 testClient.testOneway(1);
1054 uint64_t elapsed = now() - startOneway;
1055 if (elapsed > 200 * 1000) { // 0.2 seconds
Jens Geyerd629ea02015-09-23 21:16:50 +02001056 printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0);
1057 return_code |= ERR_BASETYPES;
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001058 } else {
1059 printf(" success - took %.2f ms\n", (double)elapsed / 1000.0);
1060 }
David Reiss2ab6fe82008-02-18 02:11:44 +00001061 }
1062
David Reiss2845b522008-02-18 02:11:52 +00001063 /**
David Reissc51986f2009-03-24 20:01:25 +00001064 * redo a simple test after the oneway to make sure we aren't "off by one" --
1065 * if the server treated oneway void like normal void, this next test will
David Reiss2845b522008-02-18 02:11:52 +00001066 * fail since it will get the void confirmation rather than the correct
1067 * result. In this circumstance, the client will throw the exception:
1068 *
1069 * TApplicationException: Wrong method namea
1070 */
1071 /**
1072 * I32 TEST
1073 */
James E. King, III58402ff2017-11-17 14:41:46 -05001074 cout << "re-test testI32(-1)" << flush;
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001075 int i32 = testClient.testI32(-1);
1076 cout << " = " << i32 << endl;
Roger Meier4fce9602012-05-04 06:22:09 +00001077 if (i32 != -1)
Jens Geyerd629ea02015-09-23 21:16:50 +02001078 return_code |= ERR_BASETYPES;
David Reiss2845b522008-02-18 02:11:52 +00001079
James E. King, III58402ff2017-11-17 14:41:46 -05001080 cout << endl << "All tests done." << endl << flush;
James E. King, III39eaae62017-11-19 20:17:33 -05001081
Marc Slemkobf4fd192006-08-15 21:29:39 +00001082 uint64_t stop = now();
Konrad Grochowski16a23a62014-11-13 15:33:38 +01001083 uint64_t tot = stop - start;
Mark Sleed788b2e2006-09-07 01:26:35 +00001084
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001085 cout << "Total time: " << stop - start << " us" << endl;
David Reiss0c90f6f2008-02-06 22:18:40 +00001086
Mark Sleed788b2e2006-09-07 01:26:35 +00001087 time_tot += tot;
1088 if (time_min == 0 || tot < time_min) {
1089 time_min = tot;
1090 }
1091 if (tot > time_max) {
1092 time_max = tot;
1093 }
1094
James E. King, III58402ff2017-11-17 14:41:46 -05001095 cout << flush;
Mark Sleea3302652006-10-25 19:03:32 +00001096 transport->close();
Mark Sleee8540632006-05-30 09:24:40 +00001097 }
1098
Mark Sleed788b2e2006-09-07 01:26:35 +00001099
1100 uint64_t time_avg = time_tot / numTests;
1101
Nobuaki Sukegawa9b35a7c2015-11-17 11:01:41 +09001102 cout << "Min time: " << time_min << " us" << endl;
1103 cout << "Max time: " << time_max << " us" << endl;
1104 cout << "Avg time: " << time_avg << " us" << endl;
Mark Sleed788b2e2006-09-07 01:26:35 +00001105
Jens Geyerd629ea02015-09-23 21:16:50 +02001106 return return_code;
Mark Sleee8540632006-05-30 09:24:40 +00001107}
James E. King, III39eaae62017-11-19 20:17:33 -05001108
1109void binary_fill(std::string& str, string::size_type siz)
1110{
1111 static const signed char bin_data[256]
1112 = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114,
1113 -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99,
1114 -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84,
1115 -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69,
1116 -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54,
1117 -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39,
1118 -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24,
1119 -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9,
1120 -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6,
1121 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
1122 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
1123 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
1124 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
1125 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
1126 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
1127 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
1128 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
1129 127};
1130
1131 str.resize(siz);
1132 char *ptr = &str[0];
1133 string::size_type pos = 0;
1134 for (string::size_type i = 0; i < siz; ++i)
1135 {
1136 if (pos == 255) { pos = 0; } else { ++pos; }
1137 *ptr++ = bin_data[pos];
1138 }
1139}
1140
1141int binary_test(ThriftTestClient& testClient, string::size_type siz)
1142{
1143 string bin_request;
1144 string bin_result;
1145
1146 cout << "testBinary(siz = " << siz << ")" << endl;
1147 binary_fill(bin_request, siz);
1148 try {
1149 testClient.testBinary(bin_result, bin_request);
1150
1151 if (bin_request.size() != bin_result.size()) {
1152 cout << "*** FAILED: request size " << bin_request.size() << "; result size " << bin_result.size() << endl;
1153 return ERR_BASETYPES;
1154 }
1155
1156 for (string::size_type i = 0; i < siz; ++i) {
1157 if (bin_request.at(i) != bin_result.at(i)) {
1158 cout << "*** FAILED: at position " << i << " request[i] is h" << hex << bin_request.at(i) << " result[i] is h" << hex << bin_result.at(i) << endl;
1159 return ERR_BASETYPES;
1160 }
1161 }
1162 } catch (TTransportException&) {
1163 throw;
1164 } catch (exception& ex) {
1165 cout << "*** FAILED ***" << endl << ex.what() << endl;
1166 return ERR_BASETYPES;
1167 }
1168
1169 return 0;
1170}