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