THRIFT-1592 Test clients should have a return codes that reflect whether they succeeded or not
Patch: Nathaniel Cook
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1333765 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp
index a1af77e..fbf04f0 100755
--- a/test/cpp/src/TestClient.cpp
+++ b/test/cpp/src/TestClient.cpp
@@ -222,6 +222,7 @@
uint64_t time_max = 0;
uint64_t time_tot = 0;
+ int failCount = 0;
int test = 0;
for (test = 0; test < numTests; ++test) {
@@ -246,8 +247,9 @@
printf("testVoid()");
testClient.testVoid();
printf(" = void\n");
- } catch (TApplicationException tax) {
+ } catch (TApplicationException& tax) {
printf("%s\n", tax.what());
+ failCount++;
}
/**
@@ -257,6 +259,8 @@
string s;
testClient.testString(s, "Test");
printf(" = \"%s\"\n", s.c_str());
+ if (s != "Test")
+ failCount++;
/**
* BYTE TEST
@@ -264,6 +268,8 @@
printf("testByte(1)");
uint8_t u8 = testClient.testByte(1);
printf(" = %d\n", (int)u8);
+ if (u8 != 1)
+ failCount++;
/**
* I32 TEST
@@ -271,6 +277,8 @@
printf("testI32(-1)");
int32_t i32 = testClient.testI32(-1);
printf(" = %d\n", i32);
+ if (i32 != -1)
+ failCount++;
/**
* I64 TEST
@@ -278,13 +286,16 @@
printf("testI64(-34359738368)");
int64_t i64 = testClient.testI64(-34359738368LL);
printf(" = %"PRId64"\n", i64);
-
+ if (i64 != -34359738368LL)
+ failCount++;
/**
* DOUBLE TEST
*/
printf("testDouble(-5.2098523)");
double dub = testClient.testDouble(-5.2098523);
printf(" = %f\n", dub);
+ if ((dub - (-5.2098523)) > 0.001)
+ failCount++;
/**
* STRUCT TEST
@@ -302,6 +313,8 @@
(int)in.byte_thing,
in.i32_thing,
in.i64_thing);
+ if (in != out)
+ failCount++;
/**
* NESTED STRUCT TEST
@@ -321,6 +334,8 @@
in.i32_thing,
in.i64_thing,
in2.i32_thing);
+ if (in2 != out2)
+ failCount++;
/**
* MAP TEST
@@ -354,6 +369,13 @@
printf("%d => %d", m_iter->first, m_iter->second);
}
printf("}\n");
+ if (mapin != mapout)
+ failCount++;
+
+ /**
+ * STRING MAP TEST
+ * missing
+ */
/**
* SET TEST
@@ -387,6 +409,8 @@
printf("%d", *s_iter);
}
printf("}\n");
+ if (setin != setout)
+ failCount++;
/**
* LIST TEST
@@ -420,6 +444,8 @@
printf("%d", *l_iter);
}
printf("}\n");
+ if (listin != listout)
+ failCount++;
/**
* ENUM TEST
@@ -427,22 +453,32 @@
printf("testEnum(ONE)");
Numberz::type ret = testClient.testEnum(Numberz::ONE);
printf(" = %d\n", ret);
+ if (ret != Numberz::ONE)
+ failCount++;
printf("testEnum(TWO)");
ret = testClient.testEnum(Numberz::TWO);
printf(" = %d\n", ret);
+ if (ret != Numberz::TWO)
+ failCount++;
printf("testEnum(THREE)");
ret = testClient.testEnum(Numberz::THREE);
printf(" = %d\n", ret);
+ if (ret != Numberz::THREE)
+ failCount++;
printf("testEnum(FIVE)");
ret = testClient.testEnum(Numberz::FIVE);
printf(" = %d\n", ret);
+ if (ret != Numberz::FIVE)
+ failCount++;
printf("testEnum(EIGHT)");
ret = testClient.testEnum(Numberz::EIGHT);
printf(" = %d\n", ret);
+ if (ret != Numberz::EIGHT)
+ failCount++;
/**
* TYPEDEF TEST
@@ -450,6 +486,8 @@
printf("testTypedef(309858235082523)");
UserId uid = testClient.testTypedef(309858235082523LL);
printf(" = %"PRId64"\n", uid);
+ if (uid != 309858235082523LL)
+ failCount++;
/**
* NESTED MAP TEST
@@ -524,6 +562,7 @@
printf("testClient.testException(\"Xception\") =>");
testClient.testException("Xception");
printf(" void\nFAILURE\n");
+ failCount++;
} catch(Xception& e) {
printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
@@ -533,6 +572,7 @@
printf("testClient.testException(\"TException\") =>");
testClient.testException("TException");
printf(" void\nFAILURE\n");
+ failCount++;
} catch(TException& e) {
printf(" Caught TException\n");
@@ -544,6 +584,7 @@
printf(" void\n");
} catch(...) {
printf(" exception\nFAILURE\n");
+ failCount++;
}
/* test multi exception */
@@ -553,6 +594,7 @@
Xtruct result;
testClient.testMultiException(result, "Xception", "test 1");
printf(" result\nFAILURE\n");
+ failCount++;
} catch(Xception& e) {
printf(" {%u, \"%s\"}\n", e.errorCode, e.message.c_str());
}
@@ -562,6 +604,7 @@
Xtruct result;
testClient.testMultiException(result, "Xception2", "test 2");
printf(" result\nFAILURE\n");
+ failCount++;
} catch(Xception2& e) {
printf(" {%u, {\"%s\"}}\n", e.errorCode, e.struct_thing.string_thing.c_str());
@@ -574,6 +617,7 @@
printf(" {{\"%s\"}}\n", result.string_thing.c_str());
} catch(...) {
printf(" exception\nFAILURE\n");
+ failCount++;
}
/* test oneway void */
@@ -584,6 +628,7 @@
uint64_t elapsed = now() - startOneway;
if (elapsed > 200 * 1000) { // 0.2 seconds
printf(" FAILURE - took %.2f ms\n", (double)elapsed/1000.0);
+ failCount++;
} else {
printf(" success - took %.2f ms\n", (double)elapsed/1000.0);
}
@@ -603,6 +648,8 @@
printf("re-test testI32(-1)");
i32 = testClient.testI32(-1);
printf(" = %d\n", i32);
+ if (i32 != -1)
+ failCount++;
uint64_t stop = now();
@@ -630,5 +677,5 @@
printf("Max time: %"PRIu64" us\n", time_max);
printf("Avg time: %"PRIu64" us\n", time_avg);
- return 0;
+ return failCount;
}