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