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 | |
Mark Slee | 9e288d4 | 2007-01-24 23:42:12 +0000 | [diff] [blame] | 78 | shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport)); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 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 | */ |
Mark Slee | e129a2d | 2007-02-21 05:17:48 +0000 | [diff] [blame] | 105 | try { |
| 106 | printf("testVoid()"); |
| 107 | testClient.testVoid(); |
| 108 | printf(" = void\n"); |
| 109 | } catch (TApplicationException tax) { |
| 110 | printf("%s\n", tax.what()); |
| 111 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * STRING TEST |
| 115 | */ |
| 116 | printf("testString(\"Test\")"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 117 | string s; |
| 118 | testClient.testString(s, "Test"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 119 | printf(" = \"%s\"\n", s.c_str()); |
| 120 | |
| 121 | /** |
| 122 | * BYTE TEST |
| 123 | */ |
| 124 | printf("testByte(1)"); |
| 125 | uint8_t u8 = testClient.testByte(1); |
| 126 | printf(" = %d\n", (int)u8); |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 127 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 128 | /** |
| 129 | * I32 TEST |
| 130 | */ |
| 131 | printf("testI32(-1)"); |
| 132 | int32_t i32 = testClient.testI32(-1); |
| 133 | printf(" = %d\n", i32); |
| 134 | |
| 135 | /** |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 136 | * I64 TEST |
| 137 | */ |
| 138 | printf("testI64(-34359738368)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 139 | int64_t i64 = testClient.testI64(-34359738368LL); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 140 | printf(" = %ld\n", i64); |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * DOUBLE TEST |
| 144 | */ |
| 145 | printf("testDouble(-5.2098523)"); |
| 146 | double dub = testClient.testDouble(-5.2098523); |
| 147 | printf(" = %lf\n", dub); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * STRUCT TEST |
| 151 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 152 | printf("testStruct({\"Zero\", 1, -3, -5})"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 153 | Xtruct out; |
| 154 | out.string_thing = "Zero"; |
| 155 | out.byte_thing = 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 156 | out.i32_thing = -3; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 157 | out.i64_thing = -5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 158 | Xtruct in; |
| 159 | testClient.testStruct(in, out); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 160 | printf(" = {\"%s\", %d, %d, %ld}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 161 | in.string_thing.c_str(), |
| 162 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 163 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 164 | in.i64_thing); |
| 165 | |
| 166 | /** |
| 167 | * NESTED STRUCT TEST |
| 168 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 169 | printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 170 | Xtruct2 out2; |
| 171 | out2.byte_thing = 1; |
| 172 | out2.struct_thing = out; |
| 173 | out2.i32_thing = 5; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 174 | Xtruct2 in2; |
| 175 | testClient.testNest(in2, out2); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 176 | in = in2.struct_thing; |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 177 | printf(" = {%d, {\"%s\", %d, %d, %ld}, %d}\n", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 178 | in2.byte_thing, |
| 179 | in.string_thing.c_str(), |
| 180 | (int)in.byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 181 | in.i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 182 | in.i64_thing, |
| 183 | in2.i32_thing); |
| 184 | |
| 185 | /** |
| 186 | * MAP TEST |
| 187 | */ |
| 188 | map<int32_t,int32_t> mapout; |
| 189 | for (int32_t i = 0; i < 5; ++i) { |
| 190 | mapout.insert(make_pair(i, i-10)); |
| 191 | } |
| 192 | printf("testMap({"); |
| 193 | map<int32_t, int32_t>::const_iterator m_iter; |
| 194 | bool first = true; |
| 195 | for (m_iter = mapout.begin(); m_iter != mapout.end(); ++m_iter) { |
| 196 | if (first) { |
| 197 | first = false; |
| 198 | } else { |
| 199 | printf(", "); |
| 200 | } |
| 201 | printf("%d => %d", m_iter->first, m_iter->second); |
| 202 | } |
| 203 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 204 | map<int32_t,int32_t> mapin; |
| 205 | testClient.testMap(mapin, mapout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 206 | printf(" = {"); |
| 207 | first = true; |
| 208 | for (m_iter = mapin.begin(); m_iter != mapin.end(); ++m_iter) { |
| 209 | if (first) { |
| 210 | first = false; |
| 211 | } else { |
| 212 | printf(", "); |
| 213 | } |
| 214 | printf("%d => %d", m_iter->first, m_iter->second); |
| 215 | } |
| 216 | printf("}\n"); |
| 217 | |
| 218 | /** |
| 219 | * SET TEST |
| 220 | */ |
| 221 | set<int32_t> setout; |
| 222 | for (int32_t i = -2; i < 3; ++i) { |
| 223 | setout.insert(i); |
| 224 | } |
| 225 | printf("testSet({"); |
| 226 | set<int32_t>::const_iterator s_iter; |
| 227 | first = true; |
| 228 | for (s_iter = setout.begin(); s_iter != setout.end(); ++s_iter) { |
| 229 | if (first) { |
| 230 | first = false; |
| 231 | } else { |
| 232 | printf(", "); |
| 233 | } |
| 234 | printf("%d", *s_iter); |
| 235 | } |
| 236 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 237 | set<int32_t> setin; |
| 238 | testClient.testSet(setin, setout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 239 | printf(" = {"); |
| 240 | first = true; |
| 241 | for (s_iter = setin.begin(); s_iter != setin.end(); ++s_iter) { |
| 242 | if (first) { |
| 243 | first = false; |
| 244 | } else { |
| 245 | printf(", "); |
| 246 | } |
| 247 | printf("%d", *s_iter); |
| 248 | } |
| 249 | printf("}\n"); |
| 250 | |
| 251 | /** |
| 252 | * LIST TEST |
| 253 | */ |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 254 | vector<int32_t> listout; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 255 | for (int32_t i = -2; i < 3; ++i) { |
| 256 | listout.push_back(i); |
| 257 | } |
| 258 | printf("testList({"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 259 | vector<int32_t>::const_iterator l_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 260 | first = true; |
| 261 | for (l_iter = listout.begin(); l_iter != listout.end(); ++l_iter) { |
| 262 | if (first) { |
| 263 | first = false; |
| 264 | } else { |
| 265 | printf(", "); |
| 266 | } |
| 267 | printf("%d", *l_iter); |
| 268 | } |
| 269 | printf("})"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 270 | vector<int32_t> listin; |
| 271 | testClient.testList(listin, listout); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 272 | printf(" = {"); |
| 273 | first = true; |
| 274 | for (l_iter = listin.begin(); l_iter != listin.end(); ++l_iter) { |
| 275 | if (first) { |
| 276 | first = false; |
| 277 | } else { |
| 278 | printf(", "); |
| 279 | } |
| 280 | printf("%d", *l_iter); |
| 281 | } |
| 282 | printf("}\n"); |
| 283 | |
| 284 | /** |
| 285 | * ENUM TEST |
| 286 | */ |
| 287 | printf("testEnum(ONE)"); |
| 288 | Numberz ret = testClient.testEnum(ONE); |
| 289 | printf(" = %d\n", ret); |
| 290 | |
| 291 | printf("testEnum(TWO)"); |
| 292 | ret = testClient.testEnum(TWO); |
| 293 | printf(" = %d\n", ret); |
| 294 | |
| 295 | printf("testEnum(THREE)"); |
| 296 | ret = testClient.testEnum(THREE); |
| 297 | printf(" = %d\n", ret); |
| 298 | |
| 299 | printf("testEnum(FIVE)"); |
| 300 | ret = testClient.testEnum(FIVE); |
| 301 | printf(" = %d\n", ret); |
| 302 | |
| 303 | printf("testEnum(EIGHT)"); |
| 304 | ret = testClient.testEnum(EIGHT); |
| 305 | printf(" = %d\n", ret); |
| 306 | |
| 307 | /** |
| 308 | * TYPEDEF TEST |
| 309 | */ |
| 310 | printf("testTypedef(309858235082523)"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 311 | UserId uid = testClient.testTypedef(309858235082523LL); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 312 | printf(" = %ld\n", uid); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 313 | |
| 314 | /** |
| 315 | * NESTED MAP TEST |
| 316 | */ |
| 317 | printf("testMapMap(1)"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 318 | map<int32_t, map<int32_t, int32_t> > mm; |
| 319 | testClient.testMapMap(mm, 1); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 320 | printf(" = {"); |
| 321 | map<int32_t, map<int32_t, int32_t> >::const_iterator mi; |
| 322 | for (mi = mm.begin(); mi != mm.end(); ++mi) { |
| 323 | printf("%d => {", mi->first); |
| 324 | map<int32_t, int32_t>::const_iterator mi2; |
| 325 | for (mi2 = mi->second.begin(); mi2 != mi->second.end(); ++mi2) { |
| 326 | printf("%d => %d, ", mi2->first, mi2->second); |
| 327 | } |
| 328 | printf("}, "); |
| 329 | } |
| 330 | printf("}\n"); |
| 331 | |
| 332 | /** |
| 333 | * INSANITY TEST |
| 334 | */ |
| 335 | Insanity insane; |
| 336 | insane.userMap.insert(make_pair(FIVE, 5000)); |
| 337 | Xtruct truck; |
| 338 | truck.string_thing = "Truck"; |
| 339 | truck.byte_thing = 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 340 | truck.i32_thing = 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 341 | truck.i64_thing = 8; |
| 342 | insane.xtructs.push_back(truck); |
| 343 | printf("testInsanity()"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 344 | map<UserId, map<Numberz,Insanity> > whoa; |
| 345 | testClient.testInsanity(whoa, insane); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 346 | printf(" = {"); |
| 347 | map<UserId, map<Numberz,Insanity> >::const_iterator i_iter; |
| 348 | for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) { |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 349 | printf("%ld => {", i_iter->first); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 350 | map<Numberz,Insanity>::const_iterator i2_iter; |
| 351 | for (i2_iter = i_iter->second.begin(); |
| 352 | i2_iter != i_iter->second.end(); |
| 353 | ++i2_iter) { |
| 354 | printf("%d => {", i2_iter->first); |
| 355 | map<Numberz, UserId> userMap = i2_iter->second.userMap; |
| 356 | map<Numberz, UserId>::const_iterator um; |
| 357 | printf("{"); |
| 358 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 359 | printf("%d => %ld, ", um->first, um->second); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 360 | } |
| 361 | printf("}, "); |
| 362 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 363 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 364 | vector<Xtruct>::const_iterator x; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 365 | printf("{"); |
| 366 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 367 | printf("{\"%s\", %d, %d, %ld}, ", |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 368 | x->string_thing.c_str(), |
| 369 | (int)x->byte_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 370 | x->i32_thing, |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 371 | x->i64_thing); |
| 372 | } |
| 373 | printf("}"); |
| 374 | |
| 375 | printf("}, "); |
| 376 | } |
| 377 | printf("}, "); |
| 378 | } |
| 379 | printf("}\n"); |
| 380 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 381 | /* test exception */ |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 382 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 383 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 384 | printf("testClient.testException(\"Xception\") =>"); |
| 385 | testClient.testException("Xception"); |
| 386 | printf(" void\nFAILURE\n"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 387 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 388 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 389 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 390 | } |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 391 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 392 | try { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 393 | printf("testClient.testException(\"success\") =>"); |
| 394 | testClient.testException("success"); |
| 395 | printf(" void\n"); |
| 396 | } catch(...) { |
| 397 | printf(" exception\nFAILURE\n"); |
| 398 | } |
| 399 | |
| 400 | /* test multi exception */ |
| 401 | |
| 402 | try { |
| 403 | printf("testClient.testMultiException(\"Xception\", \"test 1\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 404 | Xtruct result; |
| 405 | testClient.testMultiException(result, "Xception", "test 1"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 406 | printf(" result\nFAILURE\n"); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 407 | } catch(Xception& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 408 | printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str()); |
| 409 | } |
| 410 | |
| 411 | try { |
| 412 | printf("testClient.testMultiException(\"Xception2\", \"test 2\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 413 | Xtruct result; |
| 414 | testClient.testMultiException(result, "Xception2", "test 2"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 415 | printf(" result\nFAILURE\n"); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 416 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 417 | } catch(Xception2& e) { |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 418 | 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] | 419 | } |
| 420 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 421 | try { |
| 422 | printf("testClient.testMultiException(\"success\", \"test 3\") =>"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 423 | Xtruct result; |
| 424 | testClient.testMultiException(result, "success", "test 3"); |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 425 | printf(" {{\"%s\"}}\n", result.string_thing.c_str()); |
| 426 | } catch(...) { |
| 427 | printf(" exception\nFAILURE\n"); |
| 428 | } |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 429 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 430 | uint64_t stop = now(); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 431 | uint64_t tot = stop-start; |
| 432 | |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 433 | printf("Total time: %lu us\n", stop-start); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 434 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 435 | time_tot += tot; |
| 436 | if (time_min == 0 || tot < time_min) { |
| 437 | time_min = tot; |
| 438 | } |
| 439 | if (tot > time_max) { |
| 440 | time_max = tot; |
| 441 | } |
| 442 | |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 443 | transport->close(); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 446 | // printf("\nSocket syscalls: %u", g_socket_syscalls); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 447 | printf("\nAll tests done.\n"); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 448 | |
| 449 | uint64_t time_avg = time_tot / numTests; |
| 450 | |
| 451 | printf("Min time: %lu us\n", time_min); |
| 452 | printf("Max time: %lu us\n", time_max); |
| 453 | printf("Avg time: %lu us\n", time_avg); |
| 454 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 455 | return 0; |
| 456 | } |