David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <unistd.h> |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 22 | #include <sys/time.h> |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 23 | #include <protocol/TBinaryProtocol.h> |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 24 | #include <transport/TTransportUtils.h> |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 25 | #include <transport/TSocket.h> |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 26 | #include <transport/TSSLSocket.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 27 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 28 | #include <boost/shared_ptr.hpp> |
| 29 | #include "ThriftTest.h" |
| 30 | |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 31 | #define __STDC_FORMAT_MACROS |
| 32 | #include <inttypes.h> |
| 33 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 34 | using namespace boost; |
| 35 | using namespace std; |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 36 | using namespace apache::thrift; |
| 37 | using namespace apache::thrift::protocol; |
| 38 | using namespace apache::thrift::transport; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 39 | using namespace thrift::test; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 40 | |
| 41 | //extern uint32_t g_socket_syscalls; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 42 | |
| 43 | // Current time, microseconds since the epoch |
| 44 | uint64_t now() |
| 45 | { |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 46 | int64_t ret; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 47 | struct timeval tv; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 48 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 49 | gettimeofday(&tv, NULL); |
| 50 | ret = tv.tv_sec; |
| 51 | ret = ret*1000*1000 + tv.tv_usec; |
| 52 | return ret; |
| 53 | } |
| 54 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 55 | int main(int argc, char** argv) { |
| 56 | string host = "localhost"; |
| 57 | int port = 9090; |
| 58 | int numTests = 1; |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 59 | bool framed = false; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 60 | bool ssl = false; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 61 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 62 | for (int i = 0; i < argc; ++i) { |
| 63 | if (strcmp(argv[i], "-h") == 0) { |
| 64 | char* pch = strtok(argv[++i], ":"); |
| 65 | if (pch != NULL) { |
| 66 | host = string(pch); |
| 67 | } |
| 68 | pch = strtok(NULL, ":"); |
| 69 | if (pch != NULL) { |
| 70 | port = atoi(pch); |
| 71 | } |
| 72 | } else if (strcmp(argv[i], "-n") == 0) { |
| 73 | numTests = atoi(argv[++i]); |
| 74 | } else if (strcmp(argv[i], "-f") == 0) { |
| 75 | framed = true; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 76 | } else if (strcmp(argv[i], "--ssl") == 0) { |
| 77 | ssl = true; |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 78 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 79 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 80 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 81 | shared_ptr<TSocket> socket; |
| 82 | shared_ptr<TSSLSocketFactory> factory; |
| 83 | if (ssl) { |
| 84 | factory = shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory()); |
| 85 | factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
| 86 | factory->loadTrustedCertificates("./trusted-ca-certificate.pem"); |
| 87 | factory->authenticate(true); |
| 88 | socket = factory->createSocket(host, port); |
| 89 | } else { |
| 90 | socket = shared_ptr<TSocket>(new TSocket(host, port)); |
| 91 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 92 | |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 93 | shared_ptr<TBufferBase> transport; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 94 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 95 | if (framed) { |
| 96 | shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 97 | transport = framedSocket; |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 98 | } else { |
| 99 | shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket)); |
| 100 | transport = bufferedSocket; |
| 101 | } |
| 102 | |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 103 | shared_ptr< TBinaryProtocolT<TBufferBase> > protocol( |
| 104 | new TBinaryProtocolT<TBufferBase>(transport)); |
David Reiss | b7762a0 | 2010-10-06 17:10:00 +0000 | [diff] [blame] | 105 | ThriftTestClientT< TBinaryProtocolT<TBufferBase> > testClient(protocol); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 106 | |
| 107 | uint64_t time_min = 0; |
| 108 | uint64_t time_max = 0; |
| 109 | uint64_t time_tot = 0; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 110 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 111 | int test = 0; |
| 112 | for (test = 0; test < numTests; ++test) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 113 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 114 | try { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 115 | transport->open(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 116 | } catch (TTransportException& ttx) { |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 117 | printf("Connect failed: %s\n", ttx.what()); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 118 | continue; |
| 119 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 120 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 121 | /** |
| 122 | * CONNECT TEST |
| 123 | */ |
| 124 | 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] | 125 | |
| 126 | uint64_t start = now(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 127 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 128 | /** |
| 129 | * VOID TEST |
| 130 | */ |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 131 | try { |
| 132 | printf("testVoid()"); |
| 133 | testClient.testVoid(); |
| 134 | printf(" = void\n"); |
| 135 | } catch (TApplicationException tax) { |
| 136 | printf("%s\n", tax.what()); |
| 137 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 138 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 139 | /** |
| 140 | * STRING TEST |
| 141 | */ |
| 142 | printf("testString(\"Test\")"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 143 | string s; |
| 144 | testClient.testString(s, "Test"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 145 | printf(" = \"%s\"\n", s.c_str()); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 146 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 147 | /** |
| 148 | * BYTE TEST |
| 149 | */ |
| 150 | printf("testByte(1)"); |
| 151 | uint8_t u8 = testClient.testByte(1); |
| 152 | printf(" = %d\n", (int)u8); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 153 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 154 | /** |
| 155 | * I32 TEST |
| 156 | */ |
| 157 | printf("testI32(-1)"); |
| 158 | int32_t i32 = testClient.testI32(-1); |
| 159 | printf(" = %d\n", i32); |
| 160 | |
| 161 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 162 | * I64 TEST |
| 163 | */ |
| 164 | printf("testI64(-34359738368)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 165 | int64_t i64 = testClient.testI64(-34359738368LL); |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 166 | printf(" = %"PRId64"\n", i64); |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * DOUBLE TEST |
| 170 | */ |
| 171 | printf("testDouble(-5.2098523)"); |
| 172 | double dub = testClient.testDouble(-5.2098523); |
| 173 | printf(" = %lf\n", dub); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 174 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 175 | /** |
| 176 | * STRUCT TEST |
| 177 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 178 | printf("testStruct({\"Zero\", 1, -3, -5})"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 179 | Xtruct out; |
| 180 | out.string_thing = "Zero"; |
| 181 | out.byte_thing = 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 182 | out.i32_thing = -3; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 183 | out.i64_thing = -5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 184 | Xtruct in; |
| 185 | testClient.testStruct(in, out); |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 186 | printf(" = {\"%s\", %d, %d, %"PRId64"}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 187 | in.string_thing.c_str(), |
| 188 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 189 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 190 | in.i64_thing); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 191 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 192 | /** |
| 193 | * NESTED STRUCT TEST |
| 194 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 195 | printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 196 | Xtruct2 out2; |
| 197 | out2.byte_thing = 1; |
| 198 | out2.struct_thing = out; |
| 199 | out2.i32_thing = 5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 200 | Xtruct2 in2; |
| 201 | testClient.testNest(in2, out2); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 202 | in = in2.struct_thing; |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 203 | printf(" = {%d, {\"%s\", %d, %d, %"PRId64"}, %d}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 204 | in2.byte_thing, |
| 205 | in.string_thing.c_str(), |
| 206 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 207 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 208 | in.i64_thing, |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 209 | in2.i32_thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * MAP TEST |
| 213 | */ |
| 214 | map<int32_t,int32_t> mapout; |
| 215 | for (int32_t i = 0; i < 5; ++i) { |
| 216 | mapout.insert(make_pair(i, i-10)); |
| 217 | } |
| 218 | printf("testMap({"); |
| 219 | map<int32_t, int32_t>::const_iterator m_iter; |
| 220 | bool first = true; |
| 221 | for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) { |
| 222 | if (first) { |
| 223 | first = false; |
| 224 | } else { |
| 225 | printf(", "); |
| 226 | } |
| 227 | printf("%d => %d", m_iter->first, m_iter->second); |
| 228 | } |
| 229 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 230 | map<int32_t,int32_t> mapin; |
| 231 | testClient.testMap(mapin, mapout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 232 | printf(" = {"); |
| 233 | first = true; |
| 234 | for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { |
| 235 | if (first) { |
| 236 | first = false; |
| 237 | } else { |
| 238 | printf(", "); |
| 239 | } |
| 240 | printf("%d => %d", m_iter->first, m_iter->second); |
| 241 | } |
| 242 | printf("}\n"); |
| 243 | |
| 244 | /** |
| 245 | * SET TEST |
| 246 | */ |
| 247 | set<int32_t> setout; |
| 248 | for (int32_t i = -2; i < 3; ++i) { |
| 249 | setout.insert(i); |
| 250 | } |
| 251 | printf("testSet({"); |
| 252 | set<int32_t>::const_iterator s_iter; |
| 253 | first = true; |
| 254 | for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) { |
| 255 | if (first) { |
| 256 | first = false; |
| 257 | } else { |
| 258 | printf(", "); |
| 259 | } |
| 260 | printf("%d", *s_iter); |
| 261 | } |
| 262 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 263 | set<int32_t> setin; |
| 264 | testClient.testSet(setin, setout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 265 | printf(" = {"); |
| 266 | first = true; |
| 267 | for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { |
| 268 | if (first) { |
| 269 | first = false; |
| 270 | } else { |
| 271 | printf(", "); |
| 272 | } |
| 273 | printf("%d", *s_iter); |
| 274 | } |
| 275 | printf("}\n"); |
| 276 | |
| 277 | /** |
| 278 | * LIST TEST |
| 279 | */ |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 280 | vector<int32_t> listout; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 281 | for (int32_t i = -2; i < 3; ++i) { |
| 282 | listout.push_back(i); |
| 283 | } |
| 284 | printf("testList({"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 285 | vector<int32_t>::const_iterator l_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 286 | first = true; |
| 287 | for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { |
| 288 | if (first) { |
| 289 | first = false; |
| 290 | } else { |
| 291 | printf(", "); |
| 292 | } |
| 293 | printf("%d", *l_iter); |
| 294 | } |
| 295 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 296 | vector<int32_t> listin; |
| 297 | testClient.testList(listin, listout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 298 | printf(" = {"); |
| 299 | first = true; |
| 300 | for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { |
| 301 | if (first) { |
| 302 | first = false; |
| 303 | } else { |
| 304 | printf(", "); |
| 305 | } |
| 306 | printf("%d", *l_iter); |
| 307 | } |
| 308 | printf("}\n"); |
| 309 | |
| 310 | /** |
| 311 | * ENUM TEST |
| 312 | */ |
| 313 | printf("testEnum(ONE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 314 | Numberz::type ret = testClient.testEnum(Numberz::ONE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 315 | printf(" = %d\n", ret); |
| 316 | |
| 317 | printf("testEnum(TWO)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 318 | ret = testClient.testEnum(Numberz::TWO); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 319 | printf(" = %d\n", ret); |
| 320 | |
| 321 | printf("testEnum(THREE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 322 | ret = testClient.testEnum(Numberz::THREE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 323 | printf(" = %d\n", ret); |
| 324 | |
| 325 | printf("testEnum(FIVE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 326 | ret = testClient.testEnum(Numberz::FIVE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 327 | printf(" = %d\n", ret); |
| 328 | |
| 329 | printf("testEnum(EIGHT)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 330 | ret = testClient.testEnum(Numberz::EIGHT); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 331 | printf(" = %d\n", ret); |
| 332 | |
| 333 | /** |
| 334 | * TYPEDEF TEST |
| 335 | */ |
| 336 | printf("testTypedef(309858235082523)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 337 | UserId uid = testClient.testTypedef(309858235082523LL); |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 338 | printf(" = %"PRId64"\n", uid); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 339 | |
| 340 | /** |
| 341 | * NESTED MAP TEST |
| 342 | */ |
| 343 | printf("testMapMap(1)"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 344 | map<int32_t, map<int32_t, int32_t> > mm; |
| 345 | testClient.testMapMap(mm, 1); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 346 | printf(" = {"); |
| 347 | map<int32_t, map<int32_t, int32_t> >::const_iterator mi; |
| 348 | for (mi = mm.begin(); mi != mm.end(); ++mi) { |
| 349 | printf("%d => {", mi->first); |
| 350 | map<int32_t, int32_t>::const_iterator mi2; |
| 351 | for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) { |
| 352 | printf("%d => %d, ", mi2->first, mi2->second); |
| 353 | } |
| 354 | printf("}, "); |
| 355 | } |
| 356 | printf("}\n"); |
| 357 | |
| 358 | /** |
| 359 | * INSANITY TEST |
| 360 | */ |
| 361 | Insanity insane; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 362 | insane.userMap.insert(make_pair(Numberz::FIVE, 5000)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 363 | Xtruct truck; |
| 364 | truck.string_thing = "Truck"; |
| 365 | truck.byte_thing = 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 366 | truck.i32_thing = 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 367 | truck.i64_thing = 8; |
| 368 | insane.xtructs.push_back(truck); |
| 369 | printf("testInsanity()"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 370 | map<UserId, map<Numberz::type,Insanity> > whoa; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 371 | testClient.testInsanity(whoa, insane); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 372 | printf(" = {"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 373 | map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 374 | for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 375 | printf("%"PRId64" => {", i_iter->first); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 376 | map<Numberz::type,Insanity>::const_iterator i2_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 377 | for (i2_iter = i_iter->second.begin(); |
| 378 | i2_iter != i_iter->second.end(); |
| 379 | ++i2_iter) { |
| 380 | printf("%d => {", i2_iter->first); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 381 | map<Numberz::type, UserId> userMap = i2_iter->second.userMap; |
| 382 | map<Numberz::type, UserId>::const_iterator um; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 383 | printf("{"); |
| 384 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 385 | printf("%d => %"PRId64", ", um->first, um->second); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 386 | } |
| 387 | printf("}, "); |
| 388 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 389 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 390 | vector<Xtruct>::const_iterator x; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 391 | printf("{"); |
| 392 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 393 | printf("{\"%s\", %d, %d, %"PRId64"}, ", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 394 | x->string_thing.c_str(), |
| 395 | (int)x->byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 396 | x->i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 397 | x->i64_thing); |
| 398 | } |
| 399 | printf("}"); |
| 400 | |
| 401 | printf("}, "); |
| 402 | } |
| 403 | printf("}, "); |
| 404 | } |
| 405 | printf("}\n"); |
| 406 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 407 | /* test exception */ |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 408 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 409 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 410 | printf("testClient.testException(\"Xception\") =>"); |
| 411 | testClient.testException("Xception"); |
| 412 | printf(" void\nFAILURE\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 413 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 414 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 415 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 416 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 417 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 418 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 419 | printf("testClient.testException(\"success\") =>"); |
| 420 | testClient.testException("success"); |
| 421 | printf(" void\n"); |
| 422 | } catch(...) { |
| 423 | printf(" exception\nFAILURE\n"); |
| 424 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 425 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 426 | /* test multi exception */ |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 427 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 428 | try { |
| 429 | printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 430 | Xtruct result; |
| 431 | testClient.testMultiException(result, "Xception", "test 1"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 432 | printf(" result\nFAILURE\n"); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 433 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 434 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
| 435 | } |
| 436 | |
| 437 | try { |
| 438 | printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 439 | Xtruct result; |
| 440 | testClient.testMultiException(result, "Xception2", "test 2"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 441 | printf(" result\nFAILURE\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 442 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 443 | } catch(Xception2& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 444 | 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] | 445 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 446 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 447 | try { |
| 448 | printf("testClient.testMultiException(\"success\", \"test 3\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 449 | Xtruct result; |
| 450 | testClient.testMultiException(result, "success", "test 3"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 451 | printf(" {{\"%s\"}}\n", result.string_thing.c_str()); |
| 452 | } catch(...) { |
| 453 | printf(" exception\nFAILURE\n"); |
| 454 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 455 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 456 | /* test oneway void */ |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 457 | { |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 458 | printf("testClient.testOneway(3) =>"); |
| 459 | uint64_t startOneway = now(); |
| 460 | testClient.testOneway(3); |
| 461 | uint64_t elapsed = now() - startOneway; |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 462 | if (elapsed > 200 * 1000) { // 0.2 seconds |
| 463 | printf(" FAILURE - took %.2f ms\n", (double)elapsed/1000.0); |
| 464 | } else { |
| 465 | printf(" success - took %.2f ms\n", (double)elapsed/1000.0); |
| 466 | } |
| 467 | } |
| 468 | |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 469 | /** |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 470 | * redo a simple test after the oneway to make sure we aren't "off by one" -- |
| 471 | * 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] | 472 | * fail since it will get the void confirmation rather than the correct |
| 473 | * result. In this circumstance, the client will throw the exception: |
| 474 | * |
| 475 | * TApplicationException: Wrong method namea |
| 476 | */ |
| 477 | /** |
| 478 | * I32 TEST |
| 479 | */ |
| 480 | printf("re-test testI32(-1)"); |
| 481 | i32 = testClient.testI32(-1); |
| 482 | printf(" = %d\n", i32); |
| 483 | |
| 484 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 485 | uint64_t stop = now(); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 486 | uint64_t tot = stop-start; |
| 487 | |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 488 | printf("Total time: %"PRIu64" us\n", stop-start); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 489 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 490 | time_tot += tot; |
| 491 | if (time_min == 0 || tot < time_min) { |
| 492 | time_min = tot; |
| 493 | } |
| 494 | if (tot > time_max) { |
| 495 | time_max = tot; |
| 496 | } |
| 497 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 498 | transport->close(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 499 | } |
| 500 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 501 | // printf("\nSocket syscalls: %u", g_socket_syscalls); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 502 | printf("\nAll tests done.\n"); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 503 | |
| 504 | uint64_t time_avg = time_tot / numTests; |
| 505 | |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 506 | printf("Min time: %"PRIu64" us\n", time_min); |
| 507 | printf("Max time: %"PRIu64" us\n", time_max); |
| 508 | printf("Avg time: %"PRIu64" us\n", time_avg); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 509 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 510 | return 0; |
| 511 | } |