| 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> | 
| Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 26 | #include <thrift/protocol/THeaderProtocol.h> | 
| Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 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> | 
| cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 37 | #include <boost/filesystem.hpp> | 
| Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 38 | #include <thrift/cxxfunctional.h> | 
 | 39 | #if _WIN32 | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 40 | #include <thrift/windows/TWinsockSingleton.h> | 
| Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 41 | #endif | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 42 |  | 
| Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 43 | #include "ThriftTest.h" | 
 | 44 |  | 
| Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 45 | using namespace std; | 
| T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 46 | using namespace apache::thrift; | 
 | 47 | using namespace apache::thrift::protocol; | 
 | 48 | using namespace apache::thrift::transport; | 
| Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 49 | using namespace thrift::test; | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 50 | using namespace apache::thrift::async; | 
 | 51 |  | 
| cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 52 | // Length of argv[0] - Length of script dir | 
 | 53 | #define EXECUTABLE_FILE_NAME_LENGTH 19 | 
 | 54 |  | 
| Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 55 | // Current time, microseconds since the epoch | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 56 | uint64_t now() { | 
| Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 57 |   int64_t ret; | 
| Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 58 |   struct timeval tv; | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 59 |  | 
| Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 60 |   THRIFT_GETTIMEOFDAY(&tv, NULL); | 
| Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 61 |   ret = tv.tv_sec; | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 62 |   ret = ret * 1000 * 1000 + tv.tv_usec; | 
| Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 63 |   return ret; | 
 | 64 | } | 
 | 65 |  | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 66 | static void testString_clientReturn(const char* host, | 
 | 67 |                                     int port, | 
 | 68 |                                     event_base* base, | 
 | 69 |                                     TProtocolFactory* protocolFactory, | 
 | 70 |                                     ThriftTestCobClient* client) { | 
 | 71 |   (void)host; | 
 | 72 |   (void)port; | 
 | 73 |   (void)protocolFactory; | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 74 |   try { | 
 | 75 |     string s; | 
 | 76 |     client->recv_testString(s); | 
 | 77 |     cout << "testString: " << s << endl; | 
 | 78 |   } catch (TException& exn) { | 
| Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 79 |     cout << "Error: " << exn.what() << endl; | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 80 |   } | 
 | 81 |  | 
 | 82 |   event_base_loopbreak(base); // end test | 
 | 83 | } | 
 | 84 |  | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 85 | static void testVoid_clientReturn(const char* host, | 
 | 86 |                                   int port, | 
 | 87 |                                   event_base* base, | 
 | 88 |                                   TProtocolFactory* protocolFactory, | 
 | 89 |                                   ThriftTestCobClient* client) { | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 90 |   try { | 
 | 91 |     client->recv_testVoid(); | 
 | 92 |     cout << "testVoid" << endl; | 
 | 93 |  | 
 | 94 |     // next test | 
 | 95 |     delete client; | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 96 |     boost::shared_ptr<TAsyncChannel> channel(new TEvhttpClientChannel(host, "/", host, port, base)); | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 97 |     client = new ThriftTestCobClient(channel, protocolFactory); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 98 |     client->testString(tcxx::bind(testString_clientReturn, | 
 | 99 |                                   host, | 
 | 100 |                                   port, | 
 | 101 |                                   base, | 
 | 102 |                                   protocolFactory, | 
 | 103 |                                   tcxx::placeholders::_1), | 
 | 104 |                        "Test"); | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 105 |   } catch (TException& exn) { | 
| Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 106 |     cout << "Error: " << exn.what() << endl; | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 107 |   } | 
 | 108 | } | 
 | 109 |  | 
| Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 110 | // Workaround for absense of C++11 "auto" keyword. | 
 | 111 | template <typename T> | 
 | 112 | bool print_eq(T expected, T actual) { | 
 | 113 |   cout << "(" << actual << ")" << endl; | 
 | 114 |   if (expected != actual) { | 
 | 115 |     cout << "*** FAILED ***" << endl << "Expected: " << expected << " but got: " << actual << endl; | 
 | 116 |     return false; | 
 | 117 |   } | 
 | 118 |   return true; | 
 | 119 | } | 
 | 120 |  | 
 | 121 | #define BASETYPE_IDENTITY_TEST(func, value)                                                        \ | 
 | 122 |   cout << #func "(" << value << ") = ";                                                            \ | 
 | 123 |   try {                                                                                            \ | 
 | 124 |     if (!print_eq(value, testClient.func(value)))                                                  \ | 
 | 125 |       return_code |= ERR_BASETYPES;                                                                \ | 
 | 126 |   } catch (TTransportException&) {                                                                 \ | 
 | 127 |     throw;                                                                                         \ | 
 | 128 |   } catch (exception & ex) {                                                                       \ | 
 | 129 |     cout << "*** FAILED ***" << endl << ex.what() << endl;                                         \ | 
 | 130 |     return_code |= ERR_BASETYPES;                                                                  \ | 
 | 131 |   } | 
 | 132 |  | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 133 | int main(int argc, char** argv) { | 
| Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 134 |   int ERR_BASETYPES = 1; | 
 | 135 |   int ERR_STRUCTS = 2; | 
 | 136 |   int ERR_CONTAINERS = 4; | 
 | 137 |   int ERR_EXCEPTIONS = 8; | 
 | 138 |   int ERR_UNKNOWN = 64; | 
 | 139 |  | 
| cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 140 |   string file_path = boost::filesystem::system_complete(argv[0]).string(); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 141 |   string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH); | 
| Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 142 | #if _WIN32 | 
 | 143 |   transport::TWinsockSingleton::create(); | 
 | 144 | #endif | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 145 |   string host = "localhost"; | 
 | 146 |   int port = 9090; | 
 | 147 |   int numTests = 1; | 
| Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 148 |   bool ssl = false; | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 149 |   string transport_type = "buffered"; | 
 | 150 |   string protocol_type = "binary"; | 
 | 151 |   string domain_socket = ""; | 
| pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 152 |   bool abstract_namespace = false; | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 153 |   bool noinsane = false; | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 154 |  | 
| Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 155 |   boost::program_options::options_description desc("Allowed options"); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 156 |   desc.add_options()("help,h", | 
 | 157 |                      "produce help message")("host", | 
 | 158 |                                              boost::program_options::value<string>(&host) | 
 | 159 |                                                  ->default_value(host), | 
 | 160 |                                              "Host to connect")("port", | 
 | 161 |                                                                 boost::program_options::value<int>( | 
 | 162 |                                                                     &port)->default_value(port), | 
 | 163 |                                                                 "Port number to connect")( | 
 | 164 |       "domain-socket", | 
 | 165 |       boost::program_options::value<string>(&domain_socket)->default_value(domain_socket), | 
 | 166 |       "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")( | 
| pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 167 |       "abstract-namespace", | 
 | 168 |       "Look for the domain socket in the Abstract Namespace (no connection with filesystem pathnames)")( | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 169 |       "transport", | 
 | 170 |       boost::program_options::value<string>(&transport_type)->default_value(transport_type), | 
 | 171 |       "Transport: buffered, framed, http, evhttp")( | 
 | 172 |       "protocol", | 
 | 173 |       boost::program_options::value<string>(&protocol_type)->default_value(protocol_type), | 
| Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 174 |       "Protocol: binary, header, compact, json")("ssl", "Encrypted Transport using SSL")( | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 175 |       "testloops,n", | 
 | 176 |       boost::program_options::value<int>(&numTests)->default_value(numTests), | 
 | 177 |       "Number of Tests")("noinsane", "Do not run insanity test"); | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 178 |  | 
| Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 179 |   boost::program_options::variables_map vm; | 
 | 180 |   boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); | 
 | 181 |   boost::program_options::notify(vm); | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 182 |  | 
 | 183 |   if (vm.count("help")) { | 
 | 184 |     cout << desc << "\n"; | 
| Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 185 |     return ERR_UNKNOWN; | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 186 |   } | 
| Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 187 |  | 
| Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 188 |   try { | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 189 |     if (!protocol_type.empty()) { | 
 | 190 |       if (protocol_type == "binary") { | 
| Roger Meier | 284101c | 2014-03-11 21:20:35 +0100 | [diff] [blame] | 191 |       } else if (protocol_type == "compact") { | 
| Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 192 |       } else if (protocol_type == "header") { | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 193 |       } else if (protocol_type == "json") { | 
 | 194 |       } else { | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 195 |         throw invalid_argument("Unknown protocol type " + protocol_type); | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 196 |       } | 
 | 197 |     } | 
 | 198 |  | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 199 |     if (!transport_type.empty()) { | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 200 |       if (transport_type == "buffered") { | 
 | 201 |       } else if (transport_type == "framed") { | 
 | 202 |       } else if (transport_type == "http") { | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 203 |       } else if (transport_type == "evhttp") { | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 204 |       } else { | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 205 |         throw invalid_argument("Unknown transport type " + transport_type); | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 206 |       } | 
 | 207 |     } | 
 | 208 |  | 
 | 209 |   } catch (std::exception& e) { | 
 | 210 |     cerr << e.what() << endl; | 
 | 211 |     cout << desc << "\n"; | 
| Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 212 |     return ERR_UNKNOWN; | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 213 |   } | 
 | 214 |  | 
 | 215 |   if (vm.count("ssl")) { | 
 | 216 |     ssl = true; | 
 | 217 |   } | 
| cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 218 |  | 
| pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 219 |   if (vm.count("abstract-namespace")) { | 
 | 220 |     abstract_namespace = true; | 
 | 221 |   } | 
 | 222 |  | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 223 |   if (vm.count("noinsane")) { | 
 | 224 |     noinsane = true; | 
 | 225 |   } | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 226 |  | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 227 |   boost::shared_ptr<TTransport> transport; | 
 | 228 |   boost::shared_ptr<TProtocol> protocol; | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 229 |  | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 230 |   boost::shared_ptr<TSocket> socket; | 
 | 231 |   boost::shared_ptr<TSSLSocketFactory> factory; | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 232 |  | 
| Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 233 |   if (ssl) { | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 234 |     factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory()); | 
| Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 235 |     factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); | 
| cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 236 |     factory->loadTrustedCertificates((dir_path + "../keys/CA.pem").c_str()); | 
| Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 237 |     factory->authenticate(true); | 
 | 238 |     socket = factory->createSocket(host, port); | 
 | 239 |   } else { | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 240 |     if (domain_socket != "") { | 
| pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 241 |       if (abstract_namespace) { | 
 | 242 |         std::string abstract_socket("\0", 1); | 
 | 243 |         abstract_socket += domain_socket; | 
 | 244 |         socket = boost::shared_ptr<TSocket>(new TSocket(abstract_socket)); | 
 | 245 |       } else { | 
 | 246 |         socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket)); | 
 | 247 |       } | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 248 |       port = 0; | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 249 |     } else { | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 250 |       socket = boost::shared_ptr<TSocket>(new TSocket(host, port)); | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 251 |     } | 
| Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 252 |   } | 
| Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 253 |  | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 254 |   if (transport_type.compare("http") == 0) { | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 255 |     boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service")); | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 256 |     transport = httpSocket; | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 257 |   } else if (transport_type.compare("framed") == 0) { | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 258 |     boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket)); | 
| Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 259 |     transport = framedSocket; | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 260 |   } else { | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 261 |     boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket)); | 
| Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 262 |     transport = bufferedSocket; | 
 | 263 |   } | 
 | 264 |  | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 265 |   if (protocol_type.compare("json") == 0) { | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 266 |     boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport)); | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 267 |     protocol = jsonProtocol; | 
| Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 268 |   } else if (protocol_type.compare("compact") == 0) { | 
 | 269 |     boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport)); | 
 | 270 |     protocol = compactProtocol; | 
| Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 271 |   } else if (protocol_type == "header") { | 
 | 272 |     boost::shared_ptr<TProtocol> headerProtocol(new THeaderProtocol(transport)); | 
 | 273 |     protocol = headerProtocol; | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 274 |   } else { | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 275 |     boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport)); | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 276 |     protocol = binaryProtocol; | 
 | 277 |   } | 
 | 278 |  | 
 | 279 |   // Connection info | 
| pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 280 |   cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: "; | 
 | 281 |   if (abstract_namespace) { | 
 | 282 |     cout << '@'; | 
 | 283 |   } | 
 | 284 |   cout << domain_socket; | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 285 |   if (port != 0) { | 
 | 286 |     cout << host << ":" << port; | 
 | 287 |   } | 
 | 288 |   cout << endl; | 
 | 289 |  | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 290 |   if (transport_type.compare("evhttp") == 0) { | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 291 |     event_base* base = event_base_new(); | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 292 |     cout << "Libevent Version: " << event_get_version() << endl; | 
 | 293 |     cout << "Libevent Method: " << event_base_get_method(base) << endl; | 
 | 294 | #if LIBEVENT_VERSION_NUMBER >= 0x02000000 | 
 | 295 |     cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl; | 
 | 296 | #endif | 
 | 297 |  | 
| Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 298 |     boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 299 |  | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 300 |     boost::shared_ptr<TAsyncChannel> channel( | 
 | 301 |         new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base)); | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 302 |     ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get()); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 303 |     client->testVoid(tcxx::bind(testVoid_clientReturn, | 
 | 304 |                                 host.c_str(), | 
 | 305 |                                 port, | 
 | 306 |                                 base, | 
 | 307 |                                 protocolFactory.get(), | 
 | 308 |                                 tcxx::placeholders::_1)); | 
| Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 309 |  | 
| Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 310 |     event_base_loop(base, 0); | 
 | 311 |     return 0; | 
 | 312 |   } | 
 | 313 |  | 
| Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 314 |   ThriftTestClient testClient(protocol); | 
| Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 315 |  | 
 | 316 |   uint64_t time_min = 0; | 
 | 317 |   uint64_t time_max = 0; | 
 | 318 |   uint64_t time_tot = 0; | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 319 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 320 |   int return_code = 0; | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 321 |  | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 322 |   int test = 0; | 
 | 323 |   for (test = 0; test < numTests; ++test) { | 
| Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 324 |  | 
| Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 325 |     try { | 
| Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 326 |       transport->open(); | 
| Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 327 |     } catch (TTransportException& ttx) { | 
| Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 328 |       printf("Connect failed: %s\n", ttx.what()); | 
| Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 329 |       return ERR_UNKNOWN; | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 330 |     } | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 331 |  | 
| Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 332 |     /** | 
 | 333 |      * CONNECT TEST | 
 | 334 |      */ | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 335 |     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] | 336 |  | 
 | 337 |     uint64_t start = now(); | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 338 |  | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 339 |     /** | 
 | 340 |      * VOID TEST | 
 | 341 |      */ | 
| Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 342 |     try { | 
 | 343 |       printf("testVoid()"); | 
 | 344 |       testClient.testVoid(); | 
 | 345 |       printf(" = void\n"); | 
| Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 346 |     } catch (TApplicationException& tax) { | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 347 |       printf("*** FAILED ***\n"); | 
| Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 348 |       printf("%s\n", tax.what()); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 349 |       return_code |= ERR_BASETYPES; | 
| Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 350 |     } | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 351 |  | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 352 |     /** | 
 | 353 |      * STRING TEST | 
 | 354 |      */ | 
 | 355 |     printf("testString(\"Test\")"); | 
| Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 356 |     string s; | 
 | 357 |     testClient.testString(s, "Test"); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 358 |     printf(" = \"%s\"\n", s.c_str()); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 359 |     if (s != "Test") { | 
 | 360 |       printf("*** FAILED ***\n"); | 
 | 361 |       return_code |= ERR_BASETYPES; | 
 | 362 |     } | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 363 |  | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 364 |     /** | 
| Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 365 |      * BOOL TEST | 
 | 366 |      */ | 
 | 367 |     printf("testBool(true)"); | 
 | 368 |     bool bl = testClient.testBool(true); | 
 | 369 |     printf(" = %s\n", bl ? "true" : "false"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 370 |     if (bl != true) { | 
 | 371 |       printf("*** FAILED ***\n"); | 
 | 372 |       return_code |= ERR_BASETYPES; | 
 | 373 |     } | 
| Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 374 |  | 
 | 375 |     printf("testBool(false)"); | 
 | 376 |     bl = testClient.testBool(false); | 
 | 377 |     printf(" = %s\n", bl ? "true" : "false"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 378 |     if (bl != false) { | 
 | 379 |       printf("*** FAILED ***\n"); | 
 | 380 |       return_code |= ERR_BASETYPES; | 
 | 381 |     } | 
| Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 382 |  | 
 | 383 |     /** | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 384 |      * BYTE TEST | 
 | 385 |      */ | 
 | 386 |     printf("testByte(1)"); | 
 | 387 |     uint8_t u8 = testClient.testByte(1); | 
 | 388 |     printf(" = %d\n", (int)u8); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 389 |     if (u8 != 1) { | 
 | 390 |       printf("*** FAILED ***\n"); | 
 | 391 |       return_code |= ERR_BASETYPES; | 
 | 392 |     } | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 393 |  | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 394 |     /** | 
 | 395 |      * I32 TEST | 
 | 396 |      */ | 
 | 397 |     printf("testI32(-1)"); | 
 | 398 |     int32_t i32 = testClient.testI32(-1); | 
 | 399 |     printf(" = %d\n", i32); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 400 |     if (i32 != -1) { | 
 | 401 |       printf("*** FAILED ***\n"); | 
 | 402 |       return_code |= ERR_BASETYPES; | 
 | 403 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 404 |  | 
 | 405 |     /** | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 406 |      * I64 TEST | 
 | 407 |      */ | 
 | 408 |     printf("testI64(-34359738368)"); | 
| Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 409 |     int64_t i64 = testClient.testI64(-34359738368LL); | 
| Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 410 |     printf(" = %" PRId64 "\n", i64); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 411 |     if (i64 != -34359738368LL) { | 
 | 412 |       printf("*** FAILED ***\n"); | 
 | 413 |       return_code |= ERR_BASETYPES; | 
 | 414 |     } | 
| Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 415 |  | 
| Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 416 |     /** | 
 | 417 |      * DOUBLE TEST | 
 | 418 |      */ | 
| Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 419 |     // Comparing double values with plain equality because Thrift handles full precision of double | 
 | 420 |     BASETYPE_IDENTITY_TEST(testDouble, 0.0); | 
 | 421 |     BASETYPE_IDENTITY_TEST(testDouble, -1.0); | 
 | 422 |     BASETYPE_IDENTITY_TEST(testDouble, -5.2098523); | 
 | 423 |     BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279); | 
 | 424 |     BASETYPE_IDENTITY_TEST(testDouble, pow(2, 32)); | 
 | 425 |     BASETYPE_IDENTITY_TEST(testDouble, pow(2, 32) + 1); | 
 | 426 |     BASETYPE_IDENTITY_TEST(testDouble, pow(2, 53) - 1); | 
 | 427 |     BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 32)); | 
 | 428 |     BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 32) - 1); | 
 | 429 |     BASETYPE_IDENTITY_TEST(testDouble, -pow(2, 53) + 1); | 
 | 430 |  | 
 | 431 |     try { | 
 | 432 |       double expected = pow(10, 307); | 
 | 433 |       cout << "testDouble(" << expected << ") = "; | 
 | 434 |       double actual = testClient.testDouble(expected); | 
 | 435 |       cout << "(" << actual << ")" << endl; | 
 | 436 |       if (expected - actual > pow(10, 292)) { | 
 | 437 |         cout << "*** FAILED ***" << endl | 
 | 438 |              << "Expected: " << expected << " but got: " << actual << endl; | 
 | 439 |       } | 
 | 440 |     } catch (TTransportException&) { | 
 | 441 |       throw; | 
 | 442 |     } catch (exception& ex) { | 
 | 443 |       cout << "*** FAILED ***" << endl << ex.what() << endl; | 
 | 444 |       return_code |= ERR_BASETYPES; | 
 | 445 |     } | 
 | 446 |  | 
 | 447 |     try { | 
 | 448 |       double expected = pow(10, -292); | 
 | 449 |       cout << "testDouble(" << expected << ") = "; | 
 | 450 |       double actual = testClient.testDouble(expected); | 
 | 451 |       cout << "(" << actual << ")" << endl; | 
 | 452 |       if (expected - actual > pow(10, -307)) { | 
 | 453 |         cout << "*** FAILED ***" << endl | 
 | 454 |              << "Expected: " << expected << " but got: " << actual << endl; | 
 | 455 |       } | 
 | 456 |     } catch (TTransportException&) { | 
 | 457 |       throw; | 
 | 458 |     } catch (exception& ex) { | 
 | 459 |       cout << "*** FAILED ***" << endl << ex.what() << endl; | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 460 |       return_code |= ERR_BASETYPES; | 
 | 461 |     } | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 462 |  | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 463 |     /** | 
| Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 464 |      * BINARY TEST | 
 | 465 |      */ | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 466 |     printf("testBinary([-128..127]) = {"); | 
 | 467 |     const char bin_data[256] | 
 | 468 |         = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, | 
 | 469 |            -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99, | 
 | 470 |            -98,  -97,  -96,  -95,  -94,  -93,  -92,  -91,  -90,  -89,  -88,  -87,  -86,  -85,  -84, | 
 | 471 |            -83,  -82,  -81,  -80,  -79,  -78,  -77,  -76,  -75,  -74,  -73,  -72,  -71,  -70,  -69, | 
 | 472 |            -68,  -67,  -66,  -65,  -64,  -63,  -62,  -61,  -60,  -59,  -58,  -57,  -56,  -55,  -54, | 
 | 473 |            -53,  -52,  -51,  -50,  -49,  -48,  -47,  -46,  -45,  -44,  -43,  -42,  -41,  -40,  -39, | 
 | 474 |            -38,  -37,  -36,  -35,  -34,  -33,  -32,  -31,  -30,  -29,  -28,  -27,  -26,  -25,  -24, | 
 | 475 |            -23,  -22,  -21,  -20,  -19,  -18,  -17,  -16,  -15,  -14,  -13,  -12,  -11,  -10,  -9, | 
 | 476 |            -8,   -7,   -6,   -5,   -4,   -3,   -2,   -1,   0,    1,    2,    3,    4,    5,    6, | 
 | 477 |            7,    8,    9,    10,   11,   12,   13,   14,   15,   16,   17,   18,   19,   20,   21, | 
 | 478 |            22,   23,   24,   25,   26,   27,   28,   29,   30,   31,   32,   33,   34,   35,   36, | 
 | 479 |            37,   38,   39,   40,   41,   42,   43,   44,   45,   46,   47,   48,   49,   50,   51, | 
 | 480 |            52,   53,   54,   55,   56,   57,   58,   59,   60,   61,   62,   63,   64,   65,   66, | 
 | 481 |            67,   68,   69,   70,   71,   72,   73,   74,   75,   76,   77,   78,   79,   80,   81, | 
 | 482 |            82,   83,   84,   85,   86,   87,   88,   89,   90,   91,   92,   93,   94,   95,   96, | 
 | 483 |            97,   98,   99,   100,  101,  102,  103,  104,  105,  106,  107,  108,  109,  110,  111, | 
 | 484 |            112,  113,  114,  115,  116,  117,  118,  119,  120,  121,  122,  123,  124,  125,  126, | 
 | 485 |            127}; | 
 | 486 |     try { | 
 | 487 |       string bin_result; | 
 | 488 |       testClient.testBinary(bin_result, string(bin_data, 256)); | 
 | 489 |       if (bin_result.size() != 256) { | 
 | 490 |         printf("}\n*** FAILED ***\n"); | 
| Jens Geyer | 2faac5a | 2015-11-17 23:00:52 +0100 | [diff] [blame] | 491 |         printf("invalid length: %lu\n", static_cast<long unsigned int>(bin_result.size())); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 492 |         return_code |= ERR_BASETYPES; | 
 | 493 |       } else { | 
 | 494 |         bool first = true; | 
 | 495 |         bool failed = false; | 
 | 496 |         for (int i = 0; i < 256; ++i) { | 
 | 497 |           if (!first) | 
 | 498 |             printf(" ,"); | 
 | 499 |           else | 
 | 500 |             first = false; | 
 | 501 |           printf("%d", bin_result[i]); | 
 | 502 |           if (!failed && bin_result[i] != i - 128) { | 
 | 503 |             failed = true; | 
 | 504 |           } | 
 | 505 |         } | 
 | 506 |         printf("}\n"); | 
 | 507 |         if (failed) { | 
 | 508 |           printf("*** FAILED ***\n"); | 
 | 509 |           return_code |= ERR_BASETYPES; | 
 | 510 |         } | 
 | 511 |       } | 
 | 512 |     } catch (exception& ex) { | 
 | 513 |       printf("}\n*** FAILED ***\n"); | 
 | 514 |       printf("%s\n", ex.what()); | 
 | 515 |       return_code |= ERR_BASETYPES; | 
 | 516 |     } | 
 | 517 |  | 
| Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 518 |  | 
 | 519 |     /** | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 520 |      * STRUCT TEST | 
 | 521 |      */ | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 522 |     printf("testStruct({\"Zero\", 1, -3, -5})"); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 523 |     Xtruct out; | 
 | 524 |     out.string_thing = "Zero"; | 
 | 525 |     out.byte_thing = 1; | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 526 |     out.i32_thing = -3; | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 527 |     out.i64_thing = -5; | 
| Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 528 |     Xtruct in; | 
 | 529 |     testClient.testStruct(in, out); | 
| Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 530 |     printf(" = {\"%s\", %d, %d, %" PRId64 "}\n", | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 531 |            in.string_thing.c_str(), | 
 | 532 |            (int)in.byte_thing, | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 533 |            in.i32_thing, | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 534 |            in.i64_thing); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 535 |     if (in != out) { | 
 | 536 |       printf("*** FAILED ***\n"); | 
 | 537 |       return_code |= ERR_STRUCTS; | 
 | 538 |     } | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 539 |  | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 540 |     /** | 
 | 541 |      * NESTED STRUCT TEST | 
 | 542 |      */ | 
| Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 543 |     printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}"); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 544 |     Xtruct2 out2; | 
 | 545 |     out2.byte_thing = 1; | 
 | 546 |     out2.struct_thing = out; | 
 | 547 |     out2.i32_thing = 5; | 
| Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 548 |     Xtruct2 in2; | 
 | 549 |     testClient.testNest(in2, out2); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 550 |     in = in2.struct_thing; | 
| Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 551 |     printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n", | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 552 |            in2.byte_thing, | 
 | 553 |            in.string_thing.c_str(), | 
 | 554 |            (int)in.byte_thing, | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 555 |            in.i32_thing, | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 556 |            in.i64_thing, | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 557 |            in2.i32_thing); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 558 |     if (in2 != out2) { | 
 | 559 |       printf("*** FAILED ***\n"); | 
 | 560 |       return_code |= ERR_STRUCTS; | 
 | 561 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 562 |  | 
 | 563 |     /** | 
 | 564 |      * MAP TEST | 
 | 565 |      */ | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 566 |     map<int32_t, int32_t> mapout; | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 567 |     for (int32_t i = 0; i < 5; ++i) { | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 568 |       mapout.insert(make_pair(i, i - 10)); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 569 |     } | 
 | 570 |     printf("testMap({"); | 
 | 571 |     map<int32_t, int32_t>::const_iterator m_iter; | 
 | 572 |     bool first = true; | 
 | 573 |     for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) { | 
 | 574 |       if (first) { | 
 | 575 |         first = false; | 
 | 576 |       } else { | 
 | 577 |         printf(", "); | 
 | 578 |       } | 
 | 579 |       printf("%d => %d", m_iter->first, m_iter->second); | 
 | 580 |     } | 
 | 581 |     printf("})"); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 582 |     map<int32_t, int32_t> mapin; | 
| Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 583 |     testClient.testMap(mapin, mapout); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 584 |     printf(" = {"); | 
 | 585 |     first = true; | 
 | 586 |     for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { | 
 | 587 |       if (first) { | 
 | 588 |         first = false; | 
 | 589 |       } else { | 
 | 590 |         printf(", "); | 
 | 591 |       } | 
 | 592 |       printf("%d => %d", m_iter->first, m_iter->second); | 
 | 593 |     } | 
 | 594 |     printf("}\n"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 595 |     if (mapin != mapout) { | 
 | 596 |       printf("*** FAILED ***\n"); | 
 | 597 |       return_code |= ERR_CONTAINERS; | 
 | 598 |     } | 
| Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 599 |  | 
 | 600 |     /** | 
 | 601 |      * STRING MAP TEST | 
| Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 602 |      */ | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 603 |     printf("testStringMap({a => 2, b => blah, some => thing}) = {"); | 
 | 604 |     map<string, string> smapin; | 
 | 605 |     map<string, string> smapout; | 
 | 606 |     smapin["a"] = "2"; | 
 | 607 |     smapin["b"] = "blah"; | 
 | 608 |     smapin["some"] = "thing"; | 
 | 609 |     try { | 
 | 610 |       testClient.testStringMap(smapout, smapin); | 
 | 611 |       first = true; | 
 | 612 |       for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) { | 
 | 613 |         if (first) | 
 | 614 |           printf(","); | 
 | 615 |         else | 
 | 616 |           first = false; | 
 | 617 |         printf("%s => %s", it->first.c_str(), it->second.c_str()); | 
 | 618 |       } | 
 | 619 |       printf("}\n"); | 
 | 620 |       if (smapin != smapout) { | 
 | 621 |         printf("*** FAILED ***\n"); | 
 | 622 |         return_code |= ERR_CONTAINERS; | 
 | 623 |       } | 
 | 624 |     } catch (exception& ex) { | 
 | 625 |       printf("}\n*** FAILED ***\n"); | 
 | 626 |       printf("%s\n", ex.what()); | 
 | 627 |       return_code |= ERR_CONTAINERS; | 
 | 628 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 629 |  | 
 | 630 |     /** | 
 | 631 |      * SET TEST | 
 | 632 |      */ | 
 | 633 |     set<int32_t> setout; | 
 | 634 |     for (int32_t i = -2; i < 3; ++i) { | 
 | 635 |       setout.insert(i); | 
 | 636 |     } | 
 | 637 |     printf("testSet({"); | 
 | 638 |     set<int32_t>::const_iterator s_iter; | 
 | 639 |     first = true; | 
 | 640 |     for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) { | 
 | 641 |       if (first) { | 
 | 642 |         first = false; | 
 | 643 |       } else { | 
 | 644 |         printf(", "); | 
 | 645 |       } | 
 | 646 |       printf("%d", *s_iter); | 
 | 647 |     } | 
 | 648 |     printf("})"); | 
| Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 649 |     set<int32_t> setin; | 
 | 650 |     testClient.testSet(setin, setout); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 651 |     printf(" = {"); | 
 | 652 |     first = true; | 
 | 653 |     for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { | 
 | 654 |       if (first) { | 
 | 655 |         first = false; | 
 | 656 |       } else { | 
 | 657 |         printf(", "); | 
 | 658 |       } | 
 | 659 |       printf("%d", *s_iter); | 
 | 660 |     } | 
 | 661 |     printf("}\n"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 662 |     if (setin != setout) { | 
 | 663 |       printf("*** FAILED ***\n"); | 
 | 664 |       return_code |= ERR_CONTAINERS; | 
 | 665 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 666 |  | 
 | 667 |     /** | 
 | 668 |      * LIST TEST | 
 | 669 |      */ | 
| Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 670 |     vector<int32_t> listout; | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 671 |     for (int32_t i = -2; i < 3; ++i) { | 
 | 672 |       listout.push_back(i); | 
 | 673 |     } | 
 | 674 |     printf("testList({"); | 
| Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 675 |     vector<int32_t>::const_iterator l_iter; | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 676 |     first = true; | 
 | 677 |     for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { | 
 | 678 |       if (first) { | 
 | 679 |         first = false; | 
 | 680 |       } else { | 
 | 681 |         printf(", "); | 
 | 682 |       } | 
 | 683 |       printf("%d", *l_iter); | 
 | 684 |     } | 
 | 685 |     printf("})"); | 
| Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 686 |     vector<int32_t> listin; | 
 | 687 |     testClient.testList(listin, listout); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 688 |     printf(" = {"); | 
 | 689 |     first = true; | 
 | 690 |     for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { | 
 | 691 |       if (first) { | 
 | 692 |         first = false; | 
 | 693 |       } else { | 
 | 694 |         printf(", "); | 
 | 695 |       } | 
 | 696 |       printf("%d", *l_iter); | 
 | 697 |     } | 
 | 698 |     printf("}\n"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 699 |     if (listin != listout) { | 
 | 700 |       printf("*** FAILED ***\n"); | 
 | 701 |       return_code |= ERR_CONTAINERS; | 
 | 702 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 703 |  | 
 | 704 |     /** | 
 | 705 |      * ENUM TEST | 
 | 706 |      */ | 
 | 707 |     printf("testEnum(ONE)"); | 
| Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 708 |     Numberz::type ret = testClient.testEnum(Numberz::ONE); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 709 |     printf(" = %d\n", ret); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 710 |     if (ret != Numberz::ONE) { | 
 | 711 |       printf("*** FAILED ***\n"); | 
 | 712 |       return_code |= ERR_STRUCTS; | 
 | 713 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 714 |  | 
 | 715 |     printf("testEnum(TWO)"); | 
| Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 716 |     ret = testClient.testEnum(Numberz::TWO); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 717 |     printf(" = %d\n", ret); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 718 |     if (ret != Numberz::TWO) { | 
 | 719 |       printf("*** FAILED ***\n"); | 
 | 720 |       return_code |= ERR_STRUCTS; | 
 | 721 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 722 |  | 
 | 723 |     printf("testEnum(THREE)"); | 
| Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 724 |     ret = testClient.testEnum(Numberz::THREE); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 725 |     printf(" = %d\n", ret); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 726 |     if (ret != Numberz::THREE) { | 
 | 727 |       printf("*** FAILED ***\n"); | 
 | 728 |       return_code |= ERR_STRUCTS; | 
 | 729 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 730 |  | 
 | 731 |     printf("testEnum(FIVE)"); | 
| Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 732 |     ret = testClient.testEnum(Numberz::FIVE); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 733 |     printf(" = %d\n", ret); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 734 |     if (ret != Numberz::FIVE) { | 
 | 735 |       printf("*** FAILED ***\n"); | 
 | 736 |       return_code |= ERR_STRUCTS; | 
 | 737 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 738 |  | 
 | 739 |     printf("testEnum(EIGHT)"); | 
| Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 740 |     ret = testClient.testEnum(Numberz::EIGHT); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 741 |     printf(" = %d\n", ret); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 742 |     if (ret != Numberz::EIGHT) { | 
 | 743 |       printf("*** FAILED ***\n"); | 
 | 744 |       return_code |= ERR_STRUCTS; | 
 | 745 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 746 |  | 
 | 747 |     /** | 
 | 748 |      * TYPEDEF TEST | 
 | 749 |      */ | 
 | 750 |     printf("testTypedef(309858235082523)"); | 
| Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 751 |     UserId uid = testClient.testTypedef(309858235082523LL); | 
| Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 752 |     printf(" = %" PRId64 "\n", uid); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 753 |     if (uid != 309858235082523LL) { | 
 | 754 |       printf("*** FAILED ***\n"); | 
 | 755 |       return_code |= ERR_STRUCTS; | 
 | 756 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 757 |  | 
 | 758 |     /** | 
 | 759 |      * NESTED MAP TEST | 
 | 760 |      */ | 
 | 761 |     printf("testMapMap(1)"); | 
| Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 762 |     map<int32_t, map<int32_t, int32_t> > mm; | 
 | 763 |     testClient.testMapMap(mm, 1); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 764 |     printf(" = {"); | 
 | 765 |     map<int32_t, map<int32_t, int32_t> >::const_iterator mi; | 
 | 766 |     for (mi = mm.begin(); mi != mm.end(); ++mi) { | 
 | 767 |       printf("%d => {", mi->first); | 
 | 768 |       map<int32_t, int32_t>::const_iterator mi2; | 
 | 769 |       for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) { | 
 | 770 |         printf("%d => %d, ", mi2->first, mi2->second); | 
 | 771 |       } | 
 | 772 |       printf("}, "); | 
 | 773 |     } | 
 | 774 |     printf("}\n"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 775 |     if (mm.size() != 2 || | 
 | 776 |         mm[-4][-4] != -4 || | 
 | 777 |         mm[-4][-3] != -3 || | 
 | 778 |         mm[-4][-2] != -2 || | 
 | 779 |         mm[-4][-1] != -1 || | 
 | 780 |         mm[4][4] != 4 || | 
 | 781 |         mm[4][3] != 3 || | 
 | 782 |         mm[4][2] != 2 || | 
 | 783 |         mm[4][1] != 1) { | 
 | 784 |       printf("*** FAILED ***\n"); | 
 | 785 |       return_code |= ERR_CONTAINERS; | 
 | 786 |     } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 787 |  | 
 | 788 |     /** | 
 | 789 |      * INSANITY TEST | 
 | 790 |      */ | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 791 |     if (!noinsane) { | 
 | 792 |       Insanity insane; | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 793 |       insane.userMap.insert(make_pair(Numberz::FIVE, 5)); | 
 | 794 |       insane.userMap.insert(make_pair(Numberz::EIGHT, 8)); | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 795 |       Xtruct truck; | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 796 |       truck.string_thing = "Goodbye4"; | 
 | 797 |       truck.byte_thing = 4; | 
 | 798 |       truck.i32_thing = 4; | 
 | 799 |       truck.i64_thing = 4; | 
 | 800 |       Xtruct truck2; | 
 | 801 |       truck2.string_thing = "Hello2"; | 
 | 802 |       truck2.byte_thing = 2; | 
 | 803 |       truck2.i32_thing = 2; | 
 | 804 |       truck2.i64_thing = 2; | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 805 |       insane.xtructs.push_back(truck); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 806 |       insane.xtructs.push_back(truck2); | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 807 |       printf("testInsanity()"); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 808 |       map<UserId, map<Numberz::type, Insanity> > whoa; | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 809 |       testClient.testInsanity(whoa, insane); | 
 | 810 |       printf(" = {"); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 811 |       map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter; | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 812 |       for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { | 
 | 813 |         printf("%" PRId64 " => {", i_iter->first); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 814 |         map<Numberz::type, Insanity>::const_iterator i2_iter; | 
 | 815 |         for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) { | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 816 |           printf("%d => {", i2_iter->first); | 
 | 817 |           map<Numberz::type, UserId> userMap = i2_iter->second.userMap; | 
 | 818 |           map<Numberz::type, UserId>::const_iterator um; | 
 | 819 |           printf("{"); | 
 | 820 |           for (um = userMap.begin(); um != userMap.end(); ++um) { | 
 | 821 |             printf("%d => %" PRId64 ", ", um->first, um->second); | 
 | 822 |           } | 
 | 823 |           printf("}, "); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 824 |  | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 825 |           vector<Xtruct> xtructs = i2_iter->second.xtructs; | 
 | 826 |           vector<Xtruct>::const_iterator x; | 
 | 827 |           printf("{"); | 
 | 828 |           for (x = xtructs.begin(); x != xtructs.end(); ++x) { | 
 | 829 |             printf("{\"%s\", %d, %d, %" PRId64 "}, ", | 
 | 830 |                    x->string_thing.c_str(), | 
 | 831 |                    (int)x->byte_thing, | 
 | 832 |                    x->i32_thing, | 
 | 833 |                    x->i64_thing); | 
 | 834 |           } | 
 | 835 |           printf("}"); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 836 |  | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 837 |           printf("}, "); | 
 | 838 |         } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 839 |         printf("}, "); | 
 | 840 |       } | 
| Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 841 |       printf("}\n"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 842 |       bool failed = false; | 
 | 843 |       map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1)); | 
 | 844 |       if (whoa.size() != 2) { | 
 | 845 |         failed = true; | 
 | 846 |       } | 
 | 847 |       if (it1 == whoa.end()) { | 
 | 848 |         failed = true; | 
 | 849 |       } else { | 
 | 850 |         map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO); | 
 | 851 |         if (it12 == it1->second.end() || it12->second != insane) { | 
 | 852 |           failed = true; | 
 | 853 |         } | 
 | 854 |         map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE); | 
 | 855 |         if (it13 == it1->second.end() || it13->second != insane) { | 
 | 856 |           failed = true; | 
 | 857 |         } | 
 | 858 |       } | 
 | 859 |       map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2)); | 
 | 860 |       if (it2 == whoa.end()) { | 
 | 861 |         failed = true; | 
 | 862 |       } else { | 
 | 863 |         map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX); | 
 | 864 |         if (it26 == it1->second.end() || it26->second != Insanity()) { | 
 | 865 |           failed = true; | 
 | 866 |         } | 
 | 867 |       } | 
 | 868 |       if (failed) { | 
 | 869 |         printf("*** FAILED ***\n"); | 
 | 870 |         return_code |= ERR_STRUCTS; | 
 | 871 |       } | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 872 |     } | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 873 |  | 
 | 874 |     /** | 
 | 875 |      * MULTI TEST | 
 | 876 |      */ | 
 | 877 |     printf("testMulti()\n"); | 
 | 878 |     try { | 
 | 879 |       map<int16_t, string> mul_map; | 
 | 880 |       Xtruct mul_result; | 
 | 881 |       mul_map[1] = "blah"; | 
 | 882 |       mul_map[2] = "thing"; | 
 | 883 |       testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24)); | 
 | 884 |       Xtruct xxs; | 
 | 885 |       xxs.string_thing = "Hello2"; | 
 | 886 |       xxs.byte_thing = 42; | 
 | 887 |       xxs.i32_thing = 4242; | 
 | 888 |       xxs.i64_thing = 424242; | 
 | 889 |       if (mul_result != xxs) { | 
 | 890 |         printf("*** FAILED ***\n"); | 
 | 891 |         return_code |= ERR_STRUCTS; | 
 | 892 |       } | 
 | 893 |     } catch (exception& ex) { | 
 | 894 |       printf("*** FAILED ***\n"); | 
 | 895 |       return_code |= ERR_STRUCTS; | 
 | 896 |     } | 
 | 897 |  | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 898 |     /* test exception */ | 
| Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 899 |  | 
| Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 900 |     try { | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 901 |       printf("testClient.testException(\"Xception\") =>"); | 
 | 902 |       testClient.testException("Xception"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 903 |       printf("  void\n*** FAILED ***\n"); | 
 | 904 |       return_code |= ERR_EXCEPTIONS; | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 905 |  | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 906 |     } catch (Xception& e) { | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 907 |       printf("  {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); | 
| Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 908 |     } | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 909 |  | 
| Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 910 |     try { | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 911 |       printf("testClient.testException(\"TException\") =>"); | 
 | 912 |       testClient.testException("TException"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 913 |       printf("  void\n*** FAILED ***\n"); | 
 | 914 |       return_code |= ERR_EXCEPTIONS; | 
| Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 915 |  | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 916 |     } catch (const TException&) { | 
 | 917 |       printf("  Caught TException\n"); | 
 | 918 |     } | 
| Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 919 |  | 
 | 920 |     try { | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 921 |       printf("testClient.testException(\"success\") =>"); | 
 | 922 |       testClient.testException("success"); | 
 | 923 |       printf("  void\n"); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 924 |     } catch (...) { | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 925 |       printf("  exception\n*** FAILED ***\n"); | 
 | 926 |       return_code |= ERR_EXCEPTIONS; | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 927 |     } | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 928 |  | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 929 |     /* test multi exception */ | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 930 |  | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 931 |     try { | 
 | 932 |       printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); | 
| Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 933 |       Xtruct result; | 
 | 934 |       testClient.testMultiException(result, "Xception", "test 1"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 935 |       printf("  result\n*** FAILED ***\n"); | 
 | 936 |       return_code |= ERR_EXCEPTIONS; | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 937 |     } catch (Xception& e) { | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 938 |       printf("  {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); | 
 | 939 |     } | 
 | 940 |  | 
 | 941 |     try { | 
 | 942 |       printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>"); | 
| Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 943 |       Xtruct result; | 
 | 944 |       testClient.testMultiException(result, "Xception2", "test 2"); | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 945 |       printf("  result\n*** FAILED ***\n"); | 
 | 946 |       return_code |= ERR_EXCEPTIONS; | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 947 |  | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 948 |     } catch (Xception2& e) { | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 949 |       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] | 950 |     } | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 951 |  | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 952 |     try { | 
 | 953 |       printf("testClient.testMultiException(\"success\", \"test 3\") =>"); | 
| Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 954 |       Xtruct result; | 
 | 955 |       testClient.testMultiException(result, "success", "test 3"); | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 956 |       printf("  {{\"%s\"}}\n", result.string_thing.c_str()); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 957 |     } catch (...) { | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 958 |       printf("  exception\n*** FAILED ***\n"); | 
 | 959 |       return_code |= ERR_EXCEPTIONS; | 
| Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 960 |     } | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 961 |  | 
| David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 962 |     /* test oneway void */ | 
| David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 963 |     { | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 964 |       printf("testClient.testOneway(1) =>"); | 
 | 965 |       uint64_t startOneway = now(); | 
 | 966 |       testClient.testOneway(1); | 
 | 967 |       uint64_t elapsed = now() - startOneway; | 
 | 968 |       if (elapsed > 200 * 1000) { // 0.2 seconds | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 969 |         printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0); | 
 | 970 |       return_code |= ERR_BASETYPES; | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 971 |       } else { | 
 | 972 |         printf("  success - took %.2f ms\n", (double)elapsed / 1000.0); | 
 | 973 |       } | 
| David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 974 |     } | 
 | 975 |  | 
| David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 976 |     /** | 
| David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 977 |      * redo a simple test after the oneway to make sure we aren't "off by one" -- | 
 | 978 |      * 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] | 979 |      * fail since it will get the void confirmation rather than the correct | 
 | 980 |      * result. In this circumstance, the client will throw the exception: | 
 | 981 |      * | 
 | 982 |      *   TApplicationException: Wrong method namea | 
 | 983 |      */ | 
 | 984 |     /** | 
 | 985 |      * I32 TEST | 
 | 986 |      */ | 
 | 987 |     printf("re-test testI32(-1)"); | 
 | 988 |     i32 = testClient.testI32(-1); | 
 | 989 |     printf(" = %d\n", i32); | 
| Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 990 |     if (i32 != -1) | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 991 |       return_code |= ERR_BASETYPES; | 
| David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 992 |  | 
| Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 993 |     uint64_t stop = now(); | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 994 |     uint64_t tot = stop - start; | 
| Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 995 |  | 
| Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 996 |     printf("Total time: %" PRIu64 " us\n", stop - start); | 
| David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 997 |  | 
| Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 998 |     time_tot += tot; | 
 | 999 |     if (time_min == 0 || tot < time_min) { | 
 | 1000 |       time_min = tot; | 
 | 1001 |     } | 
 | 1002 |     if (tot > time_max) { | 
 | 1003 |       time_max = tot; | 
 | 1004 |     } | 
 | 1005 |  | 
| Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 1006 |     transport->close(); | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1007 |   } | 
 | 1008 |  | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1009 |   printf("\nAll tests done.\n"); | 
| Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1010 |  | 
 | 1011 |   uint64_t time_avg = time_tot / numTests; | 
 | 1012 |  | 
| Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 1013 |   printf("Min time: %" PRIu64 " us\n", time_min); | 
 | 1014 |   printf("Max time: %" PRIu64 " us\n", time_max); | 
 | 1015 |   printf("Avg time: %" PRIu64 " us\n", time_avg); | 
| Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1016 |  | 
| Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1017 |   return return_code; | 
| Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1018 | } |