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