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