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