diff options
-rw-r--r-- | include/gtest/gtest.h | 158 | ||||
-rw-r--r-- | include/gtest/internal/gtest-port.h | 49 | ||||
-rw-r--r-- | include/gtest/internal/gtest-string.h | 2 | ||||
-rw-r--r-- | samples/sample10_unittest.cc | 28 | ||||
-rw-r--r-- | samples/sample9_unittest.cc | 54 | ||||
-rw-r--r-- | src/gtest-filepath.cc | 33 | ||||
-rw-r--r-- | src/gtest-internal-inl.h | 2 | ||||
-rw-r--r-- | src/gtest-port.cc | 28 | ||||
-rw-r--r-- | src/gtest.cc | 103 | ||||
-rw-r--r-- | test/gtest-filepath_test.cc | 23 | ||||
-rw-r--r-- | test/gtest-listener_test.cc | 23 | ||||
-rw-r--r-- | test/gtest-options_test.cc | 8 | ||||
-rw-r--r-- | test/gtest-unittest-api_test.cc | 66 | ||||
-rw-r--r-- | test/gtest_stress_test.cc | 1 | ||||
-rw-r--r-- | test/gtest_unittest.cc | 46 | ||||
-rw-r--r-- | test/gtest_xml_output_unittest_.cc | 20 |
16 files changed, 250 insertions, 394 deletions
diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index 5c92876..2f15fa3 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -51,9 +51,6 @@ #ifndef GTEST_INCLUDE_GTEST_GTEST_H_ #define GTEST_INCLUDE_GTEST_GTEST_H_ -// The following platform macro is used throughout Google Test: -// _WIN32_WCE Windows CE (set in project files) - #include <limits> #include <gtest/internal/gtest-internal.h> #include <gtest/internal/gtest-string.h> @@ -154,10 +151,8 @@ class ExecDeathTest; class NoExecDeathTest; class FinalSuccessChecker; class GTestFlagSaver; -class TestCase; class TestInfoImpl; class TestResultAccessor; -class UnitTestAccessor; class TestEventRepeater; class WindowsDeathTest; class UnitTestImpl* GetUnitTestImpl(); @@ -371,8 +366,6 @@ class Test { typedef internal::TimeInMillis TimeInMillis; -namespace internal { - // A copyable object representing a user specified test property which can be // output as a key/value string pair. // @@ -455,14 +448,14 @@ class TestResult { const TestProperty& GetTestProperty(int i) const; private: + friend class TestInfo; + friend class UnitTest; friend class internal::DefaultGlobalTestPartResultReporter; friend class internal::ExecDeathTest; friend class internal::TestInfoImpl; friend class internal::TestResultAccessor; friend class internal::UnitTestImpl; friend class internal::WindowsDeathTest; - friend class testing::TestInfo; - friend class testing::UnitTest; // Gets the vector of TestPartResults. const internal::Vector<TestPartResult>& test_part_results() const { @@ -521,8 +514,6 @@ class TestResult { GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult); }; // class TestResult -} // namespace internal - // A TestInfo object stores the following information about a test: // // Test case name @@ -571,16 +562,16 @@ class TestInfo { bool should_run() const; // Returns the result of the test. - const internal::TestResult* result() const; + const TestResult* result() const; private: #if GTEST_HAS_DEATH_TEST friend class internal::DefaultDeathTestFactory; #endif // GTEST_HAS_DEATH_TEST + friend class Test; + friend class TestCase; friend class internal::TestInfoImpl; friend class internal::UnitTestImpl; - friend class Test; - friend class internal::TestCase; friend TestInfo* internal::MakeAndRegisterTestInfo( const char* test_case_name, const char* name, const char* test_case_comment, const char* comment, @@ -613,8 +604,6 @@ class TestInfo { GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo); }; -namespace internal { - // A test case, which consists of a vector of TestInfos. // // TestCase is not copyable. @@ -675,7 +664,7 @@ class TestCase { const TestInfo* GetTestInfo(int i) const; private: - friend class testing::Test; + friend class Test; friend class internal::UnitTestImpl; // Gets the (mutable) vector of TestInfos in this TestCase. @@ -738,8 +727,6 @@ class TestCase { GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase); }; -} // namespace internal - // An Environment object is capable of setting up and tearing down an // environment. The user should subclass this to define his own // environment(s). @@ -771,13 +758,11 @@ class Environment { virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; } }; -namespace internal { - // The interface for tracing execution of tests. The methods are organized in // the order the corresponding events are fired. -class UnitTestEventListenerInterface { +class TestEventListener { public: - virtual ~UnitTestEventListenerInterface() {} + virtual ~TestEventListener() {} // Fired before any test activity starts. virtual void OnTestProgramStart(const UnitTest& unit_test) = 0; @@ -825,10 +810,10 @@ class UnitTestEventListenerInterface { // The convenience class for users who need to override just one or two // methods and are not concerned that a possible change to a signature of -// the methods they override will not be caught during the build. -// For comments about each method please see the definition of -// UnitTestEventListenerInterface above. -class EmptyTestEventListener : public UnitTestEventListenerInterface { +// the methods they override will not be caught during the build. For +// comments about each method please see the definition of TestEventListener +// above. +class EmptyTestEventListener : public TestEventListener { public: virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {} virtual void OnTestIterationStart(const UnitTest& /*unit_test*/, @@ -850,26 +835,25 @@ class EmptyTestEventListener : public UnitTestEventListenerInterface { // EventListeners lets users add listeners to track events in Google Test. class EventListeners { public: - EventListeners(); - ~EventListeners(); + EventListeners(); + ~EventListeners(); // Appends an event listener to the end of the list. Google Test assumes // the ownership of the listener (i.e. it will delete the listener when // the test program finishes). - void Append(UnitTestEventListenerInterface* listener); + void Append(TestEventListener* listener); // Removes the given event listener from the list and returns it. It then // becomes the caller's responsibility to delete the listener. Returns // NULL if the listener is not found in the list. - UnitTestEventListenerInterface* Release( - UnitTestEventListenerInterface* listener); + TestEventListener* Release(TestEventListener* listener); // Returns the standard listener responsible for the default console // output. Can be removed from the listeners list to shut down default // console output. Note that removing this object from the listener list // with Release transfers its ownership to the caller and makes this // function return NULL the next time. - UnitTestEventListenerInterface* default_result_printer() const { + TestEventListener* default_result_printer() const { return default_result_printer_; } @@ -880,35 +864,35 @@ class EventListeners { // removing this object from the listener list with Release transfers its // ownership to the caller and makes this function return NULL the next // time. - UnitTestEventListenerInterface* default_xml_generator() const { + TestEventListener* default_xml_generator() const { return default_xml_generator_; } private: + friend class TestCase; friend class internal::DefaultGlobalTestPartResultReporter; friend class internal::EventListenersAccessor; friend class internal::NoExecDeathTest; - friend class internal::TestCase; friend class internal::TestInfoImpl; friend class internal::UnitTestImpl; - // Returns repeater that broadcasts the UnitTestEventListenerInterface - // events to all subscribers. - UnitTestEventListenerInterface* repeater(); + // Returns repeater that broadcasts the TestEventListener events to all + // subscribers. + TestEventListener* repeater(); // Sets the default_result_printer attribute to the provided listener. // The listener is also added to the listener list and previous // default_result_printer is removed from it and deleted. The listener can // also be NULL in which case it will not be added to the list. Does // nothing if the previous and the current listener objects are the same. - void SetDefaultResultPrinter(UnitTestEventListenerInterface* listener); + void SetDefaultResultPrinter(TestEventListener* listener); // Sets the default_xml_generator attribute to the provided listener. The // listener is also added to the listener list and previous // default_xml_generator is removed from it and deleted. The listener can // also be NULL in which case it will not be added to the list. Does // nothing if the previous and the current listener objects are the same. - void SetDefaultXmlGenerator(UnitTestEventListenerInterface* listener); + void SetDefaultXmlGenerator(TestEventListener* listener); // Controls whether events will be forwarded by the repeater to the // listeners in the list. @@ -918,16 +902,14 @@ class EventListeners { // The actual list of listeners. internal::TestEventRepeater* repeater_; // Listener responsible for the standard result output. - UnitTestEventListenerInterface* default_result_printer_; + TestEventListener* default_result_printer_; // Listener responsible for the creation of the XML output file. - UnitTestEventListenerInterface* default_xml_generator_; + TestEventListener* default_xml_generator_; // We disallow copying EventListeners. GTEST_DISALLOW_COPY_AND_ASSIGN_(EventListeners); }; -} // namespace internal - // A UnitTest consists of a vector of TestCases. // // This is a singleton class. The only instance of UnitTest is @@ -959,7 +941,7 @@ class UnitTest { // Returns the TestCase object for the test that's currently running, // or NULL if no test is running. - const internal::TestCase* current_test_case() const; + const TestCase* current_test_case() const; // Returns the TestInfo object for the test that's currently running, // or NULL if no test is running. @@ -976,36 +958,6 @@ class UnitTest { internal::ParameterizedTestCaseRegistry& parameterized_test_registry(); #endif // GTEST_HAS_PARAM_TEST - private: - // Registers and returns a global test environment. When a test - // program is run, all global test environments will be set-up in - // the order they were registered. After all tests in the program - // have finished, all global test environments will be torn-down in - // the *reverse* order they were registered. - // - // The UnitTest object takes ownership of the given environment. - // - // This method can only be called from the main thread. - Environment* AddEnvironment(Environment* env); - - // Adds a TestPartResult to the current TestResult object. All - // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) - // eventually call this to report their results. The user code - // should use the assertion macros instead of calling this directly. - void AddTestPartResult(TestPartResult::Type result_type, - const char* file_name, - int line_number, - const internal::String& message, - const internal::String& os_stack_trace); - - // Adds a TestProperty to the current TestResult object. If the result already - // contains a property with the same key, the value will be updated. - void RecordPropertyForCurrentTest(const char* key, const char* value); - - // Accessors for the implementation object. - internal::UnitTestImpl* impl() { return impl_; } - const internal::UnitTestImpl* impl() const { return impl_; } - // Gets the number of successful test cases. int successful_test_case_count() const; @@ -1046,36 +998,52 @@ class UnitTest { // Gets the i-th test case among all the test cases. i can range from 0 to // total_test_case_count() - 1. If i is not in that range, returns NULL. - const internal::TestCase* GetTestCase(int i) const; + const TestCase* GetTestCase(int i) const; // Returns the list of event listeners that can be used to track events // inside Google Test. - internal::EventListeners& listeners(); + EventListeners& listeners(); - // ScopedTrace is a friend as it needs to modify the per-thread - // trace stack, which is a private member of UnitTest. - // TODO(vladl@google.com): Order all declarations according to the style - // guide after publishing of the above methods is done. + private: + // Registers and returns a global test environment. When a test + // program is run, all global test environments will be set-up in + // the order they were registered. After all tests in the program + // have finished, all global test environments will be torn-down in + // the *reverse* order they were registered. + // + // The UnitTest object takes ownership of the given environment. + // + // This method can only be called from the main thread. + Environment* AddEnvironment(Environment* env); + + // Adds a TestPartResult to the current TestResult object. All + // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) + // eventually call this to report their results. The user code + // should use the assertion macros instead of calling this directly. + void AddTestPartResult(TestPartResult::Type result_type, + const char* file_name, + int line_number, + const internal::String& message, + const internal::String& os_stack_trace); + + // Adds a TestProperty to the current TestResult object. If the result already + // contains a property with the same key, the value will be updated. + void RecordPropertyForCurrentTest(const char* key, const char* value); + + // Accessors for the implementation object. + internal::UnitTestImpl* impl() { return impl_; } + const internal::UnitTestImpl* impl() const { return impl_; } + + // These classes and funcions are friends as they need to access private + // members of UnitTest. + friend class Test; + friend class internal::AssertHelper; friend class internal::ScopedTrace; friend Environment* AddGlobalTestEnvironment(Environment* env); friend internal::UnitTestImpl* internal::GetUnitTestImpl(); - friend class internal::AssertHelper; - friend class Test; friend void internal::ReportFailureInUnknownLocation( TestPartResult::Type result_type, const internal::String& message); - // TODO(vladl@google.com): Remove these when publishing the new accessors. - friend class internal::PrettyUnitTestResultPrinter; - friend class internal::TestCase; - friend class internal::TestInfoImpl; - friend class internal::UnitTestAccessor; - friend class internal::UnitTestImpl; - friend class internal::XmlUnitTestResultPrinter; - friend class FinalSuccessChecker; - FRIEND_TEST(ApiTest, UnitTestImmutableAccessorsWork); - FRIEND_TEST(ApiTest, TestCaseImmutableAccessorsWork); - FRIEND_TEST(ApiTest, DisabledTestCaseAccessorsWork); - // Creates an empty UnitTest. UnitTest(); diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index d86f780..9afbd47 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -77,7 +77,10 @@ // GTEST_OS_MAC - Mac OS X // GTEST_OS_SOLARIS - Sun Solaris // GTEST_OS_SYMBIAN - Symbian -// GTEST_OS_WINDOWS - Windows +// GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile) +// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop +// GTEST_OS_WINDOWS_MINGW - MinGW +// GTEST_OS_WINODWS_MOBILE - Windows Mobile // GTEST_OS_ZOS - z/OS // // Among the platforms, Cygwin, Linux, Max OS X, and Windows have the @@ -184,6 +187,13 @@ #define GTEST_OS_SYMBIAN 1 #elif defined _WIN32 #define GTEST_OS_WINDOWS 1 +#ifdef _WIN32_WCE +#define GTEST_OS_WINDOWS_MOBILE 1 +#elif defined(__MINGW__) || defined(__MINGW32__) +#define GTEST_OS_WINDOWS_MINGW 1 +#else +#define GTEST_OS_WINDOWS_DESKTOP 1 +#endif // _WIN32_WCE #elif defined __APPLE__ #define GTEST_OS_MAC 1 #elif defined __linux__ @@ -210,10 +220,10 @@ #elif GTEST_OS_WINDOWS -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE #include <direct.h> // NOLINT #include <io.h> // NOLINT -#endif // !_WIN32_WCE +#endif // <regex.h> is not available on Windows. Use our own simple regex // implementation instead. @@ -449,11 +459,9 @@ // (this is covered by GTEST_HAS_STD_STRING guard). // 3. abort() in a VC 7.1 application compiled as GUI in debug config // pops up a dialog window that cannot be suppressed programmatically. -#if GTEST_HAS_STD_STRING && (GTEST_OS_LINUX || \ - GTEST_OS_MAC || \ - GTEST_OS_CYGWIN || \ - (GTEST_OS_WINDOWS && (_MSC_VER >= 1400) && \ - !defined(_WIN32_WCE))) +#if GTEST_HAS_STD_STRING && \ + (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || \ + (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400)) #define GTEST_HAS_DEATH_TEST 1 #include <vector> // NOLINT #endif @@ -835,29 +843,29 @@ inline int StrCaseCmp(const char* s1, const char* s2) { } inline char* StrDup(const char* src) { return strdup(src); } #else // !__BORLANDC__ -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE inline int IsATTY(int /* fd */) { return 0; } -#else // !_WIN32_WCE +#else inline int IsATTY(int fd) { return _isatty(fd); } -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE inline int StrCaseCmp(const char* s1, const char* s2) { return _stricmp(s1, s2); } inline char* StrDup(const char* src) { return _strdup(src); } #endif // __BORLANDC__ -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); } // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this // time and thus not defined there. -#else // !_WIN32_WCE +#else inline int FileNo(FILE* file) { return _fileno(file); } inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } inline int RmDir(const char* dir) { return _rmdir(dir); } inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; } -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE #else @@ -891,20 +899,20 @@ inline const char* StrNCpy(char* dest, const char* src, size_t n) { // StrError() aren't needed on Windows CE at this time and thus not // defined there. -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE inline int ChDir(const char* dir) { return chdir(dir); } #endif inline FILE* FOpen(const char* path, const char* mode) { return fopen(path, mode); } -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE inline FILE *FReopen(const char* path, const char* mode, FILE* stream) { return freopen(path, mode, stream); } inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } #endif inline int FClose(FILE* fp) { return fclose(fp); } -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE inline int Read(int fd, void* buf, unsigned int count) { return static_cast<int>(read(fd, buf, count)); } @@ -915,7 +923,8 @@ inline int Close(int fd) { return close(fd); } inline const char* StrError(int errnum) { return strerror(errnum); } #endif inline const char* GetEnv(const char* name) { -#ifdef _WIN32_WCE // We are on Windows CE, which has no environment variables. +#if GTEST_OS_WINDOWS_MOBILE + // We are on Windows CE, which has no environment variables. return NULL; #elif defined(__BORLANDC__) // Environment variables which we programmatically clear will be set to the @@ -931,14 +940,14 @@ inline const char* GetEnv(const char* name) { #pragma warning(pop) // Restores the warning state. #endif -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE // Windows CE has no C library. The abort() function is used in // several places in Google Test. This implementation provides a reasonable // imitation of standard behaviour. void Abort(); #else inline void Abort() { abort(); } -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE } // namespace posix diff --git a/include/gtest/internal/gtest-string.h b/include/gtest/internal/gtest-string.h index 39982d1..4bc8241 100644 --- a/include/gtest/internal/gtest-string.h +++ b/include/gtest/internal/gtest-string.h @@ -98,7 +98,7 @@ class String { // memory using malloc(). static const char* CloneCString(const char* c_str); -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be // able to pass strings to Win32 APIs on CE we need to convert them // to 'Unicode', UTF-16. 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++; } } diff --git a/src/gtest-filepath.cc b/src/gtest-filepath.cc index ef74236..515d61c 100644 --- a/src/gtest-filepath.cc +++ b/src/gtest-filepath.cc @@ -34,7 +34,7 @@ #include <stdlib.h> -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE #include <windows.h> #elif GTEST_OS_WINDOWS #include <direct.h> @@ -45,7 +45,7 @@ #else #include <limits.h> #include <climits> // Some Linux distributions define PATH_MAX here. -#endif // _WIN32_WCE or _WIN32 +#endif // GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS #define GTEST_PATH_MAX_ _MAX_PATH @@ -65,7 +65,7 @@ namespace internal { #if GTEST_OS_WINDOWS const char kPathSeparator = '\\'; const char kPathSeparatorString[] = "\\"; -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE // Windows CE doesn't have a current directory. You should not use // the current directory in tests on Windows CE, but this at least // provides a reasonable fallback. @@ -74,7 +74,7 @@ const char kCurrentDirectoryString[] = "\\"; const DWORD kInvalidFileAttributes = 0xffffffff; #else const char kCurrentDirectoryString[] = ".\\"; -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE #else const char kPathSeparator = '/'; const char kPathSeparatorString[] = "/"; @@ -83,9 +83,9 @@ const char kCurrentDirectoryString[] = "./"; // Returns the current working directory, or "" if unsuccessful. FilePath FilePath::GetCurrentDir() { -#ifdef _WIN32_WCE -// Windows CE doesn't have a current directory, so we just return -// something reasonable. +#if GTEST_OS_WINDOWS_MOBILE + // Windows CE doesn't have a current directory, so we just return + // something reasonable. return FilePath(kCurrentDirectoryString); #elif GTEST_OS_WINDOWS char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; @@ -93,7 +93,7 @@ FilePath FilePath::GetCurrentDir() { #else char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; return FilePath(getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd); -#endif +#endif // GTEST_OS_WINDOWS_MOBILE } // Returns a copy of the FilePath with the case-insensitive extension removed. @@ -169,7 +169,7 @@ FilePath FilePath::ConcatPaths(const FilePath& directory, // Returns true if pathname describes something findable in the file-system, // either a file, directory, or whatever. bool FilePath::FileOrDirectoryExists() const { -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str()); const DWORD attributes = GetFileAttributes(unicode); delete [] unicode; @@ -177,7 +177,7 @@ bool FilePath::FileOrDirectoryExists() const { #else posix::StatStruct file_stat; return posix::Stat(pathname_.c_str(), &file_stat) == 0; -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE } // Returns true if pathname describes a directory in the file-system @@ -193,7 +193,7 @@ bool FilePath::DirectoryExists() const { const FilePath& path(*this); #endif -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE LPCWSTR unicode = String::AnsiToUtf16(path.c_str()); const DWORD attributes = GetFileAttributes(unicode); delete [] unicode; @@ -205,7 +205,7 @@ bool FilePath::DirectoryExists() const { posix::StatStruct file_stat; result = posix::Stat(path.c_str(), &file_stat) == 0 && posix::IsDir(file_stat); -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE return result; } @@ -284,18 +284,17 @@ bool FilePath::CreateDirectoriesRecursively() const { // directory for any reason, including if the parent directory does not // exist. Not named "CreateDirectory" because that's a macro on Windows. bool FilePath::CreateFolder() const { -#if GTEST_OS_WINDOWS -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE FilePath removed_sep(this->RemoveTrailingPathSeparator()); LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str()); int result = CreateDirectory(unicode, NULL) ? 0 : -1; delete [] unicode; -#else +#elif GTEST_OS_WINDOWS int result = _mkdir(pathname_.c_str()); -#endif // !WIN32_WCE #else int result = mkdir(pathname_.c_str(), 0777); -#endif // _WIN32 +#endif // GTEST_OS_WINDOWS_MOBILE + if (result == -1) { return this->DirectoryExists(); // An error is OK if the directory exists. } diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h index 93217f4..9826bdd 100644 --- a/src/gtest-internal-inl.h +++ b/src/gtest-internal-inl.h @@ -1140,8 +1140,6 @@ class TestResultAccessor { test_result->RecordProperty(property); } - static bool Passed(const TestResult& result) { return result.Passed(); } - static void ClearTestPartResults(TestResult* test_result) { test_result->ClearTestPartResults(); } diff --git a/src/gtest-port.cc b/src/gtest-port.cc index ba9a9a2..de169e2 100644 --- a/src/gtest-port.cc +++ b/src/gtest-port.cc @@ -35,14 +35,14 @@ #include <stdlib.h> #include <stdio.h> -#if GTEST_OS_WINDOWS -#ifndef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE +#include <windows.h> // For TerminateProcess() +#elif GTEST_OS_WINDOWS #include <io.h> #include <sys/stat.h> -#endif // _WIN32_WCE #else #include <unistd.h> -#endif // GTEST_OS_WINDOWS +#endif // GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_MAC #include <mach/mach_init.h> @@ -50,10 +50,6 @@ #include <mach/vm_map.h> #endif // GTEST_OS_MAC -#ifdef _WIN32_WCE -#include <windows.h> // For TerminateProcess() -#endif // _WIN32_WCE - #include <gtest/gtest-spi.h> #include <gtest/gtest-message.h> #include <gtest/internal/gtest-string.h> @@ -449,7 +445,7 @@ class CapturedStderr { public: // The ctor redirects stderr to a temporary file. CapturedStderr() { -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE // Not supported on Windows CE. posix::Abort(); #else @@ -474,24 +470,24 @@ class CapturedStderr { fflush(NULL); dup2(captured_fd, kStdErrFileno); close(captured_fd); -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE } ~CapturedStderr() { -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE remove(filename_.c_str()); -#endif // _WIN32_WCE +#endif // !GTEST_OS_WINDOWS_MOBILE } // Stops redirecting stderr. void StopCapture() { -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE // Restores the original stream. fflush(NULL); dup2(uncaptured_fd_, kStdErrFileno); close(uncaptured_fd_); uncaptured_fd_ = -1; -#endif // !_WIN32_WCE +#endif // !GTEST_OS_WINDOWS_MOBILE } // Returns the name of the temporary file holding the stderr output. @@ -573,14 +569,14 @@ const ::std::vector<String>& GetArgvs() { return g_argvs; } #endif // GTEST_HAS_DEATH_TEST -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE namespace posix { void Abort() { DebugBreak(); TerminateProcess(GetCurrentProcess(), 1); } } // namespace posix -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE // Returns the name of the environment variable corresponding to the // given flag. For example, FlagToEnvVar("foo") will return diff --git a/src/gtest.cc b/src/gtest.cc index 30652fe..44ec949 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -70,7 +70,7 @@ // On z/OS we additionally need strings.h for strcasecmp. #include <strings.h> // NOLINT -#elif defined(_WIN32_WCE) // We are on Windows CE. +#elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE. #include <windows.h> // NOLINT @@ -81,7 +81,7 @@ #include <sys/types.h> // NOLINT #include <sys/stat.h> // NOLINT -#if defined(__MINGW__) || defined(__MINGW32__) +#if GTEST_OS_WINDOWS_MINGW // MinGW has gettimeofday() but not _ftime64(). // TODO(kenton@google.com): Use autoconf to detect availability of // gettimeofday(). @@ -90,7 +90,7 @@ // supports these. consider using them instead. #define GTEST_HAS_GETTIMEOFDAY_ 1 #include <sys/time.h> // NOLINT -#endif // defined(__MINGW__) || defined(__MINGW32__) +#endif // GTEST_OS_WINDOWS_MINGW // cpplint thinks that the header is already included, so we want to // silence it. @@ -129,13 +129,6 @@ namespace testing { -using internal::EventListeners; -using internal::EmptyTestEventListener; -using internal::TestCase; -using internal::TestProperty; -using internal::TestResult; -using internal::UnitTestEventListenerInterface; - // Constants. // A test whose test case name or test name matches this filter is @@ -356,11 +349,11 @@ String g_executable_path; FilePath GetCurrentExecutableName() { FilePath result; -#if defined(_WIN32_WCE) || GTEST_OS_WINDOWS +#if GTEST_OS_WINDOWS result.Set(FilePath(g_executable_path).RemoveExtension("exe")); #else result.Set(FilePath(g_executable_path)); -#endif // _WIN32_WCE || GTEST_OS_WINDOWS +#endif // GTEST_OS_WINDOWS return result.RemoveDirectoryName(); } @@ -738,7 +731,7 @@ String UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) { // Returns the current time in milliseconds. TimeInMillis GetTimeInMillis() { -#if defined(_WIN32_WCE) || defined(__BORLANDC__) +#if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__) // Difference between 1970-01-01 and 1601-01-01 in milliseconds. // http://analogous.blogspot.com/2005/04/epoch.html const TimeInMillis kJavaEpochToWinFileTimeDelta = @@ -821,7 +814,7 @@ const char * String::CloneCString(const char* c_str) { NULL : CloneString(c_str, strlen(c_str)); } -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE // Creates a UTF-16 wide string from the given ANSI string, allocating // memory using new. The caller is responsible for deleting the return // value using delete[]. Returns the wide string, or NULL if the @@ -855,7 +848,7 @@ const char* String::Utf16ToAnsi(LPCWSTR utf16_str) { return ansi; } -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE // Compares two C strings. Returns true iff they have the same content. // @@ -1329,7 +1322,7 @@ namespace { AssertionResult HRESULTFailureHelper(const char* expr, const char* expected, long hr) { // NOLINT -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE // Windows CE doesn't support FormatMessage. const char error_text[] = ""; #else @@ -1353,7 +1346,7 @@ AssertionResult HRESULTFailureHelper(const char* expr, --message_length) { error_text[message_length - 1] = '\0'; } -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE const String error_hex(String::Format("0x%08X ", hr)); Message msg; @@ -1768,6 +1761,8 @@ String AppendUserMessage(const String& gtest_msg, return msg.GetString(); } +} // namespace internal + // class TestResult // Creates an empty TestResult. @@ -1887,8 +1882,6 @@ int TestResult::test_property_count() const { return test_properties_->size(); } -} // namespace internal - // class Test // Creates a Test object. @@ -2255,8 +2248,7 @@ void TestInfoImpl::Run() { UnitTestImpl* const impl = internal::GetUnitTestImpl(); impl->set_current_test_info(parent_); - UnitTestEventListenerInterface* repeater = - UnitTest::GetInstance()->listeners().repeater(); + TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); // Notifies the unit test event listeners that a test is about to start. repeater->OnTestStart(*parent_); @@ -2309,6 +2301,8 @@ void TestInfoImpl::Run() { impl->set_current_test_info(NULL); } +} // namespace internal + // class TestCase // Gets the number of successful tests in this test case. @@ -2383,8 +2377,7 @@ void TestCase::Run() { internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); impl->set_current_test_case(this); - UnitTestEventListenerInterface* repeater = - UnitTest::GetInstance()->listeners().repeater(); + TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); repeater->OnTestCaseStart(*this); impl->os_stack_trace_getter()->UponLeavingGTest(); @@ -2427,8 +2420,6 @@ bool TestCase::ShouldRunTest(const TestInfo *test_info) { return test_info->impl()->should_run(); } -} // namespace internal - // Formats a countable noun. Depending on its quantity, either the // singular form or the plural form is used. e.g. // @@ -2492,7 +2483,7 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) { // following statements add the test part result message to the Output // window such that the user can double-click on it to jump to the // corresponding source code location; otherwise they do nothing. -#if GTEST_OS_WINDOWS && !defined(_WIN32_WCE) +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE // We don't call OutputDebugString*() on Windows Mobile, as printing // to stdout is done by OutputDebugString() there already - we don't // want the same message printed twice. @@ -2512,7 +2503,7 @@ enum GTestColor { COLOR_YELLOW }; -#if GTEST_OS_WINDOWS && !defined(_WIN32_WCE) +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE // Returns the character attribute for the given color. WORD GetColorAttribute(GTestColor color) { @@ -2537,7 +2528,7 @@ const char* GetAnsiColorCode(GTestColor color) { }; } -#endif // GTEST_OS_WINDOWS && !_WIN32_WCE +#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE // Returns true iff Google Test should use colors in the output. bool ShouldUseColor(bool stdout_is_tty) { @@ -2578,13 +2569,13 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) { va_list args; va_start(args, fmt); -#if defined(_WIN32_WCE) || GTEST_OS_SYMBIAN || GTEST_OS_ZOS +#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS const bool use_color = false; #else static const bool in_color_mode = ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0); const bool use_color = in_color_mode && (color != COLOR_DEFAULT); -#endif // defined(_WIN32_WCE) || GTEST_OS_SYMBIAN || GTEST_OS_ZOS +#endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS // The '!= 0' comparison is necessary to satisfy MSVC 7.1. if (!use_color) { @@ -2593,7 +2584,7 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) { return; } -#if GTEST_OS_WINDOWS && !defined(_WIN32_WCE) +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); // Gets the current text color. @@ -2611,22 +2602,21 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) { printf("\033[0;3%sm", GetAnsiColorCode(color)); vprintf(fmt, args); printf("\033[m"); // Resets the terminal to default. -#endif // GTEST_OS_WINDOWS && !defined(_WIN32_WCE) +#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE va_end(args); } -// This class implements the UnitTestEventListenerInterface interface. +// This class implements the TestEventListener interface. // // Class PrettyUnitTestResultPrinter is copyable. -class PrettyUnitTestResultPrinter : public UnitTestEventListenerInterface { +class PrettyUnitTestResultPrinter : public TestEventListener { public: PrettyUnitTestResultPrinter() {} static void PrintTestName(const char * test_case, const char * test) { printf("%s.%s", test_case, test); } - // The following methods override what's in the - // UnitTestEventListenerInterface class. + // The following methods override what's in the TestEventListener class. virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {} virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration); virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test); @@ -2837,13 +2827,12 @@ void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) { // class TestEventRepeater // // This class forwards events to other event listeners. -class TestEventRepeater : public UnitTestEventListenerInterface { +class TestEventRepeater : public TestEventListener { public: TestEventRepeater() : forwarding_enabled_(true) {} virtual ~TestEventRepeater(); - void Append(UnitTestEventListenerInterface *listener); - UnitTestEventListenerInterface* Release( - UnitTestEventListenerInterface* listener); + void Append(TestEventListener *listener); + TestEventListener* Release(TestEventListener* listener); // Controls whether events will be forwarded to listeners_. Set to false // in death test child processes. @@ -2869,7 +2858,7 @@ class TestEventRepeater : public UnitTestEventListenerInterface { // in death test child processes. bool forwarding_enabled_; // The list of listeners that receive events. - Vector<UnitTestEventListenerInterface*> listeners_; + Vector<TestEventListener*> listeners_; GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventRepeater); }; @@ -2880,13 +2869,12 @@ TestEventRepeater::~TestEventRepeater() { } } -void TestEventRepeater::Append(UnitTestEventListenerInterface *listener) { +void TestEventRepeater::Append(TestEventListener *listener) { listeners_.PushBack(listener); } // TODO(vladl@google.com): Factor the search functionality into Vector::Find. -UnitTestEventListenerInterface* TestEventRepeater::Release( - UnitTestEventListenerInterface *listener) { +TestEventListener* TestEventRepeater::Release(TestEventListener *listener) { for (int i = 0; i < listeners_.size(); ++i) { if (listeners_.GetElement(i) == listener) { listeners_.Erase(i); @@ -3279,15 +3267,14 @@ EventListeners::~EventListeners() { delete repeater_; } // output. Can be removed from the listeners list to shut down default // console output. Note that removing this object from the listener list // with Release transfers its ownership to the user. -void EventListeners::Append(UnitTestEventListenerInterface* listener) { +void EventListeners::Append(TestEventListener* listener) { repeater_->Append(listener); } // Removes the given event listener from the list and returns it. It then // becomes the caller's responsibility to delete the listener. Returns // NULL if the listener is not found in the list. -UnitTestEventListenerInterface* EventListeners::Release( - UnitTestEventListenerInterface* listener) { +TestEventListener* EventListeners::Release(TestEventListener* listener) { if (listener == default_result_printer_) default_result_printer_ = NULL; else if (listener == default_xml_generator_) @@ -3295,17 +3282,16 @@ UnitTestEventListenerInterface* EventListeners::Release( return repeater_->Release(listener); } -// Returns repeater that broadcasts the UnitTestEventListenerInterface -// events to all subscribers. -UnitTestEventListenerInterface* EventListeners::repeater() { return repeater_; } +// Returns repeater that broadcasts the TestEventListener events to all +// subscribers. +TestEventListener* EventListeners::repeater() { return repeater_; } // Sets the default_result_printer attribute to the provided listener. // The listener is also added to the listener list and previous // default_result_printer is removed from it and deleted. The listener can // also be NULL in which case it will not be added to the list. Does // nothing if the previous and the current listener objects are the same. -void EventListeners::SetDefaultResultPrinter( - UnitTestEventListenerInterface* listener) { +void EventListeners::SetDefaultResultPrinter(TestEventListener* listener) { if (default_result_printer_ != listener) { // It is an error to pass this method a listener that is already in the // list. @@ -3321,8 +3307,7 @@ void EventListeners::SetDefaultResultPrinter( // default_xml_generator is removed from it and deleted. The listener can // also be NULL in which case it will not be added to the list. Does // nothing if the previous and the current listener objects are the same. -void EventListeners::SetDefaultXmlGenerator( - UnitTestEventListenerInterface* listener) { +void EventListeners::SetDefaultXmlGenerator(TestEventListener* listener) { if (default_xml_generator_ != listener) { // It is an error to pass this method a listener that is already in the // list. @@ -3557,20 +3542,20 @@ int UnitTest::Run() { // process. In either case the user does not want to see pop-up dialogs // about crashes - they are expected.. if (GTEST_FLAG(catch_exceptions) || in_death_test_child_process) { -#if !defined(_WIN32_WCE) +#if !GTEST_OS_WINDOWS_MOBILE // SetErrorMode doesn't exist on CE. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); -#endif // _WIN32_WCE +#endif // !GTEST_OS_WINDOWS_MOBILE -#if (defined(_MSC_VER) || defined(__MINGW32__)) && !defined(_WIN32_WCE) +#if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE // Death test children can be terminated with _abort(). On Windows, // _abort() can show a dialog with a warning message. This forces the // abort message to go to stderr instead. _set_error_mode(_OUT_TO_STDERR); #endif -#if _MSC_VER >= 1400 && !defined(_WIN32_WCE) +#if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE // In the debug version, Visual Studio pops up a separate dialog // offering a choice to debug the aborted program. We need to suppress // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement @@ -3890,7 +3875,7 @@ int UnitTestImpl::RunAllTests() { // True iff at least one test has failed. bool failed = false; - UnitTestEventListenerInterface* repeater = listeners()->repeater(); + TestEventListener* repeater = listeners()->repeater(); repeater->OnTestProgramStart(*parent_); diff --git a/test/gtest-filepath_test.cc b/test/gtest-filepath_test.cc index adf9746..5bc4daf 100644 --- a/test/gtest-filepath_test.cc +++ b/test/gtest-filepath_test.cc @@ -50,17 +50,17 @@ #include "src/gtest-internal-inl.h" #undef GTEST_IMPLEMENTATION_ -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE #include <windows.h> // NOLINT #elif GTEST_OS_WINDOWS #include <direct.h> // NOLINT -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE namespace testing { namespace internal { namespace { -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE // TODO(wan@google.com): Move these to the POSIX adapter section in // gtest-port.h. @@ -81,9 +81,7 @@ int _rmdir(const char* path) { return ret; } -#endif // _WIN32_WCE - -#ifndef _WIN32_WCE +#else TEST(GetCurrentDirTest, ReturnsCurrentDir) { const FilePath original_dir = FilePath::GetCurrentDir(); @@ -103,7 +101,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) { #endif } -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE TEST(IsEmptyTest, ReturnsTrueForEmptyPath) { EXPECT_TRUE(FilePath("").IsEmpty()); @@ -156,7 +154,7 @@ TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) { // RemoveFileName "" -> "./" TEST(RemoveFileNameTest, EmptyName) { -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE // On Windows CE, we use the root as the current directory. EXPECT_STREQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().c_str()); @@ -344,12 +342,12 @@ TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) { } #endif // GTEST_OS_WINDOWS -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE // Windows CE _does_ consider an empty directory to exist. TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) { EXPECT_FALSE(FilePath("").DirectoryExists()); } -#endif // ! _WIN32_WCE +#endif // !GTEST_OS_WINDOWS_MOBILE TEST(DirectoryTest, CurrentDirectoryExists) { #if GTEST_OS_WINDOWS // We are on Windows. @@ -449,9 +447,8 @@ class DirectoryCreationTest : public Test { } String TempDir() const { -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE return String("\\temp\\"); - #elif GTEST_OS_WINDOWS const char* temp_dir = posix::GetEnv("TEMP"); if (temp_dir == NULL || temp_dir[0] == '\0') @@ -462,7 +459,7 @@ class DirectoryCreationTest : public Test { return String::Format("%s\\", temp_dir); #else return String("/tmp/"); -#endif +#endif // GTEST_OS_WINDOWS_MOBILE } void CreateTextFile(const char* filename) { diff --git a/test/gtest-listener_test.cc b/test/gtest-listener_test.cc index 95ff0b1..f12f518 100644 --- a/test/gtest-listener_test.cc +++ b/test/gtest-listener_test.cc @@ -48,12 +48,12 @@ using ::testing::AddGlobalTestEnvironment; using ::testing::Environment; using ::testing::InitGoogleTest; using ::testing::Test; +using ::testing::TestCase; +using ::testing::TestEventListener; using ::testing::TestInfo; using ::testing::TestPartResult; using ::testing::UnitTest; using ::testing::internal::String; -using ::testing::internal::TestCase; -using ::testing::internal::UnitTestEventListenerInterface; using ::testing::internal::Vector; // Used by tests to register their events. @@ -62,17 +62,7 @@ Vector<String>* g_events = NULL; namespace testing { namespace internal { -// TODO(vladl@google.com): Remove this and use UnitTest::listeners() -// directly after it is published. -class UnitTestAccessor { - public: - static EventListeners& GetEventListeners() { - return UnitTest::GetInstance()->listeners(); - } - static bool UnitTestFailed() { return UnitTest::GetInstance()->Failed(); } -}; - -class EventRecordingListener : public UnitTestEventListenerInterface { +class EventRecordingListener : public TestEventListener { public: EventRecordingListener(const char* name) : name_(name) {} @@ -195,7 +185,6 @@ TEST_F(ListenerTest, DoesBar) { using ::testing::internal::EnvironmentInvocationCatcher; using ::testing::internal::EventRecordingListener; -using ::testing::internal::UnitTestAccessor; void VerifyResults(const Vector<String>& data, const char* const* expected_data, @@ -225,9 +214,9 @@ int main(int argc, char **argv) { g_events = &events; InitGoogleTest(&argc, argv); - UnitTestAccessor::GetEventListeners().Append( + UnitTest::GetInstance()->listeners().Append( new EventRecordingListener("1st")); - UnitTestAccessor::GetEventListeners().Append( + UnitTest::GetInstance()->listeners().Append( new EventRecordingListener("2nd")); AddGlobalTestEnvironment(new EnvironmentInvocationCatcher); @@ -326,7 +315,7 @@ int main(int argc, char **argv) { // We need to check manually for ad hoc test failures that happen after // RUN_ALL_TESTS finishes. - if (UnitTestAccessor::UnitTestFailed()) + if (UnitTest::GetInstance()->Failed()) ret_val = 1; return ret_val; diff --git a/test/gtest-options_test.cc b/test/gtest-options_test.cc index 43c6d22..31ae327 100644 --- a/test/gtest-options_test.cc +++ b/test/gtest-options_test.cc @@ -40,11 +40,11 @@ #include <gtest/gtest.h> -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE #include <windows.h> #elif GTEST_OS_WINDOWS #include <direct.h> -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE // Indicates that this translation unit is part of Google Test's // implementation. It must come before gtest-internal-inl.h is @@ -130,7 +130,7 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) { TEST(OutputFileHelpersTest, GetCurrentExecutableName) { const FilePath executable = GetCurrentExecutableName(); const char* const exe_str = executable.c_str(); -#if defined(_WIN32_WCE) || GTEST_OS_WINDOWS +#if GTEST_OS_WINDOWS ASSERT_TRUE(_strcmpi("gtest-options_test", exe_str) == 0 || _strcmpi("gtest-options-ex_test", exe_str) == 0 || _strcmpi("gtest_all_test", exe_str) == 0) @@ -143,7 +143,7 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) { String(exe_str) == "gtest_all_test" || String(exe_str) == "lt-gtest_all_test") << "GetCurrentExecutableName() returns " << exe_str; -#endif +#endif // GTEST_OS_WINDOWS } class XmlOutputChangeDirTest : public Test { diff --git a/test/gtest-unittest-api_test.cc b/test/gtest-unittest-api_test.cc index 658e298..7e0f8f8 100644 --- a/test/gtest-unittest-api_test.cc +++ b/test/gtest-unittest-api_test.cc @@ -38,21 +38,7 @@ #include <string.h> // For strcmp. #include <algorithm> -using ::testing::AddGlobalTestEnvironment; -using ::testing::Environment; using ::testing::InitGoogleTest; -using ::testing::Test; -using ::testing::TestInfo; -using ::testing::TestPartResult; -using ::testing::UnitTest; -using ::testing::internal::TestCase; -using ::testing::internal::TestProperty; - -#if GTEST_HAS_TYPED_TEST -using ::testing::Types; -using ::testing::internal::GetTypeName; -using ::testing::internal::String; -#endif // GTEST_HAS_TYPED_TEST namespace testing { namespace internal { @@ -64,20 +50,20 @@ struct LessByName { } }; -class UnitTestAccessor { +class UnitTestHelper { public: // Returns the array of pointers to all test cases sorted by the test case // name. The caller is responsible for deleting the array. static TestCase const** const GetSortedTestCases() { - UnitTest* unit_test = UnitTest::GetInstance(); + UnitTest& unit_test = *UnitTest::GetInstance(); TestCase const** const test_cases = - new const TestCase*[unit_test->total_test_case_count()]; + new const TestCase*[unit_test.total_test_case_count()]; - for (int i = 0; i < unit_test->total_test_case_count(); ++i) - test_cases[i] = unit_test->GetTestCase(i); + for (int i = 0; i < unit_test.total_test_case_count(); ++i) + test_cases[i] = unit_test.GetTestCase(i); std::sort(test_cases, - test_cases + unit_test->total_test_case_count(), + test_cases + unit_test.total_test_case_count(), LessByName<TestCase>()); return test_cases; } @@ -85,9 +71,9 @@ class UnitTestAccessor { // Returns the test case by its name. The caller doesn't own the returned // pointer. static const TestCase* FindTestCase(const char* name) { - UnitTest* unit_test = UnitTest::GetInstance(); - for (int i = 0; i < unit_test->total_test_case_count(); ++i) { - const TestCase* test_case = unit_test->GetTestCase(i); + UnitTest& unit_test = *UnitTest::GetInstance(); + for (int i = 0; i < unit_test.total_test_case_count(); ++i) { + const TestCase* test_case = unit_test.GetTestCase(i); if (0 == strcmp(test_case->name(), name)) return test_case; } @@ -104,19 +90,12 @@ class UnitTestAccessor { for (int i = 0; i < test_case->total_test_count(); ++i) tests[i] = test_case->GetTestInfo(i); - std::sort(tests, - tests + test_case->total_test_count(), + std::sort(tests, tests + test_case->total_test_count(), LessByName<TestInfo>()); return tests; } }; -// TODO(vladl@google.com): Put tests into the internal namespace after -// UnitTest methods are published. -} // namespace internal - -using internal::UnitTestAccessor; - #if GTEST_HAS_TYPED_TEST template <typename T> class TestCaseWithCommentTest : public Test {}; TYPED_TEST_CASE(TestCaseWithCommentTest, Types<int>); @@ -147,7 +126,7 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) { EXPECT_EQ(5 + kTypedTests, unit_test->total_test_count()); EXPECT_EQ(3 + kTypedTests, unit_test->test_to_run_count()); - const TestCase** const test_cases = UnitTestAccessor::GetSortedTestCases(); + const TestCase** const test_cases = UnitTestHelper::GetSortedTestCases(); EXPECT_STREQ("ApiTest", test_cases[0]->name()); EXPECT_STREQ("DISABLED_Test", test_cases[1]->name()); @@ -165,7 +144,7 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) { } TEST(ApiTest, TestCaseImmutableAccessorsWork) { - const TestCase* test_case = UnitTestAccessor::FindTestCase("ApiTest"); + const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest"); ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("ApiTest", test_case->name()); @@ -175,7 +154,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { EXPECT_EQ(3, test_case->test_to_run_count()); ASSERT_EQ(4, test_case->total_test_count()); - const TestInfo** tests = UnitTestAccessor::GetSortedTests(test_case); + const TestInfo** tests = UnitTestHelper::GetSortedTests(test_case); EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); @@ -205,7 +184,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { tests = NULL; #if GTEST_HAS_TYPED_TEST - test_case = UnitTestAccessor::FindTestCase("TestCaseWithCommentTest/0"); + test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0"); ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("TestCaseWithCommentTest/0", test_case->name()); @@ -215,7 +194,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { EXPECT_EQ(1, test_case->test_to_run_count()); ASSERT_EQ(1, test_case->total_test_count()); - tests = UnitTestAccessor::GetSortedTests(test_case); + tests = UnitTestHelper::GetSortedTests(test_case); EXPECT_STREQ("Dummy", tests[0]->name()); EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); @@ -229,7 +208,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { } TEST(ApiTest, TestCaseDisabledAccessorsWork) { - const TestCase* test_case = UnitTestAccessor::FindTestCase("DISABLED_Test"); + const TestCase* test_case = UnitTestHelper::FindTestCase("DISABLED_Test"); ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("DISABLED_Test", test_case->name()); @@ -265,7 +244,7 @@ class FinalSuccessChecker : public Environment { EXPECT_FALSE(unit_test->Failed()); ASSERT_EQ(2 + kTypedTestCases, unit_test->total_test_case_count()); - const TestCase** const test_cases = UnitTestAccessor::GetSortedTestCases(); + const TestCase** const test_cases = UnitTestHelper::GetSortedTestCases(); EXPECT_STREQ("ApiTest", test_cases[0]->name()); EXPECT_STREQ("", test_cases[0]->comment()); @@ -298,8 +277,8 @@ class FinalSuccessChecker : public Environment { EXPECT_FALSE(test_cases[2]->Failed()); #endif // GTEST_HAS_TYPED_TEST - const TestCase* test_case = UnitTestAccessor::FindTestCase("ApiTest"); - const TestInfo** tests = UnitTestAccessor::GetSortedTests(test_case); + const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest"); + const TestInfo** tests = UnitTestHelper::GetSortedTests(test_case); EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); EXPECT_FALSE(tests[0]->should_run()); @@ -334,8 +313,8 @@ class FinalSuccessChecker : public Environment { delete[] tests; #if GTEST_HAS_TYPED_TEST - test_case = UnitTestAccessor::FindTestCase("TestCaseWithCommentTest/0"); - tests = UnitTestAccessor::GetSortedTests(test_case); + test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0"); + tests = UnitTestHelper::GetSortedTests(test_case); EXPECT_STREQ("Dummy", tests[0]->name()); EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); @@ -352,12 +331,13 @@ class FinalSuccessChecker : public Environment { } }; +} // namespace internal } // namespace testing int main(int argc, char **argv) { InitGoogleTest(&argc, argv); - AddGlobalTestEnvironment(new testing::FinalSuccessChecker()); + AddGlobalTestEnvironment(new testing::internal::FinalSuccessChecker()); return RUN_ALL_TESTS(); } diff --git a/test/gtest_stress_test.cc b/test/gtest_stress_test.cc index 57ea75a..0034bb8 100644 --- a/test/gtest_stress_test.cc +++ b/test/gtest_stress_test.cc @@ -46,7 +46,6 @@ namespace testing { namespace { using internal::String; -using internal::TestProperty; using internal::TestPropertyKeyIs; using internal::Vector; diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc index d5315c4..03acfb0 100644 --- a/test/gtest_unittest.cc +++ b/test/gtest_unittest.cc @@ -88,16 +88,16 @@ bool ParseInt32Flag(const char* str, const char* flag, Int32* value); // that are needed to test it. class EventListenersAccessor { public: - static UnitTestEventListenerInterface* GetRepeater( - EventListeners* listeners) { return listeners->repeater(); } + static TestEventListener* GetRepeater(EventListeners* listeners) { + return listeners->repeater(); + } - static void SetDefaultResultPrinter( - EventListeners* listeners, - UnitTestEventListenerInterface* listener) { + static void SetDefaultResultPrinter(EventListeners* listeners, + TestEventListener* listener) { listeners->SetDefaultResultPrinter(listener); } static void SetDefaultXmlGenerator(EventListeners* listeners, - UnitTestEventListenerInterface* listener) { + TestEventListener* listener) { listeners->SetDefaultXmlGenerator(listener); } @@ -131,6 +131,8 @@ using testing::AssertionFailure; using testing::AssertionResult; using testing::AssertionSuccess; using testing::DoubleLE; +using testing::EmptyTestEventListener; +using testing::EventListeners; using testing::FloatLE; using testing::GTEST_FLAG(also_run_disabled_tests); using testing::GTEST_FLAG(break_on_failure); @@ -153,16 +155,15 @@ using testing::Message; using testing::ScopedFakeTestPartResultReporter; using testing::StaticAssertTypeEq; using testing::Test; +using testing::TestCase; using testing::TestPartResult; using testing::TestPartResultArray; +using testing::TestProperty; +using testing::TestResult; using testing::UnitTest; -using testing::internal::kMaxRandomSeed; -using testing::internal::kTestTypeIdInGoogleTest; using testing::internal::AppendUserMessage; using testing::internal::CodePointToUtf8; -using testing::internal::EmptyTestEventListener; using testing::internal::EqFailure; -using testing::internal::EventListeners; using testing::internal::FloatingPoint; using testing::internal::GTestFlagSaver; using testing::internal::GetCurrentOsStackTraceExceptTop; @@ -178,14 +179,12 @@ using testing::internal::ShouldShard; using testing::internal::ShouldUseColor; using testing::internal::StreamableToString; using testing::internal::String; -using testing::internal::TestCase; -using testing::internal::TestProperty; -using testing::internal::TestResult; using testing::internal::TestResultAccessor; using testing::internal::ThreadLocal; using testing::internal::UInt32; using testing::internal::Vector; using testing::internal::WideStringToUtf8; +using testing::internal::kMaxRandomSeed; using testing::internal::kTestTypeIdInGoogleTest; using testing::internal::scoped_ptr; @@ -1157,7 +1156,7 @@ TEST(StringTest, ShowWideCStringQuoted) { String::ShowWideCStringQuoted(L"foo").c_str()); } -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE TEST(StringTest, AnsiAndUtf16Null) { EXPECT_EQ(NULL, String::AnsiToUtf16(NULL)); EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL)); @@ -1180,7 +1179,7 @@ TEST(StringTest, AnsiAndUtf16ConvertPathChars) { EXPECT_EQ(0, wcsncmp(L".:\\ \"*?", utf16, 3)); delete [] utf16; } -#endif // _WIN32_WCE +#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS @@ -1808,7 +1807,7 @@ TEST_F(GTestFlagSaverTest, VerifyGTestFlags) { // value. If the value argument is "", unsets the environment // variable. The caller must ensure that both arguments are not NULL. static void SetEnv(const char* name, const char* value) { -#ifdef _WIN32_WCE +#if GTEST_OS_WINDOWS_MOBILE // Environment variables are not supported on Windows CE. return; #elif defined(__BORLANDC__) @@ -1826,7 +1825,6 @@ static void SetEnv(const char* name, const char* value) { added_env[name] = new String((Message() << name << "=" << value).GetString()); putenv(added_env[name]->c_str()); delete prev_env; - #elif GTEST_OS_WINDOWS // If we are on Windows proper. _putenv((Message() << name << "=" << value).GetString().c_str()); #else @@ -1835,10 +1833,10 @@ static void SetEnv(const char* name, const char* value) { } else { setenv(name, value, 1); } -#endif +#endif // GTEST_OS_WINDOWS_MOBILE } -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE // Environment variables are not supported on Windows CE. using testing::internal::Int32FromGTestEnv; @@ -1886,7 +1884,7 @@ TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) { SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "-321"); EXPECT_EQ(-321, Int32FromGTestEnv("temp", 0)); } -#endif // !defined(_WIN32_WCE) +#endif // !GTEST_OS_WINDOWS_MOBILE // Tests ParseInt32Flag(). @@ -1944,7 +1942,7 @@ TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) { // Tests that Int32FromEnvOrDie() parses the value of the var or // returns the correct default. // Environment variables are not supported on Windows CE. -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123"); @@ -1952,7 +1950,7 @@ TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "-123"); EXPECT_EQ(-123, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); } -#endif // _WIN32_WCE +#endif // !GTEST_OS_WINDOWS_MOBILE // Tests that Int32FromEnvOrDie() aborts with an error message // if the variable is not an Int32. @@ -2019,7 +2017,7 @@ TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) { // Tests that sharding is enabled if total_shards > 1 and // we are not in a death test subprocess. // Environment variables are not supported on Windows CE. -#ifndef _WIN32_WCE +#if !GTEST_OS_WINDOWS_MOBILE TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) { SetEnv(index_var_, "4"); SetEnv(total_var_, "22"); @@ -2036,7 +2034,7 @@ TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) { EXPECT_TRUE(ShouldShard(total_var_, index_var_, false)); EXPECT_FALSE(ShouldShard(total_var_, index_var_, true)); } -#endif // _WIN32_WCE +#endif // !GTEST_OS_WINDOWS_MOBILE // Tests that we exit in error if the sharding values are not valid. diff --git a/test/gtest_xml_output_unittest_.cc b/test/gtest_xml_output_unittest_.cc index bfeda3d..c0da215 100644 --- a/test/gtest_xml_output_unittest_.cc +++ b/test/gtest_xml_output_unittest_.cc @@ -40,19 +40,9 @@ #include <gtest/gtest.h> -// TODO(vladl@google.com): Remove this include when the event listener API is -// published and GetUnitTestImpl is no longer needed. -// -// Indicates that this translation unit is part of Google Test's -// implementation. It must come before gtest-internal-inl.h is -// included, or there will be a compiler error. This trick is to -// prevent a user from accidentally including gtest-internal-inl.h in -// his code. -#define GTEST_IMPLEMENTATION_ 1 -#include "src/gtest-internal-inl.h" -#undef GTEST_IMPLEMENTATION_ - +using ::testing::EventListeners; using ::testing::InitGoogleTest; +using ::testing::UnitTest; class SuccessfulTest : public testing::Test { }; @@ -137,11 +127,7 @@ int main(int argc, char** argv) { InitGoogleTest(&argc, argv); if (argc > 1 && strcmp(argv[1], "--shut_down_xml") == 0) { - // TODO(vladl@google.com): Replace GetUnitTestImpl()->listeners() with - // UnitTest::GetInstance()->listeners() when the event listener API is - // published. - ::testing::internal::EventListeners& listeners = - *::testing::internal::GetUnitTestImpl()->listeners(); + EventListeners& listeners = UnitTest::GetInstance()->listeners(); delete listeners.Release(listeners.default_xml_generator()); } return RUN_ALL_TESTS(); |