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 @@
// 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
......
......@@ -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.
......
......@@ -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
......
......@@ -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++;
}
}
......
......@@ -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.
}
......
......@@ -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();
}
......
......@@ -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
......
......@@ -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) {
......
......@@ -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;
......
......@@ -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 {
......
......@@ -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();
}
......@@ -46,7 +46,6 @@ namespace testing {
namespace {
using internal::String;
using internal::TestProperty;
using internal::TestPropertyKeyIs;
using internal::Vector;
......
......@@ -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.
......
......@@ -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();
......
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