James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 1 | /* |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 20 | #include <limits> |
| 21 | #include <locale> |
| 22 | #include <ios> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 23 | #include <iostream> |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 24 | #include <sstream> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 25 | #include <thrift/protocol/TBinaryProtocol.h> |
Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 26 | #include <thrift/protocol/TCompactProtocol.h> |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 27 | #include <thrift/protocol/THeaderProtocol.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 28 | #include <thrift/protocol/TJSONProtocol.h> |
| 29 | #include <thrift/transport/THttpClient.h> |
| 30 | #include <thrift/transport/TTransportUtils.h> |
| 31 | #include <thrift/transport/TSocket.h> |
| 32 | #include <thrift/transport/TSSLSocket.h> |
| 33 | #include <thrift/async/TEvhttpClientChannel.h> |
| 34 | #include <thrift/server/TNonblockingServer.h> // <event.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 35 | |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 36 | #ifdef HAVE_STDINT_H |
| 37 | #include <stdint.h> |
| 38 | #endif |
| 39 | #ifdef HAVE_INTTYPES_H |
| 40 | #include <inttypes.h> |
| 41 | #endif |
| 42 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 43 | #include <boost/shared_ptr.hpp> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 44 | #include <boost/program_options.hpp> |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 45 | #include <boost/filesystem.hpp> |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 46 | #include <thrift/cxxfunctional.h> |
| 47 | #if _WIN32 |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 48 | #include <thrift/windows/TWinsockSingleton.h> |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 49 | #endif |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 50 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 51 | #include "ThriftTest.h" |
| 52 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 53 | using namespace std; |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 54 | using namespace apache::thrift; |
| 55 | using namespace apache::thrift::protocol; |
| 56 | using namespace apache::thrift::transport; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 57 | using namespace thrift::test; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 58 | using namespace apache::thrift::async; |
| 59 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 60 | // Current time, microseconds since the epoch |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 61 | uint64_t now() { |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 62 | int64_t ret; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 63 | struct timeval tv; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 64 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 65 | THRIFT_GETTIMEOFDAY(&tv, NULL); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 66 | ret = tv.tv_sec; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 67 | ret = ret * 1000 * 1000 + tv.tv_usec; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 68 | return ret; |
| 69 | } |
| 70 | |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 71 | static void testString_clientReturn(event_base* base, |
| 72 | int testNr, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 73 | ThriftTestCobClient* client) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 74 | try { |
| 75 | string s; |
| 76 | client->recv_testString(s); |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 77 | std::ostringstream os; |
| 78 | os << "test" << testNr; |
| 79 | const bool ok = (s == os.str()); |
| 80 | cout << "testString: " << s << " " << ((ok) ? "ok" : "failed") << endl; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 81 | } catch (TException& exn) { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 82 | cout << "Error: " << exn.what() << endl; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 85 | if (testNr == 9) |
| 86 | event_base_loopbreak(base); // end test |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 89 | static void testVoid_clientReturn(event_base* base, ThriftTestCobClient* client) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 90 | try { |
| 91 | client->recv_testVoid(); |
| 92 | cout << "testVoid" << endl; |
| 93 | |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 94 | for (int testNr = 0; testNr < 10; ++testNr) { |
| 95 | std::ostringstream os; |
| 96 | os << "test" << testNr; |
| 97 | client->testString(tcxx::bind(testString_clientReturn, |
| 98 | base, |
| 99 | testNr, |
| 100 | tcxx::placeholders::_1), |
| 101 | os.str()); |
| 102 | } |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 103 | } catch (TException& exn) { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 104 | cout << "Error: " << exn.what() << endl; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 108 | // Workaround for absense of C++11 "auto" keyword. |
| 109 | template <typename T> |
| 110 | bool print_eq(T expected, T actual) { |
| 111 | cout << "(" << actual << ")" << endl; |
| 112 | if (expected != actual) { |
| 113 | cout << "*** FAILED ***" << endl << "Expected: " << expected << " but got: " << actual << endl; |
| 114 | return false; |
| 115 | } |
| 116 | return true; |
| 117 | } |
| 118 | |
| 119 | #define BASETYPE_IDENTITY_TEST(func, value) \ |
| 120 | cout << #func "(" << value << ") = "; \ |
| 121 | try { \ |
| 122 | if (!print_eq(value, testClient.func(value))) \ |
| 123 | return_code |= ERR_BASETYPES; \ |
| 124 | } catch (TTransportException&) { \ |
| 125 | throw; \ |
| 126 | } catch (exception & ex) { \ |
| 127 | cout << "*** FAILED ***" << endl << ex.what() << endl; \ |
| 128 | return_code |= ERR_BASETYPES; \ |
| 129 | } |
| 130 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 131 | int main(int argc, char** argv) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 132 | cout.precision(19); |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 133 | int ERR_BASETYPES = 1; |
| 134 | int ERR_STRUCTS = 2; |
| 135 | int ERR_CONTAINERS = 4; |
| 136 | int ERR_EXCEPTIONS = 8; |
| 137 | int ERR_UNKNOWN = 64; |
| 138 | |
James E. King, III | 0619087 | 2017-02-20 08:52:11 -0500 | [diff] [blame] | 139 | string testDir = boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string(); |
| 140 | string caPath = testDir + "/keys/CA.pem"; |
| 141 | string certPath = testDir + "/keys/client.crt"; |
| 142 | string keyPath = testDir + "/keys/client.key"; |
| 143 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 144 | #if _WIN32 |
| 145 | transport::TWinsockSingleton::create(); |
| 146 | #endif |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 147 | string host = "localhost"; |
| 148 | int port = 9090; |
| 149 | int numTests = 1; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 150 | bool ssl = false; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 151 | string transport_type = "buffered"; |
| 152 | string protocol_type = "binary"; |
| 153 | string domain_socket = ""; |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 154 | bool abstract_namespace = false; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 155 | bool noinsane = false; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 156 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 157 | int return_code = 0; |
| 158 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 159 | boost::program_options::options_description desc("Allowed options"); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 160 | desc.add_options()("help,h", |
| 161 | "produce help message")("host", |
| 162 | boost::program_options::value<string>(&host) |
| 163 | ->default_value(host), |
| 164 | "Host to connect")("port", |
| 165 | boost::program_options::value<int>( |
| 166 | &port)->default_value(port), |
| 167 | "Port number to connect")( |
| 168 | "domain-socket", |
| 169 | boost::program_options::value<string>(&domain_socket)->default_value(domain_socket), |
| 170 | "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")( |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 171 | "abstract-namespace", |
| 172 | "Look for the domain socket in the Abstract Namespace (no connection with filesystem pathnames)")( |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 173 | "transport", |
| 174 | boost::program_options::value<string>(&transport_type)->default_value(transport_type), |
| 175 | "Transport: buffered, framed, http, evhttp")( |
| 176 | "protocol", |
| 177 | boost::program_options::value<string>(&protocol_type)->default_value(protocol_type), |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 178 | "Protocol: binary, header, compact, json")("ssl", "Encrypted Transport using SSL")( |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 179 | "testloops,n", |
| 180 | boost::program_options::value<int>(&numTests)->default_value(numTests), |
| 181 | "Number of Tests")("noinsane", "Do not run insanity test"); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 182 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 183 | boost::program_options::variables_map vm; |
| 184 | boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); |
| 185 | boost::program_options::notify(vm); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 186 | |
| 187 | if (vm.count("help")) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 188 | cout << desc << endl; |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 189 | return ERR_UNKNOWN; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 190 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 191 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 192 | try { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 193 | if (!protocol_type.empty()) { |
| 194 | if (protocol_type == "binary") { |
Roger Meier | 284101c | 2014-03-11 21:20:35 +0100 | [diff] [blame] | 195 | } else if (protocol_type == "compact") { |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 196 | } else if (protocol_type == "header") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 197 | } else if (protocol_type == "json") { |
| 198 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 199 | throw invalid_argument("Unknown protocol type " + protocol_type); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 203 | if (!transport_type.empty()) { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 204 | if (transport_type == "buffered") { |
| 205 | } else if (transport_type == "framed") { |
| 206 | } else if (transport_type == "http") { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 207 | } else if (transport_type == "evhttp") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 208 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 209 | throw invalid_argument("Unknown transport type " + transport_type); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 213 | } catch (exception& e) { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 214 | cerr << e.what() << endl; |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 215 | cout << desc << endl; |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 216 | return ERR_UNKNOWN; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | if (vm.count("ssl")) { |
| 220 | ssl = true; |
| 221 | } |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 222 | |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 223 | if (vm.count("abstract-namespace")) { |
| 224 | abstract_namespace = true; |
| 225 | } |
| 226 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 227 | if (vm.count("noinsane")) { |
| 228 | noinsane = true; |
| 229 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 230 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 231 | boost::shared_ptr<TTransport> transport; |
| 232 | boost::shared_ptr<TProtocol> protocol; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 233 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 234 | boost::shared_ptr<TSocket> socket; |
| 235 | boost::shared_ptr<TSSLSocketFactory> factory; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 236 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 237 | if (ssl) { |
James E. King, III | 0619087 | 2017-02-20 08:52:11 -0500 | [diff] [blame] | 238 | cout << "Client Certificate File: " << certPath << endl; |
| 239 | cout << "Client Key File: " << keyPath << endl; |
| 240 | cout << "CA File: " << caPath << endl; |
| 241 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 242 | factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory()); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 243 | factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
James E. King, III | 0619087 | 2017-02-20 08:52:11 -0500 | [diff] [blame] | 244 | factory->loadTrustedCertificates(caPath.c_str()); |
| 245 | factory->loadCertificate(certPath.c_str()); |
| 246 | factory->loadPrivateKey(keyPath.c_str()); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 247 | factory->authenticate(true); |
| 248 | socket = factory->createSocket(host, port); |
| 249 | } else { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 250 | if (domain_socket != "") { |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 251 | if (abstract_namespace) { |
| 252 | std::string abstract_socket("\0", 1); |
| 253 | abstract_socket += domain_socket; |
| 254 | socket = boost::shared_ptr<TSocket>(new TSocket(abstract_socket)); |
| 255 | } else { |
| 256 | socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket)); |
| 257 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 258 | port = 0; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 259 | } else { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 260 | socket = boost::shared_ptr<TSocket>(new TSocket(host, port)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 261 | } |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 262 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 263 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 264 | if (transport_type.compare("http") == 0) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 265 | boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service")); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 266 | transport = httpSocket; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 267 | } else if (transport_type.compare("framed") == 0) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 268 | boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 269 | transport = framedSocket; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 270 | } else { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 271 | boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 272 | transport = bufferedSocket; |
| 273 | } |
| 274 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 275 | if (protocol_type.compare("json") == 0) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 276 | boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 277 | protocol = jsonProtocol; |
Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 278 | } else if (protocol_type.compare("compact") == 0) { |
| 279 | boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport)); |
| 280 | protocol = compactProtocol; |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 281 | } else if (protocol_type == "header") { |
| 282 | boost::shared_ptr<TProtocol> headerProtocol(new THeaderProtocol(transport)); |
| 283 | protocol = headerProtocol; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 284 | } else { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 285 | boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 286 | protocol = binaryProtocol; |
| 287 | } |
| 288 | |
| 289 | // Connection info |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 290 | cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: "; |
| 291 | if (abstract_namespace) { |
| 292 | cout << '@'; |
| 293 | } |
| 294 | cout << domain_socket; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 295 | if (port != 0) { |
| 296 | cout << host << ":" << port; |
| 297 | } |
| 298 | cout << endl; |
| 299 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 300 | if (transport_type.compare("evhttp") == 0) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 301 | event_base* base = event_base_new(); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 302 | cout << "Libevent Version: " << event_get_version() << endl; |
| 303 | cout << "Libevent Method: " << event_base_get_method(base) << endl; |
| 304 | #if LIBEVENT_VERSION_NUMBER >= 0x02000000 |
| 305 | cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl; |
| 306 | #endif |
| 307 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 308 | boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 309 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 310 | boost::shared_ptr<TAsyncChannel> channel( |
| 311 | new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base)); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 312 | ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get()); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 313 | client->testVoid(tcxx::bind(testVoid_clientReturn, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 314 | base, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 315 | tcxx::placeholders::_1)); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 316 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 317 | event_base_loop(base, 0); |
| 318 | return 0; |
| 319 | } |
| 320 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 321 | ThriftTestClient testClient(protocol); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 322 | |
| 323 | uint64_t time_min = 0; |
| 324 | uint64_t time_max = 0; |
| 325 | uint64_t time_tot = 0; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 326 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 327 | int test = 0; |
| 328 | for (test = 0; test < numTests; ++test) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 329 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 330 | try { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 331 | transport->open(); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 332 | } catch (TTransportException& ex) { |
| 333 | cout << "Connect failed: " << ex.what() << endl; |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 334 | return ERR_UNKNOWN; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 335 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 336 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 337 | /** |
| 338 | * CONNECT TEST |
| 339 | */ |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 340 | printf("Test #%d, connect %s:%d\n", test + 1, host.c_str(), port); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 341 | |
| 342 | uint64_t start = now(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 343 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 344 | /** |
| 345 | * VOID TEST |
| 346 | */ |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 347 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 348 | cout << "testVoid()" << flush; |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 349 | testClient.testVoid(); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 350 | cout << " = void" << endl; |
| 351 | } catch (TTransportException&) { |
| 352 | // Stop here if transport got broken |
| 353 | throw; |
| 354 | } catch (exception& ex) { |
| 355 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 356 | return_code |= ERR_BASETYPES; |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 357 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 358 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 359 | /** |
| 360 | * STRING TEST |
| 361 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 362 | cout << "testString(\"Test\")" << flush; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 363 | string s; |
| 364 | testClient.testString(s, "Test"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 365 | cout << " = " << s << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 366 | if (s != "Test") { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 367 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 368 | return_code |= ERR_BASETYPES; |
| 369 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 370 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 371 | try { |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 372 | #ifdef _MSC_VER |
| 373 | #pragma warning( push ) |
| 374 | #pragma warning( disable : 4566 ) |
| 375 | #endif |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 376 | string str( |
| 377 | "}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " |
| 378 | "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " |
| 379 | "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " |
| 380 | "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " |
| 381 | "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " |
| 382 | "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " |
| 383 | "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " |
| 384 | "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " |
| 385 | "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " |
| 386 | "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " |
| 387 | "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " |
| 388 | "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " |
| 389 | "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " |
| 390 | "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " |
| 391 | "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " |
| 392 | "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, " |
| 393 | "Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, " |
| 394 | "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " |
| 395 | "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " |
| 396 | "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " |
| 397 | "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " |
| 398 | "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " |
| 399 | "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " |
| 400 | "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " |
| 401 | "Bân-lâm-gú, 粵語"); |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 402 | #ifdef _MSC_VER |
| 403 | #pragma warning( pop ) |
| 404 | #endif |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 405 | cout << "testString(" << str << ") = " << flush; |
| 406 | testClient.testString(s, str); |
| 407 | cout << s << endl; |
| 408 | if (s != str) { |
| 409 | cout.imbue(locale("en_US.UTF8")); |
| 410 | cout << "*** FAILED ***" << endl << "Expected string: " << str << " but got: " << s << endl << "CLEAR"; |
| 411 | return_code |= ERR_BASETYPES; |
| 412 | } |
| 413 | } catch (TTransportException&) { |
| 414 | throw; |
| 415 | } catch (exception& ex) { |
| 416 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
| 417 | return_code |= ERR_BASETYPES; |
| 418 | return return_code; |
| 419 | } |
| 420 | try { |
| 421 | string str( |
| 422 | "quote: \" backslash:" |
| 423 | " forwardslash-escaped: \\/ " |
| 424 | " backspace: \b formfeed: \f newline: \n return: \r tab: " |
| 425 | " now-all-of-them-together: \"\\\\/\b\n\r\t" |
| 426 | " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><" |
| 427 | " char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ "); |
| 428 | cout << "testString(" << str << ") = " << flush; |
| 429 | testClient.testString(s, str); |
| 430 | cout << s << endl; |
| 431 | if (s != str) { |
| 432 | cout.imbue(locale("en_US.UTF8")); |
| 433 | cout << "*** FAILED ***" << endl |
| 434 | << "Expected string: " << str << " but got: " << s << endl |
| 435 | << "CLEAR"; |
| 436 | ; |
| 437 | return_code |= ERR_BASETYPES; |
| 438 | } |
| 439 | } catch (TTransportException&) { |
| 440 | throw; |
| 441 | } catch (exception& ex) { |
| 442 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
| 443 | return_code |= ERR_BASETYPES; |
| 444 | return return_code; |
| 445 | } |
| 446 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 447 | /** |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 448 | * BOOL TEST |
| 449 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 450 | cout << boolalpha; |
| 451 | BASETYPE_IDENTITY_TEST(testBool, true); |
| 452 | BASETYPE_IDENTITY_TEST(testBool, false); |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 453 | |
| 454 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 455 | * BYTE TEST |
| 456 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 457 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)0); |
| 458 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)-1); |
| 459 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)42); |
| 460 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)-42); |
| 461 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)127); |
| 462 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)-128); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 463 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 464 | /** |
| 465 | * I32 TEST |
| 466 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 467 | BASETYPE_IDENTITY_TEST(testI32, 0); |
| 468 | BASETYPE_IDENTITY_TEST(testI32, -1); |
| 469 | BASETYPE_IDENTITY_TEST(testI32, 190000013); |
| 470 | BASETYPE_IDENTITY_TEST(testI32, -190000013); |
| 471 | BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::max()); |
| 472 | BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::min()); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 473 | |
| 474 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 475 | * I64 TEST |
| 476 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 477 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)0); |
| 478 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1); |
| 479 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL); |
| 480 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL); |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 481 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32)); |
| 482 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32)); |
| 483 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32) + 1); |
| 484 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32) - 1); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 485 | BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::max()); |
| 486 | BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::min()); |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 487 | |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 488 | /** |
| 489 | * DOUBLE TEST |
| 490 | */ |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 491 | // Comparing double values with plain equality because Thrift handles full precision of double |
| 492 | BASETYPE_IDENTITY_TEST(testDouble, 0.0); |
| 493 | BASETYPE_IDENTITY_TEST(testDouble, -1.0); |
| 494 | BASETYPE_IDENTITY_TEST(testDouble, -5.2098523); |
| 495 | BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279); |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 496 | BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32)); |
| 497 | BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32) + 1); |
| 498 | BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 53) - 1); |
| 499 | BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32)); |
| 500 | BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32) - 1); |
| 501 | BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 53) + 1); |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 502 | |
| 503 | try { |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 504 | double expected = pow(static_cast<double>(10), 307); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 505 | cout << "testDouble(" << expected << ") = " << flush; |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 506 | double actual = testClient.testDouble(expected); |
| 507 | cout << "(" << actual << ")" << endl; |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 508 | if (expected - actual > pow(static_cast<double>(10), 292)) { |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 509 | cout << "*** FAILED ***" << endl |
| 510 | << "Expected: " << expected << " but got: " << actual << endl; |
| 511 | } |
| 512 | } catch (TTransportException&) { |
| 513 | throw; |
| 514 | } catch (exception& ex) { |
| 515 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
| 516 | return_code |= ERR_BASETYPES; |
| 517 | } |
| 518 | |
| 519 | try { |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 520 | double expected = pow(static_cast<double>(10), -292); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 521 | cout << "testDouble(" << expected << ") = " << flush; |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 522 | double actual = testClient.testDouble(expected); |
| 523 | cout << "(" << actual << ")" << endl; |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 524 | if (expected - actual > pow(static_cast<double>(10), -307)) { |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 525 | cout << "*** FAILED ***" << endl |
| 526 | << "Expected: " << expected << " but got: " << actual << endl; |
| 527 | } |
| 528 | } catch (TTransportException&) { |
| 529 | throw; |
| 530 | } catch (exception& ex) { |
| 531 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 532 | return_code |= ERR_BASETYPES; |
| 533 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 534 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 535 | /** |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 536 | * BINARY TEST |
| 537 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 538 | cout << "testBinary(empty)" << endl; |
Nobuaki Sukegawa | dfb6896 | 2015-12-09 22:09:26 +0900 | [diff] [blame] | 539 | try { |
| 540 | string bin_result; |
| 541 | testClient.testBinary(bin_result, string()); |
| 542 | if (!bin_result.empty()) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 543 | cout << endl << "*** FAILED ***" << endl; |
| 544 | cout << "invalid length: " << bin_result.size() << endl; |
Nobuaki Sukegawa | dfb6896 | 2015-12-09 22:09:26 +0900 | [diff] [blame] | 545 | return_code |= ERR_BASETYPES; |
| 546 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 547 | } catch (TTransportException&) { |
| 548 | throw; |
Nobuaki Sukegawa | dfb6896 | 2015-12-09 22:09:26 +0900 | [diff] [blame] | 549 | } catch (exception& ex) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 550 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Nobuaki Sukegawa | dfb6896 | 2015-12-09 22:09:26 +0900 | [diff] [blame] | 551 | return_code |= ERR_BASETYPES; |
| 552 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 553 | cout << "testBinary([-128..127]) = {" << flush; |
Cody P Schafer | 3129549 | 2016-09-09 15:50:26 -0400 | [diff] [blame] | 554 | const signed char bin_data[256] |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 555 | = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, |
| 556 | -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99, |
| 557 | -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, |
| 558 | -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69, |
| 559 | -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, |
| 560 | -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, |
| 561 | -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, |
| 562 | -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, |
| 563 | -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, |
| 564 | 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
| 565 | 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, |
| 566 | 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 567 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, |
| 568 | 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, |
| 569 | 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, |
| 570 | 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, |
| 571 | 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, |
| 572 | 127}; |
| 573 | try { |
| 574 | string bin_result; |
Cody P Schafer | 3129549 | 2016-09-09 15:50:26 -0400 | [diff] [blame] | 575 | testClient.testBinary(bin_result, string(reinterpret_cast<const char *>(bin_data), 256)); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 576 | if (bin_result.size() != 256) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 577 | cout << endl << "*** FAILED ***" << endl; |
| 578 | cout << "invalid length: " << bin_result.size() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 579 | return_code |= ERR_BASETYPES; |
| 580 | } else { |
| 581 | bool first = true; |
| 582 | bool failed = false; |
| 583 | for (int i = 0; i < 256; ++i) { |
| 584 | if (!first) |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 585 | cout << ","; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 586 | else |
| 587 | first = false; |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 588 | cout << static_cast<int>(bin_result[i]); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 589 | if (!failed && bin_result[i] != i - 128) { |
| 590 | failed = true; |
| 591 | } |
| 592 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 593 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 594 | if (failed) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 595 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 596 | return_code |= ERR_BASETYPES; |
| 597 | } |
| 598 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 599 | } catch (TTransportException&) { |
| 600 | throw; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 601 | } catch (exception& ex) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 602 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 603 | return_code |= ERR_BASETYPES; |
| 604 | } |
| 605 | |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 606 | |
| 607 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 608 | * STRUCT TEST |
| 609 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 610 | cout << "testStruct({\"Zero\", 1, -3, -5})" << flush; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 611 | Xtruct out; |
| 612 | out.string_thing = "Zero"; |
| 613 | out.byte_thing = 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 614 | out.i32_thing = -3; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 615 | out.i64_thing = -5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 616 | Xtruct in; |
| 617 | testClient.testStruct(in, out); |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 618 | printf(" = {\"%s\", %d, %d, %" PRId64 "}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 619 | in.string_thing.c_str(), |
| 620 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 621 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 622 | in.i64_thing); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 623 | if (in != out) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 624 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 625 | return_code |= ERR_STRUCTS; |
| 626 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 627 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 628 | /** |
| 629 | * NESTED STRUCT TEST |
| 630 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 631 | cout << "testNest({1, {\"Zero\", 1, -3, -5}), 5}" << flush; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 632 | Xtruct2 out2; |
| 633 | out2.byte_thing = 1; |
| 634 | out2.struct_thing = out; |
| 635 | out2.i32_thing = 5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 636 | Xtruct2 in2; |
| 637 | testClient.testNest(in2, out2); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 638 | in = in2.struct_thing; |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 639 | printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 640 | in2.byte_thing, |
| 641 | in.string_thing.c_str(), |
| 642 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 643 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 644 | in.i64_thing, |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 645 | in2.i32_thing); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 646 | if (in2 != out2) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 647 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 648 | return_code |= ERR_STRUCTS; |
| 649 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 650 | |
| 651 | /** |
| 652 | * MAP TEST |
| 653 | */ |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 654 | map<int32_t, int32_t> mapout; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 655 | for (int32_t i = 0; i < 5; ++i) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 656 | mapout.insert(make_pair(i, i - 10)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 657 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 658 | cout << "testMap({" << flush; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 659 | map<int32_t, int32_t>::const_iterator m_iter; |
| 660 | bool first = true; |
| 661 | for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) { |
| 662 | if (first) { |
| 663 | first = false; |
| 664 | } else { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 665 | cout << ","; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 666 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 667 | cout << m_iter->first << " => " << m_iter->second; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 668 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 669 | cout << "})"; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 670 | map<int32_t, int32_t> mapin; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 671 | testClient.testMap(mapin, mapout); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 672 | cout << " = {"; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 673 | first = true; |
| 674 | for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { |
| 675 | if (first) { |
| 676 | first = false; |
| 677 | } else { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 678 | cout << ","; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 679 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 680 | cout << m_iter->first << " => " << m_iter->second; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 681 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 682 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 683 | if (mapin != mapout) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 684 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 685 | return_code |= ERR_CONTAINERS; |
| 686 | } |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 687 | |
| 688 | /** |
| 689 | * STRING MAP TEST |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 690 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 691 | cout << "testStringMap({a => 2, b => blah, some => thing}) = {" << flush; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 692 | map<string, string> smapin; |
| 693 | map<string, string> smapout; |
| 694 | smapin["a"] = "2"; |
| 695 | smapin["b"] = "blah"; |
| 696 | smapin["some"] = "thing"; |
| 697 | try { |
| 698 | testClient.testStringMap(smapout, smapin); |
| 699 | first = true; |
| 700 | for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) { |
| 701 | if (first) |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 702 | cout << ","; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 703 | else |
| 704 | first = false; |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 705 | cout << it->first << " => " << it->second; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 706 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 707 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 708 | if (smapin != smapout) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 709 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 710 | return_code |= ERR_CONTAINERS; |
| 711 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 712 | } catch (TTransportException&) { |
| 713 | throw; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 714 | } catch (exception& ex) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 715 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 716 | return_code |= ERR_CONTAINERS; |
| 717 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 718 | |
| 719 | /** |
| 720 | * SET TEST |
| 721 | */ |
| 722 | set<int32_t> setout; |
| 723 | for (int32_t i = -2; i < 3; ++i) { |
| 724 | setout.insert(i); |
| 725 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 726 | cout << "testSet({" << flush; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 727 | set<int32_t>::const_iterator s_iter; |
| 728 | first = true; |
| 729 | for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) { |
| 730 | if (first) { |
| 731 | first = false; |
| 732 | } else { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 733 | cout << ","; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 734 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 735 | cout << *s_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 736 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 737 | cout << "})"; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 738 | set<int32_t> setin; |
| 739 | testClient.testSet(setin, setout); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 740 | cout << " = {"; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 741 | first = true; |
| 742 | for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { |
| 743 | if (first) { |
| 744 | first = false; |
| 745 | } else { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 746 | cout << ","; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 747 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 748 | cout << *s_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 749 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 750 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 751 | if (setin != setout) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 752 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 753 | return_code |= ERR_CONTAINERS; |
| 754 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 755 | |
| 756 | /** |
| 757 | * LIST TEST |
| 758 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 759 | cout << "testList(empty)" << flush; |
| 760 | try { |
| 761 | vector<int32_t> listout; |
| 762 | testClient.testList(listout, vector<int32_t>()); |
| 763 | if (!listout.empty()) { |
| 764 | cout << "*** FAILED ***" << endl; |
| 765 | cout << "invalid length: " << listout.size() << endl; |
| 766 | return_code |= ERR_CONTAINERS; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 767 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 768 | } catch (TTransportException&) { |
| 769 | throw; |
| 770 | } catch (exception& ex) { |
| 771 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
| 772 | return_code |= ERR_CONTAINERS; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 773 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 774 | try { |
| 775 | vector<int32_t> listout; |
| 776 | for (int32_t i = -2; i < 3; ++i) { |
| 777 | listout.push_back(i); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 778 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 779 | cout << "testList({" << flush; |
| 780 | vector<int32_t>::const_iterator l_iter; |
| 781 | first = true; |
| 782 | for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { |
| 783 | if (first) { |
| 784 | first = false; |
| 785 | } else { |
| 786 | cout << ","; |
| 787 | } |
| 788 | cout << *l_iter; |
| 789 | } |
| 790 | cout << "})"; |
| 791 | vector<int32_t> listin; |
| 792 | testClient.testList(listin, listout); |
| 793 | cout << " = {"; |
| 794 | first = true; |
| 795 | for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { |
| 796 | if (first) { |
| 797 | first = false; |
| 798 | } else { |
| 799 | cout << ","; |
| 800 | } |
| 801 | cout << *l_iter; |
| 802 | } |
| 803 | cout << "}" << endl; |
| 804 | if (listin != listout) { |
| 805 | cout << "*** FAILED ***" << endl; |
| 806 | return_code |= ERR_CONTAINERS; |
| 807 | } |
| 808 | } catch (TTransportException&) { |
| 809 | throw; |
| 810 | } catch (exception& ex) { |
| 811 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 812 | return_code |= ERR_CONTAINERS; |
| 813 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 814 | |
| 815 | /** |
| 816 | * ENUM TEST |
| 817 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 818 | cout << "testEnum(ONE)" << flush; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 819 | Numberz::type ret = testClient.testEnum(Numberz::ONE); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 820 | cout << " = " << ret << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 821 | if (ret != Numberz::ONE) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 822 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 823 | return_code |= ERR_STRUCTS; |
| 824 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 825 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 826 | cout << "testEnum(TWO)" << flush; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 827 | ret = testClient.testEnum(Numberz::TWO); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 828 | cout << " = " << ret << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 829 | if (ret != Numberz::TWO) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 830 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 831 | return_code |= ERR_STRUCTS; |
| 832 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 833 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 834 | cout << "testEnum(THREE)" << flush; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 835 | ret = testClient.testEnum(Numberz::THREE); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 836 | cout << " = " << ret << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 837 | if (ret != Numberz::THREE) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 838 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 839 | return_code |= ERR_STRUCTS; |
| 840 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 841 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 842 | cout << "testEnum(FIVE)" << flush; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 843 | ret = testClient.testEnum(Numberz::FIVE); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 844 | cout << " = " << ret << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 845 | if (ret != Numberz::FIVE) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 846 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 847 | return_code |= ERR_STRUCTS; |
| 848 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 849 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 850 | cout << "testEnum(EIGHT)" << flush; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 851 | ret = testClient.testEnum(Numberz::EIGHT); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 852 | cout << " = " << ret << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 853 | if (ret != Numberz::EIGHT) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 854 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 855 | return_code |= ERR_STRUCTS; |
| 856 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 857 | |
| 858 | /** |
| 859 | * TYPEDEF TEST |
| 860 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 861 | cout << "testTypedef(309858235082523)" << flush; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 862 | UserId uid = testClient.testTypedef(309858235082523LL); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 863 | cout << " = " << uid << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 864 | if (uid != 309858235082523LL) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 865 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 866 | return_code |= ERR_STRUCTS; |
| 867 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 868 | |
| 869 | /** |
| 870 | * NESTED MAP TEST |
| 871 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 872 | cout << "testMapMap(1)" << flush; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 873 | map<int32_t, map<int32_t, int32_t> > mm; |
| 874 | testClient.testMapMap(mm, 1); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 875 | cout << " = {"; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 876 | map<int32_t, map<int32_t, int32_t> >::const_iterator mi; |
| 877 | for (mi = mm.begin(); mi != mm.end(); ++mi) { |
| 878 | printf("%d => {", mi->first); |
| 879 | map<int32_t, int32_t>::const_iterator mi2; |
| 880 | for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 881 | cout << mi2->first << " => " << mi2->second; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 882 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 883 | cout << "}, "; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 884 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 885 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 886 | if (mm.size() != 2 || |
| 887 | mm[-4][-4] != -4 || |
| 888 | mm[-4][-3] != -3 || |
| 889 | mm[-4][-2] != -2 || |
| 890 | mm[-4][-1] != -1 || |
| 891 | mm[4][4] != 4 || |
| 892 | mm[4][3] != 3 || |
| 893 | mm[4][2] != 2 || |
| 894 | mm[4][1] != 1) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 895 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 896 | return_code |= ERR_CONTAINERS; |
| 897 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 898 | |
| 899 | /** |
| 900 | * INSANITY TEST |
| 901 | */ |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 902 | if (!noinsane) { |
| 903 | Insanity insane; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 904 | insane.userMap.insert(make_pair(Numberz::FIVE, 5)); |
| 905 | insane.userMap.insert(make_pair(Numberz::EIGHT, 8)); |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 906 | Xtruct truck; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 907 | truck.string_thing = "Goodbye4"; |
| 908 | truck.byte_thing = 4; |
| 909 | truck.i32_thing = 4; |
| 910 | truck.i64_thing = 4; |
| 911 | Xtruct truck2; |
| 912 | truck2.string_thing = "Hello2"; |
| 913 | truck2.byte_thing = 2; |
| 914 | truck2.i32_thing = 2; |
| 915 | truck2.i64_thing = 2; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 916 | insane.xtructs.push_back(truck); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 917 | insane.xtructs.push_back(truck2); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 918 | cout << "testInsanity()" << flush; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 919 | map<UserId, map<Numberz::type, Insanity> > whoa; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 920 | testClient.testInsanity(whoa, insane); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 921 | cout << " = {"; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 922 | map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 923 | for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { |
| 924 | printf("%" PRId64 " => {", i_iter->first); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 925 | map<Numberz::type, Insanity>::const_iterator i2_iter; |
| 926 | for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) { |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 927 | printf("%d => {", i2_iter->first); |
| 928 | map<Numberz::type, UserId> userMap = i2_iter->second.userMap; |
| 929 | map<Numberz::type, UserId>::const_iterator um; |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 930 | cout << "{"; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 931 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 932 | cout << um->first << " => " << um->second; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 933 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 934 | cout << "}, "; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 935 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 936 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 937 | vector<Xtruct>::const_iterator x; |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 938 | cout << "{"; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 939 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
| 940 | printf("{\"%s\", %d, %d, %" PRId64 "}, ", |
| 941 | x->string_thing.c_str(), |
| 942 | (int)x->byte_thing, |
| 943 | x->i32_thing, |
| 944 | x->i64_thing); |
| 945 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 946 | cout << "}"; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 947 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 948 | cout << "}, "; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 949 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 950 | cout << "}, "; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 951 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 952 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 953 | bool failed = false; |
| 954 | map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1)); |
| 955 | if (whoa.size() != 2) { |
| 956 | failed = true; |
| 957 | } |
| 958 | if (it1 == whoa.end()) { |
| 959 | failed = true; |
| 960 | } else { |
| 961 | map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO); |
| 962 | if (it12 == it1->second.end() || it12->second != insane) { |
| 963 | failed = true; |
| 964 | } |
| 965 | map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE); |
| 966 | if (it13 == it1->second.end() || it13->second != insane) { |
| 967 | failed = true; |
| 968 | } |
| 969 | } |
| 970 | map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2)); |
| 971 | if (it2 == whoa.end()) { |
| 972 | failed = true; |
| 973 | } else { |
| 974 | map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX); |
| 975 | if (it26 == it1->second.end() || it26->second != Insanity()) { |
| 976 | failed = true; |
| 977 | } |
| 978 | } |
| 979 | if (failed) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 980 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 981 | return_code |= ERR_STRUCTS; |
| 982 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 983 | } |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 984 | |
| 985 | /** |
| 986 | * MULTI TEST |
| 987 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 988 | cout << "testMulti()" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 989 | try { |
| 990 | map<int16_t, string> mul_map; |
| 991 | Xtruct mul_result; |
| 992 | mul_map[1] = "blah"; |
| 993 | mul_map[2] = "thing"; |
| 994 | testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24)); |
| 995 | Xtruct xxs; |
| 996 | xxs.string_thing = "Hello2"; |
| 997 | xxs.byte_thing = 42; |
| 998 | xxs.i32_thing = 4242; |
| 999 | xxs.i64_thing = 424242; |
| 1000 | if (mul_result != xxs) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1001 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1002 | return_code |= ERR_STRUCTS; |
| 1003 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1004 | } catch (TTransportException&) { |
| 1005 | throw; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1006 | } catch (exception& ex) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1007 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1008 | return_code |= ERR_STRUCTS; |
| 1009 | } |
| 1010 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1011 | /* test exception */ |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 1012 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 1013 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1014 | cout << "testClient.testException(\"Xception\") =>" << flush; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1015 | testClient.testException("Xception"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1016 | cout << " void\n*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1017 | return_code |= ERR_EXCEPTIONS; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1018 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1019 | } catch (Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1020 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 1021 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1022 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 1023 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1024 | cout << "testClient.testException(\"TException\") =>" << flush; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1025 | testClient.testException("TException"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1026 | cout << " void\n*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1027 | return_code |= ERR_EXCEPTIONS; |
Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 1028 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1029 | } catch (const TException&) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1030 | cout << " Caught TException" << endl; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1031 | } |
Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 1032 | |
| 1033 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1034 | cout << "testClient.testException(\"success\") =>" << flush; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1035 | testClient.testException("success"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1036 | cout << " void" << endl; |
| 1037 | } catch (exception & ex) { \ |
| 1038 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1039 | return_code |= ERR_EXCEPTIONS; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1040 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1041 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1042 | /* test multi exception */ |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1043 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1044 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1045 | cout << "testClient.testMultiException(\"Xception\", \"test 1\") =>" << flush; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 1046 | Xtruct result; |
| 1047 | testClient.testMultiException(result, "Xception", "test 1"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1048 | cout << " result\n*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1049 | return_code |= ERR_EXCEPTIONS; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1050 | } catch (Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1051 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
| 1052 | } |
| 1053 | |
| 1054 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1055 | cout << "testClient.testMultiException(\"Xception2\", \"test 2\") =>" << flush; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 1056 | Xtruct result; |
| 1057 | testClient.testMultiException(result, "Xception2", "test 2"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1058 | cout << " result\n*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1059 | return_code |= ERR_EXCEPTIONS; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1060 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1061 | } catch (Xception2& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1062 | printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 1063 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1064 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1065 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1066 | cout << "testClient.testMultiException(\"success\", \"test 3\") =>" << flush; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 1067 | Xtruct result; |
| 1068 | testClient.testMultiException(result, "success", "test 3"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1069 | printf(" {{\"%s\"}}\n", result.string_thing.c_str()); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1070 | } catch (exception & ex) { \ |
| 1071 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1072 | return_code |= ERR_EXCEPTIONS; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1073 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1074 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 1075 | /* test oneway void */ |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 1076 | { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1077 | cout << "testClient.testOneway(1) =>" << flush; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1078 | uint64_t startOneway = now(); |
| 1079 | testClient.testOneway(1); |
| 1080 | uint64_t elapsed = now() - startOneway; |
| 1081 | if (elapsed > 200 * 1000) { // 0.2 seconds |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1082 | printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0); |
| 1083 | return_code |= ERR_BASETYPES; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1084 | } else { |
| 1085 | printf(" success - took %.2f ms\n", (double)elapsed / 1000.0); |
| 1086 | } |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 1087 | } |
| 1088 | |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 1089 | /** |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 1090 | * redo a simple test after the oneway to make sure we aren't "off by one" -- |
| 1091 | * if the server treated oneway void like normal void, this next test will |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 1092 | * fail since it will get the void confirmation rather than the correct |
| 1093 | * result. In this circumstance, the client will throw the exception: |
| 1094 | * |
| 1095 | * TApplicationException: Wrong method namea |
| 1096 | */ |
| 1097 | /** |
| 1098 | * I32 TEST |
| 1099 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1100 | cout << "re-test testI32(-1)"; |
| 1101 | int i32 = testClient.testI32(-1); |
| 1102 | cout << " = " << i32 << endl; |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 1103 | if (i32 != -1) |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1104 | return_code |= ERR_BASETYPES; |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 1105 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 1106 | uint64_t stop = now(); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1107 | uint64_t tot = stop - start; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1108 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1109 | cout << "Total time: " << stop - start << " us" << endl; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1110 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1111 | time_tot += tot; |
| 1112 | if (time_min == 0 || tot < time_min) { |
| 1113 | time_min = tot; |
| 1114 | } |
| 1115 | if (tot > time_max) { |
| 1116 | time_max = tot; |
| 1117 | } |
| 1118 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 1119 | transport->close(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1122 | cout << endl << "All tests done." << endl; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1123 | |
| 1124 | uint64_t time_avg = time_tot / numTests; |
| 1125 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1126 | cout << "Min time: " << time_min << " us" << endl; |
| 1127 | cout << "Max time: " << time_max << " us" << endl; |
| 1128 | cout << "Avg time: " << time_avg << " us" << endl; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1129 | |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1130 | return return_code; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1131 | } |