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