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