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 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 95 | shared_ptr<TSocket> socket(new TSocket(host, port)); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 96 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 97 | if (framed) { |
| 98 | shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 99 | transport = framedSocket; |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 100 | } else { |
| 101 | shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket)); |
| 102 | transport = bufferedSocket; |
| 103 | } |
| 104 | |
David Reiss | e71115b | 2010-10-06 17:09:56 +0000 | [diff] [blame] | 105 | shared_ptr< TBinaryProtocolT<TBufferBase> > protocol( |
| 106 | new TBinaryProtocolT<TBufferBase>(transport)); |
David Reiss | b7762a0 | 2010-10-06 17:10:00 +0000 | [diff] [blame] | 107 | ThriftTestClientT< TBinaryProtocolT<TBufferBase> > testClient(protocol); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 108 | |
| 109 | uint64_t time_min = 0; |
| 110 | uint64_t time_max = 0; |
| 111 | uint64_t time_tot = 0; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 112 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 113 | int test = 0; |
| 114 | for (test = 0; test < numTests; ++test) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 115 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 116 | try { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 117 | transport->open(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 118 | } catch (TTransportException& ttx) { |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 119 | printf("Connect failed: %s\n", ttx.what()); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 120 | continue; |
| 121 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 122 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 123 | /** |
| 124 | * CONNECT TEST |
| 125 | */ |
| 126 | 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] | 127 | |
| 128 | uint64_t start = now(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 129 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 130 | /** |
| 131 | * VOID TEST |
| 132 | */ |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 133 | try { |
| 134 | printf("testVoid()"); |
| 135 | testClient.testVoid(); |
| 136 | printf(" = void\n"); |
| 137 | } catch (TApplicationException tax) { |
| 138 | printf("%s\n", tax.what()); |
| 139 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 140 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 141 | /** |
| 142 | * STRING TEST |
| 143 | */ |
| 144 | printf("testString(\"Test\")"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 145 | string s; |
| 146 | testClient.testString(s, "Test"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 147 | printf(" = \"%s\"\n", s.c_str()); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 148 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 149 | /** |
| 150 | * BYTE TEST |
| 151 | */ |
| 152 | printf("testByte(1)"); |
| 153 | uint8_t u8 = testClient.testByte(1); |
| 154 | printf(" = %d\n", (int)u8); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 155 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 156 | /** |
| 157 | * I32 TEST |
| 158 | */ |
| 159 | printf("testI32(-1)"); |
| 160 | int32_t i32 = testClient.testI32(-1); |
| 161 | printf(" = %d\n", i32); |
| 162 | |
| 163 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 164 | * I64 TEST |
| 165 | */ |
| 166 | printf("testI64(-34359738368)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 167 | int64_t i64 = testClient.testI64(-34359738368LL); |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 168 | printf(" = %"PRId64"\n", i64); |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * DOUBLE TEST |
| 172 | */ |
| 173 | printf("testDouble(-5.2098523)"); |
| 174 | double dub = testClient.testDouble(-5.2098523); |
| 175 | printf(" = %lf\n", dub); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 176 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 177 | /** |
| 178 | * STRUCT TEST |
| 179 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 180 | printf("testStruct({\"Zero\", 1, -3, -5})"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 181 | Xtruct out; |
| 182 | out.string_thing = "Zero"; |
| 183 | out.byte_thing = 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 184 | out.i32_thing = -3; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 185 | out.i64_thing = -5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 186 | Xtruct in; |
| 187 | testClient.testStruct(in, out); |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 188 | printf(" = {\"%s\", %d, %d, %"PRId64"}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 189 | in.string_thing.c_str(), |
| 190 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 191 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 192 | in.i64_thing); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 193 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 194 | /** |
| 195 | * NESTED STRUCT TEST |
| 196 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 197 | printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 198 | Xtruct2 out2; |
| 199 | out2.byte_thing = 1; |
| 200 | out2.struct_thing = out; |
| 201 | out2.i32_thing = 5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 202 | Xtruct2 in2; |
| 203 | testClient.testNest(in2, out2); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 204 | in = in2.struct_thing; |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 205 | printf(" = {%d, {\"%s\", %d, %d, %"PRId64"}, %d}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 206 | in2.byte_thing, |
| 207 | in.string_thing.c_str(), |
| 208 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 209 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 210 | in.i64_thing, |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 211 | in2.i32_thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * MAP TEST |
| 215 | */ |
| 216 | map<int32_t,int32_t> mapout; |
| 217 | for (int32_t i = 0; i < 5; ++i) { |
| 218 | mapout.insert(make_pair(i, i-10)); |
| 219 | } |
| 220 | printf("testMap({"); |
| 221 | map<int32_t, int32_t>::const_iterator m_iter; |
| 222 | bool first = true; |
| 223 | for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) { |
| 224 | if (first) { |
| 225 | first = false; |
| 226 | } else { |
| 227 | printf(", "); |
| 228 | } |
| 229 | printf("%d => %d", m_iter->first, m_iter->second); |
| 230 | } |
| 231 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 232 | map<int32_t,int32_t> mapin; |
| 233 | testClient.testMap(mapin, mapout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 234 | printf(" = {"); |
| 235 | first = true; |
| 236 | for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { |
| 237 | if (first) { |
| 238 | first = false; |
| 239 | } else { |
| 240 | printf(", "); |
| 241 | } |
| 242 | printf("%d => %d", m_iter->first, m_iter->second); |
| 243 | } |
| 244 | printf("}\n"); |
| 245 | |
| 246 | /** |
| 247 | * SET TEST |
| 248 | */ |
| 249 | set<int32_t> setout; |
| 250 | for (int32_t i = -2; i < 3; ++i) { |
| 251 | setout.insert(i); |
| 252 | } |
| 253 | printf("testSet({"); |
| 254 | set<int32_t>::const_iterator s_iter; |
| 255 | first = true; |
| 256 | for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) { |
| 257 | if (first) { |
| 258 | first = false; |
| 259 | } else { |
| 260 | printf(", "); |
| 261 | } |
| 262 | printf("%d", *s_iter); |
| 263 | } |
| 264 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 265 | set<int32_t> setin; |
| 266 | testClient.testSet(setin, setout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 267 | printf(" = {"); |
| 268 | first = true; |
| 269 | for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { |
| 270 | if (first) { |
| 271 | first = false; |
| 272 | } else { |
| 273 | printf(", "); |
| 274 | } |
| 275 | printf("%d", *s_iter); |
| 276 | } |
| 277 | printf("}\n"); |
| 278 | |
| 279 | /** |
| 280 | * LIST TEST |
| 281 | */ |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 282 | vector<int32_t> listout; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 283 | for (int32_t i = -2; i < 3; ++i) { |
| 284 | listout.push_back(i); |
| 285 | } |
| 286 | printf("testList({"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 287 | vector<int32_t>::const_iterator l_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 288 | first = true; |
| 289 | for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { |
| 290 | if (first) { |
| 291 | first = false; |
| 292 | } else { |
| 293 | printf(", "); |
| 294 | } |
| 295 | printf("%d", *l_iter); |
| 296 | } |
| 297 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 298 | vector<int32_t> listin; |
| 299 | testClient.testList(listin, listout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 300 | printf(" = {"); |
| 301 | first = true; |
| 302 | for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { |
| 303 | if (first) { |
| 304 | first = false; |
| 305 | } else { |
| 306 | printf(", "); |
| 307 | } |
| 308 | printf("%d", *l_iter); |
| 309 | } |
| 310 | printf("}\n"); |
| 311 | |
| 312 | /** |
| 313 | * ENUM TEST |
| 314 | */ |
| 315 | printf("testEnum(ONE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 316 | Numberz::type ret = testClient.testEnum(Numberz::ONE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 317 | printf(" = %d\n", ret); |
| 318 | |
| 319 | printf("testEnum(TWO)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 320 | ret = testClient.testEnum(Numberz::TWO); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 321 | printf(" = %d\n", ret); |
| 322 | |
| 323 | printf("testEnum(THREE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 324 | ret = testClient.testEnum(Numberz::THREE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 325 | printf(" = %d\n", ret); |
| 326 | |
| 327 | printf("testEnum(FIVE)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 328 | ret = testClient.testEnum(Numberz::FIVE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 329 | printf(" = %d\n", ret); |
| 330 | |
| 331 | printf("testEnum(EIGHT)"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 332 | ret = testClient.testEnum(Numberz::EIGHT); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 333 | printf(" = %d\n", ret); |
| 334 | |
| 335 | /** |
| 336 | * TYPEDEF TEST |
| 337 | */ |
| 338 | printf("testTypedef(309858235082523)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 339 | UserId uid = testClient.testTypedef(309858235082523LL); |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 340 | printf(" = %"PRId64"\n", uid); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 341 | |
| 342 | /** |
| 343 | * NESTED MAP TEST |
| 344 | */ |
| 345 | printf("testMapMap(1)"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 346 | map<int32_t, map<int32_t, int32_t> > mm; |
| 347 | testClient.testMapMap(mm, 1); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 348 | printf(" = {"); |
| 349 | map<int32_t, map<int32_t, int32_t> >::const_iterator mi; |
| 350 | for (mi = mm.begin(); mi != mm.end(); ++mi) { |
| 351 | printf("%d => {", mi->first); |
| 352 | map<int32_t, int32_t>::const_iterator mi2; |
| 353 | for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) { |
| 354 | printf("%d => %d, ", mi2->first, mi2->second); |
| 355 | } |
| 356 | printf("}, "); |
| 357 | } |
| 358 | printf("}\n"); |
| 359 | |
| 360 | /** |
| 361 | * INSANITY TEST |
| 362 | */ |
| 363 | Insanity insane; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 364 | insane.userMap.insert(make_pair(Numberz::FIVE, 5000)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 365 | Xtruct truck; |
| 366 | truck.string_thing = "Truck"; |
| 367 | truck.byte_thing = 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 368 | truck.i32_thing = 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 369 | truck.i64_thing = 8; |
| 370 | insane.xtructs.push_back(truck); |
| 371 | printf("testInsanity()"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 372 | map<UserId, map<Numberz::type,Insanity> > whoa; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 373 | testClient.testInsanity(whoa, insane); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 374 | printf(" = {"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 375 | map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 376 | for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 377 | printf("%"PRId64" => {", i_iter->first); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 378 | map<Numberz::type,Insanity>::const_iterator i2_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 379 | for (i2_iter = i_iter->second.begin(); |
| 380 | i2_iter != i_iter->second.end(); |
| 381 | ++i2_iter) { |
| 382 | printf("%d => {", i2_iter->first); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 383 | map<Numberz::type, UserId> userMap = i2_iter->second.userMap; |
| 384 | map<Numberz::type, UserId>::const_iterator um; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 385 | printf("{"); |
| 386 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 387 | printf("%d => %"PRId64", ", um->first, um->second); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 388 | } |
| 389 | printf("}, "); |
| 390 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 391 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 392 | vector<Xtruct>::const_iterator x; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 393 | printf("{"); |
| 394 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 395 | printf("{\"%s\", %d, %d, %"PRId64"}, ", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 396 | x->string_thing.c_str(), |
| 397 | (int)x->byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 398 | x->i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 399 | x->i64_thing); |
| 400 | } |
| 401 | printf("}"); |
| 402 | |
| 403 | printf("}, "); |
| 404 | } |
| 405 | printf("}, "); |
| 406 | } |
| 407 | printf("}\n"); |
| 408 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 409 | /* test exception */ |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 410 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 411 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 412 | printf("testClient.testException(\"Xception\") =>"); |
| 413 | testClient.testException("Xception"); |
| 414 | printf(" void\nFAILURE\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 415 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 416 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 417 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 418 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 419 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 420 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 421 | printf("testClient.testException(\"success\") =>"); |
| 422 | testClient.testException("success"); |
| 423 | printf(" void\n"); |
| 424 | } catch(...) { |
| 425 | printf(" exception\nFAILURE\n"); |
| 426 | } |
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 | /* test multi exception */ |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 429 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 430 | try { |
| 431 | printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 432 | Xtruct result; |
| 433 | testClient.testMultiException(result, "Xception", "test 1"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 434 | printf(" result\nFAILURE\n"); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 435 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 436 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
| 437 | } |
| 438 | |
| 439 | try { |
| 440 | printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 441 | Xtruct result; |
| 442 | testClient.testMultiException(result, "Xception2", "test 2"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 443 | printf(" result\nFAILURE\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 444 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 445 | } catch(Xception2& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 446 | 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] | 447 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 448 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 449 | try { |
| 450 | printf("testClient.testMultiException(\"success\", \"test 3\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 451 | Xtruct result; |
| 452 | testClient.testMultiException(result, "success", "test 3"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 453 | printf(" {{\"%s\"}}\n", result.string_thing.c_str()); |
| 454 | } catch(...) { |
| 455 | printf(" exception\nFAILURE\n"); |
| 456 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 457 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 458 | /* test oneway void */ |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 459 | { |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 460 | printf("testClient.testOneway(3) =>"); |
| 461 | uint64_t startOneway = now(); |
| 462 | testClient.testOneway(3); |
| 463 | uint64_t elapsed = now() - startOneway; |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 464 | if (elapsed > 200 * 1000) { // 0.2 seconds |
| 465 | printf(" FAILURE - took %.2f ms\n", (double)elapsed/1000.0); |
| 466 | } else { |
| 467 | printf(" success - took %.2f ms\n", (double)elapsed/1000.0); |
| 468 | } |
| 469 | } |
| 470 | |
David Reiss | 2845b52 | 2008-02-18 02:11:52 +0000 | [diff] [blame] | 471 | /** |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 472 | * redo a simple test after the oneway to make sure we aren't "off by one" -- |
| 473 | * 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] | 474 | * fail since it will get the void confirmation rather than the correct |
| 475 | * result. In this circumstance, the client will throw the exception: |
| 476 | * |
| 477 | * TApplicationException: Wrong method namea |
| 478 | */ |
| 479 | /** |
| 480 | * I32 TEST |
| 481 | */ |
| 482 | printf("re-test testI32(-1)"); |
| 483 | i32 = testClient.testI32(-1); |
| 484 | printf(" = %d\n", i32); |
| 485 | |
| 486 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 487 | uint64_t stop = now(); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 488 | uint64_t tot = stop-start; |
| 489 | |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 490 | printf("Total time: %"PRIu64" us\n", stop-start); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 491 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 492 | time_tot += tot; |
| 493 | if (time_min == 0 || tot < time_min) { |
| 494 | time_min = tot; |
| 495 | } |
| 496 | if (tot > time_max) { |
| 497 | time_max = tot; |
| 498 | } |
| 499 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 500 | transport->close(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 503 | // printf("\nSocket syscalls: %u", g_socket_syscalls); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 504 | printf("\nAll tests done.\n"); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 505 | |
| 506 | uint64_t time_avg = time_tot / numTests; |
| 507 | |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 508 | printf("Min time: %"PRIu64" us\n", time_min); |
| 509 | printf("Max time: %"PRIu64" us\n", time_max); |
| 510 | printf("Avg time: %"PRIu64" us\n", time_avg); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 511 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 512 | return 0; |
| 513 | } |