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 |
| 39 | #include <thrift/windows/TWinsockSingleton.h> |
| 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 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 54 | //extern uint32_t g_socket_syscalls; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 55 | |
| 56 | // Current time, microseconds since the epoch |
| 57 | uint64_t now() |
| 58 | { |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 59 | int64_t ret; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 60 | struct timeval tv; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 61 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 62 | THRIFT_GETTIMEOFDAY(&tv, NULL); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 63 | ret = tv.tv_sec; |
| 64 | ret = ret*1000*1000 + tv.tv_usec; |
| 65 | return ret; |
| 66 | } |
| 67 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 68 | static void testString_clientReturn(const char* host, int port, event_base *base, TProtocolFactory* protocolFactory, ThriftTestCobClient* client) { |
Roger Meier | a8cef6e | 2011-07-17 18:55:59 +0000 | [diff] [blame] | 69 | (void) host; |
| 70 | (void) port; |
| 71 | (void) protocolFactory; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 72 | try { |
| 73 | string s; |
| 74 | client->recv_testString(s); |
| 75 | cout << "testString: " << s << endl; |
| 76 | } catch (TException& exn) { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 77 | cout << "Error: " << exn.what() << endl; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | event_base_loopbreak(base); // end test |
| 81 | } |
| 82 | |
| 83 | static void testVoid_clientReturn(const char* host, int port, event_base *base, TProtocolFactory* protocolFactory, ThriftTestCobClient* client) { |
| 84 | try { |
| 85 | client->recv_testVoid(); |
| 86 | cout << "testVoid" << endl; |
| 87 | |
| 88 | // next test |
| 89 | delete client; |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 90 | boost::shared_ptr<TAsyncChannel> channel(new TEvhttpClientChannel(host, "/", host, port, base)); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 91 | client = new ThriftTestCobClient(channel, protocolFactory); |
Roger Meier | 0a7c69c | 2014-05-02 21:15:45 +0200 | [diff] [blame] | 92 | client->testString(tcxx::bind(testString_clientReturn, host, port, base, protocolFactory, tcxx::placeholders::_1), "Test"); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 93 | } catch (TException& exn) { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 94 | cout << "Error: " << exn.what() << endl; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 98 | int main(int argc, char** argv) { |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 99 | string file_path = boost::filesystem::system_complete(argv[0]).string(); |
| 100 | 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] | 101 | #if _WIN32 |
| 102 | transport::TWinsockSingleton::create(); |
| 103 | #endif |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 104 | string host = "localhost"; |
| 105 | int port = 9090; |
| 106 | int numTests = 1; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 107 | bool ssl = false; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 108 | string transport_type = "buffered"; |
| 109 | string protocol_type = "binary"; |
| 110 | string domain_socket = ""; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 111 | bool noinsane = false; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 112 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 113 | boost::program_options::options_description desc("Allowed options"); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 114 | desc.add_options() |
| 115 | ("help,h", "produce help message") |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 116 | ("host", boost::program_options::value<string>(&host)->default_value(host), "Host to connect") |
| 117 | ("port", boost::program_options::value<int>(&port)->default_value(port), "Port number to connect") |
| 118 | ("domain-socket", boost::program_options::value<string>(&domain_socket)->default_value(domain_socket), "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port") |
| 119 | ("transport", boost::program_options::value<string>(&transport_type)->default_value(transport_type), "Transport: buffered, framed, http, evhttp") |
Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 120 | ("protocol", boost::program_options::value<string>(&protocol_type)->default_value(protocol_type), "Protocol: binary, compact, json") |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 121 | ("ssl", "Encrypted Transport using SSL") |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 122 | ("testloops,n", boost::program_options::value<int>(&numTests)->default_value(numTests), "Number of Tests") |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 123 | ("noinsane", "Do not run insanity test") |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 124 | ; |
| 125 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 126 | boost::program_options::variables_map vm; |
| 127 | boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); |
| 128 | boost::program_options::notify(vm); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 129 | |
| 130 | if (vm.count("help")) { |
| 131 | cout << desc << "\n"; |
| 132 | return 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 133 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 134 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 135 | try { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 136 | if (!protocol_type.empty()) { |
| 137 | if (protocol_type == "binary") { |
Roger Meier | 284101c | 2014-03-11 21:20:35 +0100 | [diff] [blame] | 138 | } else if (protocol_type == "compact") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 139 | } else if (protocol_type == "json") { |
| 140 | } else { |
| 141 | throw invalid_argument("Unknown protocol type "+protocol_type); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if (!transport_type.empty()) { |
| 146 | if (transport_type == "buffered") { |
| 147 | } else if (transport_type == "framed") { |
| 148 | } else if (transport_type == "http") { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 149 | } else if (transport_type == "evhttp") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 150 | } else { |
| 151 | throw invalid_argument("Unknown transport type "+transport_type); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | } catch (std::exception& e) { |
| 156 | cerr << e.what() << endl; |
| 157 | cout << desc << "\n"; |
| 158 | return 1; |
| 159 | } |
| 160 | |
| 161 | if (vm.count("ssl")) { |
| 162 | ssl = true; |
| 163 | } |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 164 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 165 | if (vm.count("noinsane")) { |
| 166 | noinsane = true; |
| 167 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 168 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 169 | boost::shared_ptr<TTransport> transport; |
| 170 | boost::shared_ptr<TProtocol> protocol; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 171 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 172 | boost::shared_ptr<TSocket> socket; |
| 173 | boost::shared_ptr<TSSLSocketFactory> factory; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 174 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 175 | if (ssl) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 176 | factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory()); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 177 | factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 178 | factory->loadTrustedCertificates((dir_path + "../keys/CA.pem").c_str()); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 179 | factory->authenticate(true); |
| 180 | socket = factory->createSocket(host, port); |
| 181 | } else { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 182 | if (domain_socket != "") { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 183 | socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 184 | port = 0; |
| 185 | } |
| 186 | else { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 187 | socket = boost::shared_ptr<TSocket>(new TSocket(host, port)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 188 | } |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 189 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 190 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 191 | if (transport_type.compare("http") == 0) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 192 | boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service")); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 193 | transport = httpSocket; |
| 194 | } else if (transport_type.compare("framed") == 0){ |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 195 | boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 196 | transport = framedSocket; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 197 | } else{ |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 198 | boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 199 | transport = bufferedSocket; |
| 200 | } |
| 201 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 202 | if (protocol_type.compare("json") == 0) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 203 | boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 204 | protocol = jsonProtocol; |
Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 205 | } else if (protocol_type.compare("compact") == 0) { |
| 206 | boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport)); |
| 207 | protocol = compactProtocol; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 208 | } else{ |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 209 | boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 210 | protocol = binaryProtocol; |
| 211 | } |
| 212 | |
| 213 | // Connection info |
| 214 | cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: " << domain_socket; |
| 215 | if (port != 0) { |
| 216 | cout << host << ":" << port; |
| 217 | } |
| 218 | cout << endl; |
| 219 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 220 | if (transport_type.compare("evhttp") == 0) { |
| 221 | event_base *base = event_base_new(); |
| 222 | cout << "Libevent Version: " << event_get_version() << endl; |
| 223 | cout << "Libevent Method: " << event_base_get_method(base) << endl; |
| 224 | #if LIBEVENT_VERSION_NUMBER >= 0x02000000 |
| 225 | cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl; |
| 226 | #endif |
| 227 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 228 | boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 229 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 230 | boost::shared_ptr<TAsyncChannel> channel(new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base)); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 231 | ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get()); |
Roger Meier | 0a7c69c | 2014-05-02 21:15:45 +0200 | [diff] [blame] | 232 | client->testVoid(tcxx::bind(testVoid_clientReturn, host.c_str(), port, base, protocolFactory.get(), tcxx::placeholders::_1)); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 233 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 234 | event_base_loop(base, 0); |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 239 | ThriftTestClient testClient(protocol); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 240 | |
| 241 | uint64_t time_min = 0; |
| 242 | uint64_t time_max = 0; |
| 243 | uint64_t time_tot = 0; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 244 | |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 245 | int failCount = 0; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 246 | int test = 0; |
| 247 | for (test = 0; test < numTests; ++test) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 248 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 249 | try { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 250 | transport->open(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 251 | } catch (TTransportException& ttx) { |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 252 | printf("Connect failed: %s\n", ttx.what()); |
Roger Meier | 5b1e3c7 | 2011-12-08 13:20:12 +0000 | [diff] [blame] | 253 | return 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 254 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 255 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 256 | /** |
| 257 | * CONNECT TEST |
| 258 | */ |
| 259 | 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] | 260 | |
| 261 | uint64_t start = now(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 262 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 263 | /** |
| 264 | * VOID TEST |
| 265 | */ |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 266 | try { |
| 267 | printf("testVoid()"); |
| 268 | testClient.testVoid(); |
| 269 | printf(" = void\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 270 | } catch (TApplicationException& tax) { |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 271 | printf("%s\n", tax.what()); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 272 | failCount++; |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 273 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 274 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 275 | /** |
| 276 | * STRING TEST |
| 277 | */ |
| 278 | printf("testString(\"Test\")"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 279 | string s; |
| 280 | testClient.testString(s, "Test"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 281 | printf(" = \"%s\"\n", s.c_str()); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 282 | if (s != "Test") |
| 283 | failCount++; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 284 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 285 | /** |
| 286 | * BYTE TEST |
| 287 | */ |
| 288 | printf("testByte(1)"); |
| 289 | uint8_t u8 = testClient.testByte(1); |
| 290 | printf(" = %d\n", (int)u8); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 291 | if (u8 != 1) |
| 292 | failCount++; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 293 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 294 | /** |
| 295 | * I32 TEST |
| 296 | */ |
| 297 | printf("testI32(-1)"); |
| 298 | int32_t i32 = testClient.testI32(-1); |
| 299 | printf(" = %d\n", i32); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 300 | if (i32 != -1) |
| 301 | failCount++; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 302 | |
| 303 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 304 | * I64 TEST |
| 305 | */ |
| 306 | printf("testI64(-34359738368)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 307 | int64_t i64 = testClient.testI64(-34359738368LL); |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 308 | printf(" = %" PRId64 "\n", i64); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 309 | if (i64 != -34359738368LL) |
| 310 | failCount++; |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 311 | /** |
| 312 | * DOUBLE TEST |
| 313 | */ |
| 314 | printf("testDouble(-5.2098523)"); |
| 315 | double dub = testClient.testDouble(-5.2098523); |
Roger Meier | a8cef6e | 2011-07-17 18:55:59 +0000 | [diff] [blame] | 316 | printf(" = %f\n", dub); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 317 | if ((dub - (-5.2098523)) > 0.001) |
| 318 | failCount++; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 319 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 320 | /** |
| 321 | * STRUCT TEST |
| 322 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 323 | printf("testStruct({\"Zero\", 1, -3, -5})"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 324 | Xtruct out; |
| 325 | out.string_thing = "Zero"; |
| 326 | out.byte_thing = 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 327 | out.i32_thing = -3; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 328 | out.i64_thing = -5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 329 | Xtruct in; |
| 330 | testClient.testStruct(in, out); |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 331 | printf(" = {\"%s\", %d, %d, %" PRId64 "}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 332 | in.string_thing.c_str(), |
| 333 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 334 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 335 | in.i64_thing); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 336 | if (in != out) |
| 337 | failCount++; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 338 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 339 | /** |
| 340 | * NESTED STRUCT TEST |
| 341 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 342 | printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 343 | Xtruct2 out2; |
| 344 | out2.byte_thing = 1; |
| 345 | out2.struct_thing = out; |
| 346 | out2.i32_thing = 5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 347 | Xtruct2 in2; |
| 348 | testClient.testNest(in2, out2); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 349 | in = in2.struct_thing; |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 350 | printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 351 | in2.byte_thing, |
| 352 | in.string_thing.c_str(), |
| 353 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 354 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 355 | in.i64_thing, |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 356 | in2.i32_thing); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 357 | if (in2 != out2) |
| 358 | failCount++; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 359 | |
| 360 | /** |
| 361 | * MAP TEST |
| 362 | */ |
| 363 | map<int32_t,int32_t> mapout; |
| 364 | for (int32_t i = 0; i < 5; ++i) { |
| 365 | mapout.insert(make_pair(i, i-10)); |
| 366 | } |
| 367 | printf("testMap({"); |
| 368 | map<int32_t, int32_t>::const_iterator m_iter; |
| 369 | bool first = true; |
| 370 | for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) { |
| 371 | if (first) { |
| 372 | first = false; |
| 373 | } else { |
| 374 | printf(", "); |
| 375 | } |
| 376 | printf("%d => %d", m_iter->first, m_iter->second); |
| 377 | } |
| 378 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 379 | map<int32_t,int32_t> mapin; |
| 380 | testClient.testMap(mapin, mapout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 381 | printf(" = {"); |
| 382 | first = true; |
| 383 | for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { |
| 384 | if (first) { |
| 385 | first = false; |
| 386 | } else { |
| 387 | printf(", "); |
| 388 | } |
| 389 | printf("%d => %d", m_iter->first, m_iter->second); |
| 390 | } |
| 391 | printf("}\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 392 | if (mapin != mapout) |
| 393 | failCount++; |
| 394 | |
| 395 | /** |
| 396 | * STRING MAP TEST |
| 397 | * missing |
| 398 | */ |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 399 | |
| 400 | /** |
| 401 | * SET TEST |
| 402 | */ |
| 403 | set<int32_t> setout; |
| 404 | for (int32_t i = -2; i < 3; ++i) { |
| 405 | setout.insert(i); |
| 406 | } |
| 407 | printf("testSet({"); |
| 408 | set<int32_t>::const_iterator s_iter; |
| 409 | first = true; |
| 410 | for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) { |
| 411 | if (first) { |
| 412 | first = false; |
| 413 | } else { |
| 414 | printf(", "); |
| 415 | } |
| 416 | printf("%d", *s_iter); |
| 417 | } |
| 418 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 419 | set<int32_t> setin; |
| 420 | testClient.testSet(setin, setout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 421 | printf(" = {"); |
| 422 | first = true; |
| 423 | for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { |
| 424 | if (first) { |
| 425 | first = false; |
| 426 | } else { |
| 427 | printf(", "); |
| 428 | } |
| 429 | printf("%d", *s_iter); |
| 430 | } |
| 431 | printf("}\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 432 | if (setin != setout) |
| 433 | failCount++; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 434 | |
| 435 | /** |
| 436 | * LIST TEST |
| 437 | */ |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 438 | vector<int32_t> listout; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 439 | for (int32_t i = -2; i < 3; ++i) { |
| 440 | listout.push_back(i); |
| 441 | } |
| 442 | printf("testList({"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 443 | vector<int32_t>::const_iterator l_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 444 | first = true; |
| 445 | for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { |
| 446 | if (first) { |
| 447 | first = false; |
| 448 | } else { |
| 449 | printf(", "); |
| 450 | } |
| 451 | printf("%d", *l_iter); |
| 452 | } |
| 453 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 454 | vector<int32_t> listin; |
| 455 | testClient.testList(listin, listout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 456 | printf(" = {"); |
| 457 | first = true; |
| 458 | for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { |
| 459 | if (first) { |
| 460 | first = false; |
| 461 | } else { |
| 462 | printf(", "); |
| 463 | } |
| 464 | printf("%d", *l_iter); |
| 465 | } |
| 466 | printf("}\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 467 | if (listin != listout) |
| 468 | failCount++; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 469 | |
| 470 | /** |
| 471 | * ENUM TEST |
| 472 | */ |
| 473 | printf("testEnum(ONE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 474 | Numberz::type ret = testClient.testEnum(Numberz::ONE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 475 | printf(" = %d\n", ret); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 476 | if (ret != Numberz::ONE) |
| 477 | failCount++; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 478 | |
| 479 | printf("testEnum(TWO)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 480 | ret = testClient.testEnum(Numberz::TWO); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 481 | printf(" = %d\n", ret); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 482 | if (ret != Numberz::TWO) |
| 483 | failCount++; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 484 | |
| 485 | printf("testEnum(THREE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 486 | ret = testClient.testEnum(Numberz::THREE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 487 | printf(" = %d\n", ret); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 488 | if (ret != Numberz::THREE) |
| 489 | failCount++; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 490 | |
| 491 | printf("testEnum(FIVE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 492 | ret = testClient.testEnum(Numberz::FIVE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 493 | printf(" = %d\n", ret); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 494 | if (ret != Numberz::FIVE) |
| 495 | failCount++; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 496 | |
| 497 | printf("testEnum(EIGHT)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 498 | ret = testClient.testEnum(Numberz::EIGHT); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 499 | printf(" = %d\n", ret); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 500 | if (ret != Numberz::EIGHT) |
| 501 | failCount++; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * TYPEDEF TEST |
| 505 | */ |
| 506 | printf("testTypedef(309858235082523)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 507 | UserId uid = testClient.testTypedef(309858235082523LL); |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 508 | printf(" = %" PRId64 "\n", uid); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 509 | if (uid != 309858235082523LL) |
| 510 | failCount++; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 511 | |
| 512 | /** |
| 513 | * NESTED MAP TEST |
| 514 | */ |
| 515 | printf("testMapMap(1)"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 516 | map<int32_t, map<int32_t, int32_t> > mm; |
| 517 | testClient.testMapMap(mm, 1); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 518 | printf(" = {"); |
| 519 | map<int32_t, map<int32_t, int32_t> >::const_iterator mi; |
| 520 | for (mi = mm.begin(); mi != mm.end(); ++mi) { |
| 521 | printf("%d => {", mi->first); |
| 522 | map<int32_t, int32_t>::const_iterator mi2; |
| 523 | for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) { |
| 524 | printf("%d => %d, ", mi2->first, mi2->second); |
| 525 | } |
| 526 | printf("}, "); |
| 527 | } |
| 528 | printf("}\n"); |
| 529 | |
| 530 | /** |
| 531 | * INSANITY TEST |
| 532 | */ |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 533 | if (!noinsane) { |
| 534 | Insanity insane; |
| 535 | insane.userMap.insert(make_pair(Numberz::FIVE, 5000)); |
| 536 | Xtruct truck; |
| 537 | truck.string_thing = "Truck"; |
| 538 | truck.byte_thing = 8; |
| 539 | truck.i32_thing = 8; |
| 540 | truck.i64_thing = 8; |
| 541 | insane.xtructs.push_back(truck); |
| 542 | printf("testInsanity()"); |
| 543 | map<UserId, map<Numberz::type,Insanity> > whoa; |
| 544 | testClient.testInsanity(whoa, insane); |
| 545 | printf(" = {"); |
| 546 | map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter; |
| 547 | for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { |
| 548 | printf("%" PRId64 " => {", i_iter->first); |
| 549 | map<Numberz::type,Insanity>::const_iterator i2_iter; |
| 550 | for (i2_iter = i_iter->second.begin(); |
| 551 | i2_iter != i_iter->second.end(); |
| 552 | ++i2_iter) { |
| 553 | printf("%d => {", i2_iter->first); |
| 554 | map<Numberz::type, UserId> userMap = i2_iter->second.userMap; |
| 555 | map<Numberz::type, UserId>::const_iterator um; |
| 556 | printf("{"); |
| 557 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
| 558 | printf("%d => %" PRId64 ", ", um->first, um->second); |
| 559 | } |
| 560 | printf("}, "); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 561 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 562 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 563 | vector<Xtruct>::const_iterator x; |
| 564 | printf("{"); |
| 565 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
| 566 | printf("{\"%s\", %d, %d, %" PRId64 "}, ", |
| 567 | x->string_thing.c_str(), |
| 568 | (int)x->byte_thing, |
| 569 | x->i32_thing, |
| 570 | x->i64_thing); |
| 571 | } |
| 572 | printf("}"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 573 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 574 | printf("}, "); |
| 575 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 576 | printf("}, "); |
| 577 | } |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 578 | printf("}\n"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 579 | } |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 580 | /* test exception */ |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 581 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 582 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 583 | printf("testClient.testException(\"Xception\") =>"); |
| 584 | testClient.testException("Xception"); |
| 585 | printf(" void\nFAILURE\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 586 | failCount++; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 587 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 588 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 589 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 590 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 591 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 592 | try { |
Roger Meier | 99b3672 | 2012-05-03 21:21:43 +0000 | [diff] [blame] | 593 | printf("testClient.testException(\"TException\") =>"); |
| 594 | testClient.testException("TException"); |
Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 595 | printf(" void\nFAILURE\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 596 | failCount++; |
Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 597 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 598 | } catch(const TException&) { |
Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 599 | printf(" Caught TException\n"); |
| 600 | } |
| 601 | |
| 602 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 603 | printf("testClient.testException(\"success\") =>"); |
| 604 | testClient.testException("success"); |
| 605 | printf(" void\n"); |
| 606 | } catch(...) { |
| 607 | printf(" exception\nFAILURE\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 608 | failCount++; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 609 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 610 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 611 | /* test multi exception */ |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 612 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 613 | try { |
| 614 | printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 615 | Xtruct result; |
| 616 | testClient.testMultiException(result, "Xception", "test 1"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 617 | printf(" result\nFAILURE\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 618 | failCount++; |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 619 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 620 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
| 621 | } |
| 622 | |
| 623 | try { |
| 624 | printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 625 | Xtruct result; |
| 626 | testClient.testMultiException(result, "Xception2", "test 2"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 627 | printf(" result\nFAILURE\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 628 | failCount++; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 629 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 630 | } catch(Xception2& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 631 | 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] | 632 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 633 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 634 | try { |
| 635 | printf("testClient.testMultiException(\"success\", \"test 3\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 636 | Xtruct result; |
| 637 | testClient.testMultiException(result, "success", "test 3"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 638 | printf(" {{\"%s\"}}\n", result.string_thing.c_str()); |
| 639 | } catch(...) { |
| 640 | printf(" exception\nFAILURE\n"); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 641 | failCount++; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 642 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 643 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 644 | /* test oneway void */ |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 645 | { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 646 | printf("testClient.testOneway(1) =>"); |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 647 | uint64_t startOneway = now(); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 648 | testClient.testOneway(1); |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 649 | uint64_t elapsed = now() - startOneway; |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 650 | if (elapsed > 200 * 1000) { // 0.2 seconds |
| 651 | printf(" FAILURE - took %.2f ms\n", (double)elapsed/1000.0); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 652 | failCount++; |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 653 | } else { |
| 654 | printf(" success - took %.2f ms\n", (double)elapsed/1000.0); |
| 655 | } |
| 656 | } |
| 657 | |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 658 | /** |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 659 | * redo a simple test after the oneway to make sure we aren't "off by one" -- |
| 660 | * 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] | 661 | * fail since it will get the void confirmation rather than the correct |
| 662 | * result. In this circumstance, the client will throw the exception: |
| 663 | * |
| 664 | * TApplicationException: Wrong method namea |
| 665 | */ |
| 666 | /** |
| 667 | * I32 TEST |
| 668 | */ |
| 669 | printf("re-test testI32(-1)"); |
| 670 | i32 = testClient.testI32(-1); |
| 671 | printf(" = %d\n", i32); |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 672 | if (i32 != -1) |
| 673 | failCount++; |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 674 | |
| 675 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 676 | uint64_t stop = now(); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 677 | uint64_t tot = stop-start; |
| 678 | |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 679 | printf("Total time: %" PRIu64 " us\n", stop-start); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 680 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 681 | time_tot += tot; |
| 682 | if (time_min == 0 || tot < time_min) { |
| 683 | time_min = tot; |
| 684 | } |
| 685 | if (tot > time_max) { |
| 686 | time_max = tot; |
| 687 | } |
| 688 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 689 | transport->close(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 692 | // printf("\nSocket syscalls: %u", g_socket_syscalls); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 693 | printf("\nAll tests done.\n"); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 694 | |
| 695 | uint64_t time_avg = time_tot / numTests; |
| 696 | |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 697 | printf("Min time: %" PRIu64 " us\n", time_min); |
| 698 | printf("Max time: %" PRIu64 " us\n", time_max); |
| 699 | printf("Avg time: %" PRIu64 " us\n", time_avg); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 700 | |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 701 | return failCount; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 702 | } |