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> |
| 22 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 23 | #include <iostream> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 24 | #include <thrift/protocol/TBinaryProtocol.h> |
Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 25 | #include <thrift/protocol/TCompactProtocol.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 26 | #include <thrift/protocol/TJSONProtocol.h> |
| 27 | #include <thrift/transport/THttpClient.h> |
| 28 | #include <thrift/transport/TTransportUtils.h> |
| 29 | #include <thrift/transport/TSocket.h> |
| 30 | #include <thrift/transport/TSSLSocket.h> |
| 31 | #include <thrift/async/TEvhttpClientChannel.h> |
| 32 | #include <thrift/server/TNonblockingServer.h> // <event.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 33 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 34 | #include <boost/shared_ptr.hpp> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 35 | #include <boost/program_options.hpp> |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 36 | #include <boost/filesystem.hpp> |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 37 | #include <thrift/cxxfunctional.h> |
| 38 | #if _WIN32 |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 39 | #include <thrift/windows/TWinsockSingleton.h> |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 40 | #endif |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 41 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 42 | #include "ThriftTest.h" |
| 43 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 44 | using namespace std; |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 45 | using namespace apache::thrift; |
| 46 | using namespace apache::thrift::protocol; |
| 47 | using namespace apache::thrift::transport; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 48 | using namespace thrift::test; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 49 | using namespace apache::thrift::async; |
| 50 | |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 51 | // Length of argv[0] - Length of script dir |
| 52 | #define EXECUTABLE_FILE_NAME_LENGTH 19 |
| 53 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 54 | // Current time, microseconds since the epoch |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 55 | uint64_t now() { |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 56 | int64_t ret; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 57 | struct timeval tv; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 58 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 59 | THRIFT_GETTIMEOFDAY(&tv, NULL); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 60 | ret = tv.tv_sec; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 61 | ret = ret * 1000 * 1000 + tv.tv_usec; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 62 | return ret; |
| 63 | } |
| 64 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 65 | static void testString_clientReturn(const char* host, |
| 66 | int port, |
| 67 | event_base* base, |
| 68 | TProtocolFactory* protocolFactory, |
| 69 | ThriftTestCobClient* client) { |
| 70 | (void)host; |
| 71 | (void)port; |
| 72 | (void)protocolFactory; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 73 | try { |
| 74 | string s; |
| 75 | client->recv_testString(s); |
| 76 | cout << "testString: " << s << endl; |
| 77 | } catch (TException& exn) { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 78 | cout << "Error: " << exn.what() << endl; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | event_base_loopbreak(base); // end test |
| 82 | } |
| 83 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 84 | static void testVoid_clientReturn(const char* host, |
| 85 | int port, |
| 86 | event_base* base, |
| 87 | TProtocolFactory* protocolFactory, |
| 88 | ThriftTestCobClient* client) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 89 | try { |
| 90 | client->recv_testVoid(); |
| 91 | cout << "testVoid" << endl; |
| 92 | |
| 93 | // next test |
| 94 | delete client; |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 95 | boost::shared_ptr<TAsyncChannel> channel(new TEvhttpClientChannel(host, "/", host, port, base)); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 96 | client = new ThriftTestCobClient(channel, protocolFactory); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 97 | client->testString(tcxx::bind(testString_clientReturn, |
| 98 | host, |
| 99 | port, |
| 100 | base, |
| 101 | protocolFactory, |
| 102 | tcxx::placeholders::_1), |
| 103 | "Test"); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 104 | } catch (TException& exn) { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 105 | cout << "Error: " << exn.what() << endl; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame^] | 109 | // Workaround for absense of C++11 "auto" keyword. |
| 110 | template <typename T> |
| 111 | bool print_eq(T expected, T actual) { |
| 112 | cout << "(" << actual << ")" << endl; |
| 113 | if (expected != actual) { |
| 114 | cout << "*** FAILED ***" << endl << "Expected: " << expected << " but got: " << actual << endl; |
| 115 | return false; |
| 116 | } |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | #define BASETYPE_IDENTITY_TEST(func, value) \ |
| 121 | cout << #func "(" << value << ") = "; \ |
| 122 | try { \ |
| 123 | if (!print_eq(value, testClient.func(value))) \ |
| 124 | return_code |= ERR_BASETYPES; \ |
| 125 | } catch (TTransportException&) { \ |
| 126 | throw; \ |
| 127 | } catch (exception & ex) { \ |
| 128 | cout << "*** FAILED ***" << endl << ex.what() << endl; \ |
| 129 | return_code |= ERR_BASETYPES; \ |
| 130 | } |
| 131 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 132 | int main(int argc, char** argv) { |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 133 | int ERR_BASETYPES = 1; |
| 134 | int ERR_STRUCTS = 2; |
| 135 | int ERR_CONTAINERS = 4; |
| 136 | int ERR_EXCEPTIONS = 8; |
| 137 | int ERR_UNKNOWN = 64; |
| 138 | |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 139 | string file_path = boost::filesystem::system_complete(argv[0]).string(); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 140 | 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] | 141 | #if _WIN32 |
| 142 | transport::TWinsockSingleton::create(); |
| 143 | #endif |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 144 | string host = "localhost"; |
| 145 | int port = 9090; |
| 146 | int numTests = 1; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 147 | bool ssl = false; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 148 | string transport_type = "buffered"; |
| 149 | string protocol_type = "binary"; |
| 150 | string domain_socket = ""; |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 151 | bool abstract_namespace = false; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 152 | bool noinsane = false; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 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), |
| 173 | "Protocol: binary, compact, json")("ssl", "Encrypted Transport using SSL")( |
| 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")) { |
| 183 | cout << desc << "\n"; |
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") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 191 | } else if (protocol_type == "json") { |
| 192 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 193 | throw invalid_argument("Unknown protocol type " + protocol_type); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 197 | if (!transport_type.empty()) { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 198 | if (transport_type == "buffered") { |
| 199 | } else if (transport_type == "framed") { |
| 200 | } else if (transport_type == "http") { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 201 | } else if (transport_type == "evhttp") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 202 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 203 | throw invalid_argument("Unknown transport type " + transport_type); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
| 207 | } catch (std::exception& e) { |
| 208 | cerr << e.what() << endl; |
| 209 | cout << desc << "\n"; |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 210 | return ERR_UNKNOWN; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | if (vm.count("ssl")) { |
| 214 | ssl = true; |
| 215 | } |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 216 | |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 217 | if (vm.count("abstract-namespace")) { |
| 218 | abstract_namespace = true; |
| 219 | } |
| 220 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 221 | if (vm.count("noinsane")) { |
| 222 | noinsane = true; |
| 223 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 224 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 225 | boost::shared_ptr<TTransport> transport; |
| 226 | boost::shared_ptr<TProtocol> protocol; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 227 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 228 | boost::shared_ptr<TSocket> socket; |
| 229 | boost::shared_ptr<TSSLSocketFactory> factory; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 230 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 231 | if (ssl) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 232 | factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory()); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 233 | factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 234 | factory->loadTrustedCertificates((dir_path + "../keys/CA.pem").c_str()); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 235 | factory->authenticate(true); |
| 236 | socket = factory->createSocket(host, port); |
| 237 | } else { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 238 | if (domain_socket != "") { |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 239 | if (abstract_namespace) { |
| 240 | std::string abstract_socket("\0", 1); |
| 241 | abstract_socket += domain_socket; |
| 242 | socket = boost::shared_ptr<TSocket>(new TSocket(abstract_socket)); |
| 243 | } else { |
| 244 | socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket)); |
| 245 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 246 | port = 0; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 247 | } else { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 248 | socket = boost::shared_ptr<TSocket>(new TSocket(host, port)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 249 | } |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 250 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 251 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 252 | if (transport_type.compare("http") == 0) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 253 | boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service")); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 254 | transport = httpSocket; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 255 | } else if (transport_type.compare("framed") == 0) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 256 | boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 257 | transport = framedSocket; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 258 | } else { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 259 | boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 260 | transport = bufferedSocket; |
| 261 | } |
| 262 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 263 | if (protocol_type.compare("json") == 0) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 264 | boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 265 | protocol = jsonProtocol; |
Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 266 | } else if (protocol_type.compare("compact") == 0) { |
| 267 | boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport)); |
| 268 | protocol = compactProtocol; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 269 | } else { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 270 | boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 271 | protocol = binaryProtocol; |
| 272 | } |
| 273 | |
| 274 | // Connection info |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 275 | cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: "; |
| 276 | if (abstract_namespace) { |
| 277 | cout << '@'; |
| 278 | } |
| 279 | cout << domain_socket; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 280 | if (port != 0) { |
| 281 | cout << host << ":" << port; |
| 282 | } |
| 283 | cout << endl; |
| 284 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 285 | if (transport_type.compare("evhttp") == 0) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 286 | event_base* base = event_base_new(); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 287 | cout << "Libevent Version: " << event_get_version() << endl; |
| 288 | cout << "Libevent Method: " << event_base_get_method(base) << endl; |
| 289 | #if LIBEVENT_VERSION_NUMBER >= 0x02000000 |
| 290 | cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl; |
| 291 | #endif |
| 292 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 293 | boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 294 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 295 | boost::shared_ptr<TAsyncChannel> channel( |
| 296 | new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base)); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 297 | ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get()); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 298 | client->testVoid(tcxx::bind(testVoid_clientReturn, |
| 299 | host.c_str(), |
| 300 | port, |
| 301 | base, |
| 302 | protocolFactory.get(), |
| 303 | tcxx::placeholders::_1)); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 304 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 305 | event_base_loop(base, 0); |
| 306 | return 0; |
| 307 | } |
| 308 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 309 | ThriftTestClient testClient(protocol); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 310 | |
| 311 | uint64_t time_min = 0; |
| 312 | uint64_t time_max = 0; |
| 313 | uint64_t time_tot = 0; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 314 | |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 315 | int return_code = 0; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 316 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 317 | int test = 0; |
| 318 | for (test = 0; test < numTests; ++test) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 319 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 320 | try { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 321 | transport->open(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 322 | } catch (TTransportException& ttx) { |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 323 | printf("Connect failed: %s\n", ttx.what()); |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 324 | return ERR_UNKNOWN; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 325 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 326 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 327 | /** |
| 328 | * CONNECT TEST |
| 329 | */ |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 330 | 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] | 331 | |
| 332 | uint64_t start = now(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 333 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 334 | /** |
| 335 | * VOID TEST |
| 336 | */ |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 337 | try { |
| 338 | printf("testVoid()"); |
| 339 | testClient.testVoid(); |
| 340 | printf(" = void\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 341 | } catch (TApplicationException& tax) { |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 342 | printf("*** FAILED ***\n"); |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 343 | printf("%s\n", tax.what()); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 344 | return_code |= ERR_BASETYPES; |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 345 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 346 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 347 | /** |
| 348 | * STRING TEST |
| 349 | */ |
| 350 | printf("testString(\"Test\")"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 351 | string s; |
| 352 | testClient.testString(s, "Test"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 353 | printf(" = \"%s\"\n", s.c_str()); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 354 | if (s != "Test") { |
| 355 | printf("*** FAILED ***\n"); |
| 356 | return_code |= ERR_BASETYPES; |
| 357 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 358 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 359 | /** |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 360 | * BOOL TEST |
| 361 | */ |
| 362 | printf("testBool(true)"); |
| 363 | bool bl = testClient.testBool(true); |
| 364 | printf(" = %s\n", bl ? "true" : "false"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 365 | if (bl != true) { |
| 366 | printf("*** FAILED ***\n"); |
| 367 | return_code |= ERR_BASETYPES; |
| 368 | } |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 369 | |
| 370 | printf("testBool(false)"); |
| 371 | bl = testClient.testBool(false); |
| 372 | printf(" = %s\n", bl ? "true" : "false"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 373 | if (bl != false) { |
| 374 | printf("*** FAILED ***\n"); |
| 375 | return_code |= ERR_BASETYPES; |
| 376 | } |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 377 | |
| 378 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 379 | * BYTE TEST |
| 380 | */ |
| 381 | printf("testByte(1)"); |
| 382 | uint8_t u8 = testClient.testByte(1); |
| 383 | printf(" = %d\n", (int)u8); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 384 | if (u8 != 1) { |
| 385 | printf("*** FAILED ***\n"); |
| 386 | return_code |= ERR_BASETYPES; |
| 387 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 388 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 389 | /** |
| 390 | * I32 TEST |
| 391 | */ |
| 392 | printf("testI32(-1)"); |
| 393 | int32_t i32 = testClient.testI32(-1); |
| 394 | printf(" = %d\n", i32); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 395 | if (i32 != -1) { |
| 396 | printf("*** FAILED ***\n"); |
| 397 | return_code |= ERR_BASETYPES; |
| 398 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 399 | |
| 400 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 401 | * I64 TEST |
| 402 | */ |
| 403 | printf("testI64(-34359738368)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 404 | int64_t i64 = testClient.testI64(-34359738368LL); |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 405 | printf(" = %" PRId64 "\n", i64); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 406 | if (i64 != -34359738368LL) { |
| 407 | printf("*** FAILED ***\n"); |
| 408 | return_code |= ERR_BASETYPES; |
| 409 | } |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 410 | |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 411 | /** |
| 412 | * DOUBLE TEST |
| 413 | */ |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame^] | 414 | // Comparing double values with plain equality because Thrift handles full precision of double |
| 415 | BASETYPE_IDENTITY_TEST(testDouble, 0.0); |
| 416 | BASETYPE_IDENTITY_TEST(testDouble, -1.0); |
| 417 | BASETYPE_IDENTITY_TEST(testDouble, -5.2098523); |
| 418 | BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279); |
| 419 | BASETYPE_IDENTITY_TEST(testDouble, pow(2, 32)); |
| 420 | BASETYPE_IDENTITY_TEST(testDouble, pow(2, 32) + 1); |
| 421 | BASETYPE_IDENTITY_TEST(testDouble, pow(2, 53) - 1); |
| 422 | BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 32)); |
| 423 | BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 32) - 1); |
| 424 | BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 53) + 1); |
| 425 | |
| 426 | try { |
| 427 | double expected = pow(10, 307); |
| 428 | cout << "testDouble(" << expected << ") = "; |
| 429 | double actual = testClient.testDouble(expected); |
| 430 | cout << "(" << actual << ")" << endl; |
| 431 | if (expected - actual > pow(10, 292)) { |
| 432 | cout << "*** FAILED ***" << endl |
| 433 | << "Expected: " << expected << " but got: " << actual << endl; |
| 434 | } |
| 435 | } catch (TTransportException&) { |
| 436 | throw; |
| 437 | } catch (exception& ex) { |
| 438 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
| 439 | return_code |= ERR_BASETYPES; |
| 440 | } |
| 441 | |
| 442 | try { |
| 443 | double expected = pow(10, -292); |
| 444 | cout << "testDouble(" << expected << ") = "; |
| 445 | double actual = testClient.testDouble(expected); |
| 446 | cout << "(" << actual << ")" << endl; |
| 447 | if (expected - actual > pow(10, -307)) { |
| 448 | cout << "*** FAILED ***" << endl |
| 449 | << "Expected: " << expected << " but got: " << actual << endl; |
| 450 | } |
| 451 | } catch (TTransportException&) { |
| 452 | throw; |
| 453 | } catch (exception& ex) { |
| 454 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 455 | return_code |= ERR_BASETYPES; |
| 456 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 457 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 458 | /** |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 459 | * BINARY TEST |
| 460 | */ |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 461 | printf("testBinary([-128..127]) = {"); |
| 462 | const char bin_data[256] |
| 463 | = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, |
| 464 | -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99, |
| 465 | -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, |
| 466 | -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69, |
| 467 | -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, |
| 468 | -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, |
| 469 | -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, |
| 470 | -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, |
| 471 | -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, |
| 472 | 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
| 473 | 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, |
| 474 | 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 475 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, |
| 476 | 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, |
| 477 | 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, |
| 478 | 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, |
| 479 | 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, |
| 480 | 127}; |
| 481 | try { |
| 482 | string bin_result; |
| 483 | testClient.testBinary(bin_result, string(bin_data, 256)); |
| 484 | if (bin_result.size() != 256) { |
| 485 | printf("}\n*** FAILED ***\n"); |
| 486 | printf("invalid length: %lu\n", bin_result.size()); |
| 487 | return_code |= ERR_BASETYPES; |
| 488 | } else { |
| 489 | bool first = true; |
| 490 | bool failed = false; |
| 491 | for (int i = 0; i < 256; ++i) { |
| 492 | if (!first) |
| 493 | printf(" ,"); |
| 494 | else |
| 495 | first = false; |
| 496 | printf("%d", bin_result[i]); |
| 497 | if (!failed && bin_result[i] != i - 128) { |
| 498 | failed = true; |
| 499 | } |
| 500 | } |
| 501 | printf("}\n"); |
| 502 | if (failed) { |
| 503 | printf("*** FAILED ***\n"); |
| 504 | return_code |= ERR_BASETYPES; |
| 505 | } |
| 506 | } |
| 507 | } catch (exception& ex) { |
| 508 | printf("}\n*** FAILED ***\n"); |
| 509 | printf("%s\n", ex.what()); |
| 510 | return_code |= ERR_BASETYPES; |
| 511 | } |
| 512 | |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 513 | |
| 514 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 515 | * STRUCT TEST |
| 516 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 517 | printf("testStruct({\"Zero\", 1, -3, -5})"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 518 | Xtruct out; |
| 519 | out.string_thing = "Zero"; |
| 520 | out.byte_thing = 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 521 | out.i32_thing = -3; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 522 | out.i64_thing = -5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 523 | Xtruct in; |
| 524 | testClient.testStruct(in, out); |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 525 | printf(" = {\"%s\", %d, %d, %" PRId64 "}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 526 | in.string_thing.c_str(), |
| 527 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 528 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 529 | in.i64_thing); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 530 | if (in != out) { |
| 531 | printf("*** FAILED ***\n"); |
| 532 | return_code |= ERR_STRUCTS; |
| 533 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 534 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 535 | /** |
| 536 | * NESTED STRUCT TEST |
| 537 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 538 | printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 539 | Xtruct2 out2; |
| 540 | out2.byte_thing = 1; |
| 541 | out2.struct_thing = out; |
| 542 | out2.i32_thing = 5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 543 | Xtruct2 in2; |
| 544 | testClient.testNest(in2, out2); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 545 | in = in2.struct_thing; |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 546 | printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 547 | in2.byte_thing, |
| 548 | in.string_thing.c_str(), |
| 549 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 550 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 551 | in.i64_thing, |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 552 | in2.i32_thing); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 553 | if (in2 != out2) { |
| 554 | printf("*** FAILED ***\n"); |
| 555 | return_code |= ERR_STRUCTS; |
| 556 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 557 | |
| 558 | /** |
| 559 | * MAP TEST |
| 560 | */ |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 561 | map<int32_t, int32_t> mapout; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 562 | for (int32_t i = 0; i < 5; ++i) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 563 | mapout.insert(make_pair(i, i - 10)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 564 | } |
| 565 | printf("testMap({"); |
| 566 | map<int32_t, int32_t>::const_iterator m_iter; |
| 567 | bool first = true; |
| 568 | for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) { |
| 569 | if (first) { |
| 570 | first = false; |
| 571 | } else { |
| 572 | printf(", "); |
| 573 | } |
| 574 | printf("%d => %d", m_iter->first, m_iter->second); |
| 575 | } |
| 576 | printf("})"); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 577 | map<int32_t, int32_t> mapin; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 578 | testClient.testMap(mapin, mapout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 579 | printf(" = {"); |
| 580 | first = true; |
| 581 | for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { |
| 582 | if (first) { |
| 583 | first = false; |
| 584 | } else { |
| 585 | printf(", "); |
| 586 | } |
| 587 | printf("%d => %d", m_iter->first, m_iter->second); |
| 588 | } |
| 589 | printf("}\n"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 590 | if (mapin != mapout) { |
| 591 | printf("*** FAILED ***\n"); |
| 592 | return_code |= ERR_CONTAINERS; |
| 593 | } |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 594 | |
| 595 | /** |
| 596 | * STRING MAP TEST |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 597 | */ |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 598 | printf("testStringMap({a => 2, b => blah, some => thing}) = {"); |
| 599 | map<string, string> smapin; |
| 600 | map<string, string> smapout; |
| 601 | smapin["a"] = "2"; |
| 602 | smapin["b"] = "blah"; |
| 603 | smapin["some"] = "thing"; |
| 604 | try { |
| 605 | testClient.testStringMap(smapout, smapin); |
| 606 | first = true; |
| 607 | for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) { |
| 608 | if (first) |
| 609 | printf(","); |
| 610 | else |
| 611 | first = false; |
| 612 | printf("%s => %s", it->first.c_str(), it->second.c_str()); |
| 613 | } |
| 614 | printf("}\n"); |
| 615 | if (smapin != smapout) { |
| 616 | printf("*** FAILED ***\n"); |
| 617 | return_code |= ERR_CONTAINERS; |
| 618 | } |
| 619 | } catch (exception& ex) { |
| 620 | printf("}\n*** FAILED ***\n"); |
| 621 | printf("%s\n", ex.what()); |
| 622 | return_code |= ERR_CONTAINERS; |
| 623 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 624 | |
| 625 | /** |
| 626 | * SET TEST |
| 627 | */ |
| 628 | set<int32_t> setout; |
| 629 | for (int32_t i = -2; i < 3; ++i) { |
| 630 | setout.insert(i); |
| 631 | } |
| 632 | printf("testSet({"); |
| 633 | set<int32_t>::const_iterator s_iter; |
| 634 | first = true; |
| 635 | for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) { |
| 636 | if (first) { |
| 637 | first = false; |
| 638 | } else { |
| 639 | printf(", "); |
| 640 | } |
| 641 | printf("%d", *s_iter); |
| 642 | } |
| 643 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 644 | set<int32_t> setin; |
| 645 | testClient.testSet(setin, setout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 646 | printf(" = {"); |
| 647 | first = true; |
| 648 | for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { |
| 649 | if (first) { |
| 650 | first = false; |
| 651 | } else { |
| 652 | printf(", "); |
| 653 | } |
| 654 | printf("%d", *s_iter); |
| 655 | } |
| 656 | printf("}\n"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 657 | if (setin != setout) { |
| 658 | printf("*** FAILED ***\n"); |
| 659 | return_code |= ERR_CONTAINERS; |
| 660 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 661 | |
| 662 | /** |
| 663 | * LIST TEST |
| 664 | */ |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 665 | vector<int32_t> listout; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 666 | for (int32_t i = -2; i < 3; ++i) { |
| 667 | listout.push_back(i); |
| 668 | } |
| 669 | printf("testList({"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 670 | vector<int32_t>::const_iterator l_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 671 | first = true; |
| 672 | for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { |
| 673 | if (first) { |
| 674 | first = false; |
| 675 | } else { |
| 676 | printf(", "); |
| 677 | } |
| 678 | printf("%d", *l_iter); |
| 679 | } |
| 680 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 681 | vector<int32_t> listin; |
| 682 | testClient.testList(listin, listout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 683 | printf(" = {"); |
| 684 | first = true; |
| 685 | for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { |
| 686 | if (first) { |
| 687 | first = false; |
| 688 | } else { |
| 689 | printf(", "); |
| 690 | } |
| 691 | printf("%d", *l_iter); |
| 692 | } |
| 693 | printf("}\n"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 694 | if (listin != listout) { |
| 695 | printf("*** FAILED ***\n"); |
| 696 | return_code |= ERR_CONTAINERS; |
| 697 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 698 | |
| 699 | /** |
| 700 | * ENUM TEST |
| 701 | */ |
| 702 | printf("testEnum(ONE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 703 | Numberz::type ret = testClient.testEnum(Numberz::ONE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 704 | printf(" = %d\n", ret); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 705 | if (ret != Numberz::ONE) { |
| 706 | printf("*** FAILED ***\n"); |
| 707 | return_code |= ERR_STRUCTS; |
| 708 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 709 | |
| 710 | printf("testEnum(TWO)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 711 | ret = testClient.testEnum(Numberz::TWO); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 712 | printf(" = %d\n", ret); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 713 | if (ret != Numberz::TWO) { |
| 714 | printf("*** FAILED ***\n"); |
| 715 | return_code |= ERR_STRUCTS; |
| 716 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 717 | |
| 718 | printf("testEnum(THREE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 719 | ret = testClient.testEnum(Numberz::THREE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 720 | printf(" = %d\n", ret); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 721 | if (ret != Numberz::THREE) { |
| 722 | printf("*** FAILED ***\n"); |
| 723 | return_code |= ERR_STRUCTS; |
| 724 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 725 | |
| 726 | printf("testEnum(FIVE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 727 | ret = testClient.testEnum(Numberz::FIVE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 728 | printf(" = %d\n", ret); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 729 | if (ret != Numberz::FIVE) { |
| 730 | printf("*** FAILED ***\n"); |
| 731 | return_code |= ERR_STRUCTS; |
| 732 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 733 | |
| 734 | printf("testEnum(EIGHT)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 735 | ret = testClient.testEnum(Numberz::EIGHT); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 736 | printf(" = %d\n", ret); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 737 | if (ret != Numberz::EIGHT) { |
| 738 | printf("*** FAILED ***\n"); |
| 739 | return_code |= ERR_STRUCTS; |
| 740 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 741 | |
| 742 | /** |
| 743 | * TYPEDEF TEST |
| 744 | */ |
| 745 | printf("testTypedef(309858235082523)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 746 | UserId uid = testClient.testTypedef(309858235082523LL); |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 747 | printf(" = %" PRId64 "\n", uid); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 748 | if (uid != 309858235082523LL) { |
| 749 | printf("*** FAILED ***\n"); |
| 750 | return_code |= ERR_STRUCTS; |
| 751 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 752 | |
| 753 | /** |
| 754 | * NESTED MAP TEST |
| 755 | */ |
| 756 | printf("testMapMap(1)"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 757 | map<int32_t, map<int32_t, int32_t> > mm; |
| 758 | testClient.testMapMap(mm, 1); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 759 | printf(" = {"); |
| 760 | map<int32_t, map<int32_t, int32_t> >::const_iterator mi; |
| 761 | for (mi = mm.begin(); mi != mm.end(); ++mi) { |
| 762 | printf("%d => {", mi->first); |
| 763 | map<int32_t, int32_t>::const_iterator mi2; |
| 764 | for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) { |
| 765 | printf("%d => %d, ", mi2->first, mi2->second); |
| 766 | } |
| 767 | printf("}, "); |
| 768 | } |
| 769 | printf("}\n"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 770 | if (mm.size() != 2 || |
| 771 | mm[-4][-4] != -4 || |
| 772 | mm[-4][-3] != -3 || |
| 773 | mm[-4][-2] != -2 || |
| 774 | mm[-4][-1] != -1 || |
| 775 | mm[4][4] != 4 || |
| 776 | mm[4][3] != 3 || |
| 777 | mm[4][2] != 2 || |
| 778 | mm[4][1] != 1) { |
| 779 | printf("*** FAILED ***\n"); |
| 780 | return_code |= ERR_CONTAINERS; |
| 781 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 782 | |
| 783 | /** |
| 784 | * INSANITY TEST |
| 785 | */ |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 786 | if (!noinsane) { |
| 787 | Insanity insane; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 788 | insane.userMap.insert(make_pair(Numberz::FIVE, 5)); |
| 789 | insane.userMap.insert(make_pair(Numberz::EIGHT, 8)); |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 790 | Xtruct truck; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 791 | truck.string_thing = "Goodbye4"; |
| 792 | truck.byte_thing = 4; |
| 793 | truck.i32_thing = 4; |
| 794 | truck.i64_thing = 4; |
| 795 | Xtruct truck2; |
| 796 | truck2.string_thing = "Hello2"; |
| 797 | truck2.byte_thing = 2; |
| 798 | truck2.i32_thing = 2; |
| 799 | truck2.i64_thing = 2; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 800 | insane.xtructs.push_back(truck); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 801 | insane.xtructs.push_back(truck2); |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 802 | printf("testInsanity()"); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 803 | map<UserId, map<Numberz::type, Insanity> > whoa; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 804 | testClient.testInsanity(whoa, insane); |
| 805 | printf(" = {"); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 806 | map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 807 | for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { |
| 808 | printf("%" PRId64 " => {", i_iter->first); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 809 | map<Numberz::type, Insanity>::const_iterator i2_iter; |
| 810 | 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] | 811 | printf("%d => {", i2_iter->first); |
| 812 | map<Numberz::type, UserId> userMap = i2_iter->second.userMap; |
| 813 | map<Numberz::type, UserId>::const_iterator um; |
| 814 | printf("{"); |
| 815 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
| 816 | printf("%d => %" PRId64 ", ", um->first, um->second); |
| 817 | } |
| 818 | printf("}, "); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 819 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 820 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 821 | vector<Xtruct>::const_iterator x; |
| 822 | printf("{"); |
| 823 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
| 824 | printf("{\"%s\", %d, %d, %" PRId64 "}, ", |
| 825 | x->string_thing.c_str(), |
| 826 | (int)x->byte_thing, |
| 827 | x->i32_thing, |
| 828 | x->i64_thing); |
| 829 | } |
| 830 | printf("}"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 831 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 832 | printf("}, "); |
| 833 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 834 | printf("}, "); |
| 835 | } |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 836 | printf("}\n"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 837 | bool failed = false; |
| 838 | map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1)); |
| 839 | if (whoa.size() != 2) { |
| 840 | failed = true; |
| 841 | } |
| 842 | if (it1 == whoa.end()) { |
| 843 | failed = true; |
| 844 | } else { |
| 845 | map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO); |
| 846 | if (it12 == it1->second.end() || it12->second != insane) { |
| 847 | failed = true; |
| 848 | } |
| 849 | map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE); |
| 850 | if (it13 == it1->second.end() || it13->second != insane) { |
| 851 | failed = true; |
| 852 | } |
| 853 | } |
| 854 | map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2)); |
| 855 | if (it2 == whoa.end()) { |
| 856 | failed = true; |
| 857 | } else { |
| 858 | map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX); |
| 859 | if (it26 == it1->second.end() || it26->second != Insanity()) { |
| 860 | failed = true; |
| 861 | } |
| 862 | } |
| 863 | if (failed) { |
| 864 | printf("*** FAILED ***\n"); |
| 865 | return_code |= ERR_STRUCTS; |
| 866 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 867 | } |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 868 | |
| 869 | /** |
| 870 | * MULTI TEST |
| 871 | */ |
| 872 | printf("testMulti()\n"); |
| 873 | try { |
| 874 | map<int16_t, string> mul_map; |
| 875 | Xtruct mul_result; |
| 876 | mul_map[1] = "blah"; |
| 877 | mul_map[2] = "thing"; |
| 878 | testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24)); |
| 879 | Xtruct xxs; |
| 880 | xxs.string_thing = "Hello2"; |
| 881 | xxs.byte_thing = 42; |
| 882 | xxs.i32_thing = 4242; |
| 883 | xxs.i64_thing = 424242; |
| 884 | if (mul_result != xxs) { |
| 885 | printf("*** FAILED ***\n"); |
| 886 | return_code |= ERR_STRUCTS; |
| 887 | } |
| 888 | } catch (exception& ex) { |
| 889 | printf("*** FAILED ***\n"); |
| 890 | return_code |= ERR_STRUCTS; |
| 891 | } |
| 892 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 893 | /* test exception */ |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 894 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 895 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 896 | printf("testClient.testException(\"Xception\") =>"); |
| 897 | testClient.testException("Xception"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 898 | printf(" void\n*** FAILED ***\n"); |
| 899 | return_code |= ERR_EXCEPTIONS; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 900 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 901 | } catch (Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 902 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 903 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 904 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 905 | try { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 906 | printf("testClient.testException(\"TException\") =>"); |
| 907 | testClient.testException("TException"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 908 | printf(" void\n*** FAILED ***\n"); |
| 909 | return_code |= ERR_EXCEPTIONS; |
Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 910 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 911 | } catch (const TException&) { |
| 912 | printf(" Caught TException\n"); |
| 913 | } |
Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 914 | |
| 915 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 916 | printf("testClient.testException(\"success\") =>"); |
| 917 | testClient.testException("success"); |
| 918 | printf(" void\n"); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 919 | } catch (...) { |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 920 | printf(" exception\n*** FAILED ***\n"); |
| 921 | return_code |= ERR_EXCEPTIONS; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 922 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 923 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 924 | /* test multi exception */ |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 925 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 926 | try { |
| 927 | printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 928 | Xtruct result; |
| 929 | testClient.testMultiException(result, "Xception", "test 1"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 930 | printf(" result\n*** FAILED ***\n"); |
| 931 | return_code |= ERR_EXCEPTIONS; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 932 | } catch (Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 933 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
| 934 | } |
| 935 | |
| 936 | try { |
| 937 | printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 938 | Xtruct result; |
| 939 | testClient.testMultiException(result, "Xception2", "test 2"); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 940 | printf(" result\n*** FAILED ***\n"); |
| 941 | return_code |= ERR_EXCEPTIONS; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 942 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 943 | } catch (Xception2& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 944 | 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] | 945 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 946 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 947 | try { |
| 948 | printf("testClient.testMultiException(\"success\", \"test 3\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 949 | Xtruct result; |
| 950 | testClient.testMultiException(result, "success", "test 3"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 951 | printf(" {{\"%s\"}}\n", result.string_thing.c_str()); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 952 | } catch (...) { |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 953 | printf(" exception\n*** FAILED ***\n"); |
| 954 | return_code |= ERR_EXCEPTIONS; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 955 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 956 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 957 | /* test oneway void */ |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 958 | { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 959 | printf("testClient.testOneway(1) =>"); |
| 960 | uint64_t startOneway = now(); |
| 961 | testClient.testOneway(1); |
| 962 | uint64_t elapsed = now() - startOneway; |
| 963 | if (elapsed > 200 * 1000) { // 0.2 seconds |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 964 | printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0); |
| 965 | return_code |= ERR_BASETYPES; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 966 | } else { |
| 967 | printf(" success - took %.2f ms\n", (double)elapsed / 1000.0); |
| 968 | } |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 969 | } |
| 970 | |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 971 | /** |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 972 | * redo a simple test after the oneway to make sure we aren't "off by one" -- |
| 973 | * 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] | 974 | * fail since it will get the void confirmation rather than the correct |
| 975 | * result. In this circumstance, the client will throw the exception: |
| 976 | * |
| 977 | * TApplicationException: Wrong method namea |
| 978 | */ |
| 979 | /** |
| 980 | * I32 TEST |
| 981 | */ |
| 982 | printf("re-test testI32(-1)"); |
| 983 | i32 = testClient.testI32(-1); |
| 984 | printf(" = %d\n", i32); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 985 | if (i32 != -1) |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 986 | return_code |= ERR_BASETYPES; |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 987 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 988 | uint64_t stop = now(); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 989 | uint64_t tot = stop - start; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 990 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 991 | printf("Total time: %" PRIu64 " us\n", stop - start); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 992 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 993 | time_tot += tot; |
| 994 | if (time_min == 0 || tot < time_min) { |
| 995 | time_min = tot; |
| 996 | } |
| 997 | if (tot > time_max) { |
| 998 | time_max = tot; |
| 999 | } |
| 1000 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 1001 | transport->close(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1004 | printf("\nAll tests done.\n"); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1005 | |
| 1006 | uint64_t time_avg = time_tot / numTests; |
| 1007 | |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 1008 | printf("Min time: %" PRIu64 " us\n", time_min); |
| 1009 | printf("Max time: %" PRIu64 " us\n", time_max); |
| 1010 | printf("Avg time: %" PRIu64 " us\n", time_avg); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1011 | |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1012 | return return_code; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1013 | } |