Commit b50ef44a by zhanyong.wan

Publishes the even listener API (by Vlad Losev); adds OS-indicating macros to…

Publishes the even listener API (by Vlad Losev); adds OS-indicating macros to simplify gtest code (by Zhanyong Wan).
parent 7fba282c
...@@ -77,7 +77,10 @@ ...@@ -77,7 +77,10 @@
// GTEST_OS_MAC - Mac OS X // GTEST_OS_MAC - Mac OS X
// GTEST_OS_SOLARIS - Sun Solaris // GTEST_OS_SOLARIS - Sun Solaris
// GTEST_OS_SYMBIAN - Symbian // 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 // GTEST_OS_ZOS - z/OS
// //
// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the // Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
...@@ -184,6 +187,13 @@ ...@@ -184,6 +187,13 @@
#define GTEST_OS_SYMBIAN 1 #define GTEST_OS_SYMBIAN 1
#elif defined _WIN32 #elif defined _WIN32
#define GTEST_OS_WINDOWS 1 #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__ #elif defined __APPLE__
#define GTEST_OS_MAC 1 #define GTEST_OS_MAC 1
#elif defined __linux__ #elif defined __linux__
...@@ -210,10 +220,10 @@ ...@@ -210,10 +220,10 @@
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
#ifndef _WIN32_WCE #if !GTEST_OS_WINDOWS_MOBILE
#include <direct.h> // NOLINT #include <direct.h> // NOLINT
#include <io.h> // NOLINT #include <io.h> // NOLINT
#endif // !_WIN32_WCE #endif
// <regex.h> is not available on Windows. Use our own simple regex // <regex.h> is not available on Windows. Use our own simple regex
// implementation instead. // implementation instead.
...@@ -449,11 +459,9 @@ ...@@ -449,11 +459,9 @@
// (this is covered by GTEST_HAS_STD_STRING guard). // (this is covered by GTEST_HAS_STD_STRING guard).
// 3. abort() in a VC 7.1 application compiled as GUI in debug config // 3. abort() in a VC 7.1 application compiled as GUI in debug config
// pops up a dialog window that cannot be suppressed programmatically. // pops up a dialog window that cannot be suppressed programmatically.
#if GTEST_HAS_STD_STRING && (GTEST_OS_LINUX || \ #if GTEST_HAS_STD_STRING && \
GTEST_OS_MAC || \ (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || \
GTEST_OS_CYGWIN || \ (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400))
(GTEST_OS_WINDOWS && (_MSC_VER >= 1400) && \
!defined(_WIN32_WCE)))
#define GTEST_HAS_DEATH_TEST 1 #define GTEST_HAS_DEATH_TEST 1
#include <vector> // NOLINT #include <vector> // NOLINT
#endif #endif
...@@ -835,29 +843,29 @@ inline int StrCaseCmp(const char* s1, const char* s2) { ...@@ -835,29 +843,29 @@ inline int StrCaseCmp(const char* s1, const char* s2) {
} }
inline char* StrDup(const char* src) { return strdup(src); } inline char* StrDup(const char* src) { return strdup(src); }
#else // !__BORLANDC__ #else // !__BORLANDC__
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
inline int IsATTY(int /* fd */) { return 0; } inline int IsATTY(int /* fd */) { return 0; }
#else // !_WIN32_WCE #else
inline int IsATTY(int fd) { return _isatty(fd); } 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) { inline int StrCaseCmp(const char* s1, const char* s2) {
return _stricmp(s1, s2); return _stricmp(s1, s2);
} }
inline char* StrDup(const char* src) { return _strdup(src); } inline char* StrDup(const char* src) { return _strdup(src); }
#endif // __BORLANDC__ #endif // __BORLANDC__
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); } inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
// time and thus not defined there. // time and thus not defined there.
#else // !_WIN32_WCE #else
inline int FileNo(FILE* file) { return _fileno(file); } inline int FileNo(FILE* file) { return _fileno(file); }
inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
inline int RmDir(const char* dir) { return _rmdir(dir); } inline int RmDir(const char* dir) { return _rmdir(dir); }
inline bool IsDir(const StatStruct& st) { inline bool IsDir(const StatStruct& st) {
return (_S_IFDIR & st.st_mode) != 0; return (_S_IFDIR & st.st_mode) != 0;
} }
#endif // _WIN32_WCE #endif // GTEST_OS_WINDOWS_MOBILE
#else #else
...@@ -891,20 +899,20 @@ inline const char* StrNCpy(char* dest, const char* src, size_t n) { ...@@ -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 // StrError() aren't needed on Windows CE at this time and thus not
// defined there. // defined there.
#ifndef _WIN32_WCE #if !GTEST_OS_WINDOWS_MOBILE
inline int ChDir(const char* dir) { return chdir(dir); } inline int ChDir(const char* dir) { return chdir(dir); }
#endif #endif
inline FILE* FOpen(const char* path, const char* mode) { inline FILE* FOpen(const char* path, const char* mode) {
return fopen(path, mode); return fopen(path, mode);
} }
#ifndef _WIN32_WCE #if !GTEST_OS_WINDOWS_MOBILE
inline FILE *FReopen(const char* path, const char* mode, FILE* stream) { inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
return freopen(path, mode, stream); return freopen(path, mode, stream);
} }
inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
#endif #endif
inline int FClose(FILE* fp) { return fclose(fp); } 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) { inline int Read(int fd, void* buf, unsigned int count) {
return static_cast<int>(read(fd, buf, count)); return static_cast<int>(read(fd, buf, count));
} }
...@@ -915,7 +923,8 @@ inline int Close(int fd) { return close(fd); } ...@@ -915,7 +923,8 @@ inline int Close(int fd) { return close(fd); }
inline const char* StrError(int errnum) { return strerror(errnum); } inline const char* StrError(int errnum) { return strerror(errnum); }
#endif #endif
inline const char* GetEnv(const char* name) { 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; return NULL;
#elif defined(__BORLANDC__) #elif defined(__BORLANDC__)
// Environment variables which we programmatically clear will be set to the // Environment variables which we programmatically clear will be set to the
...@@ -931,14 +940,14 @@ inline const char* GetEnv(const char* name) { ...@@ -931,14 +940,14 @@ inline const char* GetEnv(const char* name) {
#pragma warning(pop) // Restores the warning state. #pragma warning(pop) // Restores the warning state.
#endif #endif
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
// Windows CE has no C library. The abort() function is used in // Windows CE has no C library. The abort() function is used in
// several places in Google Test. This implementation provides a reasonable // several places in Google Test. This implementation provides a reasonable
// imitation of standard behaviour. // imitation of standard behaviour.
void Abort(); void Abort();
#else #else
inline void Abort() { abort(); } inline void Abort() { abort(); }
#endif // _WIN32_WCE #endif // GTEST_OS_WINDOWS_MOBILE
} // namespace posix } // namespace posix
......
...@@ -98,7 +98,7 @@ class String { ...@@ -98,7 +98,7 @@ class String {
// memory using malloc(). // memory using malloc().
static const char* CloneCString(const char* c_str); 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 // 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 // able to pass strings to Win32 APIs on CE we need to convert them
// to 'Unicode', UTF-16. // to 'Unicode', UTF-16.
......
...@@ -36,33 +36,14 @@ ...@@ -36,33 +36,14 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using ::testing::EmptyTestEventListener;
using ::testing::EventListeners;
using ::testing::InitGoogleTest; using ::testing::InitGoogleTest;
using ::testing::Test; using ::testing::Test;
using ::testing::TestCase;
using ::testing::TestInfo; using ::testing::TestInfo;
using ::testing::TestPartResult; using ::testing::TestPartResult;
using ::testing::UnitTest; 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 { namespace {
...@@ -142,8 +123,7 @@ int main(int argc, char **argv) { ...@@ -142,8 +123,7 @@ int main(int argc, char **argv) {
// If we are given the --check_for_leaks command line flag, installs the // If we are given the --check_for_leaks command line flag, installs the
// leak checker. // leak checker.
if (check_for_leaks) { if (check_for_leaks) {
EventListeners& listeners = UnitTestAccessor::listeners( EventListeners& listeners = UnitTest::GetInstance()->listeners();
UnitTest::GetInstance());
// Adds the leak checker to the end of the test event listener list, // Adds the leak checker to the end of the test event listener list,
// after the default text output printer and the default XML report // after the default text output printer and the default XML report
......
...@@ -36,38 +36,14 @@ ...@@ -36,38 +36,14 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using ::testing::EmptyTestEventListener;
using ::testing::EventListeners;
using ::testing::InitGoogleTest; using ::testing::InitGoogleTest;
using ::testing::Test; using ::testing::Test;
using ::testing::TestCase;
using ::testing::TestInfo; using ::testing::TestInfo;
using ::testing::TestPartResult; using ::testing::TestPartResult;
using ::testing::UnitTest; 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 { namespace {
...@@ -80,9 +56,7 @@ class TersePrinter : public EmptyTestEventListener { ...@@ -80,9 +56,7 @@ class TersePrinter : public EmptyTestEventListener {
// Called after all test activities have ended. // Called after all test activities have ended.
virtual void OnTestProgramEnd(const UnitTest& unit_test) { virtual void OnTestProgramEnd(const UnitTest& unit_test) {
fprintf(stdout, fprintf(stdout, "TEST %s\n", unit_test.Passed() ? "PASSED" : "FAILED");
"TEST %s\n",
UnitTestAccessor::Passed(unit_test) ? "PASSED" : "FAILED");
fflush(stdout); fflush(stdout);
} }
...@@ -141,11 +115,12 @@ int main(int argc, char **argv) { ...@@ -141,11 +115,12 @@ int main(int argc, char **argv) {
printf("%s\n", "Run this program with --terse_output to change the way " printf("%s\n", "Run this program with --terse_output to change the way "
"it prints its output."); "it prints its output.");
UnitTest& unit_test = *UnitTest::GetInstance();
// If we are given the --terse_output command line flag, suppresses the // If we are given the --terse_output command line flag, suppresses the
// standard output and attaches own result printer. // standard output and attaches own result printer.
if (terse_output) { if (terse_output) {
EventListeners& listeners = UnitTestAccessor::listeners( EventListeners& listeners = unit_test.listeners();
UnitTest::GetInstance());
// Removes the default console output listener from the list so it will // 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 // not receive events from Google Test and won't print any output. Since
...@@ -164,17 +139,14 @@ int main(int argc, char **argv) { ...@@ -164,17 +139,14 @@ int main(int argc, char **argv) {
// This is an example of using the UnitTest reflection API to inspect test // 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. // results. Here we discount failures from the tests we expected to fail.
int unexpectedly_failed_tests = 0; int unexpectedly_failed_tests = 0;
for (int i = 0; for (int i = 0; i < unit_test.total_test_case_count(); ++i) {
i < UnitTestAccessor::GetTotalTestCaseCount(*UnitTest::GetInstance()); const TestCase& test_case = *unit_test.GetTestCase(i);
++i) { for (int j = 0; j < test_case.total_test_count(); ++j) {
const TestCase* test_case = UnitTestAccessor::GetTestCase( const TestInfo& test_info = *test_case.GetTestInfo(j);
*UnitTest::GetInstance(), 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 // Counts failed tests that were not meant to fail (those without
// 'Fails' in the name). // 'Fails' in the name).
if (test_info->result()->Failed() && if (test_info.result()->Failed() &&
strcmp(test_info->name(), "Fails") != 0) { strcmp(test_info.name(), "Fails") != 0) {
unexpectedly_failed_tests++; unexpectedly_failed_tests++;
} }
} }
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include <stdlib.h> #include <stdlib.h>
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
#include <windows.h> #include <windows.h>
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
#include <direct.h> #include <direct.h>
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#else #else
#include <limits.h> #include <limits.h>
#include <climits> // Some Linux distributions define PATH_MAX here. #include <climits> // Some Linux distributions define PATH_MAX here.
#endif // _WIN32_WCE or _WIN32 #endif // GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
#define GTEST_PATH_MAX_ _MAX_PATH #define GTEST_PATH_MAX_ _MAX_PATH
...@@ -65,7 +65,7 @@ namespace internal { ...@@ -65,7 +65,7 @@ namespace internal {
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
const char kPathSeparator = '\\'; const char kPathSeparator = '\\';
const char kPathSeparatorString[] = "\\"; const char kPathSeparatorString[] = "\\";
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have a current directory. You should not use // Windows CE doesn't have a current directory. You should not use
// the current directory in tests on Windows CE, but this at least // the current directory in tests on Windows CE, but this at least
// provides a reasonable fallback. // provides a reasonable fallback.
...@@ -74,7 +74,7 @@ const char kCurrentDirectoryString[] = "\\"; ...@@ -74,7 +74,7 @@ const char kCurrentDirectoryString[] = "\\";
const DWORD kInvalidFileAttributes = 0xffffffff; const DWORD kInvalidFileAttributes = 0xffffffff;
#else #else
const char kCurrentDirectoryString[] = ".\\"; const char kCurrentDirectoryString[] = ".\\";
#endif // _WIN32_WCE #endif // GTEST_OS_WINDOWS_MOBILE
#else #else
const char kPathSeparator = '/'; const char kPathSeparator = '/';
const char kPathSeparatorString[] = "/"; const char kPathSeparatorString[] = "/";
...@@ -83,9 +83,9 @@ const char kCurrentDirectoryString[] = "./"; ...@@ -83,9 +83,9 @@ const char kCurrentDirectoryString[] = "./";
// Returns the current working directory, or "" if unsuccessful. // Returns the current working directory, or "" if unsuccessful.
FilePath FilePath::GetCurrentDir() { FilePath FilePath::GetCurrentDir() {
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have a current directory, so we just return // Windows CE doesn't have a current directory, so we just return
// something reasonable. // something reasonable.
return FilePath(kCurrentDirectoryString); return FilePath(kCurrentDirectoryString);
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
...@@ -93,7 +93,7 @@ FilePath FilePath::GetCurrentDir() { ...@@ -93,7 +93,7 @@ FilePath FilePath::GetCurrentDir() {
#else #else
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
return FilePath(getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd); 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. // Returns a copy of the FilePath with the case-insensitive extension removed.
...@@ -169,7 +169,7 @@ FilePath FilePath::ConcatPaths(const FilePath& directory, ...@@ -169,7 +169,7 @@ FilePath FilePath::ConcatPaths(const FilePath& directory,
// Returns true if pathname describes something findable in the file-system, // Returns true if pathname describes something findable in the file-system,
// either a file, directory, or whatever. // either a file, directory, or whatever.
bool FilePath::FileOrDirectoryExists() const { bool FilePath::FileOrDirectoryExists() const {
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str()); LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
const DWORD attributes = GetFileAttributes(unicode); const DWORD attributes = GetFileAttributes(unicode);
delete [] unicode; delete [] unicode;
...@@ -177,7 +177,7 @@ bool FilePath::FileOrDirectoryExists() const { ...@@ -177,7 +177,7 @@ bool FilePath::FileOrDirectoryExists() const {
#else #else
posix::StatStruct file_stat; posix::StatStruct file_stat;
return posix::Stat(pathname_.c_str(), &file_stat) == 0; 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 // Returns true if pathname describes a directory in the file-system
...@@ -193,7 +193,7 @@ bool FilePath::DirectoryExists() const { ...@@ -193,7 +193,7 @@ bool FilePath::DirectoryExists() const {
const FilePath& path(*this); const FilePath& path(*this);
#endif #endif
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
LPCWSTR unicode = String::AnsiToUtf16(path.c_str()); LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
const DWORD attributes = GetFileAttributes(unicode); const DWORD attributes = GetFileAttributes(unicode);
delete [] unicode; delete [] unicode;
...@@ -205,7 +205,7 @@ bool FilePath::DirectoryExists() const { ...@@ -205,7 +205,7 @@ bool FilePath::DirectoryExists() const {
posix::StatStruct file_stat; posix::StatStruct file_stat;
result = posix::Stat(path.c_str(), &file_stat) == 0 && result = posix::Stat(path.c_str(), &file_stat) == 0 &&
posix::IsDir(file_stat); posix::IsDir(file_stat);
#endif // _WIN32_WCE #endif // GTEST_OS_WINDOWS_MOBILE
return result; return result;
} }
...@@ -284,18 +284,17 @@ bool FilePath::CreateDirectoriesRecursively() const { ...@@ -284,18 +284,17 @@ bool FilePath::CreateDirectoriesRecursively() const {
// directory for any reason, including if the parent directory does not // directory for any reason, including if the parent directory does not
// exist. Not named "CreateDirectory" because that's a macro on Windows. // exist. Not named "CreateDirectory" because that's a macro on Windows.
bool FilePath::CreateFolder() const { bool FilePath::CreateFolder() const {
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS_MOBILE
#ifdef _WIN32_WCE
FilePath removed_sep(this->RemoveTrailingPathSeparator()); FilePath removed_sep(this->RemoveTrailingPathSeparator());
LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str()); LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
int result = CreateDirectory(unicode, NULL) ? 0 : -1; int result = CreateDirectory(unicode, NULL) ? 0 : -1;
delete [] unicode; delete [] unicode;
#else #elif GTEST_OS_WINDOWS
int result = _mkdir(pathname_.c_str()); int result = _mkdir(pathname_.c_str());
#endif // !WIN32_WCE
#else #else
int result = mkdir(pathname_.c_str(), 0777); int result = mkdir(pathname_.c_str(), 0777);
#endif // _WIN32 #endif // GTEST_OS_WINDOWS_MOBILE
if (result == -1) { if (result == -1) {
return this->DirectoryExists(); // An error is OK if the directory exists. return this->DirectoryExists(); // An error is OK if the directory exists.
} }
......
...@@ -1140,8 +1140,6 @@ class TestResultAccessor { ...@@ -1140,8 +1140,6 @@ class TestResultAccessor {
test_result->RecordProperty(property); test_result->RecordProperty(property);
} }
static bool Passed(const TestResult& result) { return result.Passed(); }
static void ClearTestPartResults(TestResult* test_result) { static void ClearTestPartResults(TestResult* test_result) {
test_result->ClearTestPartResults(); test_result->ClearTestPartResults();
} }
......
...@@ -35,14 +35,14 @@ ...@@ -35,14 +35,14 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS_MOBILE
#ifndef _WIN32_WCE #include <windows.h> // For TerminateProcess()
#elif GTEST_OS_WINDOWS
#include <io.h> #include <io.h>
#include <sys/stat.h> #include <sys/stat.h>
#endif // _WIN32_WCE
#else #else
#include <unistd.h> #include <unistd.h>
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_MAC #if GTEST_OS_MAC
#include <mach/mach_init.h> #include <mach/mach_init.h>
...@@ -50,10 +50,6 @@ ...@@ -50,10 +50,6 @@
#include <mach/vm_map.h> #include <mach/vm_map.h>
#endif // GTEST_OS_MAC #endif // GTEST_OS_MAC
#ifdef _WIN32_WCE
#include <windows.h> // For TerminateProcess()
#endif // _WIN32_WCE
#include <gtest/gtest-spi.h> #include <gtest/gtest-spi.h>
#include <gtest/gtest-message.h> #include <gtest/gtest-message.h>
#include <gtest/internal/gtest-string.h> #include <gtest/internal/gtest-string.h>
...@@ -449,7 +445,7 @@ class CapturedStderr { ...@@ -449,7 +445,7 @@ class CapturedStderr {
public: public:
// The ctor redirects stderr to a temporary file. // The ctor redirects stderr to a temporary file.
CapturedStderr() { CapturedStderr() {
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
// Not supported on Windows CE. // Not supported on Windows CE.
posix::Abort(); posix::Abort();
#else #else
...@@ -474,24 +470,24 @@ class CapturedStderr { ...@@ -474,24 +470,24 @@ class CapturedStderr {
fflush(NULL); fflush(NULL);
dup2(captured_fd, kStdErrFileno); dup2(captured_fd, kStdErrFileno);
close(captured_fd); close(captured_fd);
#endif // _WIN32_WCE #endif // GTEST_OS_WINDOWS_MOBILE
} }
~CapturedStderr() { ~CapturedStderr() {
#ifndef _WIN32_WCE #if !GTEST_OS_WINDOWS_MOBILE
remove(filename_.c_str()); remove(filename_.c_str());
#endif // _WIN32_WCE #endif // !GTEST_OS_WINDOWS_MOBILE
} }
// Stops redirecting stderr. // Stops redirecting stderr.
void StopCapture() { void StopCapture() {
#ifndef _WIN32_WCE #if !GTEST_OS_WINDOWS_MOBILE
// Restores the original stream. // Restores the original stream.
fflush(NULL); fflush(NULL);
dup2(uncaptured_fd_, kStdErrFileno); dup2(uncaptured_fd_, kStdErrFileno);
close(uncaptured_fd_); close(uncaptured_fd_);
uncaptured_fd_ = -1; uncaptured_fd_ = -1;
#endif // !_WIN32_WCE #endif // !GTEST_OS_WINDOWS_MOBILE
} }
// Returns the name of the temporary file holding the stderr output. // Returns the name of the temporary file holding the stderr output.
...@@ -573,14 +569,14 @@ const ::std::vector<String>& GetArgvs() { return g_argvs; } ...@@ -573,14 +569,14 @@ const ::std::vector<String>& GetArgvs() { return g_argvs; }
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
namespace posix { namespace posix {
void Abort() { void Abort() {
DebugBreak(); DebugBreak();
TerminateProcess(GetCurrentProcess(), 1); TerminateProcess(GetCurrentProcess(), 1);
} }
} // namespace posix } // namespace posix
#endif // _WIN32_WCE #endif // GTEST_OS_WINDOWS_MOBILE
// Returns the name of the environment variable corresponding to the // Returns the name of the environment variable corresponding to the
// given flag. For example, FlagToEnvVar("foo") will return // given flag. For example, FlagToEnvVar("foo") will return
......
...@@ -50,17 +50,17 @@ ...@@ -50,17 +50,17 @@
#include "src/gtest-internal-inl.h" #include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_ #undef GTEST_IMPLEMENTATION_
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
#include <windows.h> // NOLINT #include <windows.h> // NOLINT
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
#include <direct.h> // NOLINT #include <direct.h> // NOLINT
#endif // _WIN32_WCE #endif // GTEST_OS_WINDOWS_MOBILE
namespace testing { namespace testing {
namespace internal { namespace internal {
namespace { namespace {
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
// TODO(wan@google.com): Move these to the POSIX adapter section in // TODO(wan@google.com): Move these to the POSIX adapter section in
// gtest-port.h. // gtest-port.h.
...@@ -81,9 +81,7 @@ int _rmdir(const char* path) { ...@@ -81,9 +81,7 @@ int _rmdir(const char* path) {
return ret; return ret;
} }
#endif // _WIN32_WCE #else
#ifndef _WIN32_WCE
TEST(GetCurrentDirTest, ReturnsCurrentDir) { TEST(GetCurrentDirTest, ReturnsCurrentDir) {
const FilePath original_dir = FilePath::GetCurrentDir(); const FilePath original_dir = FilePath::GetCurrentDir();
...@@ -103,7 +101,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) { ...@@ -103,7 +101,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
#endif #endif
} }
#endif // _WIN32_WCE #endif // GTEST_OS_WINDOWS_MOBILE
TEST(IsEmptyTest, ReturnsTrueForEmptyPath) { TEST(IsEmptyTest, ReturnsTrueForEmptyPath) {
EXPECT_TRUE(FilePath("").IsEmpty()); EXPECT_TRUE(FilePath("").IsEmpty());
...@@ -156,7 +154,7 @@ TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) { ...@@ -156,7 +154,7 @@ TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) {
// RemoveFileName "" -> "./" // RemoveFileName "" -> "./"
TEST(RemoveFileNameTest, EmptyName) { TEST(RemoveFileNameTest, EmptyName) {
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
// On Windows CE, we use the root as the current directory. // On Windows CE, we use the root as the current directory.
EXPECT_STREQ(GTEST_PATH_SEP_, EXPECT_STREQ(GTEST_PATH_SEP_,
FilePath("").RemoveFileName().c_str()); FilePath("").RemoveFileName().c_str());
...@@ -344,12 +342,12 @@ TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) { ...@@ -344,12 +342,12 @@ TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
} }
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#ifndef _WIN32_WCE #if !GTEST_OS_WINDOWS_MOBILE
// Windows CE _does_ consider an empty directory to exist. // Windows CE _does_ consider an empty directory to exist.
TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) { TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
EXPECT_FALSE(FilePath("").DirectoryExists()); EXPECT_FALSE(FilePath("").DirectoryExists());
} }
#endif // ! _WIN32_WCE #endif // !GTEST_OS_WINDOWS_MOBILE
TEST(DirectoryTest, CurrentDirectoryExists) { TEST(DirectoryTest, CurrentDirectoryExists) {
#if GTEST_OS_WINDOWS // We are on Windows. #if GTEST_OS_WINDOWS // We are on Windows.
...@@ -449,9 +447,8 @@ class DirectoryCreationTest : public Test { ...@@ -449,9 +447,8 @@ class DirectoryCreationTest : public Test {
} }
String TempDir() const { String TempDir() const {
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
return String("\\temp\\"); return String("\\temp\\");
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
const char* temp_dir = posix::GetEnv("TEMP"); const char* temp_dir = posix::GetEnv("TEMP");
if (temp_dir == NULL || temp_dir[0] == '\0') if (temp_dir == NULL || temp_dir[0] == '\0')
...@@ -462,7 +459,7 @@ class DirectoryCreationTest : public Test { ...@@ -462,7 +459,7 @@ class DirectoryCreationTest : public Test {
return String::Format("%s\\", temp_dir); return String::Format("%s\\", temp_dir);
#else #else
return String("/tmp/"); return String("/tmp/");
#endif #endif // GTEST_OS_WINDOWS_MOBILE
} }
void CreateTextFile(const char* filename) { void CreateTextFile(const char* filename) {
......
...@@ -48,12 +48,12 @@ using ::testing::AddGlobalTestEnvironment; ...@@ -48,12 +48,12 @@ using ::testing::AddGlobalTestEnvironment;
using ::testing::Environment; using ::testing::Environment;
using ::testing::InitGoogleTest; using ::testing::InitGoogleTest;
using ::testing::Test; using ::testing::Test;
using ::testing::TestCase;
using ::testing::TestEventListener;
using ::testing::TestInfo; using ::testing::TestInfo;
using ::testing::TestPartResult; using ::testing::TestPartResult;
using ::testing::UnitTest; using ::testing::UnitTest;
using ::testing::internal::String; using ::testing::internal::String;
using ::testing::internal::TestCase;
using ::testing::internal::UnitTestEventListenerInterface;
using ::testing::internal::Vector; using ::testing::internal::Vector;
// Used by tests to register their events. // Used by tests to register their events.
...@@ -62,17 +62,7 @@ Vector<String>* g_events = NULL; ...@@ -62,17 +62,7 @@ Vector<String>* g_events = NULL;
namespace testing { namespace testing {
namespace internal { namespace internal {
// TODO(vladl@google.com): Remove this and use UnitTest::listeners() class EventRecordingListener : public TestEventListener {
// 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 {
public: public:
EventRecordingListener(const char* name) : name_(name) {} EventRecordingListener(const char* name) : name_(name) {}
...@@ -195,7 +185,6 @@ TEST_F(ListenerTest, DoesBar) { ...@@ -195,7 +185,6 @@ TEST_F(ListenerTest, DoesBar) {
using ::testing::internal::EnvironmentInvocationCatcher; using ::testing::internal::EnvironmentInvocationCatcher;
using ::testing::internal::EventRecordingListener; using ::testing::internal::EventRecordingListener;
using ::testing::internal::UnitTestAccessor;
void VerifyResults(const Vector<String>& data, void VerifyResults(const Vector<String>& data,
const char* const* expected_data, const char* const* expected_data,
...@@ -225,9 +214,9 @@ int main(int argc, char **argv) { ...@@ -225,9 +214,9 @@ int main(int argc, char **argv) {
g_events = &events; g_events = &events;
InitGoogleTest(&argc, argv); InitGoogleTest(&argc, argv);
UnitTestAccessor::GetEventListeners().Append( UnitTest::GetInstance()->listeners().Append(
new EventRecordingListener("1st")); new EventRecordingListener("1st"));
UnitTestAccessor::GetEventListeners().Append( UnitTest::GetInstance()->listeners().Append(
new EventRecordingListener("2nd")); new EventRecordingListener("2nd"));
AddGlobalTestEnvironment(new EnvironmentInvocationCatcher); AddGlobalTestEnvironment(new EnvironmentInvocationCatcher);
...@@ -326,7 +315,7 @@ int main(int argc, char **argv) { ...@@ -326,7 +315,7 @@ int main(int argc, char **argv) {
// We need to check manually for ad hoc test failures that happen after // We need to check manually for ad hoc test failures that happen after
// RUN_ALL_TESTS finishes. // RUN_ALL_TESTS finishes.
if (UnitTestAccessor::UnitTestFailed()) if (UnitTest::GetInstance()->Failed())
ret_val = 1; ret_val = 1;
return ret_val; return ret_val;
......
...@@ -40,11 +40,11 @@ ...@@ -40,11 +40,11 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
#include <windows.h> #include <windows.h>
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
#include <direct.h> #include <direct.h>
#endif // _WIN32_WCE #endif // GTEST_OS_WINDOWS_MOBILE
// Indicates that this translation unit is part of Google Test's // Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is // implementation. It must come before gtest-internal-inl.h is
...@@ -130,7 +130,7 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) { ...@@ -130,7 +130,7 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
TEST(OutputFileHelpersTest, GetCurrentExecutableName) { TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
const FilePath executable = GetCurrentExecutableName(); const FilePath executable = GetCurrentExecutableName();
const char* const exe_str = executable.c_str(); 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 || ASSERT_TRUE(_strcmpi("gtest-options_test", exe_str) == 0 ||
_strcmpi("gtest-options-ex_test", exe_str) == 0 || _strcmpi("gtest-options-ex_test", exe_str) == 0 ||
_strcmpi("gtest_all_test", exe_str) == 0) _strcmpi("gtest_all_test", exe_str) == 0)
...@@ -143,7 +143,7 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) { ...@@ -143,7 +143,7 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
String(exe_str) == "gtest_all_test" || String(exe_str) == "gtest_all_test" ||
String(exe_str) == "lt-gtest_all_test") String(exe_str) == "lt-gtest_all_test")
<< "GetCurrentExecutableName() returns " << exe_str; << "GetCurrentExecutableName() returns " << exe_str;
#endif #endif // GTEST_OS_WINDOWS
} }
class XmlOutputChangeDirTest : public Test { class XmlOutputChangeDirTest : public Test {
......
...@@ -38,21 +38,7 @@ ...@@ -38,21 +38,7 @@
#include <string.h> // For strcmp. #include <string.h> // For strcmp.
#include <algorithm> #include <algorithm>
using ::testing::AddGlobalTestEnvironment;
using ::testing::Environment;
using ::testing::InitGoogleTest; 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 testing {
namespace internal { namespace internal {
...@@ -64,20 +50,20 @@ struct LessByName { ...@@ -64,20 +50,20 @@ struct LessByName {
} }
}; };
class UnitTestAccessor { class UnitTestHelper {
public: public:
// Returns the array of pointers to all test cases sorted by the test case // Returns the array of pointers to all test cases sorted by the test case
// name. The caller is responsible for deleting the array. // name. The caller is responsible for deleting the array.
static TestCase const** const GetSortedTestCases() { static TestCase const** const GetSortedTestCases() {
UnitTest* unit_test = UnitTest::GetInstance(); UnitTest& unit_test = *UnitTest::GetInstance();
TestCase const** const test_cases = 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) for (int i = 0; i < unit_test.total_test_case_count(); ++i)
test_cases[i] = unit_test->GetTestCase(i); test_cases[i] = unit_test.GetTestCase(i);
std::sort(test_cases, std::sort(test_cases,
test_cases + unit_test->total_test_case_count(), test_cases + unit_test.total_test_case_count(),
LessByName<TestCase>()); LessByName<TestCase>());
return test_cases; return test_cases;
} }
...@@ -85,9 +71,9 @@ class UnitTestAccessor { ...@@ -85,9 +71,9 @@ class UnitTestAccessor {
// Returns the test case by its name. The caller doesn't own the returned // Returns the test case by its name. The caller doesn't own the returned
// pointer. // pointer.
static const TestCase* FindTestCase(const char* name) { static const TestCase* FindTestCase(const char* name) {
UnitTest* unit_test = UnitTest::GetInstance(); UnitTest& unit_test = *UnitTest::GetInstance();
for (int i = 0; i < unit_test->total_test_case_count(); ++i) { for (int i = 0; i < unit_test.total_test_case_count(); ++i) {
const TestCase* test_case = unit_test->GetTestCase(i); const TestCase* test_case = unit_test.GetTestCase(i);
if (0 == strcmp(test_case->name(), name)) if (0 == strcmp(test_case->name(), name))
return test_case; return test_case;
} }
...@@ -104,19 +90,12 @@ class UnitTestAccessor { ...@@ -104,19 +90,12 @@ class UnitTestAccessor {
for (int i = 0; i < test_case->total_test_count(); ++i) for (int i = 0; i < test_case->total_test_count(); ++i)
tests[i] = test_case->GetTestInfo(i); tests[i] = test_case->GetTestInfo(i);
std::sort(tests, std::sort(tests, tests + test_case->total_test_count(),
tests + test_case->total_test_count(),
LessByName<TestInfo>()); LessByName<TestInfo>());
return tests; 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 #if GTEST_HAS_TYPED_TEST
template <typename T> class TestCaseWithCommentTest : public Test {}; template <typename T> class TestCaseWithCommentTest : public Test {};
TYPED_TEST_CASE(TestCaseWithCommentTest, Types<int>); TYPED_TEST_CASE(TestCaseWithCommentTest, Types<int>);
...@@ -147,7 +126,7 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) { ...@@ -147,7 +126,7 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) {
EXPECT_EQ(5 + kTypedTests, unit_test->total_test_count()); EXPECT_EQ(5 + kTypedTests, unit_test->total_test_count());
EXPECT_EQ(3 + kTypedTests, unit_test->test_to_run_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("ApiTest", test_cases[0]->name());
EXPECT_STREQ("DISABLED_Test", test_cases[1]->name()); EXPECT_STREQ("DISABLED_Test", test_cases[1]->name());
...@@ -165,7 +144,7 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) { ...@@ -165,7 +144,7 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) {
} }
TEST(ApiTest, TestCaseImmutableAccessorsWork) { TEST(ApiTest, TestCaseImmutableAccessorsWork) {
const TestCase* test_case = UnitTestAccessor::FindTestCase("ApiTest"); const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest");
ASSERT_TRUE(test_case != NULL); ASSERT_TRUE(test_case != NULL);
EXPECT_STREQ("ApiTest", test_case->name()); EXPECT_STREQ("ApiTest", test_case->name());
...@@ -175,7 +154,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { ...@@ -175,7 +154,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) {
EXPECT_EQ(3, test_case->test_to_run_count()); EXPECT_EQ(3, test_case->test_to_run_count());
ASSERT_EQ(4, test_case->total_test_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("DISABLED_Dummy1", tests[0]->name());
EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); EXPECT_STREQ("ApiTest", tests[0]->test_case_name());
...@@ -205,7 +184,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { ...@@ -205,7 +184,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) {
tests = NULL; tests = NULL;
#if GTEST_HAS_TYPED_TEST #if GTEST_HAS_TYPED_TEST
test_case = UnitTestAccessor::FindTestCase("TestCaseWithCommentTest/0"); test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0");
ASSERT_TRUE(test_case != NULL); ASSERT_TRUE(test_case != NULL);
EXPECT_STREQ("TestCaseWithCommentTest/0", test_case->name()); EXPECT_STREQ("TestCaseWithCommentTest/0", test_case->name());
...@@ -215,7 +194,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { ...@@ -215,7 +194,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) {
EXPECT_EQ(1, test_case->test_to_run_count()); EXPECT_EQ(1, test_case->test_to_run_count());
ASSERT_EQ(1, test_case->total_test_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("Dummy", tests[0]->name());
EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name());
...@@ -229,7 +208,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { ...@@ -229,7 +208,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) {
} }
TEST(ApiTest, TestCaseDisabledAccessorsWork) { TEST(ApiTest, TestCaseDisabledAccessorsWork) {
const TestCase* test_case = UnitTestAccessor::FindTestCase("DISABLED_Test"); const TestCase* test_case = UnitTestHelper::FindTestCase("DISABLED_Test");
ASSERT_TRUE(test_case != NULL); ASSERT_TRUE(test_case != NULL);
EXPECT_STREQ("DISABLED_Test", test_case->name()); EXPECT_STREQ("DISABLED_Test", test_case->name());
...@@ -265,7 +244,7 @@ class FinalSuccessChecker : public Environment { ...@@ -265,7 +244,7 @@ class FinalSuccessChecker : public Environment {
EXPECT_FALSE(unit_test->Failed()); EXPECT_FALSE(unit_test->Failed());
ASSERT_EQ(2 + kTypedTestCases, unit_test->total_test_case_count()); 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("ApiTest", test_cases[0]->name());
EXPECT_STREQ("", test_cases[0]->comment()); EXPECT_STREQ("", test_cases[0]->comment());
...@@ -298,8 +277,8 @@ class FinalSuccessChecker : public Environment { ...@@ -298,8 +277,8 @@ class FinalSuccessChecker : public Environment {
EXPECT_FALSE(test_cases[2]->Failed()); EXPECT_FALSE(test_cases[2]->Failed());
#endif // GTEST_HAS_TYPED_TEST #endif // GTEST_HAS_TYPED_TEST
const TestCase* test_case = UnitTestAccessor::FindTestCase("ApiTest"); const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest");
const TestInfo** tests = UnitTestAccessor::GetSortedTests(test_case); const TestInfo** tests = UnitTestHelper::GetSortedTests(test_case);
EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name());
EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); EXPECT_STREQ("ApiTest", tests[0]->test_case_name());
EXPECT_FALSE(tests[0]->should_run()); EXPECT_FALSE(tests[0]->should_run());
...@@ -334,8 +313,8 @@ class FinalSuccessChecker : public Environment { ...@@ -334,8 +313,8 @@ class FinalSuccessChecker : public Environment {
delete[] tests; delete[] tests;
#if GTEST_HAS_TYPED_TEST #if GTEST_HAS_TYPED_TEST
test_case = UnitTestAccessor::FindTestCase("TestCaseWithCommentTest/0"); test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0");
tests = UnitTestAccessor::GetSortedTests(test_case); tests = UnitTestHelper::GetSortedTests(test_case);
EXPECT_STREQ("Dummy", tests[0]->name()); EXPECT_STREQ("Dummy", tests[0]->name());
EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name());
...@@ -352,12 +331,13 @@ class FinalSuccessChecker : public Environment { ...@@ -352,12 +331,13 @@ class FinalSuccessChecker : public Environment {
} }
}; };
} // namespace internal
} // namespace testing } // namespace testing
int main(int argc, char **argv) { int main(int argc, char **argv) {
InitGoogleTest(&argc, argv); InitGoogleTest(&argc, argv);
AddGlobalTestEnvironment(new testing::FinalSuccessChecker()); AddGlobalTestEnvironment(new testing::internal::FinalSuccessChecker());
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
...@@ -46,7 +46,6 @@ namespace testing { ...@@ -46,7 +46,6 @@ namespace testing {
namespace { namespace {
using internal::String; using internal::String;
using internal::TestProperty;
using internal::TestPropertyKeyIs; using internal::TestPropertyKeyIs;
using internal::Vector; using internal::Vector;
......
...@@ -88,16 +88,16 @@ bool ParseInt32Flag(const char* str, const char* flag, Int32* value); ...@@ -88,16 +88,16 @@ bool ParseInt32Flag(const char* str, const char* flag, Int32* value);
// that are needed to test it. // that are needed to test it.
class EventListenersAccessor { class EventListenersAccessor {
public: public:
static UnitTestEventListenerInterface* GetRepeater( static TestEventListener* GetRepeater(EventListeners* listeners) {
EventListeners* listeners) { return listeners->repeater(); } return listeners->repeater();
}
static void SetDefaultResultPrinter( static void SetDefaultResultPrinter(EventListeners* listeners,
EventListeners* listeners, TestEventListener* listener) {
UnitTestEventListenerInterface* listener) {
listeners->SetDefaultResultPrinter(listener); listeners->SetDefaultResultPrinter(listener);
} }
static void SetDefaultXmlGenerator(EventListeners* listeners, static void SetDefaultXmlGenerator(EventListeners* listeners,
UnitTestEventListenerInterface* listener) { TestEventListener* listener) {
listeners->SetDefaultXmlGenerator(listener); listeners->SetDefaultXmlGenerator(listener);
} }
...@@ -131,6 +131,8 @@ using testing::AssertionFailure; ...@@ -131,6 +131,8 @@ using testing::AssertionFailure;
using testing::AssertionResult; using testing::AssertionResult;
using testing::AssertionSuccess; using testing::AssertionSuccess;
using testing::DoubleLE; using testing::DoubleLE;
using testing::EmptyTestEventListener;
using testing::EventListeners;
using testing::FloatLE; using testing::FloatLE;
using testing::GTEST_FLAG(also_run_disabled_tests); using testing::GTEST_FLAG(also_run_disabled_tests);
using testing::GTEST_FLAG(break_on_failure); using testing::GTEST_FLAG(break_on_failure);
...@@ -153,16 +155,15 @@ using testing::Message; ...@@ -153,16 +155,15 @@ using testing::Message;
using testing::ScopedFakeTestPartResultReporter; using testing::ScopedFakeTestPartResultReporter;
using testing::StaticAssertTypeEq; using testing::StaticAssertTypeEq;
using testing::Test; using testing::Test;
using testing::TestCase;
using testing::TestPartResult; using testing::TestPartResult;
using testing::TestPartResultArray; using testing::TestPartResultArray;
using testing::TestProperty;
using testing::TestResult;
using testing::UnitTest; using testing::UnitTest;
using testing::internal::kMaxRandomSeed;
using testing::internal::kTestTypeIdInGoogleTest;
using testing::internal::AppendUserMessage; using testing::internal::AppendUserMessage;
using testing::internal::CodePointToUtf8; using testing::internal::CodePointToUtf8;
using testing::internal::EmptyTestEventListener;
using testing::internal::EqFailure; using testing::internal::EqFailure;
using testing::internal::EventListeners;
using testing::internal::FloatingPoint; using testing::internal::FloatingPoint;
using testing::internal::GTestFlagSaver; using testing::internal::GTestFlagSaver;
using testing::internal::GetCurrentOsStackTraceExceptTop; using testing::internal::GetCurrentOsStackTraceExceptTop;
...@@ -178,14 +179,12 @@ using testing::internal::ShouldShard; ...@@ -178,14 +179,12 @@ using testing::internal::ShouldShard;
using testing::internal::ShouldUseColor; using testing::internal::ShouldUseColor;
using testing::internal::StreamableToString; using testing::internal::StreamableToString;
using testing::internal::String; using testing::internal::String;
using testing::internal::TestCase;
using testing::internal::TestProperty;
using testing::internal::TestResult;
using testing::internal::TestResultAccessor; using testing::internal::TestResultAccessor;
using testing::internal::ThreadLocal; using testing::internal::ThreadLocal;
using testing::internal::UInt32; using testing::internal::UInt32;
using testing::internal::Vector; using testing::internal::Vector;
using testing::internal::WideStringToUtf8; using testing::internal::WideStringToUtf8;
using testing::internal::kMaxRandomSeed;
using testing::internal::kTestTypeIdInGoogleTest; using testing::internal::kTestTypeIdInGoogleTest;
using testing::internal::scoped_ptr; using testing::internal::scoped_ptr;
...@@ -1157,7 +1156,7 @@ TEST(StringTest, ShowWideCStringQuoted) { ...@@ -1157,7 +1156,7 @@ TEST(StringTest, ShowWideCStringQuoted) {
String::ShowWideCStringQuoted(L"foo").c_str()); String::ShowWideCStringQuoted(L"foo").c_str());
} }
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS_MOBILE
TEST(StringTest, AnsiAndUtf16Null) { TEST(StringTest, AnsiAndUtf16Null) {
EXPECT_EQ(NULL, String::AnsiToUtf16(NULL)); EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL)); EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
...@@ -1180,7 +1179,7 @@ TEST(StringTest, AnsiAndUtf16ConvertPathChars) { ...@@ -1180,7 +1179,7 @@ TEST(StringTest, AnsiAndUtf16ConvertPathChars) {
EXPECT_EQ(0, wcsncmp(L".:\\ \"*?", utf16, 3)); EXPECT_EQ(0, wcsncmp(L".:\\ \"*?", utf16, 3));
delete [] utf16; delete [] utf16;
} }
#endif // _WIN32_WCE #endif // GTEST_OS_WINDOWS_MOBILE
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
...@@ -1808,7 +1807,7 @@ TEST_F(GTestFlagSaverTest, VerifyGTestFlags) { ...@@ -1808,7 +1807,7 @@ TEST_F(GTestFlagSaverTest, VerifyGTestFlags) {
// value. If the value argument is "", unsets the environment // value. If the value argument is "", unsets the environment
// variable. The caller must ensure that both arguments are not NULL. // variable. The caller must ensure that both arguments are not NULL.
static void SetEnv(const char* name, const char* value) { 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. // Environment variables are not supported on Windows CE.
return; return;
#elif defined(__BORLANDC__) #elif defined(__BORLANDC__)
...@@ -1826,7 +1825,6 @@ static void SetEnv(const char* name, const char* value) { ...@@ -1826,7 +1825,6 @@ static void SetEnv(const char* name, const char* value) {
added_env[name] = new String((Message() << name << "=" << value).GetString()); added_env[name] = new String((Message() << name << "=" << value).GetString());
putenv(added_env[name]->c_str()); putenv(added_env[name]->c_str());
delete prev_env; delete prev_env;
#elif GTEST_OS_WINDOWS // If we are on Windows proper. #elif GTEST_OS_WINDOWS // If we are on Windows proper.
_putenv((Message() << name << "=" << value).GetString().c_str()); _putenv((Message() << name << "=" << value).GetString().c_str());
#else #else
...@@ -1835,10 +1833,10 @@ static void SetEnv(const char* name, const char* value) { ...@@ -1835,10 +1833,10 @@ static void SetEnv(const char* name, const char* value) {
} else { } else {
setenv(name, value, 1); 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. // Environment variables are not supported on Windows CE.
using testing::internal::Int32FromGTestEnv; using testing::internal::Int32FromGTestEnv;
...@@ -1886,7 +1884,7 @@ TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) { ...@@ -1886,7 +1884,7 @@ TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "-321"); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "-321");
EXPECT_EQ(-321, Int32FromGTestEnv("temp", 0)); EXPECT_EQ(-321, Int32FromGTestEnv("temp", 0));
} }
#endif // !defined(_WIN32_WCE) #endif // !GTEST_OS_WINDOWS_MOBILE
// Tests ParseInt32Flag(). // Tests ParseInt32Flag().
...@@ -1944,7 +1942,7 @@ TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) { ...@@ -1944,7 +1942,7 @@ TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
// Tests that Int32FromEnvOrDie() parses the value of the var or // Tests that Int32FromEnvOrDie() parses the value of the var or
// returns the correct default. // returns the correct default.
// Environment variables are not supported on Windows CE. // Environment variables are not supported on Windows CE.
#ifndef _WIN32_WCE #if !GTEST_OS_WINDOWS_MOBILE
TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333));
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123"); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123");
...@@ -1952,7 +1950,7 @@ TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { ...@@ -1952,7 +1950,7 @@ TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "-123"); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "-123");
EXPECT_EQ(-123, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); 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 // Tests that Int32FromEnvOrDie() aborts with an error message
// if the variable is not an Int32. // if the variable is not an Int32.
...@@ -2019,7 +2017,7 @@ TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) { ...@@ -2019,7 +2017,7 @@ TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
// Tests that sharding is enabled if total_shards > 1 and // Tests that sharding is enabled if total_shards > 1 and
// we are not in a death test subprocess. // we are not in a death test subprocess.
// Environment variables are not supported on Windows CE. // Environment variables are not supported on Windows CE.
#ifndef _WIN32_WCE #if !GTEST_OS_WINDOWS_MOBILE
TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) { TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
SetEnv(index_var_, "4"); SetEnv(index_var_, "4");
SetEnv(total_var_, "22"); SetEnv(total_var_, "22");
...@@ -2036,7 +2034,7 @@ TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) { ...@@ -2036,7 +2034,7 @@ TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
EXPECT_TRUE(ShouldShard(total_var_, index_var_, false)); EXPECT_TRUE(ShouldShard(total_var_, index_var_, false));
EXPECT_FALSE(ShouldShard(total_var_, index_var_, true)); 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. // Tests that we exit in error if the sharding values are not valid.
......
...@@ -40,19 +40,9 @@ ...@@ -40,19 +40,9 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
// TODO(vladl@google.com): Remove this include when the event listener API is using ::testing::EventListeners;
// 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::InitGoogleTest; using ::testing::InitGoogleTest;
using ::testing::UnitTest;
class SuccessfulTest : public testing::Test { class SuccessfulTest : public testing::Test {
}; };
...@@ -137,11 +127,7 @@ int main(int argc, char** argv) { ...@@ -137,11 +127,7 @@ int main(int argc, char** argv) {
InitGoogleTest(&argc, argv); InitGoogleTest(&argc, argv);
if (argc > 1 && strcmp(argv[1], "--shut_down_xml") == 0) { if (argc > 1 && strcmp(argv[1], "--shut_down_xml") == 0) {
// TODO(vladl@google.com): Replace GetUnitTestImpl()->listeners() with EventListeners& listeners = UnitTest::GetInstance()->listeners();
// UnitTest::GetInstance()->listeners() when the event listener API is
// published.
::testing::internal::EventListeners& listeners =
*::testing::internal::GetUnitTestImpl()->listeners();
delete listeners.Release(listeners.default_xml_generator()); delete listeners.Release(listeners.default_xml_generator());
} }
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment