summaryrefslogtreecommitdiff
path: root/samples
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
commitfff033497b70e96a5dcadb6ba9570c12b5921d74 (patch)
treeceb0f9819c41f511d74cf72066ec48620dea8caa /samples
parent9c54fe88bc2b5d03bb9594b0c8f5ad1e0b905996 (diff)
downloadgoogletest-fff033497b70e96a5dcadb6ba9570c12b5921d74.tar.gz
Publishes the even listener API (by Vlad Losev); adds OS-indicating macros to simplify gtest code (by Zhanyong Wan).
git-svn-id: http://googletest.googlecode.com/svn/trunk@320 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'samples')
-rw-r--r--samples/sample10_unittest.cc28
-rw-r--r--samples/sample9_unittest.cc54
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++;
}
}