diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-09-24 21:15:59 (GMT) |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-09-24 21:15:59 (GMT) |
commit | b50ef44a3527d958270ff1f08cb99e3ac633bd17 (patch) | |
tree | ceb0f9819c41f511d74cf72066ec48620dea8caa /samples | |
parent | 7fba282ce74ce527cba5c686945d18ae1b7cb3d2 (diff) | |
download | googletest-b50ef44a3527d958270ff1f08cb99e3ac633bd17.zip googletest-b50ef44a3527d958270ff1f08cb99e3ac633bd17.tar.gz googletest-b50ef44a3527d958270ff1f08cb99e3ac633bd17.tar.bz2 |
Publishes the even listener API (by Vlad Losev); adds OS-indicating macros to simplify gtest code (by Zhanyong Wan).
Diffstat (limited to 'samples')
-rw-r--r-- | samples/sample10_unittest.cc | 28 | ||||
-rw-r--r-- | samples/sample9_unittest.cc | 54 |
2 files changed, 17 insertions, 65 deletions
diff --git a/samples/sample10_unittest.cc b/samples/sample10_unittest.cc index 8cb958f..e136859 100644 --- a/samples/sample10_unittest.cc +++ b/samples/sample10_unittest.cc @@ -36,33 +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(); - } - -}; - -} // namespace internal -} // namespace testing - -using ::testing::internal::UnitTestAccessor; namespace { @@ -142,8 +123,7 @@ int main(int argc, char **argv) { // If we are given the --check_for_leaks command line flag, installs the // leak checker. if (check_for_leaks) { - EventListeners& listeners = UnitTestAccessor::listeners( - UnitTest::GetInstance()); + EventListeners& listeners = UnitTest::GetInstance()->listeners(); // Adds the leak checker to the end of the test event listener list, // after the default text output printer and the default XML report diff --git a/samples/sample9_unittest.cc b/samples/sample9_unittest.cc index 8229751..9bf865e 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++; } } |