James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 1 | /* |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 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 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 20 | #include <limits> |
| 21 | #include <locale> |
| 22 | #include <ios> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 23 | #include <iostream> |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 24 | #include <sstream> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 25 | #include <thrift/protocol/TBinaryProtocol.h> |
Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 26 | #include <thrift/protocol/TCompactProtocol.h> |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 27 | #include <thrift/protocol/THeaderProtocol.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 28 | #include <thrift/protocol/TJSONProtocol.h> |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 29 | #include <thrift/protocol/TMultiplexedProtocol.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 30 | #include <thrift/transport/THttpClient.h> |
| 31 | #include <thrift/transport/TTransportUtils.h> |
| 32 | #include <thrift/transport/TSocket.h> |
| 33 | #include <thrift/transport/TSSLSocket.h> |
| 34 | #include <thrift/async/TEvhttpClientChannel.h> |
| 35 | #include <thrift/server/TNonblockingServer.h> // <event.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 36 | |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 37 | #ifdef HAVE_STDINT_H |
| 38 | #include <stdint.h> |
| 39 | #endif |
| 40 | #ifdef HAVE_INTTYPES_H |
| 41 | #include <inttypes.h> |
| 42 | #endif |
| 43 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 44 | #include <boost/algorithm/string.hpp> |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 45 | #include <boost/filesystem.hpp> |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 46 | #include <boost/program_options.hpp> |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 47 | #include <boost/random/random_device.hpp> |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 48 | #include <thrift/stdcxx.h> |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 49 | #if _WIN32 |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 50 | #include <thrift/windows/TWinsockSingleton.h> |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 51 | #endif |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 52 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 53 | #include "SecondService.h" |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 54 | #include "ThriftTest.h" |
| 55 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 56 | using namespace std; |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 57 | using namespace apache::thrift; |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 58 | using namespace apache::thrift::async; |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 59 | using namespace apache::thrift::protocol; |
| 60 | using namespace apache::thrift::transport; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 61 | using namespace thrift::test; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 62 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 63 | // Current time, microseconds since the epoch |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 64 | uint64_t now() { |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 65 | int64_t ret; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 66 | struct timeval tv; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 67 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 68 | THRIFT_GETTIMEOFDAY(&tv, NULL); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 69 | ret = tv.tv_sec; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 70 | ret = ret * 1000 * 1000 + tv.tv_usec; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 71 | return ret; |
| 72 | } |
| 73 | |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 74 | static void testString_clientReturn(event_base* base, |
| 75 | int testNr, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 76 | ThriftTestCobClient* client) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 77 | try { |
| 78 | string s; |
| 79 | client->recv_testString(s); |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 80 | std::ostringstream os; |
| 81 | os << "test" << testNr; |
| 82 | const bool ok = (s == os.str()); |
| 83 | cout << "testString: " << s << " " << ((ok) ? "ok" : "failed") << endl; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 84 | } catch (TException& exn) { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 85 | cout << "Error: " << exn.what() << endl; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 88 | if (testNr == 9) |
| 89 | event_base_loopbreak(base); // end test |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 92 | static void testVoid_clientReturn(event_base* base, ThriftTestCobClient* client) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 93 | try { |
| 94 | client->recv_testVoid(); |
| 95 | cout << "testVoid" << endl; |
| 96 | |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 97 | for (int testNr = 0; testNr < 10; ++testNr) { |
| 98 | std::ostringstream os; |
| 99 | os << "test" << testNr; |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 100 | client->testString(stdcxx::bind(testString_clientReturn, |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 101 | base, |
| 102 | testNr, |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 103 | stdcxx::placeholders::_1), |
Sebastian Zenker | 39e505c | 2015-12-18 16:15:08 +0100 | [diff] [blame] | 104 | os.str()); |
| 105 | } |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 106 | } catch (TException& exn) { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 107 | cout << "Error: " << exn.what() << endl; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 111 | // Workaround for absense of C++11 "auto" keyword. |
| 112 | template <typename T> |
| 113 | bool print_eq(T expected, T actual) { |
| 114 | cout << "(" << actual << ")" << endl; |
| 115 | if (expected != actual) { |
| 116 | cout << "*** FAILED ***" << endl << "Expected: " << expected << " but got: " << actual << endl; |
| 117 | return false; |
| 118 | } |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | #define BASETYPE_IDENTITY_TEST(func, value) \ |
| 123 | cout << #func "(" << value << ") = "; \ |
| 124 | try { \ |
| 125 | if (!print_eq(value, testClient.func(value))) \ |
| 126 | return_code |= ERR_BASETYPES; \ |
| 127 | } catch (TTransportException&) { \ |
| 128 | throw; \ |
| 129 | } catch (exception & ex) { \ |
| 130 | cout << "*** FAILED ***" << endl << ex.what() << endl; \ |
| 131 | return_code |= ERR_BASETYPES; \ |
| 132 | } |
| 133 | |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 134 | int binary_test(ThriftTestClient& testClient, string::size_type siz); |
| 135 | |
| 136 | BOOST_CONSTEXPR_OR_CONST int ERR_BASETYPES = 1; |
| 137 | BOOST_CONSTEXPR_OR_CONST int ERR_STRUCTS = 2; |
| 138 | BOOST_CONSTEXPR_OR_CONST int ERR_CONTAINERS = 4; |
| 139 | BOOST_CONSTEXPR_OR_CONST int ERR_EXCEPTIONS = 8; |
| 140 | BOOST_CONSTEXPR_OR_CONST int ERR_UNKNOWN = 64; |
| 141 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 142 | int main(int argc, char** argv) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 143 | cout.precision(19); |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 144 | |
James E. King, III | 0619087 | 2017-02-20 08:52:11 -0500 | [diff] [blame] | 145 | string testDir = boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string(); |
| 146 | string caPath = testDir + "/keys/CA.pem"; |
| 147 | string certPath = testDir + "/keys/client.crt"; |
| 148 | string keyPath = testDir + "/keys/client.key"; |
| 149 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 150 | #if _WIN32 |
| 151 | transport::TWinsockSingleton::create(); |
| 152 | #endif |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 153 | string host = "localhost"; |
| 154 | int port = 9090; |
| 155 | int numTests = 1; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 156 | bool ssl = false; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 157 | string transport_type = "buffered"; |
| 158 | string protocol_type = "binary"; |
| 159 | string domain_socket = ""; |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 160 | bool abstract_namespace = false; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 161 | bool noinsane = false; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 162 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 163 | int return_code = 0; |
| 164 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 165 | boost::program_options::options_description desc("Allowed options"); |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 166 | desc.add_options() |
| 167 | ("help,h", "produce help message") |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 168 | ("host", |
| 169 | boost::program_options::value<string>(&host)->default_value(host), |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 170 | "Host to connect") |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 171 | ("port", |
| 172 | boost::program_options::value<int>(&port)->default_value(port), |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 173 | "Port number to connect") |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 174 | ("domain-socket", |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 175 | boost::program_options::value<string>(&domain_socket)->default_value(domain_socket), |
| 176 | "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port") |
| 177 | ("abstract-namespace", |
| 178 | "Look for the domain socket in the Abstract Namespace" |
| 179 | " (no connection with filesystem pathnames)") |
| 180 | ("transport", |
| 181 | boost::program_options::value<string>(&transport_type)->default_value(transport_type), |
| 182 | "Transport: buffered, framed, http, evhttp") |
| 183 | ("protocol", |
| 184 | boost::program_options::value<string>(&protocol_type)->default_value(protocol_type), |
| 185 | "Protocol: binary, compact, header, json, multi, multic, multih, multij") |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 186 | ("ssl", |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 187 | "Encrypted Transport using SSL") |
| 188 | ("testloops,n", |
| 189 | boost::program_options::value<int>(&numTests)->default_value(numTests), |
| 190 | "Number of Tests") |
| 191 | ("noinsane", |
| 192 | "Do not run insanity test"); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 193 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 194 | boost::program_options::variables_map vm; |
| 195 | boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); |
| 196 | boost::program_options::notify(vm); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 197 | |
| 198 | if (vm.count("help")) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 199 | cout << desc << endl; |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 200 | return ERR_UNKNOWN; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 201 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 202 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 203 | try { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 204 | if (!protocol_type.empty()) { |
| 205 | if (protocol_type == "binary") { |
Roger Meier | 284101c | 2014-03-11 21:20:35 +0100 | [diff] [blame] | 206 | } else if (protocol_type == "compact") { |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 207 | } else if (protocol_type == "header") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 208 | } else if (protocol_type == "json") { |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 209 | } else if (protocol_type == "multi") { |
| 210 | } else if (protocol_type == "multic") { |
| 211 | } else if (protocol_type == "multih") { |
| 212 | } else if (protocol_type == "multij") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 213 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 214 | throw invalid_argument("Unknown protocol type " + protocol_type); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 218 | if (!transport_type.empty()) { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 219 | if (transport_type == "buffered") { |
| 220 | } else if (transport_type == "framed") { |
| 221 | } else if (transport_type == "http") { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 222 | } else if (transport_type == "evhttp") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 223 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 224 | throw invalid_argument("Unknown transport type " + transport_type); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 228 | } catch (exception& e) { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 229 | cerr << e.what() << endl; |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 230 | cout << desc << endl; |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 231 | return ERR_UNKNOWN; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | if (vm.count("ssl")) { |
| 235 | ssl = true; |
| 236 | } |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 237 | |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 238 | if (vm.count("abstract-namespace")) { |
| 239 | abstract_namespace = true; |
| 240 | } |
| 241 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 242 | if (vm.count("noinsane")) { |
| 243 | noinsane = true; |
| 244 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 245 | |
James E. King, III | 7f5a8c2 | 2017-04-04 09:36:38 -0400 | [diff] [blame] | 246 | // THRIFT-4164: The factory MUST outlive any sockets it creates for correct behavior! |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 247 | stdcxx::shared_ptr<TSSLSocketFactory> factory; |
| 248 | stdcxx::shared_ptr<TSocket> socket; |
| 249 | stdcxx::shared_ptr<TTransport> transport; |
| 250 | stdcxx::shared_ptr<TProtocol> protocol; |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 251 | stdcxx::shared_ptr<TProtocol> protocol2; // SecondService for multiplexed |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 252 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 253 | if (ssl) { |
James E. King, III | 0619087 | 2017-02-20 08:52:11 -0500 | [diff] [blame] | 254 | cout << "Client Certificate File: " << certPath << endl; |
| 255 | cout << "Client Key File: " << keyPath << endl; |
| 256 | cout << "CA File: " << caPath << endl; |
| 257 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 258 | factory = stdcxx::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory()); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 259 | factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
James E. King, III | 0619087 | 2017-02-20 08:52:11 -0500 | [diff] [blame] | 260 | factory->loadTrustedCertificates(caPath.c_str()); |
| 261 | factory->loadCertificate(certPath.c_str()); |
| 262 | factory->loadPrivateKey(keyPath.c_str()); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 263 | factory->authenticate(true); |
| 264 | socket = factory->createSocket(host, port); |
| 265 | } else { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 266 | if (domain_socket != "") { |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 267 | if (abstract_namespace) { |
| 268 | std::string abstract_socket("\0", 1); |
| 269 | abstract_socket += domain_socket; |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 270 | socket = stdcxx::shared_ptr<TSocket>(new TSocket(abstract_socket)); |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 271 | } else { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 272 | socket = stdcxx::shared_ptr<TSocket>(new TSocket(domain_socket)); |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 273 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 274 | port = 0; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 275 | } else { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 276 | socket = stdcxx::shared_ptr<TSocket>(new TSocket(host, port)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 277 | } |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 278 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 279 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 280 | if (transport_type.compare("http") == 0) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 281 | stdcxx::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service")); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 282 | transport = httpSocket; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 283 | } else if (transport_type.compare("framed") == 0) { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 284 | stdcxx::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 285 | transport = framedSocket; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 286 | } else { |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 287 | stdcxx::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 288 | transport = bufferedSocket; |
| 289 | } |
| 290 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 291 | if (protocol_type == "json" || protocol_type == "multij") { |
| 292 | protocol = stdcxx::make_shared<TJSONProtocol>(transport); |
| 293 | } else if (protocol_type == "compact" || protocol_type == "multic") { |
| 294 | protocol = stdcxx::make_shared<TCompactProtocol>(transport); |
| 295 | } else if (protocol_type == "header" || protocol_type == "multih") { |
| 296 | protocol = stdcxx::make_shared<THeaderProtocol>(transport); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 297 | } else { |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 298 | protocol = stdcxx::make_shared<TBinaryProtocol>(transport); |
| 299 | } |
| 300 | |
| 301 | if (boost::starts_with(protocol_type, "multi")) { |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 302 | protocol2 = stdcxx::make_shared<TMultiplexedProtocol>(protocol, "SecondService"); |
| 303 | // we don't need access to the original protocol any more, so... |
| 304 | protocol = stdcxx::make_shared<TMultiplexedProtocol>(protocol, "ThriftTest"); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | // Connection info |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 308 | cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: "; |
| 309 | if (abstract_namespace) { |
| 310 | cout << '@'; |
| 311 | } |
| 312 | cout << domain_socket; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 313 | if (port != 0) { |
| 314 | cout << host << ":" << port; |
| 315 | } |
| 316 | cout << endl; |
| 317 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 318 | if (transport_type.compare("evhttp") == 0) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 319 | event_base* base = event_base_new(); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 320 | cout << "Libevent Version: " << event_get_version() << endl; |
| 321 | cout << "Libevent Method: " << event_base_get_method(base) << endl; |
| 322 | #if LIBEVENT_VERSION_NUMBER >= 0x02000000 |
| 323 | cout << "Libevent Features: 0x" << hex << event_base_get_features(base) << endl; |
| 324 | #endif |
| 325 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 326 | stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 327 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 328 | stdcxx::shared_ptr<TAsyncChannel> channel( |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 329 | new TEvhttpClientChannel(host.c_str(), "/", host.c_str(), port, base)); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 330 | ThriftTestCobClient* client = new ThriftTestCobClient(channel, protocolFactory.get()); |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 331 | client->testVoid(stdcxx::bind(testVoid_clientReturn, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 332 | base, |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 333 | stdcxx::placeholders::_1)); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 334 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 335 | event_base_loop(base, 0); |
| 336 | return 0; |
| 337 | } |
| 338 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 339 | ThriftTestClient testClient(protocol); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 340 | |
| 341 | uint64_t time_min = 0; |
| 342 | uint64_t time_max = 0; |
| 343 | uint64_t time_tot = 0; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 344 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 345 | int test = 0; |
| 346 | for (test = 0; test < numTests; ++test) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 347 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 348 | try { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 349 | transport->open(); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 350 | } catch (TTransportException& ex) { |
| 351 | cout << "Connect failed: " << ex.what() << endl; |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 352 | return ERR_UNKNOWN; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 353 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 354 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 355 | /** |
| 356 | * CONNECT TEST |
| 357 | */ |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 358 | 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] | 359 | |
| 360 | uint64_t start = now(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 361 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 362 | /** |
| 363 | * VOID TEST |
| 364 | */ |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 365 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 366 | cout << "testVoid()" << flush; |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 367 | testClient.testVoid(); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 368 | cout << " = void" << endl; |
| 369 | } catch (TTransportException&) { |
| 370 | // Stop here if transport got broken |
| 371 | throw; |
| 372 | } catch (exception& ex) { |
| 373 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 374 | return_code |= ERR_BASETYPES; |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 375 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 376 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 377 | /** |
| 378 | * STRING TEST |
| 379 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 380 | cout << "testString(\"Test\")" << flush; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 381 | string s; |
| 382 | testClient.testString(s, "Test"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 383 | cout << " = " << s << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 384 | if (s != "Test") { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 385 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 386 | return_code |= ERR_BASETYPES; |
| 387 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 388 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 389 | // |
| 390 | // Multiplexed protocol - call another service method |
| 391 | // in the middle of the ThriftTest |
| 392 | // |
| 393 | if (boost::starts_with(protocol_type, "multi")) { |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 394 | SecondServiceClient ssc(protocol2); |
| 395 | // transport is already open... |
| 396 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 397 | try { |
| 398 | cout << "secondService.secondTestString(\"foo\") => " << flush; |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 399 | std::string result; |
| 400 | ssc.secondtestString(result, "foo"); |
| 401 | cout << "{" << result << "}" << endl; |
| 402 | } catch (std::exception& e) { |
| 403 | cout << " *** FAILED *** " << e.what() << endl; |
| 404 | return_code |= ERR_EXCEPTIONS; |
| 405 | } |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 406 | } |
| 407 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 408 | try { |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 409 | #ifdef _MSC_VER |
| 410 | #pragma warning( push ) |
| 411 | #pragma warning( disable : 4566 ) |
| 412 | #endif |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 413 | string str( |
| 414 | "}{Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " |
| 415 | "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " |
| 416 | "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " |
| 417 | "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " |
| 418 | "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " |
| 419 | "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " |
| 420 | "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " |
| 421 | "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " |
| 422 | "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " |
| 423 | "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " |
| 424 | "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " |
| 425 | "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " |
| 426 | "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " |
| 427 | "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " |
| 428 | "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " |
| 429 | "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, " |
| 430 | "Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, " |
| 431 | "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " |
| 432 | "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " |
| 433 | "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " |
| 434 | "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " |
| 435 | "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " |
| 436 | "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " |
| 437 | "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " |
| 438 | "Bân-lâm-gú, 粵語"); |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 439 | #ifdef _MSC_VER |
| 440 | #pragma warning( pop ) |
| 441 | #endif |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 442 | cout << "testString(" << str << ") = " << flush; |
| 443 | testClient.testString(s, str); |
| 444 | cout << s << endl; |
| 445 | if (s != str) { |
| 446 | cout.imbue(locale("en_US.UTF8")); |
| 447 | cout << "*** FAILED ***" << endl << "Expected string: " << str << " but got: " << s << endl << "CLEAR"; |
| 448 | return_code |= ERR_BASETYPES; |
| 449 | } |
| 450 | } catch (TTransportException&) { |
| 451 | throw; |
| 452 | } catch (exception& ex) { |
| 453 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
| 454 | return_code |= ERR_BASETYPES; |
| 455 | return return_code; |
| 456 | } |
| 457 | try { |
| 458 | string str( |
| 459 | "quote: \" backslash:" |
| 460 | " forwardslash-escaped: \\/ " |
| 461 | " backspace: \b formfeed: \f newline: \n return: \r tab: " |
| 462 | " now-all-of-them-together: \"\\\\/\b\n\r\t" |
| 463 | " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><" |
| 464 | " char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ "); |
| 465 | cout << "testString(" << str << ") = " << flush; |
| 466 | testClient.testString(s, str); |
| 467 | cout << s << endl; |
| 468 | if (s != str) { |
| 469 | cout.imbue(locale("en_US.UTF8")); |
| 470 | cout << "*** FAILED ***" << endl |
| 471 | << "Expected string: " << str << " but got: " << s << endl |
| 472 | << "CLEAR"; |
| 473 | ; |
| 474 | return_code |= ERR_BASETYPES; |
| 475 | } |
| 476 | } catch (TTransportException&) { |
| 477 | throw; |
| 478 | } catch (exception& ex) { |
| 479 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
| 480 | return_code |= ERR_BASETYPES; |
| 481 | return return_code; |
| 482 | } |
| 483 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 484 | /** |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 485 | * BOOL TEST |
| 486 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 487 | cout << boolalpha; |
| 488 | BASETYPE_IDENTITY_TEST(testBool, true); |
| 489 | BASETYPE_IDENTITY_TEST(testBool, false); |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 490 | |
| 491 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 492 | * BYTE TEST |
| 493 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 494 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)0); |
| 495 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)-1); |
| 496 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)42); |
| 497 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)-42); |
| 498 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)127); |
| 499 | BASETYPE_IDENTITY_TEST(testByte, (int8_t)-128); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 500 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 501 | /** |
| 502 | * I32 TEST |
| 503 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 504 | BASETYPE_IDENTITY_TEST(testI32, 0); |
| 505 | BASETYPE_IDENTITY_TEST(testI32, -1); |
| 506 | BASETYPE_IDENTITY_TEST(testI32, 190000013); |
| 507 | BASETYPE_IDENTITY_TEST(testI32, -190000013); |
| 508 | BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::max()); |
| 509 | BASETYPE_IDENTITY_TEST(testI32, numeric_limits<int32_t>::min()); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 510 | |
| 511 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 512 | * I64 TEST |
| 513 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 514 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)0); |
| 515 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)-1); |
| 516 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)7000000000000000123LL); |
| 517 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)-7000000000000000123LL); |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 518 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32)); |
| 519 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32)); |
| 520 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)pow(static_cast<double>(2LL), 32) + 1); |
| 521 | BASETYPE_IDENTITY_TEST(testI64, (int64_t)-pow(static_cast<double>(2LL), 32) - 1); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 522 | BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::max()); |
| 523 | BASETYPE_IDENTITY_TEST(testI64, numeric_limits<int64_t>::min()); |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 524 | |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 525 | /** |
| 526 | * DOUBLE TEST |
| 527 | */ |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 528 | // Comparing double values with plain equality because Thrift handles full precision of double |
| 529 | BASETYPE_IDENTITY_TEST(testDouble, 0.0); |
| 530 | BASETYPE_IDENTITY_TEST(testDouble, -1.0); |
| 531 | BASETYPE_IDENTITY_TEST(testDouble, -5.2098523); |
| 532 | BASETYPE_IDENTITY_TEST(testDouble, -0.000341012439638598279); |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 533 | BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32)); |
| 534 | BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 32) + 1); |
| 535 | BASETYPE_IDENTITY_TEST(testDouble, pow(static_cast<double>(2), 53) - 1); |
| 536 | BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32)); |
| 537 | BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 32) - 1); |
| 538 | BASETYPE_IDENTITY_TEST(testDouble, -pow(static_cast<double>(2), 53) + 1); |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 539 | |
| 540 | try { |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 541 | double expected = pow(static_cast<double>(10), 307); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 542 | cout << "testDouble(" << expected << ") = " << flush; |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 543 | double actual = testClient.testDouble(expected); |
| 544 | cout << "(" << actual << ")" << endl; |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 545 | if (expected - actual > pow(static_cast<double>(10), 292)) { |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 546 | cout << "*** FAILED ***" << endl |
| 547 | << "Expected: " << expected << " but got: " << actual << endl; |
| 548 | } |
| 549 | } catch (TTransportException&) { |
| 550 | throw; |
| 551 | } catch (exception& ex) { |
| 552 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
| 553 | return_code |= ERR_BASETYPES; |
| 554 | } |
| 555 | |
| 556 | try { |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 557 | double expected = pow(static_cast<double>(10), -292); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 558 | cout << "testDouble(" << expected << ") = " << flush; |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 559 | double actual = testClient.testDouble(expected); |
| 560 | cout << "(" << actual << ")" << endl; |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 561 | if (expected - actual > pow(static_cast<double>(10), -307)) { |
Nobuaki Sukegawa | 228b328 | 2015-10-10 03:11:49 +0900 | [diff] [blame] | 562 | cout << "*** FAILED ***" << endl |
| 563 | << "Expected: " << expected << " but got: " << actual << endl; |
| 564 | } |
| 565 | } catch (TTransportException&) { |
| 566 | throw; |
| 567 | } catch (exception& ex) { |
| 568 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 569 | return_code |= ERR_BASETYPES; |
| 570 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 571 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 572 | /** |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 573 | * BINARY TEST |
| 574 | */ |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 575 | for (string::size_type i = 0; i < 131073 && !return_code; ) { |
| 576 | return_code |= binary_test(testClient, i); |
| 577 | if (i > 0) { i *= 2; } else { ++i; } |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 578 | } |
| 579 | |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 580 | |
| 581 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 582 | * STRUCT TEST |
| 583 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 584 | cout << "testStruct({\"Zero\", 1, -3, -5})" << flush; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 585 | Xtruct out; |
| 586 | out.string_thing = "Zero"; |
| 587 | out.byte_thing = 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 588 | out.i32_thing = -3; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 589 | out.i64_thing = -5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 590 | Xtruct in; |
| 591 | testClient.testStruct(in, out); |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 592 | printf(" = {\"%s\", %d, %d, %" PRId64 "}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 593 | in.string_thing.c_str(), |
| 594 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 595 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 596 | in.i64_thing); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 597 | if (in != out) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 598 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 599 | return_code |= ERR_STRUCTS; |
| 600 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 601 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 602 | /** |
| 603 | * NESTED STRUCT TEST |
| 604 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 605 | cout << "testNest({1, {\"Zero\", 1, -3, -5}), 5}" << flush; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 606 | Xtruct2 out2; |
| 607 | out2.byte_thing = 1; |
| 608 | out2.struct_thing = out; |
| 609 | out2.i32_thing = 5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 610 | Xtruct2 in2; |
| 611 | testClient.testNest(in2, out2); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 612 | in = in2.struct_thing; |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 613 | printf(" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 614 | in2.byte_thing, |
| 615 | in.string_thing.c_str(), |
| 616 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 617 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 618 | in.i64_thing, |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 619 | in2.i32_thing); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 620 | if (in2 != out2) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 621 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 622 | return_code |= ERR_STRUCTS; |
| 623 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 624 | |
| 625 | /** |
| 626 | * MAP TEST |
| 627 | */ |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 628 | map<int32_t, int32_t> mapout; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 629 | for (int32_t i = 0; i < 5; ++i) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 630 | mapout.insert(make_pair(i, i - 10)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 631 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 632 | cout << "testMap({" << flush; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 633 | map<int32_t, int32_t>::const_iterator m_iter; |
| 634 | bool first = true; |
| 635 | for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) { |
| 636 | if (first) { |
| 637 | first = false; |
| 638 | } else { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 639 | cout << ","; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 640 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 641 | cout << m_iter->first << " => " << m_iter->second; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 642 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 643 | cout << "})"; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 644 | map<int32_t, int32_t> mapin; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 645 | testClient.testMap(mapin, mapout); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 646 | cout << " = {"; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 647 | first = true; |
| 648 | for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { |
| 649 | if (first) { |
| 650 | first = false; |
| 651 | } else { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 652 | cout << ","; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 653 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 654 | cout << m_iter->first << " => " << m_iter->second; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 655 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 656 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 657 | if (mapin != mapout) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 658 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 659 | return_code |= ERR_CONTAINERS; |
| 660 | } |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 661 | |
| 662 | /** |
| 663 | * STRING MAP TEST |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 664 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 665 | cout << "testStringMap({a => 2, b => blah, some => thing}) = {" << flush; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 666 | map<string, string> smapin; |
| 667 | map<string, string> smapout; |
| 668 | smapin["a"] = "2"; |
| 669 | smapin["b"] = "blah"; |
| 670 | smapin["some"] = "thing"; |
| 671 | try { |
| 672 | testClient.testStringMap(smapout, smapin); |
| 673 | first = true; |
| 674 | for (map<string, string>::const_iterator it = smapout.begin(); it != smapout.end(); ++it) { |
| 675 | if (first) |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 676 | cout << ","; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 677 | else |
| 678 | first = false; |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 679 | cout << it->first << " => " << it->second; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 680 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 681 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 682 | if (smapin != smapout) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 683 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 684 | return_code |= ERR_CONTAINERS; |
| 685 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 686 | } catch (TTransportException&) { |
| 687 | throw; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 688 | } catch (exception& ex) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 689 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 690 | return_code |= ERR_CONTAINERS; |
| 691 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 692 | |
| 693 | /** |
| 694 | * SET TEST |
| 695 | */ |
| 696 | set<int32_t> setout; |
| 697 | for (int32_t i = -2; i < 3; ++i) { |
| 698 | setout.insert(i); |
| 699 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 700 | cout << "testSet({" << flush; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 701 | set<int32_t>::const_iterator s_iter; |
| 702 | first = true; |
| 703 | for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) { |
| 704 | if (first) { |
| 705 | first = false; |
| 706 | } else { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 707 | cout << ","; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 708 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 709 | cout << *s_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 710 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 711 | cout << "})"; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 712 | set<int32_t> setin; |
| 713 | testClient.testSet(setin, setout); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 714 | cout << " = {"; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 715 | first = true; |
| 716 | for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { |
| 717 | if (first) { |
| 718 | first = false; |
| 719 | } else { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 720 | cout << ","; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 721 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 722 | cout << *s_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 723 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 724 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 725 | if (setin != setout) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 726 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 727 | return_code |= ERR_CONTAINERS; |
| 728 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 729 | |
| 730 | /** |
| 731 | * LIST TEST |
| 732 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 733 | cout << "testList(empty)" << flush; |
| 734 | try { |
| 735 | vector<int32_t> listout; |
| 736 | testClient.testList(listout, vector<int32_t>()); |
| 737 | if (!listout.empty()) { |
| 738 | cout << "*** FAILED ***" << endl; |
| 739 | cout << "invalid length: " << listout.size() << endl; |
| 740 | return_code |= ERR_CONTAINERS; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 741 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 742 | } catch (TTransportException&) { |
| 743 | throw; |
| 744 | } catch (exception& ex) { |
| 745 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
| 746 | return_code |= ERR_CONTAINERS; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 747 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 748 | try { |
| 749 | vector<int32_t> listout; |
| 750 | for (int32_t i = -2; i < 3; ++i) { |
| 751 | listout.push_back(i); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 752 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 753 | cout << "testList({" << flush; |
| 754 | vector<int32_t>::const_iterator l_iter; |
| 755 | first = true; |
| 756 | for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { |
| 757 | if (first) { |
| 758 | first = false; |
| 759 | } else { |
| 760 | cout << ","; |
| 761 | } |
| 762 | cout << *l_iter; |
| 763 | } |
| 764 | cout << "})"; |
| 765 | vector<int32_t> listin; |
| 766 | testClient.testList(listin, listout); |
| 767 | cout << " = {"; |
| 768 | first = true; |
| 769 | for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { |
| 770 | if (first) { |
| 771 | first = false; |
| 772 | } else { |
| 773 | cout << ","; |
| 774 | } |
| 775 | cout << *l_iter; |
| 776 | } |
| 777 | cout << "}" << endl; |
| 778 | if (listin != listout) { |
| 779 | cout << "*** FAILED ***" << endl; |
| 780 | return_code |= ERR_CONTAINERS; |
| 781 | } |
| 782 | } catch (TTransportException&) { |
| 783 | throw; |
| 784 | } catch (exception& ex) { |
| 785 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 786 | return_code |= ERR_CONTAINERS; |
| 787 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 788 | |
| 789 | /** |
| 790 | * ENUM TEST |
| 791 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 792 | cout << "testEnum(ONE)" << flush; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 793 | Numberz::type ret = testClient.testEnum(Numberz::ONE); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 794 | cout << " = " << ret << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 795 | if (ret != Numberz::ONE) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 796 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 797 | return_code |= ERR_STRUCTS; |
| 798 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 799 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 800 | cout << "testEnum(TWO)" << flush; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 801 | ret = testClient.testEnum(Numberz::TWO); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 802 | cout << " = " << ret << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 803 | if (ret != Numberz::TWO) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 804 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 805 | return_code |= ERR_STRUCTS; |
| 806 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 807 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 808 | cout << "testEnum(THREE)" << flush; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 809 | ret = testClient.testEnum(Numberz::THREE); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 810 | cout << " = " << ret << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 811 | if (ret != Numberz::THREE) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 812 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 813 | return_code |= ERR_STRUCTS; |
| 814 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 815 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 816 | cout << "testEnum(FIVE)" << flush; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 817 | ret = testClient.testEnum(Numberz::FIVE); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 818 | cout << " = " << ret << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 819 | if (ret != Numberz::FIVE) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 820 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 821 | return_code |= ERR_STRUCTS; |
| 822 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 823 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 824 | cout << "testEnum(EIGHT)" << flush; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 825 | ret = testClient.testEnum(Numberz::EIGHT); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 826 | cout << " = " << ret << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 827 | if (ret != Numberz::EIGHT) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 828 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 829 | return_code |= ERR_STRUCTS; |
| 830 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 831 | |
| 832 | /** |
| 833 | * TYPEDEF TEST |
| 834 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 835 | cout << "testTypedef(309858235082523)" << flush; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 836 | UserId uid = testClient.testTypedef(309858235082523LL); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 837 | cout << " = " << uid << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 838 | if (uid != 309858235082523LL) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 839 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 840 | return_code |= ERR_STRUCTS; |
| 841 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 842 | |
| 843 | /** |
| 844 | * NESTED MAP TEST |
| 845 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 846 | cout << "testMapMap(1)" << flush; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 847 | map<int32_t, map<int32_t, int32_t> > mm; |
| 848 | testClient.testMapMap(mm, 1); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 849 | cout << " = {"; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 850 | map<int32_t, map<int32_t, int32_t> >::const_iterator mi; |
| 851 | for (mi = mm.begin(); mi != mm.end(); ++mi) { |
| 852 | printf("%d => {", mi->first); |
| 853 | map<int32_t, int32_t>::const_iterator mi2; |
| 854 | for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 855 | cout << mi2->first << " => " << mi2->second; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 856 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 857 | cout << "}, "; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 858 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 859 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 860 | if (mm.size() != 2 || |
| 861 | mm[-4][-4] != -4 || |
| 862 | mm[-4][-3] != -3 || |
| 863 | mm[-4][-2] != -2 || |
| 864 | mm[-4][-1] != -1 || |
| 865 | mm[4][4] != 4 || |
| 866 | mm[4][3] != 3 || |
| 867 | mm[4][2] != 2 || |
| 868 | mm[4][1] != 1) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 869 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 870 | return_code |= ERR_CONTAINERS; |
| 871 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 872 | |
| 873 | /** |
| 874 | * INSANITY TEST |
| 875 | */ |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 876 | if (!noinsane) { |
| 877 | Insanity insane; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 878 | insane.userMap.insert(make_pair(Numberz::FIVE, 5)); |
| 879 | insane.userMap.insert(make_pair(Numberz::EIGHT, 8)); |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 880 | Xtruct truck; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 881 | truck.string_thing = "Goodbye4"; |
| 882 | truck.byte_thing = 4; |
| 883 | truck.i32_thing = 4; |
| 884 | truck.i64_thing = 4; |
| 885 | Xtruct truck2; |
| 886 | truck2.string_thing = "Hello2"; |
| 887 | truck2.byte_thing = 2; |
| 888 | truck2.i32_thing = 2; |
| 889 | truck2.i64_thing = 2; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 890 | insane.xtructs.push_back(truck); |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 891 | insane.xtructs.push_back(truck2); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 892 | cout << "testInsanity()" << flush; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 893 | map<UserId, map<Numberz::type, Insanity> > whoa; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 894 | testClient.testInsanity(whoa, insane); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 895 | cout << " = {"; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 896 | map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 897 | for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { |
| 898 | printf("%" PRId64 " => {", i_iter->first); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 899 | map<Numberz::type, Insanity>::const_iterator i2_iter; |
| 900 | 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] | 901 | printf("%d => {", i2_iter->first); |
| 902 | map<Numberz::type, UserId> userMap = i2_iter->second.userMap; |
| 903 | map<Numberz::type, UserId>::const_iterator um; |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 904 | cout << "{"; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 905 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 906 | cout << um->first << " => " << um->second; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 907 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 908 | cout << "}, "; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 909 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 910 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 911 | vector<Xtruct>::const_iterator x; |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 912 | cout << "{"; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 913 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
| 914 | printf("{\"%s\", %d, %d, %" PRId64 "}, ", |
| 915 | x->string_thing.c_str(), |
| 916 | (int)x->byte_thing, |
| 917 | x->i32_thing, |
| 918 | x->i64_thing); |
| 919 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 920 | cout << "}"; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 921 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 922 | cout << "}, "; |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 923 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 924 | cout << "}, "; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 925 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 926 | cout << "}" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 927 | bool failed = false; |
| 928 | map<UserId, map<Numberz::type, Insanity> >::const_iterator it1 = whoa.find(UserId(1)); |
| 929 | if (whoa.size() != 2) { |
| 930 | failed = true; |
| 931 | } |
| 932 | if (it1 == whoa.end()) { |
| 933 | failed = true; |
| 934 | } else { |
| 935 | map<Numberz::type, Insanity>::const_iterator it12 = it1->second.find(Numberz::TWO); |
| 936 | if (it12 == it1->second.end() || it12->second != insane) { |
| 937 | failed = true; |
| 938 | } |
| 939 | map<Numberz::type, Insanity>::const_iterator it13 = it1->second.find(Numberz::THREE); |
| 940 | if (it13 == it1->second.end() || it13->second != insane) { |
| 941 | failed = true; |
| 942 | } |
| 943 | } |
| 944 | map<UserId, map<Numberz::type, Insanity> >::const_iterator it2 = whoa.find(UserId(2)); |
| 945 | if (it2 == whoa.end()) { |
| 946 | failed = true; |
| 947 | } else { |
| 948 | map<Numberz::type, Insanity>::const_iterator it26 = it2->second.find(Numberz::SIX); |
| 949 | if (it26 == it1->second.end() || it26->second != Insanity()) { |
| 950 | failed = true; |
| 951 | } |
| 952 | } |
| 953 | if (failed) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 954 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 955 | return_code |= ERR_STRUCTS; |
| 956 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 957 | } |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 958 | |
| 959 | /** |
| 960 | * MULTI TEST |
| 961 | */ |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 962 | cout << "testMulti()" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 963 | try { |
| 964 | map<int16_t, string> mul_map; |
| 965 | Xtruct mul_result; |
| 966 | mul_map[1] = "blah"; |
| 967 | mul_map[2] = "thing"; |
| 968 | testClient.testMulti(mul_result, 42, 4242, 424242, mul_map, Numberz::EIGHT, UserId(24)); |
| 969 | Xtruct xxs; |
| 970 | xxs.string_thing = "Hello2"; |
| 971 | xxs.byte_thing = 42; |
| 972 | xxs.i32_thing = 4242; |
| 973 | xxs.i64_thing = 424242; |
| 974 | if (mul_result != xxs) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 975 | cout << "*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 976 | return_code |= ERR_STRUCTS; |
| 977 | } |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 978 | } catch (TTransportException&) { |
| 979 | throw; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 980 | } catch (exception& ex) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 981 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 982 | return_code |= ERR_STRUCTS; |
| 983 | } |
| 984 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 985 | /* test exception */ |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 986 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 987 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 988 | cout << "testClient.testException(\"Xception\") =>" << flush; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 989 | testClient.testException("Xception"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 990 | cout << " void\n*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 991 | return_code |= ERR_EXCEPTIONS; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 992 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 993 | } catch (Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 994 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 995 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 996 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 997 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 998 | cout << "testClient.testException(\"TException\") =>" << flush; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 999 | testClient.testException("TException"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1000 | cout << " void\n*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1001 | return_code |= ERR_EXCEPTIONS; |
Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 1002 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1003 | } catch (const TException&) { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1004 | cout << " Caught TException" << endl; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1005 | } |
Roger Meier | f50df7f | 2012-05-02 22:49:55 +0000 | [diff] [blame] | 1006 | |
| 1007 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1008 | cout << "testClient.testException(\"success\") =>" << flush; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1009 | testClient.testException("success"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1010 | cout << " void" << endl; |
| 1011 | } catch (exception & ex) { \ |
| 1012 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1013 | return_code |= ERR_EXCEPTIONS; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1014 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1015 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1016 | /* test multi exception */ |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1017 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1018 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1019 | cout << "testClient.testMultiException(\"Xception\", \"test 1\") =>" << flush; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 1020 | Xtruct result; |
| 1021 | testClient.testMultiException(result, "Xception", "test 1"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1022 | cout << " result\n*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1023 | return_code |= ERR_EXCEPTIONS; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1024 | } catch (Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1025 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
| 1026 | } |
| 1027 | |
| 1028 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1029 | cout << "testClient.testMultiException(\"Xception2\", \"test 2\") =>" << flush; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 1030 | Xtruct result; |
| 1031 | testClient.testMultiException(result, "Xception2", "test 2"); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1032 | cout << " result\n*** FAILED ***" << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1033 | return_code |= ERR_EXCEPTIONS; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1034 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1035 | } catch (Xception2& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1036 | 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] | 1037 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1038 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1039 | try { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1040 | cout << "testClient.testMultiException(\"success\", \"test 3\") =>" << flush; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 1041 | Xtruct result; |
| 1042 | testClient.testMultiException(result, "success", "test 3"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1043 | printf(" {{\"%s\"}}\n", result.string_thing.c_str()); |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1044 | } catch (exception & ex) { \ |
| 1045 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1046 | return_code |= ERR_EXCEPTIONS; |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 1047 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1048 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 1049 | /* test oneway void */ |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 1050 | { |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1051 | cout << "testClient.testOneway(1) =>" << flush; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1052 | uint64_t startOneway = now(); |
| 1053 | testClient.testOneway(1); |
| 1054 | uint64_t elapsed = now() - startOneway; |
| 1055 | if (elapsed > 200 * 1000) { // 0.2 seconds |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1056 | printf("*** FAILED *** - took %.2f ms\n", (double)elapsed / 1000.0); |
| 1057 | return_code |= ERR_BASETYPES; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1058 | } else { |
| 1059 | printf(" success - took %.2f ms\n", (double)elapsed / 1000.0); |
| 1060 | } |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 1063 | /** |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 1064 | * redo a simple test after the oneway to make sure we aren't "off by one" -- |
| 1065 | * 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] | 1066 | * fail since it will get the void confirmation rather than the correct |
| 1067 | * result. In this circumstance, the client will throw the exception: |
| 1068 | * |
| 1069 | * TApplicationException: Wrong method namea |
| 1070 | */ |
| 1071 | /** |
| 1072 | * I32 TEST |
| 1073 | */ |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 1074 | cout << "re-test testI32(-1)" << flush; |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1075 | int i32 = testClient.testI32(-1); |
| 1076 | cout << " = " << i32 << endl; |
Roger Meier | 4fce960 | 2012-05-04 06:22:09 +0000 | [diff] [blame] | 1077 | if (i32 != -1) |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1078 | return_code |= ERR_BASETYPES; |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 1079 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 1080 | cout << endl << "All tests done." << endl << flush; |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 1081 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 1082 | uint64_t stop = now(); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 1083 | uint64_t tot = stop - start; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1084 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1085 | cout << "Total time: " << stop - start << " us" << endl; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 1086 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1087 | time_tot += tot; |
| 1088 | if (time_min == 0 || tot < time_min) { |
| 1089 | time_min = tot; |
| 1090 | } |
| 1091 | if (tot > time_max) { |
| 1092 | time_max = tot; |
| 1093 | } |
| 1094 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 1095 | cout << flush; |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 1096 | transport->close(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1099 | |
| 1100 | uint64_t time_avg = time_tot / numTests; |
| 1101 | |
Nobuaki Sukegawa | 9b35a7c | 2015-11-17 11:01:41 +0900 | [diff] [blame] | 1102 | cout << "Min time: " << time_min << " us" << endl; |
| 1103 | cout << "Max time: " << time_max << " us" << endl; |
| 1104 | cout << "Avg time: " << time_avg << " us" << endl; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 1105 | |
Jens Geyer | d629ea0 | 2015-09-23 21:16:50 +0200 | [diff] [blame] | 1106 | return return_code; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1107 | } |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 1108 | |
| 1109 | void binary_fill(std::string& str, string::size_type siz) |
| 1110 | { |
| 1111 | static const signed char bin_data[256] |
| 1112 | = {-128, -127, -126, -125, -124, -123, -122, -121, -120, -119, -118, -117, -116, -115, -114, |
| 1113 | -113, -112, -111, -110, -109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99, |
| 1114 | -98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, -85, -84, |
| 1115 | -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, -72, -71, -70, -69, |
| 1116 | -68, -67, -66, -65, -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, |
| 1117 | -53, -52, -51, -50, -49, -48, -47, -46, -45, -44, -43, -42, -41, -40, -39, |
| 1118 | -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, |
| 1119 | -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, |
| 1120 | -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, |
| 1121 | 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
| 1122 | 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, |
| 1123 | 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 1124 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, |
| 1125 | 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, |
| 1126 | 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, |
| 1127 | 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, |
| 1128 | 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, |
| 1129 | 127}; |
| 1130 | |
| 1131 | str.resize(siz); |
| 1132 | char *ptr = &str[0]; |
| 1133 | string::size_type pos = 0; |
| 1134 | for (string::size_type i = 0; i < siz; ++i) |
| 1135 | { |
| 1136 | if (pos == 255) { pos = 0; } else { ++pos; } |
| 1137 | *ptr++ = bin_data[pos]; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | int binary_test(ThriftTestClient& testClient, string::size_type siz) |
| 1142 | { |
| 1143 | string bin_request; |
| 1144 | string bin_result; |
| 1145 | |
| 1146 | cout << "testBinary(siz = " << siz << ")" << endl; |
| 1147 | binary_fill(bin_request, siz); |
| 1148 | try { |
| 1149 | testClient.testBinary(bin_result, bin_request); |
| 1150 | |
| 1151 | if (bin_request.size() != bin_result.size()) { |
| 1152 | cout << "*** FAILED: request size " << bin_request.size() << "; result size " << bin_result.size() << endl; |
| 1153 | return ERR_BASETYPES; |
| 1154 | } |
| 1155 | |
| 1156 | for (string::size_type i = 0; i < siz; ++i) { |
| 1157 | if (bin_request.at(i) != bin_result.at(i)) { |
| 1158 | cout << "*** FAILED: at position " << i << " request[i] is h" << hex << bin_request.at(i) << " result[i] is h" << hex << bin_result.at(i) << endl; |
| 1159 | return ERR_BASETYPES; |
| 1160 | } |
| 1161 | } |
| 1162 | } catch (TTransportException&) { |
| 1163 | throw; |
| 1164 | } catch (exception& ex) { |
| 1165 | cout << "*** FAILED ***" << endl << ex.what() << endl; |
| 1166 | return ERR_BASETYPES; |
| 1167 | } |
| 1168 | |
| 1169 | return 0; |
| 1170 | } |