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