Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <unistd.h> |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 3 | #include <sys/time.h> |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 4 | #include <protocol/TBinaryProtocol.h> |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 5 | #include <transport/TTransportUtils.h> |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 6 | #include <transport/TSocket.h> |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 7 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 8 | #include <boost/shared_ptr.hpp> |
| 9 | #include "ThriftTest.h" |
| 10 | |
| 11 | using namespace boost; |
| 12 | using namespace std; |
| 13 | using namespace facebook::thrift; |
| 14 | using namespace facebook::thrift::protocol; |
| 15 | using namespace facebook::thrift::transport; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 16 | using namespace thrift::test; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 17 | |
| 18 | //extern uint32_t g_socket_syscalls; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 19 | |
| 20 | // Current time, microseconds since the epoch |
| 21 | uint64_t now() |
| 22 | { |
| 23 | long long ret; |
| 24 | struct timeval tv; |
| 25 | |
| 26 | gettimeofday(&tv, NULL); |
| 27 | ret = tv.tv_sec; |
| 28 | ret = ret*1000*1000 + tv.tv_usec; |
| 29 | return ret; |
| 30 | } |
| 31 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 32 | int main(int argc, char** argv) { |
| 33 | string host = "localhost"; |
| 34 | int port = 9090; |
| 35 | int numTests = 1; |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 36 | bool framed = false; |
| 37 | bool frameInput = true; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 38 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 39 | for (int i = 0; i < argc; ++i) { |
| 40 | if (strcmp(argv[i], "-h") == 0) { |
| 41 | char* pch = strtok(argv[++i], ":"); |
| 42 | if (pch != NULL) { |
| 43 | host = string(pch); |
| 44 | } |
| 45 | pch = strtok(NULL, ":"); |
| 46 | if (pch != NULL) { |
| 47 | port = atoi(pch); |
| 48 | } |
| 49 | } else if (strcmp(argv[i], "-n") == 0) { |
| 50 | numTests = atoi(argv[++i]); |
| 51 | } else if (strcmp(argv[i], "-f") == 0) { |
| 52 | framed = true; |
| 53 | } else if (strcmp(argv[i], "-fo") == 0) { |
| 54 | framed = true; |
| 55 | frameInput = false; |
| 56 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 57 | } |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 58 | |
| 59 | |
| 60 | shared_ptr<TTransport> transport; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 61 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 62 | shared_ptr<TSocket> socket(new TSocket(host, port)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 63 | |
| 64 | if (framed) { |
| 65 | shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket)); |
| 66 | framedSocket->setRead(frameInput); |
| 67 | transport = framedSocket; |
| 68 | if (frameInput) { |
| 69 | printf("Using bi-directional framed transport mode\n"); |
| 70 | } else { |
| 71 | printf("Using framed output only mode\n"); |
| 72 | } |
| 73 | } else { |
| 74 | shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket)); |
| 75 | transport = bufferedSocket; |
| 76 | } |
| 77 | |
| 78 | shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport, transport)); |
| 79 | ThriftTestClient testClient(protocol); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 80 | |
| 81 | uint64_t time_min = 0; |
| 82 | uint64_t time_max = 0; |
| 83 | uint64_t time_tot = 0; |
| 84 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 85 | int test = 0; |
| 86 | for (test = 0; test < numTests; ++test) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 87 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 88 | try { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 89 | transport->open(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 90 | } catch (TTransportException& ttx) { |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 91 | printf("Connect failed: %s\n", ttx.what()); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 92 | continue; |
| 93 | } |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * CONNECT TEST |
| 97 | */ |
| 98 | 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] | 99 | |
| 100 | uint64_t start = now(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * VOID TEST |
| 104 | */ |
| 105 | printf("testVoid()"); |
| 106 | testClient.testVoid(); |
| 107 | printf(" = void\n"); |
| 108 | |
| 109 | /** |
| 110 | * STRING TEST |
| 111 | */ |
| 112 | printf("testString(\"Test\")"); |
| 113 | string s = testClient.testString("Test"); |
| 114 | printf(" = \"%s\"\n", s.c_str()); |
| 115 | |
| 116 | /** |
| 117 | * BYTE TEST |
| 118 | */ |
| 119 | printf("testByte(1)"); |
| 120 | uint8_t u8 = testClient.testByte(1); |
| 121 | printf(" = %d\n", (int)u8); |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 122 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 123 | /** |
| 124 | * I32 TEST |
| 125 | */ |
| 126 | printf("testI32(-1)"); |
| 127 | int32_t i32 = testClient.testI32(-1); |
| 128 | printf(" = %d\n", i32); |
| 129 | |
| 130 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 131 | * I64 TEST |
| 132 | */ |
| 133 | printf("testI64(-34359738368)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 134 | int64_t i64 = testClient.testI64(-34359738368LL); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 135 | printf(" = %ld\n", i64); |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * DOUBLE TEST |
| 139 | */ |
| 140 | printf("testDouble(-5.2098523)"); |
| 141 | double dub = testClient.testDouble(-5.2098523); |
| 142 | printf(" = %lf\n", dub); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * STRUCT TEST |
| 146 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 147 | printf("testStruct({\"Zero\", 1, -3, -5})"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 148 | Xtruct out; |
| 149 | out.string_thing = "Zero"; |
| 150 | out.byte_thing = 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 151 | out.i32_thing = -3; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 152 | out.i64_thing = -5; |
| 153 | Xtruct in = testClient.testStruct(out); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 154 | printf(" = {\"%s\", %d, %d, %ld}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 155 | in.string_thing.c_str(), |
| 156 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 157 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 158 | in.i64_thing); |
| 159 | |
| 160 | /** |
| 161 | * NESTED STRUCT TEST |
| 162 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 163 | printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 164 | Xtruct2 out2; |
| 165 | out2.byte_thing = 1; |
| 166 | out2.struct_thing = out; |
| 167 | out2.i32_thing = 5; |
| 168 | Xtruct2 in2 = testClient.testNest(out2); |
| 169 | in = in2.struct_thing; |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 170 | printf(" = {%d, {\"%s\", %d, %d, %ld}, %d}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 171 | in2.byte_thing, |
| 172 | in.string_thing.c_str(), |
| 173 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 174 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 175 | in.i64_thing, |
| 176 | in2.i32_thing); |
| 177 | |
| 178 | /** |
| 179 | * MAP TEST |
| 180 | */ |
| 181 | map<int32_t,int32_t> mapout; |
| 182 | for (int32_t i = 0; i < 5; ++i) { |
| 183 | mapout.insert(make_pair(i, i-10)); |
| 184 | } |
| 185 | printf("testMap({"); |
| 186 | map<int32_t, int32_t>::const_iterator m_iter; |
| 187 | bool first = true; |
| 188 | for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) { |
| 189 | if (first) { |
| 190 | first = false; |
| 191 | } else { |
| 192 | printf(", "); |
| 193 | } |
| 194 | printf("%d => %d", m_iter->first, m_iter->second); |
| 195 | } |
| 196 | printf("})"); |
| 197 | map<int32_t,int32_t> mapin = testClient.testMap(mapout); |
| 198 | printf(" = {"); |
| 199 | first = true; |
| 200 | for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { |
| 201 | if (first) { |
| 202 | first = false; |
| 203 | } else { |
| 204 | printf(", "); |
| 205 | } |
| 206 | printf("%d => %d", m_iter->first, m_iter->second); |
| 207 | } |
| 208 | printf("}\n"); |
| 209 | |
| 210 | /** |
| 211 | * SET TEST |
| 212 | */ |
| 213 | set<int32_t> setout; |
| 214 | for (int32_t i = -2; i < 3; ++i) { |
| 215 | setout.insert(i); |
| 216 | } |
| 217 | printf("testSet({"); |
| 218 | set<int32_t>::const_iterator s_iter; |
| 219 | first = true; |
| 220 | for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) { |
| 221 | if (first) { |
| 222 | first = false; |
| 223 | } else { |
| 224 | printf(", "); |
| 225 | } |
| 226 | printf("%d", *s_iter); |
| 227 | } |
| 228 | printf("})"); |
| 229 | set<int32_t> setin = testClient.testSet(setout); |
| 230 | printf(" = {"); |
| 231 | first = true; |
| 232 | for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { |
| 233 | if (first) { |
| 234 | first = false; |
| 235 | } else { |
| 236 | printf(", "); |
| 237 | } |
| 238 | printf("%d", *s_iter); |
| 239 | } |
| 240 | printf("}\n"); |
| 241 | |
| 242 | /** |
| 243 | * LIST TEST |
| 244 | */ |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 245 | vector<int32_t> listout; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 246 | for (int32_t i = -2; i < 3; ++i) { |
| 247 | listout.push_back(i); |
| 248 | } |
| 249 | printf("testList({"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 250 | vector<int32_t>::const_iterator l_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 251 | first = true; |
| 252 | for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { |
| 253 | if (first) { |
| 254 | first = false; |
| 255 | } else { |
| 256 | printf(", "); |
| 257 | } |
| 258 | printf("%d", *l_iter); |
| 259 | } |
| 260 | printf("})"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 261 | vector<int32_t> listin = testClient.testList(listout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 262 | printf(" = {"); |
| 263 | first = true; |
| 264 | for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { |
| 265 | if (first) { |
| 266 | first = false; |
| 267 | } else { |
| 268 | printf(", "); |
| 269 | } |
| 270 | printf("%d", *l_iter); |
| 271 | } |
| 272 | printf("}\n"); |
| 273 | |
| 274 | /** |
| 275 | * ENUM TEST |
| 276 | */ |
| 277 | printf("testEnum(ONE)"); |
| 278 | Numberz ret = testClient.testEnum(ONE); |
| 279 | printf(" = %d\n", ret); |
| 280 | |
| 281 | printf("testEnum(TWO)"); |
| 282 | ret = testClient.testEnum(TWO); |
| 283 | printf(" = %d\n", ret); |
| 284 | |
| 285 | printf("testEnum(THREE)"); |
| 286 | ret = testClient.testEnum(THREE); |
| 287 | printf(" = %d\n", ret); |
| 288 | |
| 289 | printf("testEnum(FIVE)"); |
| 290 | ret = testClient.testEnum(FIVE); |
| 291 | printf(" = %d\n", ret); |
| 292 | |
| 293 | printf("testEnum(EIGHT)"); |
| 294 | ret = testClient.testEnum(EIGHT); |
| 295 | printf(" = %d\n", ret); |
| 296 | |
| 297 | /** |
| 298 | * TYPEDEF TEST |
| 299 | */ |
| 300 | printf("testTypedef(309858235082523)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 301 | UserId uid = testClient.testTypedef(309858235082523LL); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 302 | printf(" = %ld\n", uid); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 303 | |
| 304 | /** |
| 305 | * NESTED MAP TEST |
| 306 | */ |
| 307 | printf("testMapMap(1)"); |
| 308 | map<int32_t, map<int32_t, int32_t> > mm = testClient.testMapMap(1); |
| 309 | printf(" = {"); |
| 310 | map<int32_t, map<int32_t, int32_t> >::const_iterator mi; |
| 311 | for (mi = mm.begin(); mi != mm.end(); ++mi) { |
| 312 | printf("%d => {", mi->first); |
| 313 | map<int32_t, int32_t>::const_iterator mi2; |
| 314 | for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) { |
| 315 | printf("%d => %d, ", mi2->first, mi2->second); |
| 316 | } |
| 317 | printf("}, "); |
| 318 | } |
| 319 | printf("}\n"); |
| 320 | |
| 321 | /** |
| 322 | * INSANITY TEST |
| 323 | */ |
| 324 | Insanity insane; |
| 325 | insane.userMap.insert(make_pair(FIVE, 5000)); |
| 326 | Xtruct truck; |
| 327 | truck.string_thing = "Truck"; |
| 328 | truck.byte_thing = 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 329 | truck.i32_thing = 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 330 | truck.i64_thing = 8; |
| 331 | insane.xtructs.push_back(truck); |
| 332 | printf("testInsanity()"); |
| 333 | map<UserId, map<Numberz,Insanity> > whoa = testClient.testInsanity(insane); |
| 334 | printf(" = {"); |
| 335 | map<UserId, map<Numberz,Insanity> >::const_iterator i_iter; |
| 336 | for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 337 | printf("%ld => {", i_iter->first); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 338 | map<Numberz,Insanity>::const_iterator i2_iter; |
| 339 | for (i2_iter = i_iter->second.begin(); |
| 340 | i2_iter != i_iter->second.end(); |
| 341 | ++i2_iter) { |
| 342 | printf("%d => {", i2_iter->first); |
| 343 | map<Numberz, UserId> userMap = i2_iter->second.userMap; |
| 344 | map<Numberz, UserId>::const_iterator um; |
| 345 | printf("{"); |
| 346 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 347 | printf("%d => %ld, ", um->first, um->second); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 348 | } |
| 349 | printf("}, "); |
| 350 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 351 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 352 | vector<Xtruct>::const_iterator x; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 353 | printf("{"); |
| 354 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 355 | printf("{\"%s\", %d, %d, %ld}, ", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 356 | x->string_thing.c_str(), |
| 357 | (int)x->byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 358 | x->i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 359 | x->i64_thing); |
| 360 | } |
| 361 | printf("}"); |
| 362 | |
| 363 | printf("}, "); |
| 364 | } |
| 365 | printf("}, "); |
| 366 | } |
| 367 | printf("}\n"); |
| 368 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 369 | /* test exception */ |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 370 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 371 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 372 | printf("testClient.testException(\"Xception\") =>"); |
| 373 | testClient.testException("Xception"); |
| 374 | printf(" void\nFAILURE\n"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 375 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 376 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 377 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 378 | } |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 379 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 380 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 381 | printf("testClient.testException(\"success\") =>"); |
| 382 | testClient.testException("success"); |
| 383 | printf(" void\n"); |
| 384 | } catch(...) { |
| 385 | printf(" exception\nFAILURE\n"); |
| 386 | } |
| 387 | |
| 388 | /* test multi exception */ |
| 389 | |
| 390 | try { |
| 391 | printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); |
| 392 | Xtruct result = testClient.testMultiException("Xception", "test 1"); |
| 393 | printf(" result\nFAILURE\n"); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 394 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 395 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
| 396 | } |
| 397 | |
| 398 | try { |
| 399 | printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 400 | Xtruct result = testClient.testMultiException("Xception2", "test 2"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 401 | printf(" result\nFAILURE\n"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 402 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 403 | } catch(Xception2& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 404 | 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] | 405 | } |
| 406 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 407 | try { |
| 408 | printf("testClient.testMultiException(\"success\", \"test 3\") =>"); |
| 409 | Xtruct result = testClient.testMultiException("success", "test 3"); |
| 410 | printf(" {{\"%s\"}}\n", result.string_thing.c_str()); |
| 411 | } catch(...) { |
| 412 | printf(" exception\nFAILURE\n"); |
| 413 | } |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 414 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 415 | uint64_t stop = now(); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 416 | uint64_t tot = stop-start; |
| 417 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 418 | printf("Total time: %lu us\n", stop-start); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 419 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 420 | time_tot += tot; |
| 421 | if (time_min == 0 || tot < time_min) { |
| 422 | time_min = tot; |
| 423 | } |
| 424 | if (tot > time_max) { |
| 425 | time_max = tot; |
| 426 | } |
| 427 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 428 | transport->close(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 431 | // printf("\nSocket syscalls: %u", g_socket_syscalls); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 432 | printf("\nAll tests done.\n"); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 433 | |
| 434 | uint64_t time_avg = time_tot / numTests; |
| 435 | |
| 436 | printf("Min time: %lu us\n", time_min); |
| 437 | printf("Max time: %lu us\n", time_max); |
| 438 | printf("Avg time: %lu us\n", time_avg); |
| 439 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 440 | return 0; |
| 441 | } |