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