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