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