aboutsummaryrefslogtreecommitdiffstats
path: root/samples/sample9_unittest.cc
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-09-24 21:15:59 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-09-24 21:15:59 +0000
commitb50ef44a3527d958270ff1f08cb99e3ac633bd17 (patch)
treeceb0f9819c41f511d74cf72066ec48620dea8caa /samples/sample9_unittest.cc
parent7fba282ce74ce527cba5c686945d18ae1b7cb3d2 (diff)
downloadgoogletest-b50ef44a3527d958270ff1f08cb99e3ac633bd17.tar.gz
googletest-b50ef44a3527d958270ff1f08cb99e3ac633bd17.tar.bz2
googletest-b50ef44a3527d958270ff1f08cb99e3ac633bd17.zip
Publishes the even listener API (by Vlad Losev); adds OS-indicating macros to simplify gtest code (by Zhanyong Wan).
Diffstat (limited to 'samples/sample9_unittest.cc')
-rw-r--r--samples/sample9_unittest.cc54
1 files changed, 13 insertions, 41 deletions
diff --git a/samples/sample9_unittest.cc b/samples/sample9_unittest.cc
index 82297516..9bf865ec 100644
--- a/samples/sample9_unittest.cc
+++ b/samples/sample9_unittest.cc
@@ -36,38 +36,14 @@
#include <gtest/gtest.h>
+using ::testing::EmptyTestEventListener;
+using ::testing::EventListeners;
using ::testing::InitGoogleTest;
using ::testing::Test;
+using ::testing::TestCase;
using ::testing::TestInfo;
using ::testing::TestPartResult;
using ::testing::UnitTest;
-using ::testing::internal::EmptyTestEventListener;
-using ::testing::internal::EventListeners;
-using ::testing::internal::TestCase;
-
-namespace testing {
-namespace internal {
-
-// TODO(vladl@google.com): Get rid of the accessor class once the API is
-// published.
-class UnitTestAccessor {
- public:
- static bool Passed(const UnitTest& unit_test) { return unit_test.Passed(); }
- static EventListeners& listeners(UnitTest* unit_test) {
- return unit_test->listeners();
- }
- static int GetTotalTestCaseCount(const UnitTest& unit_test) {
- return unit_test.total_test_case_count();
- }
- static const TestCase* GetTestCase(const UnitTest& unit_test, int index) {
- return unit_test.GetTestCase(index);
- }
-};
-
-} // namespace internal
-} // namespace testing
-
-using ::testing::internal::UnitTestAccessor;
namespace {
@@ -80,9 +56,7 @@ class TersePrinter : public EmptyTestEventListener {
// Called after all test activities have ended.
virtual void OnTestProgramEnd(const UnitTest& unit_test) {
- fprintf(stdout,
- "TEST %s\n",
- UnitTestAccessor::Passed(unit_test) ? "PASSED" : "FAILED");
+ fprintf(stdout, "TEST %s\n", unit_test.Passed() ? "PASSED" : "FAILED");
fflush(stdout);
}
@@ -141,11 +115,12 @@ int main(int argc, char **argv) {
printf("%s\n", "Run this program with --terse_output to change the way "
"it prints its output.");
+ UnitTest& unit_test = *UnitTest::GetInstance();
+
// If we are given the --terse_output command line flag, suppresses the
// standard output and attaches own result printer.
if (terse_output) {
- EventListeners& listeners = UnitTestAccessor::listeners(
- UnitTest::GetInstance());
+ EventListeners& listeners = unit_test.listeners();
// Removes the default console output listener from the list so it will
// not receive events from Google Test and won't print any output. Since
@@ -164,17 +139,14 @@ int main(int argc, char **argv) {
// This is an example of using the UnitTest reflection API to inspect test
// results. Here we discount failures from the tests we expected to fail.
int unexpectedly_failed_tests = 0;
- for (int i = 0;
- i < UnitTestAccessor::GetTotalTestCaseCount(*UnitTest::GetInstance());
- ++i) {
- const TestCase* test_case = UnitTestAccessor::GetTestCase(
- *UnitTest::GetInstance(), i);
- for (int j = 0; j < test_case->total_test_count(); ++j) {
- const TestInfo* test_info = test_case->GetTestInfo(j);
+ for (int i = 0; i < unit_test.total_test_case_count(); ++i) {
+ const TestCase& test_case = *unit_test.GetTestCase(i);
+ for (int j = 0; j < test_case.total_test_count(); ++j) {
+ const TestInfo& test_info = *test_case.GetTestInfo(j);
// Counts failed tests that were not meant to fail (those without
// 'Fails' in the name).
- if (test_info->result()->Failed() &&
- strcmp(test_info->name(), "Fails") != 0) {
+ if (test_info.result()->Failed() &&
+ strcmp(test_info.name(), "Fails") != 0) {
unexpectedly_failed_tests++;
}
}