mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
Merge gtest-1.6.0.
llvm-svn: 136212
This commit is contained in:
parent
8a0f9f17a3
commit
b02d795b0c
@ -1,14 +1,14 @@
|
||||
LLVM notes
|
||||
----------
|
||||
|
||||
This directory contains Google Test 1.5.0, with all elements removed except for
|
||||
This directory contains Google Test 1.6.0, with all elements removed except for
|
||||
the actual source code, to minimize the addition to the LLVM distribution.
|
||||
|
||||
Cleaned up as follows:
|
||||
|
||||
# Remove all the unnecessary files and directories
|
||||
$ rm -f aclocal* CMakeLists.txt configure* Makefile* CHANGES CONTRIBUTORS README
|
||||
$ rm -rf build-aux codegear fused-src m4 make msvc samples scripts test xcode
|
||||
$ rm -rf build-aux cmake codegear fused-src m4 make msvc samples scripts test xcode
|
||||
$ rm -f `find . -name \*\.pump`
|
||||
|
||||
# Move all the source files to the current directory
|
||||
@ -21,6 +21,8 @@ $ mv *.h include/gtest/internal/
|
||||
# Update paths to the included files
|
||||
$ perl -pi -e 's|^#include "src/|#include "gtest/internal/|' *.cc
|
||||
|
||||
$ rm -f gtest-all.cc gtest_main.cc
|
||||
|
||||
$ mv COPYING LICENSE.TXT
|
||||
|
||||
|
||||
|
@ -31,31 +31,31 @@
|
||||
//
|
||||
// This file implements death tests.
|
||||
|
||||
#include <gtest/gtest-death-test.h>
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include "gtest/gtest-death-test.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
#if GTEST_OS_MAC
|
||||
#include <crt_externs.h>
|
||||
#endif // GTEST_OS_MAC
|
||||
# if GTEST_OS_MAC
|
||||
# include <crt_externs.h>
|
||||
# endif // GTEST_OS_MAC
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
# include <errno.h>
|
||||
# include <fcntl.h>
|
||||
# include <limits.h>
|
||||
# include <stdarg.h>
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#include <sys/wait.h>
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS
|
||||
# include <windows.h>
|
||||
# else
|
||||
# include <sys/mman.h>
|
||||
# include <sys/wait.h>
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
#include <gtest/gtest-message.h>
|
||||
#include <gtest/internal/gtest-string.h>
|
||||
#include "gtest/gtest-message.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
// Indicates that this translation unit is part of Google Test's
|
||||
// implementation. It must come before gtest-internal-inl.h is
|
||||
@ -113,14 +113,18 @@ ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {
|
||||
|
||||
// ExitedWithCode function-call operator.
|
||||
bool ExitedWithCode::operator()(int exit_status) const {
|
||||
#if GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
return exit_status == exit_code_;
|
||||
#else
|
||||
|
||||
# else
|
||||
|
||||
return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_;
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
}
|
||||
|
||||
#if !GTEST_OS_WINDOWS
|
||||
# if !GTEST_OS_WINDOWS
|
||||
// KilledBySignal constructor.
|
||||
KilledBySignal::KilledBySignal(int signum) : signum_(signum) {
|
||||
}
|
||||
@ -129,7 +133,7 @@ KilledBySignal::KilledBySignal(int signum) : signum_(signum) {
|
||||
bool KilledBySignal::operator()(int exit_status) const {
|
||||
return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_;
|
||||
}
|
||||
#endif // !GTEST_OS_WINDOWS
|
||||
# endif // !GTEST_OS_WINDOWS
|
||||
|
||||
namespace internal {
|
||||
|
||||
@ -139,20 +143,25 @@ namespace internal {
|
||||
// specified by wait(2).
|
||||
static String ExitSummary(int exit_code) {
|
||||
Message m;
|
||||
#if GTEST_OS_WINDOWS
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
m << "Exited with exit status " << exit_code;
|
||||
#else
|
||||
|
||||
# else
|
||||
|
||||
if (WIFEXITED(exit_code)) {
|
||||
m << "Exited with exit status " << WEXITSTATUS(exit_code);
|
||||
} else if (WIFSIGNALED(exit_code)) {
|
||||
m << "Terminated by signal " << WTERMSIG(exit_code);
|
||||
}
|
||||
#ifdef WCOREDUMP
|
||||
# ifdef WCOREDUMP
|
||||
if (WCOREDUMP(exit_code)) {
|
||||
m << " (core dumped)";
|
||||
}
|
||||
#endif
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
# endif
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
||||
return m.GetString();
|
||||
}
|
||||
|
||||
@ -162,7 +171,7 @@ bool ExitedUnsuccessfully(int exit_status) {
|
||||
return !ExitedWithCode(0)(exit_status);
|
||||
}
|
||||
|
||||
#if !GTEST_OS_WINDOWS
|
||||
# if !GTEST_OS_WINDOWS
|
||||
// Generates a textual failure message when a death test finds more than
|
||||
// one thread running, or cannot determine the number of threads, prior
|
||||
// to executing the given statement. It is the responsibility of the
|
||||
@ -177,20 +186,24 @@ static String DeathTestThreadWarning(size_t thread_count) {
|
||||
msg << "detected " << thread_count << " threads.";
|
||||
return msg.GetString();
|
||||
}
|
||||
#endif // !GTEST_OS_WINDOWS
|
||||
# endif // !GTEST_OS_WINDOWS
|
||||
|
||||
// Flag characters for reporting a death test that did not die.
|
||||
static const char kDeathTestLived = 'L';
|
||||
static const char kDeathTestReturned = 'R';
|
||||
static const char kDeathTestThrew = 'T';
|
||||
static const char kDeathTestInternalError = 'I';
|
||||
|
||||
// An enumeration describing all of the possible ways that a death test
|
||||
// can conclude. DIED means that the process died while executing the
|
||||
// test code; LIVED means that process lived beyond the end of the test
|
||||
// code; and RETURNED means that the test statement attempted a "return,"
|
||||
// which is not allowed. IN_PROGRESS means the test has not yet
|
||||
// concluded.
|
||||
enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED };
|
||||
// An enumeration describing all of the possible ways that a death test can
|
||||
// conclude. DIED means that the process died while executing the test
|
||||
// code; LIVED means that process lived beyond the end of the test code;
|
||||
// RETURNED means that the test statement attempted to execute a return
|
||||
// statement, which is not allowed; THREW means that the test statement
|
||||
// returned control by throwing an exception. IN_PROGRESS means the test
|
||||
// has not yet concluded.
|
||||
// TODO(vladl@google.com): Unify names and possibly values for
|
||||
// AbortReason, DeathTestOutcome, and flag characters above.
|
||||
enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
|
||||
|
||||
// Routine for aborting the program which is safe to call from an
|
||||
// exec-style death test child process, in which case the error
|
||||
@ -212,13 +225,13 @@ void DeathTestAbort(const String& message) {
|
||||
} else {
|
||||
fprintf(stderr, "%s", message.c_str());
|
||||
fflush(stderr);
|
||||
abort();
|
||||
posix::Abort();
|
||||
}
|
||||
}
|
||||
|
||||
// A replacement for CHECK that calls DeathTestAbort if the assertion
|
||||
// fails.
|
||||
#define GTEST_DEATH_TEST_CHECK_(expression) \
|
||||
# define GTEST_DEATH_TEST_CHECK_(expression) \
|
||||
do { \
|
||||
if (!::testing::internal::IsTrue(expression)) { \
|
||||
DeathTestAbort(::testing::internal::String::Format( \
|
||||
@ -234,7 +247,7 @@ void DeathTestAbort(const String& message) {
|
||||
// evaluates the expression as long as it evaluates to -1 and sets
|
||||
// errno to EINTR. If the expression evaluates to -1 but errno is
|
||||
// something other than EINTR, DeathTestAbort is called.
|
||||
#define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \
|
||||
# define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \
|
||||
do { \
|
||||
int gtest_retval; \
|
||||
do { \
|
||||
@ -388,6 +401,9 @@ void DeathTestImpl::ReadAndInterpretStatusByte() {
|
||||
case kDeathTestReturned:
|
||||
set_outcome(RETURNED);
|
||||
break;
|
||||
case kDeathTestThrew:
|
||||
set_outcome(THREW);
|
||||
break;
|
||||
case kDeathTestLived:
|
||||
set_outcome(LIVED);
|
||||
break;
|
||||
@ -416,19 +432,46 @@ void DeathTestImpl::Abort(AbortReason reason) {
|
||||
// it finds any data in our pipe. So, here we write a single flag byte
|
||||
// to the pipe, then exit.
|
||||
const char status_ch =
|
||||
reason == TEST_DID_NOT_DIE ? kDeathTestLived : kDeathTestReturned;
|
||||
reason == TEST_DID_NOT_DIE ? kDeathTestLived :
|
||||
reason == TEST_THREW_EXCEPTION ? kDeathTestThrew : kDeathTestReturned;
|
||||
|
||||
GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Write(write_fd(), &status_ch, 1));
|
||||
GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Close(write_fd()));
|
||||
// We are leaking the descriptor here because on some platforms (i.e.,
|
||||
// when built as Windows DLL), destructors of global objects will still
|
||||
// run after calling _exit(). On such systems, write_fd_ will be
|
||||
// indirectly closed from the destructor of UnitTestImpl, causing double
|
||||
// close if it is also closed here. On debug configurations, double close
|
||||
// may assert. As there are no in-process buffers to flush here, we are
|
||||
// relying on the OS to close the descriptor after the process terminates
|
||||
// when the destructors are not run.
|
||||
_exit(1); // Exits w/o any normal exit hooks (we were supposed to crash)
|
||||
}
|
||||
|
||||
// Returns an indented copy of stderr output for a death test.
|
||||
// This makes distinguishing death test output lines from regular log lines
|
||||
// much easier.
|
||||
static ::std::string FormatDeathTestOutput(const ::std::string& output) {
|
||||
::std::string ret;
|
||||
for (size_t at = 0; ; ) {
|
||||
const size_t line_end = output.find('\n', at);
|
||||
ret += "[ DEATH ] ";
|
||||
if (line_end == ::std::string::npos) {
|
||||
ret += output.substr(at);
|
||||
break;
|
||||
}
|
||||
ret += output.substr(at, line_end + 1 - at);
|
||||
at = line_end + 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Assesses the success or failure of a death test, using both private
|
||||
// members which have previously been set, and one argument:
|
||||
//
|
||||
// Private data members:
|
||||
// outcome: An enumeration describing how the death test
|
||||
// concluded: DIED, LIVED, or RETURNED. The death test fails
|
||||
// in the latter two cases.
|
||||
// concluded: DIED, LIVED, THREW, or RETURNED. The death test
|
||||
// fails in the latter three cases.
|
||||
// status: The exit status of the child process. On *nix, it is in the
|
||||
// in the format specified by wait(2). On Windows, this is the
|
||||
// value supplied to the ExitProcess() API or a numeric code
|
||||
@ -457,11 +500,15 @@ bool DeathTestImpl::Passed(bool status_ok) {
|
||||
switch (outcome()) {
|
||||
case LIVED:
|
||||
buffer << " Result: failed to die.\n"
|
||||
<< " Error msg: " << error_message;
|
||||
<< " Error msg:\n" << FormatDeathTestOutput(error_message);
|
||||
break;
|
||||
case THREW:
|
||||
buffer << " Result: threw an exception.\n"
|
||||
<< " Error msg:\n" << FormatDeathTestOutput(error_message);
|
||||
break;
|
||||
case RETURNED:
|
||||
buffer << " Result: illegal return in test statement.\n"
|
||||
<< " Error msg: " << error_message;
|
||||
<< " Error msg:\n" << FormatDeathTestOutput(error_message);
|
||||
break;
|
||||
case DIED:
|
||||
if (status_ok) {
|
||||
@ -471,11 +518,12 @@ bool DeathTestImpl::Passed(bool status_ok) {
|
||||
} else {
|
||||
buffer << " Result: died but not with expected error.\n"
|
||||
<< " Expected: " << regex()->pattern() << "\n"
|
||||
<< "Actual msg: " << error_message;
|
||||
<< "Actual msg:\n" << FormatDeathTestOutput(error_message);
|
||||
}
|
||||
} else {
|
||||
buffer << " Result: died but not with expected exit code:\n"
|
||||
<< " " << ExitSummary(status()) << "\n";
|
||||
<< " " << ExitSummary(status()) << "\n"
|
||||
<< "Actual msg:\n" << FormatDeathTestOutput(error_message);
|
||||
}
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
@ -488,7 +536,7 @@ bool DeathTestImpl::Passed(bool status_ok) {
|
||||
return success;
|
||||
}
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS
|
||||
// WindowsDeathTest implements death tests on Windows. Due to the
|
||||
// specifics of starting new processes on Windows, death tests there are
|
||||
// always threadsafe, and Google Test considers the
|
||||
@ -519,11 +567,11 @@ bool DeathTestImpl::Passed(bool status_ok) {
|
||||
//
|
||||
class WindowsDeathTest : public DeathTestImpl {
|
||||
public:
|
||||
WindowsDeathTest(const char* statement,
|
||||
const RE* regex,
|
||||
WindowsDeathTest(const char* a_statement,
|
||||
const RE* a_regex,
|
||||
const char* file,
|
||||
int line)
|
||||
: DeathTestImpl(statement, regex), file_(file), line_(line) {}
|
||||
: DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {}
|
||||
|
||||
// All of these virtual functions are inherited from DeathTest.
|
||||
virtual int Wait();
|
||||
@ -580,12 +628,12 @@ int WindowsDeathTest::Wait() {
|
||||
GTEST_DEATH_TEST_CHECK_(
|
||||
WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(),
|
||||
INFINITE));
|
||||
DWORD status;
|
||||
GTEST_DEATH_TEST_CHECK_(::GetExitCodeProcess(child_handle_.Get(), &status)
|
||||
!= FALSE);
|
||||
DWORD status_code;
|
||||
GTEST_DEATH_TEST_CHECK_(
|
||||
::GetExitCodeProcess(child_handle_.Get(), &status_code) != FALSE);
|
||||
child_handle_.Reset();
|
||||
set_status(static_cast<int>(status));
|
||||
return this->status();
|
||||
set_status(static_cast<int>(status_code));
|
||||
return status();
|
||||
}
|
||||
|
||||
// The AssumeRole process for a Windows death test. It creates a child
|
||||
@ -684,7 +732,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
||||
set_spawned(true);
|
||||
return OVERSEE_TEST;
|
||||
}
|
||||
#else // We are not on Windows.
|
||||
# else // We are not on Windows.
|
||||
|
||||
// ForkingDeathTest provides implementations for most of the abstract
|
||||
// methods of the DeathTest interface. Only the AssumeRole method is
|
||||
@ -832,19 +880,19 @@ struct ExecDeathTestArgs {
|
||||
int close_fd; // File descriptor to close; the read end of a pipe
|
||||
};
|
||||
|
||||
#if GTEST_OS_MAC
|
||||
# if GTEST_OS_MAC
|
||||
inline char** GetEnviron() {
|
||||
// When Google Test is built as a framework on MacOS X, the environ variable
|
||||
// is unavailable. Apple's documentation (man environ) recommends using
|
||||
// _NSGetEnviron() instead.
|
||||
return *_NSGetEnviron();
|
||||
}
|
||||
#else
|
||||
# else
|
||||
// Some POSIX platforms expect you to declare environ. extern "C" makes
|
||||
// it reside in the global namespace.
|
||||
extern "C" char** environ;
|
||||
inline char** GetEnviron() { return environ; }
|
||||
#endif // GTEST_OS_MAC
|
||||
# endif // GTEST_OS_MAC
|
||||
|
||||
// The main function for a threadsafe-style death test child process.
|
||||
// This function is called in a clone()-ed process and thus must avoid
|
||||
@ -884,6 +932,11 @@ static int ExecDeathTestChildMain(void* child_arg) {
|
||||
// This could be accomplished more elegantly by a single recursive
|
||||
// function, but we want to guard against the unlikely possibility of
|
||||
// a smart compiler optimizing the recursion away.
|
||||
//
|
||||
// GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining
|
||||
// StackLowerThanAddress into StackGrowsDown, which then doesn't give
|
||||
// correct answer.
|
||||
bool StackLowerThanAddress(const void* ptr) GTEST_NO_INLINE_;
|
||||
bool StackLowerThanAddress(const void* ptr) {
|
||||
int dummy;
|
||||
return &dummy < ptr;
|
||||
@ -901,7 +954,7 @@ static pid_t ExecDeathTestFork(char* const* argv, int close_fd) {
|
||||
ExecDeathTestArgs args = { argv, close_fd };
|
||||
pid_t child_pid = -1;
|
||||
|
||||
#if GTEST_HAS_CLONE
|
||||
# if GTEST_HAS_CLONE
|
||||
const bool use_fork = GTEST_FLAG(death_test_use_fork);
|
||||
|
||||
if (!use_fork) {
|
||||
@ -918,9 +971,9 @@ static pid_t ExecDeathTestFork(char* const* argv, int close_fd) {
|
||||
|
||||
GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
|
||||
}
|
||||
#else
|
||||
# else
|
||||
const bool use_fork = true;
|
||||
#endif // GTEST_HAS_CLONE
|
||||
# endif // GTEST_HAS_CLONE
|
||||
|
||||
if (use_fork && (child_pid = fork()) == 0) {
|
||||
ExecDeathTestChildMain(&args);
|
||||
@ -981,7 +1034,7 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
|
||||
return OVERSEE_TEST;
|
||||
}
|
||||
|
||||
#endif // !GTEST_OS_WINDOWS
|
||||
# endif // !GTEST_OS_WINDOWS
|
||||
|
||||
// Creates a concrete DeathTest-derived class that depends on the
|
||||
// --gtest_death_test_style flag, and sets the pointer pointed to
|
||||
@ -1012,18 +1065,23 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
|
||||
}
|
||||
}
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
if (GTEST_FLAG(death_test_style) == "threadsafe" ||
|
||||
GTEST_FLAG(death_test_style) == "fast") {
|
||||
*test = new WindowsDeathTest(statement, regex, file, line);
|
||||
}
|
||||
#else
|
||||
|
||||
# else
|
||||
|
||||
if (GTEST_FLAG(death_test_style) == "threadsafe") {
|
||||
*test = new ExecDeathTest(statement, regex, file, line);
|
||||
} else if (GTEST_FLAG(death_test_style) == "fast") {
|
||||
*test = new NoExecDeathTest(statement, regex);
|
||||
}
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
||||
else { // NOLINT - this is more readable than unbalanced brackets inside #if.
|
||||
DeathTest::set_last_death_test_message(String::Format(
|
||||
"Unknown death test style \"%s\" encountered",
|
||||
@ -1054,7 +1112,7 @@ static void SplitString(const ::std::string& str, char delimiter,
|
||||
dest->swap(parsed);
|
||||
}
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS
|
||||
// Recreates the pipe and event handles from the provided parameters,
|
||||
// signals the event, and returns a file descriptor wrapped around the pipe
|
||||
// handle. This function is called in the child process only.
|
||||
@ -1118,7 +1176,7 @@ int GetStatusFileDescriptor(unsigned int parent_process_id,
|
||||
|
||||
return write_fd;
|
||||
}
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
||||
// Returns a newly created InternalRunDeathTestFlag object with fields
|
||||
// initialized from the GTEST_FLAG(internal_run_death_test) flag if
|
||||
@ -1134,7 +1192,8 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
|
||||
SplitString(GTEST_FLAG(internal_run_death_test).c_str(), '|', &fields);
|
||||
int write_fd = -1;
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
unsigned int parent_process_id = 0;
|
||||
size_t write_handle_as_size_t = 0;
|
||||
size_t event_handle_as_size_t = 0;
|
||||
@ -1152,7 +1211,8 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
|
||||
write_fd = GetStatusFileDescriptor(parent_process_id,
|
||||
write_handle_as_size_t,
|
||||
event_handle_as_size_t);
|
||||
#else
|
||||
# else
|
||||
|
||||
if (fields.size() != 4
|
||||
|| !ParseNaturalNumber(fields[1], &line)
|
||||
|| !ParseNaturalNumber(fields[2], &index)
|
||||
@ -1161,7 +1221,9 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
|
||||
"Bad --gtest_internal_run_death_test flag: %s",
|
||||
GTEST_FLAG(internal_run_death_test).c_str()));
|
||||
}
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
||||
return new InternalRunDeathTestFlag(fields[0], line, index, write_fd);
|
||||
}
|
||||
|
||||
|
@ -29,35 +29,35 @@
|
||||
//
|
||||
// Authors: keith.ray@gmail.com (Keith Ray)
|
||||
|
||||
#include <gtest/internal/gtest-filepath.h>
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include "gtest/internal/gtest-filepath.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
#include <windows.h>
|
||||
# include <windows.h>
|
||||
#elif GTEST_OS_WINDOWS
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#elif GTEST_OS_SYMBIAN
|
||||
// Symbian OpenC has PATH_MAX in sys/syslimits.h
|
||||
#include <sys/syslimits.h>
|
||||
# include <direct.h>
|
||||
# include <io.h>
|
||||
#elif GTEST_OS_SYMBIAN || GTEST_OS_NACL
|
||||
// Symbian OpenC and NaCl have PATH_MAX in sys/syslimits.h
|
||||
# include <sys/syslimits.h>
|
||||
#else
|
||||
#include <limits.h>
|
||||
#include <climits> // Some Linux distributions define PATH_MAX here.
|
||||
# include <limits.h>
|
||||
# include <climits> // Some Linux distributions define PATH_MAX here.
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
#define GTEST_PATH_MAX_ _MAX_PATH
|
||||
# define GTEST_PATH_MAX_ _MAX_PATH
|
||||
#elif defined(PATH_MAX)
|
||||
#define GTEST_PATH_MAX_ PATH_MAX
|
||||
# define GTEST_PATH_MAX_ PATH_MAX
|
||||
#elif defined(_XOPEN_PATH_MAX)
|
||||
#define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
|
||||
# define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
|
||||
#else
|
||||
#define GTEST_PATH_MAX_ _POSIX_PATH_MAX
|
||||
# define GTEST_PATH_MAX_ _POSIX_PATH_MAX
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
#include <gtest/internal/gtest-string.h>
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
@ -71,16 +71,16 @@ const char kPathSeparator = '\\';
|
||||
const char kAlternatePathSeparator = '/';
|
||||
const char kPathSeparatorString[] = "\\";
|
||||
const char kAlternatePathSeparatorString[] = "/";
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
# 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.
|
||||
const char kCurrentDirectoryString[] = "\\";
|
||||
// Windows CE doesn't define INVALID_FILE_ATTRIBUTES
|
||||
const DWORD kInvalidFileAttributes = 0xffffffff;
|
||||
#else
|
||||
# else
|
||||
const char kCurrentDirectoryString[] = ".\\";
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
# endif // GTEST_OS_WINDOWS_MOBILE
|
||||
#else
|
||||
const char kPathSeparator = '/';
|
||||
const char kPathSeparatorString[] = "/";
|
||||
|
@ -29,30 +29,32 @@
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if GTEST_OS_WINDOWS_MOBILE
|
||||
#include <windows.h> // For TerminateProcess()
|
||||
# include <windows.h> // For TerminateProcess()
|
||||
#elif GTEST_OS_WINDOWS
|
||||
#include <io.h>
|
||||
#include <sys/stat.h>
|
||||
# include <io.h>
|
||||
# include <sys/stat.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
# include <unistd.h>
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
#if GTEST_OS_MAC
|
||||
#include <mach/mach_init.h>
|
||||
#include <mach/task.h>
|
||||
#include <mach/vm_map.h>
|
||||
# include <mach/mach_init.h>
|
||||
# include <mach/task.h>
|
||||
# include <mach/vm_map.h>
|
||||
#endif // GTEST_OS_MAC
|
||||
|
||||
#include <gtest/gtest-spi.h>
|
||||
#include <gtest/gtest-message.h>
|
||||
#include <gtest/internal/gtest-string.h>
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "gtest/gtest-message.h"
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
// Indicates that this translation unit is part of Google Test's
|
||||
// implementation. It must come before gtest-internal-inl.h is
|
||||
@ -180,20 +182,20 @@ bool IsInSet(char ch, const char* str) {
|
||||
// Returns true iff ch belongs to the given classification. Unlike
|
||||
// similar functions in <ctype.h>, these aren't affected by the
|
||||
// current locale.
|
||||
bool IsDigit(char ch) { return '0' <= ch && ch <= '9'; }
|
||||
bool IsPunct(char ch) {
|
||||
bool IsAsciiDigit(char ch) { return '0' <= ch && ch <= '9'; }
|
||||
bool IsAsciiPunct(char ch) {
|
||||
return IsInSet(ch, "^-!\"#$%&'()*+,./:;<=>?@[\\]_`{|}~");
|
||||
}
|
||||
bool IsRepeat(char ch) { return IsInSet(ch, "?*+"); }
|
||||
bool IsWhiteSpace(char ch) { return IsInSet(ch, " \f\n\r\t\v"); }
|
||||
bool IsWordChar(char ch) {
|
||||
bool IsAsciiWhiteSpace(char ch) { return IsInSet(ch, " \f\n\r\t\v"); }
|
||||
bool IsAsciiWordChar(char ch) {
|
||||
return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') ||
|
||||
('0' <= ch && ch <= '9') || ch == '_';
|
||||
}
|
||||
|
||||
// Returns true iff "\\c" is a supported escape sequence.
|
||||
bool IsValidEscape(char c) {
|
||||
return (IsPunct(c) || IsInSet(c, "dDfnrsStvwW"));
|
||||
return (IsAsciiPunct(c) || IsInSet(c, "dDfnrsStvwW"));
|
||||
}
|
||||
|
||||
// Returns true iff the given atom (specified by escaped and pattern)
|
||||
@ -201,19 +203,19 @@ bool IsValidEscape(char c) {
|
||||
bool AtomMatchesChar(bool escaped, char pattern_char, char ch) {
|
||||
if (escaped) { // "\\p" where p is pattern_char.
|
||||
switch (pattern_char) {
|
||||
case 'd': return IsDigit(ch);
|
||||
case 'D': return !IsDigit(ch);
|
||||
case 'd': return IsAsciiDigit(ch);
|
||||
case 'D': return !IsAsciiDigit(ch);
|
||||
case 'f': return ch == '\f';
|
||||
case 'n': return ch == '\n';
|
||||
case 'r': return ch == '\r';
|
||||
case 's': return IsWhiteSpace(ch);
|
||||
case 'S': return !IsWhiteSpace(ch);
|
||||
case 's': return IsAsciiWhiteSpace(ch);
|
||||
case 'S': return !IsAsciiWhiteSpace(ch);
|
||||
case 't': return ch == '\t';
|
||||
case 'v': return ch == '\v';
|
||||
case 'w': return IsWordChar(ch);
|
||||
case 'W': return !IsWordChar(ch);
|
||||
case 'w': return IsAsciiWordChar(ch);
|
||||
case 'W': return !IsAsciiWordChar(ch);
|
||||
}
|
||||
return IsPunct(pattern_char) && pattern_char == ch;
|
||||
return IsAsciiPunct(pattern_char) && pattern_char == ch;
|
||||
}
|
||||
|
||||
return (pattern_char == '.' && ch != '\n') || pattern_char == ch;
|
||||
@ -422,6 +424,38 @@ void RE::Init(const char* regex) {
|
||||
|
||||
#endif // GTEST_USES_POSIX_RE
|
||||
|
||||
const char kUnknownFile[] = "unknown file";
|
||||
|
||||
// Formats a source file path and a line number as they would appear
|
||||
// in an error message from the compiler used to compile this code.
|
||||
GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {
|
||||
const char* const file_name = file == NULL ? kUnknownFile : file;
|
||||
|
||||
if (line < 0) {
|
||||
return String::Format("%s:", file_name).c_str();
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
return String::Format("%s(%d):", file_name, line).c_str();
|
||||
#else
|
||||
return String::Format("%s:%d:", file_name, line).c_str();
|
||||
#endif // _MSC_VER
|
||||
}
|
||||
|
||||
// Formats a file location for compiler-independent XML output.
|
||||
// Although this function is not platform dependent, we put it next to
|
||||
// FormatFileLocation in order to contrast the two functions.
|
||||
// Note that FormatCompilerIndependentFileLocation() does NOT append colon
|
||||
// to the file location it produces, unlike FormatFileLocation().
|
||||
GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(
|
||||
const char* file, int line) {
|
||||
const char* const file_name = file == NULL ? kUnknownFile : file;
|
||||
|
||||
if (line < 0)
|
||||
return file_name;
|
||||
else
|
||||
return String::Format("%s:%d", file_name, line).c_str();
|
||||
}
|
||||
|
||||
|
||||
GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line)
|
||||
: severity_(severity) {
|
||||
@ -444,18 +478,19 @@ GTestLog::~GTestLog() {
|
||||
// Disable Microsoft deprecation warnings for POSIX functions called from
|
||||
// this class (creat, dup, dup2, and close)
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4996)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4996)
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if GTEST_HAS_STREAM_REDIRECTION_
|
||||
#if GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
// Object that captures an output stream (stdout/stderr).
|
||||
class CapturedStream {
|
||||
public:
|
||||
// The ctor redirects the stream to a temporary file.
|
||||
CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
|
||||
#if GTEST_OS_WINDOWS
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT
|
||||
char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT
|
||||
|
||||
@ -470,14 +505,14 @@ class CapturedStream {
|
||||
GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file "
|
||||
<< temp_file_path;
|
||||
filename_ = temp_file_path;
|
||||
#else
|
||||
# else
|
||||
// There's no guarantee that a test has write access to the
|
||||
// current directory, so we create the temporary file in the /tmp
|
||||
// directory instead.
|
||||
char name_template[] = "/tmp/captured_stream.XXXXXX";
|
||||
const int captured_fd = mkstemp(name_template);
|
||||
filename_ = name_template;
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
fflush(NULL);
|
||||
dup2(captured_fd, fd_);
|
||||
close(captured_fd);
|
||||
@ -546,9 +581,9 @@ String CapturedStream::ReadEntireFile(FILE* file) {
|
||||
return content;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif // _MSC_VER
|
||||
# ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
# endif // _MSC_VER
|
||||
|
||||
static CapturedStream* g_captured_stderr = NULL;
|
||||
static CapturedStream* g_captured_stdout = NULL;
|
||||
@ -588,7 +623,7 @@ String GetCapturedStdout() { return GetCapturedStream(&g_captured_stdout); }
|
||||
// Stops capturing stderr and returns the captured string.
|
||||
String GetCapturedStderr() { return GetCapturedStream(&g_captured_stderr); }
|
||||
|
||||
#endif // GTEST_HAS_STREAM_REDIRECTION_
|
||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
@ -618,7 +653,7 @@ static String FlagToEnvVar(const char* flag) {
|
||||
|
||||
Message env_var;
|
||||
for (size_t i = 0; i != full_flag.length(); i++) {
|
||||
env_var << static_cast<char>(toupper(full_flag.c_str()[i]));
|
||||
env_var << ToUpper(full_flag.c_str()[i]);
|
||||
}
|
||||
|
||||
return env_var.GetString();
|
||||
|
356
utils/unittest/googletest/gtest-printers.cc
Normal file
356
utils/unittest/googletest/gtest-printers.cc
Normal file
@ -0,0 +1,356 @@
|
||||
// Copyright 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
// Google Test - The Google C++ Testing Framework
|
||||
//
|
||||
// This file implements a universal value printer that can print a
|
||||
// value of any type T:
|
||||
//
|
||||
// void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
|
||||
//
|
||||
// It uses the << operator when possible, and prints the bytes in the
|
||||
// object otherwise. A user can override its behavior for a class
|
||||
// type Foo by defining either operator<<(::std::ostream&, const Foo&)
|
||||
// or void PrintTo(const Foo&, ::std::ostream*) in the namespace that
|
||||
// defines Foo.
|
||||
|
||||
#include "gtest/gtest-printers.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <ostream> // NOLINT
|
||||
#include <string>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
namespace {
|
||||
|
||||
using ::std::ostream;
|
||||
|
||||
#if GTEST_OS_WINDOWS_MOBILE // Windows CE does not define _snprintf_s.
|
||||
# define snprintf _snprintf
|
||||
#elif _MSC_VER >= 1400 // VC 8.0 and later deprecate snprintf and _snprintf.
|
||||
# define snprintf _snprintf_s
|
||||
#elif _MSC_VER
|
||||
# define snprintf _snprintf
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
// Prints a segment of bytes in the given object.
|
||||
void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
|
||||
size_t count, ostream* os) {
|
||||
char text[5] = "";
|
||||
for (size_t i = 0; i != count; i++) {
|
||||
const size_t j = start + i;
|
||||
if (i != 0) {
|
||||
// Organizes the bytes into groups of 2 for easy parsing by
|
||||
// human.
|
||||
if ((j % 2) == 0)
|
||||
*os << ' ';
|
||||
else
|
||||
*os << '-';
|
||||
}
|
||||
snprintf(text, sizeof(text), "%02X", obj_bytes[j]);
|
||||
*os << text;
|
||||
}
|
||||
}
|
||||
|
||||
// Prints the bytes in the given value to the given ostream.
|
||||
void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,
|
||||
ostream* os) {
|
||||
// Tells the user how big the object is.
|
||||
*os << count << "-byte object <";
|
||||
|
||||
const size_t kThreshold = 132;
|
||||
const size_t kChunkSize = 64;
|
||||
// If the object size is bigger than kThreshold, we'll have to omit
|
||||
// some details by printing only the first and the last kChunkSize
|
||||
// bytes.
|
||||
// TODO(wan): let the user control the threshold using a flag.
|
||||
if (count < kThreshold) {
|
||||
PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
|
||||
} else {
|
||||
PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);
|
||||
*os << " ... ";
|
||||
// Rounds up to 2-byte boundary.
|
||||
const size_t resume_pos = (count - kChunkSize + 1)/2*2;
|
||||
PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os);
|
||||
}
|
||||
*os << ">";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace internal2 {
|
||||
|
||||
// Delegates to PrintBytesInObjectToImpl() to print the bytes in the
|
||||
// given object. The delegation simplifies the implementation, which
|
||||
// uses the << operator and thus is easier done outside of the
|
||||
// ::testing::internal namespace, which contains a << operator that
|
||||
// sometimes conflicts with the one in STL.
|
||||
void PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count,
|
||||
ostream* os) {
|
||||
PrintBytesInObjectToImpl(obj_bytes, count, os);
|
||||
}
|
||||
|
||||
} // namespace internal2
|
||||
|
||||
namespace internal {
|
||||
|
||||
// Depending on the value of a char (or wchar_t), we print it in one
|
||||
// of three formats:
|
||||
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
|
||||
// - as a hexidecimal escape sequence (e.g. '\x7F'), or
|
||||
// - as a special escape sequence (e.g. '\r', '\n').
|
||||
enum CharFormat {
|
||||
kAsIs,
|
||||
kHexEscape,
|
||||
kSpecialEscape
|
||||
};
|
||||
|
||||
// Returns true if c is a printable ASCII character. We test the
|
||||
// value of c directly instead of calling isprint(), which is buggy on
|
||||
// Windows Mobile.
|
||||
inline bool IsPrintableAscii(wchar_t c) {
|
||||
return 0x20 <= c && c <= 0x7E;
|
||||
}
|
||||
|
||||
// Prints a wide or narrow char c as a character literal without the
|
||||
// quotes, escaping it when necessary; returns how c was formatted.
|
||||
// The template argument UnsignedChar is the unsigned version of Char,
|
||||
// which is the type of c.
|
||||
template <typename UnsignedChar, typename Char>
|
||||
static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {
|
||||
switch (static_cast<wchar_t>(c)) {
|
||||
case L'\0':
|
||||
*os << "\\0";
|
||||
break;
|
||||
case L'\'':
|
||||
*os << "\\'";
|
||||
break;
|
||||
case L'\\':
|
||||
*os << "\\\\";
|
||||
break;
|
||||
case L'\a':
|
||||
*os << "\\a";
|
||||
break;
|
||||
case L'\b':
|
||||
*os << "\\b";
|
||||
break;
|
||||
case L'\f':
|
||||
*os << "\\f";
|
||||
break;
|
||||
case L'\n':
|
||||
*os << "\\n";
|
||||
break;
|
||||
case L'\r':
|
||||
*os << "\\r";
|
||||
break;
|
||||
case L'\t':
|
||||
*os << "\\t";
|
||||
break;
|
||||
case L'\v':
|
||||
*os << "\\v";
|
||||
break;
|
||||
default:
|
||||
if (IsPrintableAscii(c)) {
|
||||
*os << static_cast<char>(c);
|
||||
return kAsIs;
|
||||
} else {
|
||||
*os << String::Format("\\x%X", static_cast<UnsignedChar>(c));
|
||||
return kHexEscape;
|
||||
}
|
||||
}
|
||||
return kSpecialEscape;
|
||||
}
|
||||
|
||||
// Prints a char c as if it's part of a string literal, escaping it when
|
||||
// necessary; returns how c was formatted.
|
||||
static CharFormat PrintAsWideStringLiteralTo(wchar_t c, ostream* os) {
|
||||
switch (c) {
|
||||
case L'\'':
|
||||
*os << "'";
|
||||
return kAsIs;
|
||||
case L'"':
|
||||
*os << "\\\"";
|
||||
return kSpecialEscape;
|
||||
default:
|
||||
return PrintAsCharLiteralTo<wchar_t>(c, os);
|
||||
}
|
||||
}
|
||||
|
||||
// Prints a char c as if it's part of a string literal, escaping it when
|
||||
// necessary; returns how c was formatted.
|
||||
static CharFormat PrintAsNarrowStringLiteralTo(char c, ostream* os) {
|
||||
return PrintAsWideStringLiteralTo(static_cast<unsigned char>(c), os);
|
||||
}
|
||||
|
||||
// Prints a wide or narrow character c and its code. '\0' is printed
|
||||
// as "'\\0'", other unprintable characters are also properly escaped
|
||||
// using the standard C++ escape sequence. The template argument
|
||||
// UnsignedChar is the unsigned version of Char, which is the type of c.
|
||||
template <typename UnsignedChar, typename Char>
|
||||
void PrintCharAndCodeTo(Char c, ostream* os) {
|
||||
// First, print c as a literal in the most readable form we can find.
|
||||
*os << ((sizeof(c) > 1) ? "L'" : "'");
|
||||
const CharFormat format = PrintAsCharLiteralTo<UnsignedChar>(c, os);
|
||||
*os << "'";
|
||||
|
||||
// To aid user debugging, we also print c's code in decimal, unless
|
||||
// it's 0 (in which case c was printed as '\\0', making the code
|
||||
// obvious).
|
||||
if (c == 0)
|
||||
return;
|
||||
*os << " (" << String::Format("%d", c).c_str();
|
||||
|
||||
// For more convenience, we print c's code again in hexidecimal,
|
||||
// unless c was already printed in the form '\x##' or the code is in
|
||||
// [1, 9].
|
||||
if (format == kHexEscape || (1 <= c && c <= 9)) {
|
||||
// Do nothing.
|
||||
} else {
|
||||
*os << String::Format(", 0x%X",
|
||||
static_cast<UnsignedChar>(c)).c_str();
|
||||
}
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
void PrintTo(unsigned char c, ::std::ostream* os) {
|
||||
PrintCharAndCodeTo<unsigned char>(c, os);
|
||||
}
|
||||
void PrintTo(signed char c, ::std::ostream* os) {
|
||||
PrintCharAndCodeTo<unsigned char>(c, os);
|
||||
}
|
||||
|
||||
// Prints a wchar_t as a symbol if it is printable or as its internal
|
||||
// code otherwise and also as its code. L'\0' is printed as "L'\\0'".
|
||||
void PrintTo(wchar_t wc, ostream* os) {
|
||||
PrintCharAndCodeTo<wchar_t>(wc, os);
|
||||
}
|
||||
|
||||
// Prints the given array of characters to the ostream.
|
||||
// The array starts at *begin, the length is len, it may include '\0' characters
|
||||
// and may not be null-terminated.
|
||||
static void PrintCharsAsStringTo(const char* begin, size_t len, ostream* os) {
|
||||
*os << "\"";
|
||||
bool is_previous_hex = false;
|
||||
for (size_t index = 0; index < len; ++index) {
|
||||
const char cur = begin[index];
|
||||
if (is_previous_hex && IsXDigit(cur)) {
|
||||
// Previous character is of '\x..' form and this character can be
|
||||
// interpreted as another hexadecimal digit in its number. Break string to
|
||||
// disambiguate.
|
||||
*os << "\" \"";
|
||||
}
|
||||
is_previous_hex = PrintAsNarrowStringLiteralTo(cur, os) == kHexEscape;
|
||||
}
|
||||
*os << "\"";
|
||||
}
|
||||
|
||||
// Prints a (const) char array of 'len' elements, starting at address 'begin'.
|
||||
void UniversalPrintArray(const char* begin, size_t len, ostream* os) {
|
||||
PrintCharsAsStringTo(begin, len, os);
|
||||
}
|
||||
|
||||
// Prints the given array of wide characters to the ostream.
|
||||
// The array starts at *begin, the length is len, it may include L'\0'
|
||||
// characters and may not be null-terminated.
|
||||
static void PrintWideCharsAsStringTo(const wchar_t* begin, size_t len,
|
||||
ostream* os) {
|
||||
*os << "L\"";
|
||||
bool is_previous_hex = false;
|
||||
for (size_t index = 0; index < len; ++index) {
|
||||
const wchar_t cur = begin[index];
|
||||
if (is_previous_hex && isascii(cur) && IsXDigit(static_cast<char>(cur))) {
|
||||
// Previous character is of '\x..' form and this character can be
|
||||
// interpreted as another hexadecimal digit in its number. Break string to
|
||||
// disambiguate.
|
||||
*os << "\" L\"";
|
||||
}
|
||||
is_previous_hex = PrintAsWideStringLiteralTo(cur, os) == kHexEscape;
|
||||
}
|
||||
*os << "\"";
|
||||
}
|
||||
|
||||
// Prints the given C string to the ostream.
|
||||
void PrintTo(const char* s, ostream* os) {
|
||||
if (s == NULL) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
*os << ImplicitCast_<const void*>(s) << " pointing to ";
|
||||
PrintCharsAsStringTo(s, strlen(s), os);
|
||||
}
|
||||
}
|
||||
|
||||
// MSVC compiler can be configured to define whar_t as a typedef
|
||||
// of unsigned short. Defining an overload for const wchar_t* in that case
|
||||
// would cause pointers to unsigned shorts be printed as wide strings,
|
||||
// possibly accessing more memory than intended and causing invalid
|
||||
// memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
|
||||
// wchar_t is implemented as a native type.
|
||||
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
|
||||
// Prints the given wide C string to the ostream.
|
||||
void PrintTo(const wchar_t* s, ostream* os) {
|
||||
if (s == NULL) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
*os << ImplicitCast_<const void*>(s) << " pointing to ";
|
||||
PrintWideCharsAsStringTo(s, wcslen(s), os);
|
||||
}
|
||||
}
|
||||
#endif // wchar_t is native
|
||||
|
||||
// Prints a ::string object.
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
void PrintStringTo(const ::string& s, ostream* os) {
|
||||
PrintCharsAsStringTo(s.data(), s.size(), os);
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
void PrintStringTo(const ::std::string& s, ostream* os) {
|
||||
PrintCharsAsStringTo(s.data(), s.size(), os);
|
||||
}
|
||||
|
||||
// Prints a ::wstring object.
|
||||
#if GTEST_HAS_GLOBAL_WSTRING
|
||||
void PrintWideStringTo(const ::wstring& s, ostream* os) {
|
||||
PrintWideCharsAsStringTo(s.data(), s.size(), os);
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_WSTRING
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
void PrintWideStringTo(const ::std::wstring& s, ostream* os) {
|
||||
PrintWideCharsAsStringTo(s.data(), s.size(), os);
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
} // namespace internal
|
||||
|
||||
} // namespace testing
|
@ -31,7 +31,7 @@
|
||||
//
|
||||
// The Google C++ Testing Framework (Google Test)
|
||||
|
||||
#include <gtest/gtest-test-part.h>
|
||||
#include "gtest/gtest-test-part.h"
|
||||
|
||||
// Indicates that this translation unit is part of Google Test's
|
||||
// implementation. It must come before gtest-internal-inl.h is
|
||||
|
@ -29,8 +29,8 @@
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
#include <gtest/gtest-typed-test.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "gtest/gtest-typed-test.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
@ -40,7 +40,7 @@ namespace internal {
|
||||
// Skips to the first non-space char in str. Returns an empty string if str
|
||||
// contains only whitespace characters.
|
||||
static const char* SkipSpaces(const char* str) {
|
||||
while (isspace(*str))
|
||||
while (IsSpace(*str))
|
||||
str++;
|
||||
return str;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,7 +38,7 @@
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
|
||||
|
||||
#include <gtest/internal/gtest-death-test-internal.h>
|
||||
#include "gtest/internal/gtest-death-test-internal.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
@ -154,24 +154,24 @@ GTEST_DECLARE_string_(death_test_style);
|
||||
// Asserts that a given statement causes the program to exit, with an
|
||||
// integer exit status that satisfies predicate, and emitting error output
|
||||
// that matches regex.
|
||||
#define ASSERT_EXIT(statement, predicate, regex) \
|
||||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
|
||||
# define ASSERT_EXIT(statement, predicate, regex) \
|
||||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
|
||||
|
||||
// Like ASSERT_EXIT, but continues on to successive tests in the
|
||||
// test case, if any:
|
||||
#define EXPECT_EXIT(statement, predicate, regex) \
|
||||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
|
||||
# define EXPECT_EXIT(statement, predicate, regex) \
|
||||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
|
||||
|
||||
// Asserts that a given statement causes the program to exit, either by
|
||||
// explicitly exiting with a nonzero exit code or being killed by a
|
||||
// signal, and emitting error output that matches regex.
|
||||
#define ASSERT_DEATH(statement, regex) \
|
||||
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
||||
# define ASSERT_DEATH(statement, regex) \
|
||||
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
||||
|
||||
// Like ASSERT_DEATH, but continues on to successive tests in the
|
||||
// test case, if any:
|
||||
#define EXPECT_DEATH(statement, regex) \
|
||||
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
||||
# define EXPECT_DEATH(statement, regex) \
|
||||
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
||||
|
||||
// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
|
||||
|
||||
@ -187,7 +187,7 @@ class GTEST_API_ ExitedWithCode {
|
||||
const int exit_code_;
|
||||
};
|
||||
|
||||
#if !GTEST_OS_WINDOWS
|
||||
# if !GTEST_OS_WINDOWS
|
||||
// Tests that an exit code describes an exit due to termination by a
|
||||
// given signal.
|
||||
class GTEST_API_ KilledBySignal {
|
||||
@ -197,7 +197,7 @@ class GTEST_API_ KilledBySignal {
|
||||
private:
|
||||
const int signum_;
|
||||
};
|
||||
#endif // !GTEST_OS_WINDOWS
|
||||
# endif // !GTEST_OS_WINDOWS
|
||||
|
||||
// EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode.
|
||||
// The death testing framework causes this to have interesting semantics,
|
||||
@ -242,23 +242,23 @@ class GTEST_API_ KilledBySignal {
|
||||
// EXPECT_EQ(12, DieInDebugOr12(&sideeffect));
|
||||
// }, "death");
|
||||
//
|
||||
#ifdef NDEBUG
|
||||
# ifdef NDEBUG
|
||||
|
||||
#define EXPECT_DEBUG_DEATH(statement, regex) \
|
||||
# define EXPECT_DEBUG_DEATH(statement, regex) \
|
||||
do { statement; } while (::testing::internal::AlwaysFalse())
|
||||
|
||||
#define ASSERT_DEBUG_DEATH(statement, regex) \
|
||||
# define ASSERT_DEBUG_DEATH(statement, regex) \
|
||||
do { statement; } while (::testing::internal::AlwaysFalse())
|
||||
|
||||
#else
|
||||
# else
|
||||
|
||||
#define EXPECT_DEBUG_DEATH(statement, regex) \
|
||||
# define EXPECT_DEBUG_DEATH(statement, regex) \
|
||||
EXPECT_DEATH(statement, regex)
|
||||
|
||||
#define ASSERT_DEBUG_DEATH(statement, regex) \
|
||||
# define ASSERT_DEBUG_DEATH(statement, regex) \
|
||||
ASSERT_DEATH(statement, regex)
|
||||
|
||||
#endif // NDEBUG for EXPECT_DEBUG_DEATH
|
||||
# endif // NDEBUG for EXPECT_DEBUG_DEATH
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
// EXPECT_DEATH_IF_SUPPORTED(statement, regex) and
|
||||
@ -267,14 +267,14 @@ class GTEST_API_ KilledBySignal {
|
||||
// useful when you are combining death test assertions with normal test
|
||||
// assertions in one test.
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
EXPECT_DEATH(statement, regex)
|
||||
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
ASSERT_DEATH(statement, regex)
|
||||
#else
|
||||
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, )
|
||||
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
|
||||
GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, return)
|
||||
#endif
|
||||
|
||||
|
@ -48,8 +48,8 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <gtest/internal/gtest-string.h>
|
||||
#include <gtest/internal/gtest-internal.h>
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
@ -58,7 +58,7 @@ namespace testing {
|
||||
// Typical usage:
|
||||
//
|
||||
// 1. You stream a bunch of values to a Message object.
|
||||
// It will remember the text in a StrStream.
|
||||
// It will remember the text in a stringstream.
|
||||
// 2. Then you stream the Message object to an ostream.
|
||||
// This causes the text in the Message to be streamed
|
||||
// to the ostream.
|
||||
@ -74,7 +74,7 @@ namespace testing {
|
||||
// Message is not intended to be inherited from. In particular, its
|
||||
// destructor is not virtual.
|
||||
//
|
||||
// Note that StrStream behaves differently in gcc and in MSVC. You
|
||||
// Note that stringstream behaves differently in gcc and in MSVC. You
|
||||
// can stream a NULL char pointer to it in the former, but not in the
|
||||
// latter (it causes an access violation if you do). The Message
|
||||
// class hides this difference by treating a NULL char pointer as
|
||||
@ -87,27 +87,26 @@ class GTEST_API_ Message {
|
||||
|
||||
public:
|
||||
// Constructs an empty Message.
|
||||
// We allocate the StrStream separately because it otherwise each use of
|
||||
// We allocate the stringstream separately because otherwise each use of
|
||||
// ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's
|
||||
// stack frame leading to huge stack frames in some cases; gcc does not reuse
|
||||
// the stack space.
|
||||
Message() : ss_(new internal::StrStream) {
|
||||
Message() : ss_(new ::std::stringstream) {
|
||||
// By default, we want there to be enough precision when printing
|
||||
// a double to a Message.
|
||||
*ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
|
||||
}
|
||||
|
||||
// Copy constructor.
|
||||
Message(const Message& msg) : ss_(new internal::StrStream) { // NOLINT
|
||||
Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT
|
||||
*ss_ << msg.GetString();
|
||||
}
|
||||
|
||||
// Constructs a Message from a C-string.
|
||||
explicit Message(const char* str) : ss_(new internal::StrStream) {
|
||||
explicit Message(const char* str) : ss_(new ::std::stringstream) {
|
||||
*ss_ << str;
|
||||
}
|
||||
|
||||
~Message() { delete ss_; }
|
||||
#if GTEST_OS_SYMBIAN
|
||||
// Streams a value (either a pointer or not) to this object.
|
||||
template <typename T>
|
||||
@ -119,7 +118,7 @@ class GTEST_API_ Message {
|
||||
// Streams a non-pointer value to this object.
|
||||
template <typename T>
|
||||
inline Message& operator <<(const T& val) {
|
||||
::GTestStreamToHelper(ss_, val);
|
||||
::GTestStreamToHelper(ss_.get(), val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -141,7 +140,7 @@ class GTEST_API_ Message {
|
||||
if (pointer == NULL) {
|
||||
*ss_ << "(null)";
|
||||
} else {
|
||||
::GTestStreamToHelper(ss_, pointer);
|
||||
::GTestStreamToHelper(ss_.get(), pointer);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@ -189,10 +188,11 @@ class GTEST_API_ Message {
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
internal::String GetString() const {
|
||||
return internal::StrStreamToString(ss_);
|
||||
return internal::StringStreamToString(ss_.get());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
#if GTEST_OS_SYMBIAN
|
||||
// These are needed as the Nokia Symbian Compiler cannot decide between
|
||||
// const T& and const T* in a function template. The Nokia compiler _can_
|
||||
@ -203,17 +203,17 @@ class GTEST_API_ Message {
|
||||
if (pointer == NULL) {
|
||||
*ss_ << "(null)";
|
||||
} else {
|
||||
::GTestStreamToHelper(ss_, pointer);
|
||||
::GTestStreamToHelper(ss_.get(), pointer);
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
inline void StreamHelper(internal::false_type /*dummy*/, const T& value) {
|
||||
::GTestStreamToHelper(ss_, value);
|
||||
::GTestStreamToHelper(ss_.get(), value);
|
||||
}
|
||||
#endif // GTEST_OS_SYMBIAN
|
||||
|
||||
// We'll hold the text streamed to this object here.
|
||||
internal::StrStream* const ss_;
|
||||
const internal::scoped_ptr< ::std::stringstream> ss_;
|
||||
|
||||
// We declare (but don't implement) this to prevent the compiler
|
||||
// from implementing the assignment operator.
|
||||
|
@ -1,4 +1,6 @@
|
||||
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
|
||||
// This file was GENERATED by command:
|
||||
// pump.py gtest-param-test.h.pump
|
||||
// DO NOT EDIT BY HAND!!!
|
||||
|
||||
// Copyright 2008, Google Inc.
|
||||
// All rights reserved.
|
||||
@ -48,10 +50,12 @@
|
||||
#if 0
|
||||
|
||||
// To write value-parameterized tests, first you should define a fixture
|
||||
// class. It must be derived from testing::TestWithParam<T>, where T is
|
||||
// the type of your parameter values. TestWithParam<T> is itself derived
|
||||
// from testing::Test. T can be any copyable type. If it's a raw pointer,
|
||||
// you are responsible for managing the lifespan of the pointed values.
|
||||
// class. It is usually derived from testing::TestWithParam<T> (see below for
|
||||
// another inheritance scheme that's sometimes useful in more complicated
|
||||
// class hierarchies), where the type of your parameter values.
|
||||
// TestWithParam<T> is itself derived from testing::Test. T can be any
|
||||
// copyable type. If it's a raw pointer, you are responsible for managing the
|
||||
// lifespan of the pointed values.
|
||||
|
||||
class FooTest : public ::testing::TestWithParam<const char*> {
|
||||
// You can implement all the usual class fixture members here.
|
||||
@ -146,20 +150,46 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
||||
// In the future, we plan to publish the API for defining new parameter
|
||||
// generators. But for now this interface remains part of the internal
|
||||
// implementation and is subject to change.
|
||||
//
|
||||
//
|
||||
// A parameterized test fixture must be derived from testing::Test and from
|
||||
// testing::WithParamInterface<T>, where T is the type of the parameter
|
||||
// values. Inheriting from TestWithParam<T> satisfies that requirement because
|
||||
// TestWithParam<T> inherits from both Test and WithParamInterface. In more
|
||||
// complicated hierarchies, however, it is occasionally useful to inherit
|
||||
// separately from Test and WithParamInterface. For example:
|
||||
|
||||
class BaseTest : public ::testing::Test {
|
||||
// You can inherit all the usual members for a non-parameterized test
|
||||
// fixture here.
|
||||
};
|
||||
|
||||
class DerivedTest : public BaseTest, public ::testing::WithParamInterface<int> {
|
||||
// The usual test fixture members go here too.
|
||||
};
|
||||
|
||||
TEST_F(BaseTest, HasFoo) {
|
||||
// This is an ordinary non-parameterized test.
|
||||
}
|
||||
|
||||
TEST_P(DerivedTest, DoesBlah) {
|
||||
// GetParam works just the same here as if you inherit from TestWithParam.
|
||||
EXPECT_TRUE(foo.Blah(GetParam()));
|
||||
}
|
||||
|
||||
#endif // 0
|
||||
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if !GTEST_OS_SYMBIAN
|
||||
#include <utility>
|
||||
# include <utility>
|
||||
#endif
|
||||
|
||||
// scripts/fuse_gtest.py depends on gtest's own header being #included
|
||||
// *unconditionally*. Therefore these #includes cannot be moved
|
||||
// inside #if GTEST_HAS_PARAM_TEST.
|
||||
#include <gtest/internal/gtest-internal.h>
|
||||
#include <gtest/internal/gtest-param-util.h>
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-param-util.h"
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
|
||||
@ -275,11 +305,10 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
||||
//
|
||||
template <typename ForwardIterator>
|
||||
internal::ParamGenerator<
|
||||
typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn(
|
||||
ForwardIterator begin,
|
||||
ForwardIterator end) {
|
||||
typedef typename ::std::iterator_traits<ForwardIterator>::value_type
|
||||
ParamType;
|
||||
typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
|
||||
ValuesIn(ForwardIterator begin, ForwardIterator end) {
|
||||
typedef typename ::testing::internal::IteratorTraits<ForwardIterator>
|
||||
::value_type ParamType;
|
||||
return internal::ParamGenerator<ParamType>(
|
||||
new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));
|
||||
}
|
||||
@ -1197,7 +1226,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
||||
return Values(false, true);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_COMBINE
|
||||
# if GTEST_HAS_COMBINE
|
||||
// Combine() allows the user to combine two or more sequences to produce
|
||||
// values of a Cartesian product of those sequences' elements.
|
||||
//
|
||||
@ -1349,11 +1378,11 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
||||
Generator10>(
|
||||
g1, g2, g3, g4, g5, g6, g7, g8, g9, g10);
|
||||
}
|
||||
#endif // GTEST_HAS_COMBINE
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
|
||||
|
||||
#define TEST_P(test_case_name, test_name) \
|
||||
# define TEST_P(test_case_name, test_name) \
|
||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
: public test_case_name { \
|
||||
public: \
|
||||
@ -1379,7 +1408,7 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
||||
|
||||
#define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
|
||||
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
|
||||
::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
||||
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
|
||||
int gtest_##prefix##test_case_name##_dummy_ = \
|
||||
|
796
utils/unittest/googletest/include/gtest/gtest-printers.h
Normal file
796
utils/unittest/googletest/include/gtest/gtest-printers.h
Normal file
@ -0,0 +1,796 @@
|
||||
// Copyright 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Author: wan@google.com (Zhanyong Wan)
|
||||
|
||||
// Google Test - The Google C++ Testing Framework
|
||||
//
|
||||
// This file implements a universal value printer that can print a
|
||||
// value of any type T:
|
||||
//
|
||||
// void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
|
||||
//
|
||||
// A user can teach this function how to print a class type T by
|
||||
// defining either operator<<() or PrintTo() in the namespace that
|
||||
// defines T. More specifically, the FIRST defined function in the
|
||||
// following list will be used (assuming T is defined in namespace
|
||||
// foo):
|
||||
//
|
||||
// 1. foo::PrintTo(const T&, ostream*)
|
||||
// 2. operator<<(ostream&, const T&) defined in either foo or the
|
||||
// global namespace.
|
||||
//
|
||||
// If none of the above is defined, it will print the debug string of
|
||||
// the value if it is a protocol buffer, or print the raw bytes in the
|
||||
// value otherwise.
|
||||
//
|
||||
// To aid debugging: when T is a reference type, the address of the
|
||||
// value is also printed; when T is a (const) char pointer, both the
|
||||
// pointer value and the NUL-terminated string it points to are
|
||||
// printed.
|
||||
//
|
||||
// We also provide some convenient wrappers:
|
||||
//
|
||||
// // Prints a value to a string. For a (const or not) char
|
||||
// // pointer, the NUL-terminated string (but not the pointer) is
|
||||
// // printed.
|
||||
// std::string ::testing::PrintToString(const T& value);
|
||||
//
|
||||
// // Prints a value tersely: for a reference type, the referenced
|
||||
// // value (but not the address) is printed; for a (const or not) char
|
||||
// // pointer, the NUL-terminated string (but not the pointer) is
|
||||
// // printed.
|
||||
// void ::testing::internal::UniversalTersePrint(const T& value, ostream*);
|
||||
//
|
||||
// // Prints value using the type inferred by the compiler. The difference
|
||||
// // from UniversalTersePrint() is that this function prints both the
|
||||
// // pointer and the NUL-terminated string for a (const or not) char pointer.
|
||||
// void ::testing::internal::UniversalPrint(const T& value, ostream*);
|
||||
//
|
||||
// // Prints the fields of a tuple tersely to a string vector, one
|
||||
// // element for each field. Tuple support must be enabled in
|
||||
// // gtest-port.h.
|
||||
// std::vector<string> UniversalTersePrintTupleFieldsToStrings(
|
||||
// const Tuple& value);
|
||||
//
|
||||
// Known limitation:
|
||||
//
|
||||
// The print primitives print the elements of an STL-style container
|
||||
// using the compiler-inferred type of *iter where iter is a
|
||||
// const_iterator of the container. When const_iterator is an input
|
||||
// iterator but not a forward iterator, this inferred type may not
|
||||
// match value_type, and the print output may be incorrect. In
|
||||
// practice, this is rarely a problem as for most containers
|
||||
// const_iterator is a forward iterator. We'll fix this if there's an
|
||||
// actual need for it. Note that this fix cannot rely on value_type
|
||||
// being defined as many user-defined container types don't have
|
||||
// value_type.
|
||||
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||
|
||||
#include <ostream> // NOLINT
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Definitions in the 'internal' and 'internal2' name spaces are
|
||||
// subject to change without notice. DO NOT USE THEM IN USER CODE!
|
||||
namespace internal2 {
|
||||
|
||||
// Prints the given number of bytes in the given object to the given
|
||||
// ostream.
|
||||
GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes,
|
||||
size_t count,
|
||||
::std::ostream* os);
|
||||
|
||||
// For selecting which printer to use when a given type has neither <<
|
||||
// nor PrintTo().
|
||||
enum TypeKind {
|
||||
kProtobuf, // a protobuf type
|
||||
kConvertibleToInteger, // a type implicitly convertible to BiggestInt
|
||||
// (e.g. a named or unnamed enum type)
|
||||
kOtherType // anything else
|
||||
};
|
||||
|
||||
// TypeWithoutFormatter<T, kTypeKind>::PrintValue(value, os) is called
|
||||
// by the universal printer to print a value of type T when neither
|
||||
// operator<< nor PrintTo() is defined for T, where kTypeKind is the
|
||||
// "kind" of T as defined by enum TypeKind.
|
||||
template <typename T, TypeKind kTypeKind>
|
||||
class TypeWithoutFormatter {
|
||||
public:
|
||||
// This default version is called when kTypeKind is kOtherType.
|
||||
static void PrintValue(const T& value, ::std::ostream* os) {
|
||||
PrintBytesInObjectTo(reinterpret_cast<const unsigned char*>(&value),
|
||||
sizeof(value), os);
|
||||
}
|
||||
};
|
||||
|
||||
// We print a protobuf using its ShortDebugString() when the string
|
||||
// doesn't exceed this many characters; otherwise we print it using
|
||||
// DebugString() for better readability.
|
||||
const size_t kProtobufOneLinerMaxLength = 50;
|
||||
|
||||
template <typename T>
|
||||
class TypeWithoutFormatter<T, kProtobuf> {
|
||||
public:
|
||||
static void PrintValue(const T& value, ::std::ostream* os) {
|
||||
const ::testing::internal::string short_str = value.ShortDebugString();
|
||||
const ::testing::internal::string pretty_str =
|
||||
short_str.length() <= kProtobufOneLinerMaxLength ?
|
||||
short_str : ("\n" + value.DebugString());
|
||||
*os << ("<" + pretty_str + ">");
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class TypeWithoutFormatter<T, kConvertibleToInteger> {
|
||||
public:
|
||||
// Since T has no << operator or PrintTo() but can be implicitly
|
||||
// converted to BiggestInt, we print it as a BiggestInt.
|
||||
//
|
||||
// Most likely T is an enum type (either named or unnamed), in which
|
||||
// case printing it as an integer is the desired behavior. In case
|
||||
// T is not an enum, printing it as an integer is the best we can do
|
||||
// given that it has no user-defined printer.
|
||||
static void PrintValue(const T& value, ::std::ostream* os) {
|
||||
const internal::BiggestInt kBigInt = value;
|
||||
*os << kBigInt;
|
||||
}
|
||||
};
|
||||
|
||||
// Prints the given value to the given ostream. If the value is a
|
||||
// protocol message, its debug string is printed; if it's an enum or
|
||||
// of a type implicitly convertible to BiggestInt, it's printed as an
|
||||
// integer; otherwise the bytes in the value are printed. This is
|
||||
// what UniversalPrinter<T>::Print() does when it knows nothing about
|
||||
// type T and T has neither << operator nor PrintTo().
|
||||
//
|
||||
// A user can override this behavior for a class type Foo by defining
|
||||
// a << operator in the namespace where Foo is defined.
|
||||
//
|
||||
// We put this operator in namespace 'internal2' instead of 'internal'
|
||||
// to simplify the implementation, as much code in 'internal' needs to
|
||||
// use << in STL, which would conflict with our own << were it defined
|
||||
// in 'internal'.
|
||||
//
|
||||
// Note that this operator<< takes a generic std::basic_ostream<Char,
|
||||
// CharTraits> type instead of the more restricted std::ostream. If
|
||||
// we define it to take an std::ostream instead, we'll get an
|
||||
// "ambiguous overloads" compiler error when trying to print a type
|
||||
// Foo that supports streaming to std::basic_ostream<Char,
|
||||
// CharTraits>, as the compiler cannot tell whether
|
||||
// operator<<(std::ostream&, const T&) or
|
||||
// operator<<(std::basic_stream<Char, CharTraits>, const Foo&) is more
|
||||
// specific.
|
||||
template <typename Char, typename CharTraits, typename T>
|
||||
::std::basic_ostream<Char, CharTraits>& operator<<(
|
||||
::std::basic_ostream<Char, CharTraits>& os, const T& x) {
|
||||
TypeWithoutFormatter<T,
|
||||
(internal::IsAProtocolMessage<T>::value ? kProtobuf :
|
||||
internal::ImplicitlyConvertible<const T&, internal::BiggestInt>::value ?
|
||||
kConvertibleToInteger : kOtherType)>::PrintValue(x, &os);
|
||||
return os;
|
||||
}
|
||||
|
||||
} // namespace internal2
|
||||
} // namespace testing
|
||||
|
||||
// This namespace MUST NOT BE NESTED IN ::testing, or the name look-up
|
||||
// magic needed for implementing UniversalPrinter won't work.
|
||||
namespace testing_internal {
|
||||
|
||||
// Used to print a value that is not an STL-style container when the
|
||||
// user doesn't define PrintTo() for it.
|
||||
template <typename T>
|
||||
void DefaultPrintNonContainerTo(const T& value, ::std::ostream* os) {
|
||||
// With the following statement, during unqualified name lookup,
|
||||
// testing::internal2::operator<< appears as if it was declared in
|
||||
// the nearest enclosing namespace that contains both
|
||||
// ::testing_internal and ::testing::internal2, i.e. the global
|
||||
// namespace. For more details, refer to the C++ Standard section
|
||||
// 7.3.4-1 [namespace.udir]. This allows us to fall back onto
|
||||
// testing::internal2::operator<< in case T doesn't come with a <<
|
||||
// operator.
|
||||
//
|
||||
// We cannot write 'using ::testing::internal2::operator<<;', which
|
||||
// gcc 3.3 fails to compile due to a compiler bug.
|
||||
using namespace ::testing::internal2; // NOLINT
|
||||
|
||||
// Assuming T is defined in namespace foo, in the next statement,
|
||||
// the compiler will consider all of:
|
||||
//
|
||||
// 1. foo::operator<< (thanks to Koenig look-up),
|
||||
// 2. ::operator<< (as the current namespace is enclosed in ::),
|
||||
// 3. testing::internal2::operator<< (thanks to the using statement above).
|
||||
//
|
||||
// The operator<< whose type matches T best will be picked.
|
||||
//
|
||||
// We deliberately allow #2 to be a candidate, as sometimes it's
|
||||
// impossible to define #1 (e.g. when foo is ::std, defining
|
||||
// anything in it is undefined behavior unless you are a compiler
|
||||
// vendor.).
|
||||
*os << value;
|
||||
}
|
||||
|
||||
} // namespace testing_internal
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// UniversalPrinter<T>::Print(value, ostream_ptr) prints the given
|
||||
// value to the given ostream. The caller must ensure that
|
||||
// 'ostream_ptr' is not NULL, or the behavior is undefined.
|
||||
//
|
||||
// We define UniversalPrinter as a class template (as opposed to a
|
||||
// function template), as we need to partially specialize it for
|
||||
// reference types, which cannot be done with function templates.
|
||||
template <typename T>
|
||||
class UniversalPrinter;
|
||||
|
||||
template <typename T>
|
||||
void UniversalPrint(const T& value, ::std::ostream* os);
|
||||
|
||||
// Used to print an STL-style container when the user doesn't define
|
||||
// a PrintTo() for it.
|
||||
template <typename C>
|
||||
void DefaultPrintTo(IsContainer /* dummy */,
|
||||
false_type /* is not a pointer */,
|
||||
const C& container, ::std::ostream* os) {
|
||||
const size_t kMaxCount = 32; // The maximum number of elements to print.
|
||||
*os << '{';
|
||||
size_t count = 0;
|
||||
for (typename C::const_iterator it = container.begin();
|
||||
it != container.end(); ++it, ++count) {
|
||||
if (count > 0) {
|
||||
*os << ',';
|
||||
if (count == kMaxCount) { // Enough has been printed.
|
||||
*os << " ...";
|
||||
break;
|
||||
}
|
||||
}
|
||||
*os << ' ';
|
||||
// We cannot call PrintTo(*it, os) here as PrintTo() doesn't
|
||||
// handle *it being a native array.
|
||||
internal::UniversalPrint(*it, os);
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
*os << ' ';
|
||||
}
|
||||
*os << '}';
|
||||
}
|
||||
|
||||
// Used to print a pointer that is neither a char pointer nor a member
|
||||
// pointer, when the user doesn't define PrintTo() for it. (A member
|
||||
// variable pointer or member function pointer doesn't really point to
|
||||
// a location in the address space. Their representation is
|
||||
// implementation-defined. Therefore they will be printed as raw
|
||||
// bytes.)
|
||||
template <typename T>
|
||||
void DefaultPrintTo(IsNotContainer /* dummy */,
|
||||
true_type /* is a pointer */,
|
||||
T* p, ::std::ostream* os) {
|
||||
if (p == NULL) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
// C++ doesn't allow casting from a function pointer to any object
|
||||
// pointer.
|
||||
//
|
||||
// IsTrue() silences warnings: "Condition is always true",
|
||||
// "unreachable code".
|
||||
if (IsTrue(ImplicitlyConvertible<T*, const void*>::value)) {
|
||||
// T is not a function type. We just call << to print p,
|
||||
// relying on ADL to pick up user-defined << for their pointer
|
||||
// types, if any.
|
||||
*os << p;
|
||||
} else {
|
||||
// T is a function type, so '*os << p' doesn't do what we want
|
||||
// (it just prints p as bool). We want to print p as a const
|
||||
// void*. However, we cannot cast it to const void* directly,
|
||||
// even using reinterpret_cast, as earlier versions of gcc
|
||||
// (e.g. 3.4.5) cannot compile the cast when p is a function
|
||||
// pointer. Casting to UInt64 first solves the problem.
|
||||
*os << reinterpret_cast<const void*>(
|
||||
reinterpret_cast<internal::UInt64>(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Used to print a non-container, non-pointer value when the user
|
||||
// doesn't define PrintTo() for it.
|
||||
template <typename T>
|
||||
void DefaultPrintTo(IsNotContainer /* dummy */,
|
||||
false_type /* is not a pointer */,
|
||||
const T& value, ::std::ostream* os) {
|
||||
::testing_internal::DefaultPrintNonContainerTo(value, os);
|
||||
}
|
||||
|
||||
// Prints the given value using the << operator if it has one;
|
||||
// otherwise prints the bytes in it. This is what
|
||||
// UniversalPrinter<T>::Print() does when PrintTo() is not specialized
|
||||
// or overloaded for type T.
|
||||
//
|
||||
// A user can override this behavior for a class type Foo by defining
|
||||
// an overload of PrintTo() in the namespace where Foo is defined. We
|
||||
// give the user this option as sometimes defining a << operator for
|
||||
// Foo is not desirable (e.g. the coding style may prevent doing it,
|
||||
// or there is already a << operator but it doesn't do what the user
|
||||
// wants).
|
||||
template <typename T>
|
||||
void PrintTo(const T& value, ::std::ostream* os) {
|
||||
// DefaultPrintTo() is overloaded. The type of its first two
|
||||
// arguments determine which version will be picked. If T is an
|
||||
// STL-style container, the version for container will be called; if
|
||||
// T is a pointer, the pointer version will be called; otherwise the
|
||||
// generic version will be called.
|
||||
//
|
||||
// Note that we check for container types here, prior to we check
|
||||
// for protocol message types in our operator<<. The rationale is:
|
||||
//
|
||||
// For protocol messages, we want to give people a chance to
|
||||
// override Google Mock's format by defining a PrintTo() or
|
||||
// operator<<. For STL containers, other formats can be
|
||||
// incompatible with Google Mock's format for the container
|
||||
// elements; therefore we check for container types here to ensure
|
||||
// that our format is used.
|
||||
//
|
||||
// The second argument of DefaultPrintTo() is needed to bypass a bug
|
||||
// in Symbian's C++ compiler that prevents it from picking the right
|
||||
// overload between:
|
||||
//
|
||||
// PrintTo(const T& x, ...);
|
||||
// PrintTo(T* x, ...);
|
||||
DefaultPrintTo(IsContainerTest<T>(0), is_pointer<T>(), value, os);
|
||||
}
|
||||
|
||||
// The following list of PrintTo() overloads tells
|
||||
// UniversalPrinter<T>::Print() how to print standard types (built-in
|
||||
// types, strings, plain arrays, and pointers).
|
||||
|
||||
// Overloads for various char types.
|
||||
GTEST_API_ void PrintTo(unsigned char c, ::std::ostream* os);
|
||||
GTEST_API_ void PrintTo(signed char c, ::std::ostream* os);
|
||||
inline void PrintTo(char c, ::std::ostream* os) {
|
||||
// When printing a plain char, we always treat it as unsigned. This
|
||||
// way, the output won't be affected by whether the compiler thinks
|
||||
// char is signed or not.
|
||||
PrintTo(static_cast<unsigned char>(c), os);
|
||||
}
|
||||
|
||||
// Overloads for other simple built-in types.
|
||||
inline void PrintTo(bool x, ::std::ostream* os) {
|
||||
*os << (x ? "true" : "false");
|
||||
}
|
||||
|
||||
// Overload for wchar_t type.
|
||||
// Prints a wchar_t as a symbol if it is printable or as its internal
|
||||
// code otherwise and also as its decimal code (except for L'\0').
|
||||
// The L'\0' char is printed as "L'\\0'". The decimal code is printed
|
||||
// as signed integer when wchar_t is implemented by the compiler
|
||||
// as a signed type and is printed as an unsigned integer when wchar_t
|
||||
// is implemented as an unsigned type.
|
||||
GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os);
|
||||
|
||||
// Overloads for C strings.
|
||||
GTEST_API_ void PrintTo(const char* s, ::std::ostream* os);
|
||||
inline void PrintTo(char* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const char*>(s), os);
|
||||
}
|
||||
|
||||
// signed/unsigned char is often used for representing binary data, so
|
||||
// we print pointers to it as void* to be safe.
|
||||
inline void PrintTo(const signed char* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const void*>(s), os);
|
||||
}
|
||||
inline void PrintTo(signed char* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const void*>(s), os);
|
||||
}
|
||||
inline void PrintTo(const unsigned char* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const void*>(s), os);
|
||||
}
|
||||
inline void PrintTo(unsigned char* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const void*>(s), os);
|
||||
}
|
||||
|
||||
// MSVC can be configured to define wchar_t as a typedef of unsigned
|
||||
// short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native
|
||||
// type. When wchar_t is a typedef, defining an overload for const
|
||||
// wchar_t* would cause unsigned short* be printed as a wide string,
|
||||
// possibly causing invalid memory accesses.
|
||||
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
|
||||
// Overloads for wide C strings
|
||||
GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os);
|
||||
inline void PrintTo(wchar_t* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const wchar_t*>(s), os);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Overload for C arrays. Multi-dimensional arrays are printed
|
||||
// properly.
|
||||
|
||||
// Prints the given number of elements in an array, without printing
|
||||
// the curly braces.
|
||||
template <typename T>
|
||||
void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) {
|
||||
UniversalPrint(a[0], os);
|
||||
for (size_t i = 1; i != count; i++) {
|
||||
*os << ", ";
|
||||
UniversalPrint(a[i], os);
|
||||
}
|
||||
}
|
||||
|
||||
// Overloads for ::string and ::std::string.
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
GTEST_API_ void PrintStringTo(const ::string&s, ::std::ostream* os);
|
||||
inline void PrintTo(const ::string& s, ::std::ostream* os) {
|
||||
PrintStringTo(s, os);
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
GTEST_API_ void PrintStringTo(const ::std::string&s, ::std::ostream* os);
|
||||
inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
|
||||
PrintStringTo(s, os);
|
||||
}
|
||||
|
||||
// Overloads for ::wstring and ::std::wstring.
|
||||
#if GTEST_HAS_GLOBAL_WSTRING
|
||||
GTEST_API_ void PrintWideStringTo(const ::wstring&s, ::std::ostream* os);
|
||||
inline void PrintTo(const ::wstring& s, ::std::ostream* os) {
|
||||
PrintWideStringTo(s, os);
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_WSTRING
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);
|
||||
inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
|
||||
PrintWideStringTo(s, os);
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
// Overload for ::std::tr1::tuple. Needed for printing function arguments,
|
||||
// which are packed as tuples.
|
||||
|
||||
// Helper function for printing a tuple. T must be instantiated with
|
||||
// a tuple type.
|
||||
template <typename T>
|
||||
void PrintTupleTo(const T& t, ::std::ostream* os);
|
||||
|
||||
// Overloaded PrintTo() for tuples of various arities. We support
|
||||
// tuples of up-to 10 fields. The following implementation works
|
||||
// regardless of whether tr1::tuple is implemented using the
|
||||
// non-standard variadic template feature or not.
|
||||
|
||||
inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
void PrintTo(const ::std::tr1::tuple<T1>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4>& t, ::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9>
|
||||
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10>
|
||||
void PrintTo(
|
||||
const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& t,
|
||||
::std::ostream* os) {
|
||||
PrintTupleTo(t, os);
|
||||
}
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
// Overload for std::pair.
|
||||
template <typename T1, typename T2>
|
||||
void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
|
||||
*os << '(';
|
||||
// We cannot use UniversalPrint(value.first, os) here, as T1 may be
|
||||
// a reference type. The same for printing value.second.
|
||||
UniversalPrinter<T1>::Print(value.first, os);
|
||||
*os << ", ";
|
||||
UniversalPrinter<T2>::Print(value.second, os);
|
||||
*os << ')';
|
||||
}
|
||||
|
||||
// Implements printing a non-reference type T by letting the compiler
|
||||
// pick the right overload of PrintTo() for T.
|
||||
template <typename T>
|
||||
class UniversalPrinter {
|
||||
public:
|
||||
// MSVC warns about adding const to a function type, so we want to
|
||||
// disable the warning.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push) // Saves the current warning state.
|
||||
# pragma warning(disable:4180) // Temporarily disables warning 4180.
|
||||
#endif // _MSC_VER
|
||||
|
||||
// Note: we deliberately don't call this PrintTo(), as that name
|
||||
// conflicts with ::testing::internal::PrintTo in the body of the
|
||||
// function.
|
||||
static void Print(const T& value, ::std::ostream* os) {
|
||||
// By default, ::testing::internal::PrintTo() is used for printing
|
||||
// the value.
|
||||
//
|
||||
// Thanks to Koenig look-up, if T is a class and has its own
|
||||
// PrintTo() function defined in its namespace, that function will
|
||||
// be visible here. Since it is more specific than the generic ones
|
||||
// in ::testing::internal, it will be picked by the compiler in the
|
||||
// following statement - exactly what we want.
|
||||
PrintTo(value, os);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop) // Restores the warning state.
|
||||
#endif // _MSC_VER
|
||||
};
|
||||
|
||||
// UniversalPrintArray(begin, len, os) prints an array of 'len'
|
||||
// elements, starting at address 'begin'.
|
||||
template <typename T>
|
||||
void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
|
||||
if (len == 0) {
|
||||
*os << "{}";
|
||||
} else {
|
||||
*os << "{ ";
|
||||
const size_t kThreshold = 18;
|
||||
const size_t kChunkSize = 8;
|
||||
// If the array has more than kThreshold elements, we'll have to
|
||||
// omit some details by printing only the first and the last
|
||||
// kChunkSize elements.
|
||||
// TODO(wan@google.com): let the user control the threshold using a flag.
|
||||
if (len <= kThreshold) {
|
||||
PrintRawArrayTo(begin, len, os);
|
||||
} else {
|
||||
PrintRawArrayTo(begin, kChunkSize, os);
|
||||
*os << ", ..., ";
|
||||
PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os);
|
||||
}
|
||||
*os << " }";
|
||||
}
|
||||
}
|
||||
// This overload prints a (const) char array compactly.
|
||||
GTEST_API_ void UniversalPrintArray(const char* begin,
|
||||
size_t len,
|
||||
::std::ostream* os);
|
||||
|
||||
// Implements printing an array type T[N].
|
||||
template <typename T, size_t N>
|
||||
class UniversalPrinter<T[N]> {
|
||||
public:
|
||||
// Prints the given array, omitting some elements when there are too
|
||||
// many.
|
||||
static void Print(const T (&a)[N], ::std::ostream* os) {
|
||||
UniversalPrintArray(a, N, os);
|
||||
}
|
||||
};
|
||||
|
||||
// Implements printing a reference type T&.
|
||||
template <typename T>
|
||||
class UniversalPrinter<T&> {
|
||||
public:
|
||||
// MSVC warns about adding const to a function type, so we want to
|
||||
// disable the warning.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push) // Saves the current warning state.
|
||||
# pragma warning(disable:4180) // Temporarily disables warning 4180.
|
||||
#endif // _MSC_VER
|
||||
|
||||
static void Print(const T& value, ::std::ostream* os) {
|
||||
// Prints the address of the value. We use reinterpret_cast here
|
||||
// as static_cast doesn't compile when T is a function type.
|
||||
*os << "@" << reinterpret_cast<const void*>(&value) << " ";
|
||||
|
||||
// Then prints the value itself.
|
||||
UniversalPrint(value, os);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop) // Restores the warning state.
|
||||
#endif // _MSC_VER
|
||||
};
|
||||
|
||||
// Prints a value tersely: for a reference type, the referenced value
|
||||
// (but not the address) is printed; for a (const) char pointer, the
|
||||
// NUL-terminated string (but not the pointer) is printed.
|
||||
template <typename T>
|
||||
void UniversalTersePrint(const T& value, ::std::ostream* os) {
|
||||
UniversalPrint(value, os);
|
||||
}
|
||||
inline void UniversalTersePrint(const char* str, ::std::ostream* os) {
|
||||
if (str == NULL) {
|
||||
*os << "NULL";
|
||||
} else {
|
||||
UniversalPrint(string(str), os);
|
||||
}
|
||||
}
|
||||
inline void UniversalTersePrint(char* str, ::std::ostream* os) {
|
||||
UniversalTersePrint(static_cast<const char*>(str), os);
|
||||
}
|
||||
|
||||
// Prints a value using the type inferred by the compiler. The
|
||||
// difference between this and UniversalTersePrint() is that for a
|
||||
// (const) char pointer, this prints both the pointer and the
|
||||
// NUL-terminated string.
|
||||
template <typename T>
|
||||
void UniversalPrint(const T& value, ::std::ostream* os) {
|
||||
UniversalPrinter<T>::Print(value, os);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
typedef ::std::vector<string> Strings;
|
||||
|
||||
// This helper template allows PrintTo() for tuples and
|
||||
// UniversalTersePrintTupleFieldsToStrings() to be defined by
|
||||
// induction on the number of tuple fields. The idea is that
|
||||
// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
|
||||
// fields in tuple t, and can be defined in terms of
|
||||
// TuplePrefixPrinter<N - 1>.
|
||||
|
||||
// The inductive case.
|
||||
template <size_t N>
|
||||
struct TuplePrefixPrinter {
|
||||
// Prints the first N fields of a tuple.
|
||||
template <typename Tuple>
|
||||
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
|
||||
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
|
||||
*os << ", ";
|
||||
UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type>
|
||||
::Print(::std::tr1::get<N - 1>(t), os);
|
||||
}
|
||||
|
||||
// Tersely prints the first N fields of a tuple to a string vector,
|
||||
// one element for each field.
|
||||
template <typename Tuple>
|
||||
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
|
||||
TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
|
||||
::std::stringstream ss;
|
||||
UniversalTersePrint(::std::tr1::get<N - 1>(t), &ss);
|
||||
strings->push_back(ss.str());
|
||||
}
|
||||
};
|
||||
|
||||
// Base cases.
|
||||
template <>
|
||||
struct TuplePrefixPrinter<0> {
|
||||
template <typename Tuple>
|
||||
static void PrintPrefixTo(const Tuple&, ::std::ostream*) {}
|
||||
|
||||
template <typename Tuple>
|
||||
static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
|
||||
};
|
||||
// We have to specialize the entire TuplePrefixPrinter<> class
|
||||
// template here, even though the definition of
|
||||
// TersePrintPrefixToStrings() is the same as the generic version, as
|
||||
// Embarcadero (formerly CodeGear, formerly Borland) C++ doesn't
|
||||
// support specializing a method template of a class template.
|
||||
template <>
|
||||
struct TuplePrefixPrinter<1> {
|
||||
template <typename Tuple>
|
||||
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
|
||||
UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::
|
||||
Print(::std::tr1::get<0>(t), os);
|
||||
}
|
||||
|
||||
template <typename Tuple>
|
||||
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
|
||||
::std::stringstream ss;
|
||||
UniversalTersePrint(::std::tr1::get<0>(t), &ss);
|
||||
strings->push_back(ss.str());
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function for printing a tuple. T must be instantiated with
|
||||
// a tuple type.
|
||||
template <typename T>
|
||||
void PrintTupleTo(const T& t, ::std::ostream* os) {
|
||||
*os << "(";
|
||||
TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::
|
||||
PrintPrefixTo(t, os);
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
// Prints the fields of a tuple tersely to a string vector, one
|
||||
// element for each field. See the comment before
|
||||
// UniversalTersePrint() for how we define "tersely".
|
||||
template <typename Tuple>
|
||||
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
|
||||
Strings result;
|
||||
TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>::
|
||||
TersePrintPrefixToStrings(value, &result);
|
||||
return result;
|
||||
}
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
} // namespace internal
|
||||
|
||||
template <typename T>
|
||||
::std::string PrintToString(const T& value) {
|
||||
::std::stringstream ss;
|
||||
internal::UniversalTersePrint(value, &ss);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
@ -35,7 +35,7 @@
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
|
||||
#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
@ -98,12 +98,12 @@ class GTEST_API_ SingleFailureChecker {
|
||||
// The constructor remembers the arguments.
|
||||
SingleFailureChecker(const TestPartResultArray* results,
|
||||
TestPartResult::Type type,
|
||||
const char* substr);
|
||||
const string& substr);
|
||||
~SingleFailureChecker();
|
||||
private:
|
||||
const TestPartResultArray* const results_;
|
||||
const TestPartResult::Type type_;
|
||||
const String substr_;
|
||||
const string substr_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
|
||||
};
|
||||
|
@ -35,8 +35,8 @@
|
||||
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <gtest/internal/gtest-internal.h>
|
||||
#include <gtest/internal/gtest-string.h>
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
|
@ -146,8 +146,8 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
|
||||
#endif // 0
|
||||
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include <gtest/internal/gtest-type-util.h>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/internal/gtest-type-util.h"
|
||||
|
||||
// Implements typed tests.
|
||||
|
||||
@ -157,16 +157,16 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
//
|
||||
// Expands to the name of the typedef for the type parameters of the
|
||||
// given test case.
|
||||
#define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_
|
||||
# define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_
|
||||
|
||||
// The 'Types' template argument below must have spaces around it
|
||||
// since some compilers may choke on '>>' when passing a template
|
||||
// instance (e.g. Types<int>)
|
||||
#define TYPED_TEST_CASE(CaseName, Types) \
|
||||
# define TYPED_TEST_CASE(CaseName, Types) \
|
||||
typedef ::testing::internal::TypeList< Types >::type \
|
||||
GTEST_TYPE_PARAMS_(CaseName)
|
||||
|
||||
#define TYPED_TEST(CaseName, TestName) \
|
||||
# define TYPED_TEST(CaseName, TestName) \
|
||||
template <typename gtest_TypeParam_> \
|
||||
class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
|
||||
: public CaseName<gtest_TypeParam_> { \
|
||||
@ -175,7 +175,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
typedef gtest_TypeParam_ TypeParam; \
|
||||
virtual void TestBody(); \
|
||||
}; \
|
||||
bool gtest_##CaseName##_##TestName##_registered_ = \
|
||||
bool gtest_##CaseName##_##TestName##_registered_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::internal::TypeParameterizedTest< \
|
||||
CaseName, \
|
||||
::testing::internal::TemplateSel< \
|
||||
@ -196,31 +196,31 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
// Expands to the namespace name that the type-parameterized tests for
|
||||
// the given type-parameterized test case are defined in. The exact
|
||||
// name of the namespace is subject to change without notice.
|
||||
#define GTEST_CASE_NAMESPACE_(TestCaseName) \
|
||||
# define GTEST_CASE_NAMESPACE_(TestCaseName) \
|
||||
gtest_case_##TestCaseName##_
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Expands to the name of the variable used to remember the names of
|
||||
// the defined tests in the given test case.
|
||||
#define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \
|
||||
# define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \
|
||||
gtest_typed_test_case_p_state_##TestCaseName##_
|
||||
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
|
||||
//
|
||||
// Expands to the name of the variable used to remember the names of
|
||||
// the registered tests in the given test case.
|
||||
#define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \
|
||||
# define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \
|
||||
gtest_registered_test_names_##TestCaseName##_
|
||||
|
||||
// The variables defined in the type-parameterized test macros are
|
||||
// static as typically these macros are used in a .h file that can be
|
||||
// #included in multiple translation units linked together.
|
||||
#define TYPED_TEST_CASE_P(CaseName) \
|
||||
# define TYPED_TEST_CASE_P(CaseName) \
|
||||
static ::testing::internal::TypedTestCasePState \
|
||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName)
|
||||
|
||||
#define TYPED_TEST_P(CaseName, TestName) \
|
||||
# define TYPED_TEST_P(CaseName, TestName) \
|
||||
namespace GTEST_CASE_NAMESPACE_(CaseName) { \
|
||||
template <typename gtest_TypeParam_> \
|
||||
class TestName : public CaseName<gtest_TypeParam_> { \
|
||||
@ -229,14 +229,14 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
typedef gtest_TypeParam_ TypeParam; \
|
||||
virtual void TestBody(); \
|
||||
}; \
|
||||
static bool gtest_##TestName##_defined_ = \
|
||||
static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\
|
||||
__FILE__, __LINE__, #CaseName, #TestName); \
|
||||
} \
|
||||
template <typename gtest_TypeParam_> \
|
||||
void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBody()
|
||||
|
||||
#define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \
|
||||
# define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \
|
||||
namespace GTEST_CASE_NAMESPACE_(CaseName) { \
|
||||
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
|
||||
} \
|
||||
@ -247,8 +247,8 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
||||
// The 'Types' template argument below must have spaces around it
|
||||
// since some compilers may choke on '>>' when passing a template
|
||||
// instance (e.g. Types<int>)
|
||||
#define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \
|
||||
bool gtest_##Prefix##_##CaseName = \
|
||||
# define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \
|
||||
bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \
|
||||
::testing::internal::TypeParameterizedTestCase<CaseName, \
|
||||
GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \
|
||||
::testing::internal::TypeList< Types >::type>::Register(\
|
||||
|
@ -54,14 +54,15 @@
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/internal/gtest-internal.h>
|
||||
#include <gtest/internal/gtest-string.h>
|
||||
#include <gtest/gtest-death-test.h>
|
||||
#include <gtest/gtest-message.h>
|
||||
#include <gtest/gtest-param-test.h>
|
||||
#include <gtest/gtest_prod.h>
|
||||
#include <gtest/gtest-test-part.h>
|
||||
#include <gtest/gtest-typed-test.h>
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
#include "gtest/gtest-death-test.h"
|
||||
#include "gtest/gtest-message.h"
|
||||
#include "gtest/gtest-param-test.h"
|
||||
#include "gtest/gtest-printers.h"
|
||||
#include "gtest/gtest_prod.h"
|
||||
#include "gtest/gtest-test-part.h"
|
||||
#include "gtest/gtest-typed-test.h"
|
||||
|
||||
// Depending on the platform, different string classes are available.
|
||||
// On Linux, in addition to ::std::string, Google also makes use of
|
||||
@ -136,6 +137,11 @@ GTEST_DECLARE_int32_(stack_trace_depth);
|
||||
// non-zero code otherwise.
|
||||
GTEST_DECLARE_bool_(throw_on_failure);
|
||||
|
||||
// When this flag is set with a "host:port" string, on supported
|
||||
// platforms test results are streamed to the specified port on
|
||||
// the specified host machine.
|
||||
GTEST_DECLARE_string_(stream_result_to);
|
||||
|
||||
// The upper limit for valid stack trace depths.
|
||||
const int kMaxStackTraceDepth = 100;
|
||||
|
||||
@ -147,7 +153,6 @@ class ExecDeathTest;
|
||||
class NoExecDeathTest;
|
||||
class FinalSuccessChecker;
|
||||
class GTestFlagSaver;
|
||||
class TestInfoImpl;
|
||||
class TestResultAccessor;
|
||||
class TestEventListenersAccessor;
|
||||
class TestEventRepeater;
|
||||
@ -155,8 +160,6 @@ class WindowsDeathTest;
|
||||
class UnitTestImpl* GetUnitTestImpl();
|
||||
void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
|
||||
const String& message);
|
||||
class PrettyUnitTestResultPrinter;
|
||||
class XmlUnitTestResultPrinter;
|
||||
|
||||
// Converts a streamable value to a String. A NULL pointer is
|
||||
// converted to "(null)". When the input value is a ::string,
|
||||
@ -172,6 +175,14 @@ String StreamableToString(const T& streamable) {
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// The friend relationship of some of these classes is cyclic.
|
||||
// If we don't forward declare them the compiler might confuse the classes
|
||||
// in friendship clauses with same named classes on the scope.
|
||||
class Test;
|
||||
class TestCase;
|
||||
class TestInfo;
|
||||
class UnitTest;
|
||||
|
||||
// A class for indicating whether an assertion was successful. When
|
||||
// the assertion wasn't successful, the AssertionResult object
|
||||
// remembers a non-empty message that describes how it failed.
|
||||
@ -270,20 +281,33 @@ class GTEST_API_ AssertionResult {
|
||||
// assertion's expectation). When nothing has been streamed into the
|
||||
// object, returns an empty string.
|
||||
const char* message() const {
|
||||
return message_.get() != NULL && message_->c_str() != NULL ?
|
||||
message_->c_str() : "";
|
||||
return message_.get() != NULL ? message_->c_str() : "";
|
||||
}
|
||||
// TODO(vladl@google.com): Remove this after making sure no clients use it.
|
||||
// Deprecated; please use message() instead.
|
||||
const char* failure_message() const { return message(); }
|
||||
|
||||
// Streams a custom failure message into this object.
|
||||
template <typename T> AssertionResult& operator<<(const T& value);
|
||||
template <typename T> AssertionResult& operator<<(const T& value) {
|
||||
AppendMessage(Message() << value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Allows streaming basic output manipulators such as endl or flush into
|
||||
// this object.
|
||||
AssertionResult& operator<<(
|
||||
::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
|
||||
AppendMessage(Message() << basic_manipulator);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
// No implementation - we want AssertionResult to be
|
||||
// copy-constructible but not assignable.
|
||||
void operator=(const AssertionResult& other);
|
||||
// Appends the contents of message to message_.
|
||||
void AppendMessage(const Message& a_message) {
|
||||
if (message_.get() == NULL)
|
||||
message_.reset(new ::std::string);
|
||||
message_->append(a_message.GetString().c_str());
|
||||
}
|
||||
|
||||
// Stores result of the assertion predicate.
|
||||
bool success_;
|
||||
@ -291,19 +315,10 @@ class GTEST_API_ AssertionResult {
|
||||
// construct is not satisfied with the predicate's outcome.
|
||||
// Referenced via a pointer to avoid taking too much stack frame space
|
||||
// with test assertions.
|
||||
internal::scoped_ptr<internal::String> message_;
|
||||
}; // class AssertionResult
|
||||
internal::scoped_ptr< ::std::string> message_;
|
||||
|
||||
// Streams a custom failure message into this object.
|
||||
template <typename T>
|
||||
AssertionResult& AssertionResult::operator<<(const T& value) {
|
||||
Message msg;
|
||||
if (message_.get() != NULL)
|
||||
msg << *message_;
|
||||
msg << value;
|
||||
message_.reset(new internal::String(msg.GetString()));
|
||||
return *this;
|
||||
}
|
||||
GTEST_DISALLOW_ASSIGN_(AssertionResult);
|
||||
};
|
||||
|
||||
// Makes a successful assertion result.
|
||||
GTEST_API_ AssertionResult AssertionSuccess();
|
||||
@ -340,7 +355,7 @@ GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
|
||||
// Test is not copyable.
|
||||
class GTEST_API_ Test {
|
||||
public:
|
||||
friend class internal::TestInfoImpl;
|
||||
friend class TestInfo;
|
||||
|
||||
// Defines types for pointers to functions that set up and tear down
|
||||
// a test case.
|
||||
@ -417,6 +432,10 @@ class GTEST_API_ Test {
|
||||
// Sets up, executes, and tears down the test.
|
||||
void Run();
|
||||
|
||||
// Deletes self. We deliberately pick an unusual name for this
|
||||
// internal method to avoid clashing with names used in user TESTs.
|
||||
void DeleteSelf_() { delete this; }
|
||||
|
||||
// Uses a GTestFlagSaver to save and restore all Google Test flags.
|
||||
const internal::GTestFlagSaver* const gtest_flag_saver_;
|
||||
|
||||
@ -531,7 +550,6 @@ class GTEST_API_ TestResult {
|
||||
friend class UnitTest;
|
||||
friend class internal::DefaultGlobalTestPartResultReporter;
|
||||
friend class internal::ExecDeathTest;
|
||||
friend class internal::TestInfoImpl;
|
||||
friend class internal::TestResultAccessor;
|
||||
friend class internal::UnitTestImpl;
|
||||
friend class internal::WindowsDeathTest;
|
||||
@ -611,16 +629,26 @@ class GTEST_API_ TestInfo {
|
||||
~TestInfo();
|
||||
|
||||
// Returns the test case name.
|
||||
const char* test_case_name() const;
|
||||
const char* test_case_name() const { return test_case_name_.c_str(); }
|
||||
|
||||
// Returns the test name.
|
||||
const char* name() const;
|
||||
const char* name() const { return name_.c_str(); }
|
||||
|
||||
// Returns the test case comment.
|
||||
const char* test_case_comment() const;
|
||||
// Returns the name of the parameter type, or NULL if this is not a typed
|
||||
// or a type-parameterized test.
|
||||
const char* type_param() const {
|
||||
if (type_param_.get() != NULL)
|
||||
return type_param_->c_str();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Returns the test comment.
|
||||
const char* comment() const;
|
||||
// Returns the text representation of the value parameter, or NULL if this
|
||||
// is not a value-parameterized test.
|
||||
const char* value_param() const {
|
||||
if (value_param_.get() != NULL)
|
||||
return value_param_->c_str();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Returns true if this test should run, that is if the test is not disabled
|
||||
// (or it is disabled but the also_run_disabled_tests flag has been specified)
|
||||
@ -638,47 +666,70 @@ class GTEST_API_ TestInfo {
|
||||
//
|
||||
// For example, *A*:Foo.* is a filter that matches any string that
|
||||
// contains the character 'A' or starts with "Foo.".
|
||||
bool should_run() const;
|
||||
bool should_run() const { return should_run_; }
|
||||
|
||||
// Returns the result of the test.
|
||||
const TestResult* result() const;
|
||||
const TestResult* result() const { return &result_; }
|
||||
|
||||
private:
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
friend class internal::DefaultDeathTestFactory;
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
friend class Test;
|
||||
friend class TestCase;
|
||||
friend class internal::TestInfoImpl;
|
||||
friend class internal::UnitTestImpl;
|
||||
friend TestInfo* internal::MakeAndRegisterTestInfo(
|
||||
const char* test_case_name, const char* name,
|
||||
const char* test_case_comment, const char* comment,
|
||||
const char* type_param,
|
||||
const char* value_param,
|
||||
internal::TypeId fixture_class_id,
|
||||
Test::SetUpTestCaseFunc set_up_tc,
|
||||
Test::TearDownTestCaseFunc tear_down_tc,
|
||||
internal::TestFactoryBase* factory);
|
||||
|
||||
// Returns true if this test matches the user-specified filter.
|
||||
bool matches_filter() const;
|
||||
|
||||
// Increments the number of death tests encountered in this test so
|
||||
// far.
|
||||
int increment_death_test_count();
|
||||
|
||||
// Accessors for the implementation object.
|
||||
internal::TestInfoImpl* impl() { return impl_; }
|
||||
const internal::TestInfoImpl* impl() const { return impl_; }
|
||||
|
||||
// Constructs a TestInfo object. The newly constructed instance assumes
|
||||
// ownership of the factory object.
|
||||
TestInfo(const char* test_case_name, const char* name,
|
||||
const char* test_case_comment, const char* comment,
|
||||
const char* a_type_param,
|
||||
const char* a_value_param,
|
||||
internal::TypeId fixture_class_id,
|
||||
internal::TestFactoryBase* factory);
|
||||
|
||||
// An opaque implementation object.
|
||||
internal::TestInfoImpl* impl_;
|
||||
// Increments the number of death tests encountered in this test so
|
||||
// far.
|
||||
int increment_death_test_count() {
|
||||
return result_.increment_death_test_count();
|
||||
}
|
||||
|
||||
// Creates the test object, runs it, records its result, and then
|
||||
// deletes it.
|
||||
void Run();
|
||||
|
||||
static void ClearTestResult(TestInfo* test_info) {
|
||||
test_info->result_.Clear();
|
||||
}
|
||||
|
||||
// These fields are immutable properties of the test.
|
||||
const std::string test_case_name_; // Test case name
|
||||
const std::string name_; // Test name
|
||||
// Name of the parameter type, or NULL if this is not a typed or a
|
||||
// type-parameterized test.
|
||||
const internal::scoped_ptr<const ::std::string> type_param_;
|
||||
// Text representation of the value parameter, or NULL if this is not a
|
||||
// value-parameterized test.
|
||||
const internal::scoped_ptr<const ::std::string> value_param_;
|
||||
const internal::TypeId fixture_class_id_; // ID of the test fixture class
|
||||
bool should_run_; // True iff this test should run
|
||||
bool is_disabled_; // True iff this test is disabled
|
||||
bool matches_filter_; // True if this test matches the
|
||||
// user-specified filter.
|
||||
internal::TestFactoryBase* const factory_; // The factory that creates
|
||||
// the test object
|
||||
|
||||
// This field is mutable and needs to be reset before running the
|
||||
// test for the second time.
|
||||
TestResult result_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
|
||||
};
|
||||
@ -696,9 +747,11 @@ class GTEST_API_ TestCase {
|
||||
// Arguments:
|
||||
//
|
||||
// name: name of the test case
|
||||
// a_type_param: the name of the test's type parameter, or NULL if
|
||||
// this is not a type-parameterized test.
|
||||
// set_up_tc: pointer to the function that sets up the test case
|
||||
// tear_down_tc: pointer to the function that tears down the test case
|
||||
TestCase(const char* name, const char* comment,
|
||||
TestCase(const char* name, const char* a_type_param,
|
||||
Test::SetUpTestCaseFunc set_up_tc,
|
||||
Test::TearDownTestCaseFunc tear_down_tc);
|
||||
|
||||
@ -708,8 +761,13 @@ class GTEST_API_ TestCase {
|
||||
// Gets the name of the TestCase.
|
||||
const char* name() const { return name_.c_str(); }
|
||||
|
||||
// Returns the test case comment.
|
||||
const char* comment() const { return comment_.c_str(); }
|
||||
// Returns the name of the parameter type, or NULL if this is not a
|
||||
// type-parameterized test case.
|
||||
const char* type_param() const {
|
||||
if (type_param_.get() != NULL)
|
||||
return type_param_->c_str();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Returns true if any test in this test case should run.
|
||||
bool should_run() const { return should_run_; }
|
||||
@ -776,17 +834,33 @@ class GTEST_API_ TestCase {
|
||||
// Runs every test in this TestCase.
|
||||
void Run();
|
||||
|
||||
// Runs SetUpTestCase() for this TestCase. This wrapper is needed
|
||||
// for catching exceptions thrown from SetUpTestCase().
|
||||
void RunSetUpTestCase() { (*set_up_tc_)(); }
|
||||
|
||||
// Runs TearDownTestCase() for this TestCase. This wrapper is
|
||||
// needed for catching exceptions thrown from TearDownTestCase().
|
||||
void RunTearDownTestCase() { (*tear_down_tc_)(); }
|
||||
|
||||
// Returns true iff test passed.
|
||||
static bool TestPassed(const TestInfo * test_info);
|
||||
static bool TestPassed(const TestInfo* test_info) {
|
||||
return test_info->should_run() && test_info->result()->Passed();
|
||||
}
|
||||
|
||||
// Returns true iff test failed.
|
||||
static bool TestFailed(const TestInfo * test_info);
|
||||
static bool TestFailed(const TestInfo* test_info) {
|
||||
return test_info->should_run() && test_info->result()->Failed();
|
||||
}
|
||||
|
||||
// Returns true iff test is disabled.
|
||||
static bool TestDisabled(const TestInfo * test_info);
|
||||
static bool TestDisabled(const TestInfo* test_info) {
|
||||
return test_info->is_disabled_;
|
||||
}
|
||||
|
||||
// Returns true if the given test should run.
|
||||
static bool ShouldRunTest(const TestInfo *test_info);
|
||||
static bool ShouldRunTest(const TestInfo* test_info) {
|
||||
return test_info->should_run();
|
||||
}
|
||||
|
||||
// Shuffles the tests in this test case.
|
||||
void ShuffleTests(internal::Random* random);
|
||||
@ -796,8 +870,9 @@ class GTEST_API_ TestCase {
|
||||
|
||||
// Name of the test case.
|
||||
internal::String name_;
|
||||
// Comment on the test case.
|
||||
internal::String comment_;
|
||||
// Name of the parameter type, or NULL if this is not a typed or a
|
||||
// type-parameterized test.
|
||||
const internal::scoped_ptr<const ::std::string> type_param_;
|
||||
// The vector of TestInfos in their original order. It owns the
|
||||
// elements in the vector.
|
||||
std::vector<TestInfo*> test_info_list_;
|
||||
@ -876,7 +951,7 @@ class TestEventListener {
|
||||
// Fired before the test starts.
|
||||
virtual void OnTestStart(const TestInfo& test_info) = 0;
|
||||
|
||||
// Fired after a failed assertion or a SUCCESS().
|
||||
// Fired after a failed assertion or a SUCCEED() invocation.
|
||||
virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
|
||||
|
||||
// Fired after the test ends.
|
||||
@ -961,10 +1036,10 @@ class GTEST_API_ TestEventListeners {
|
||||
|
||||
private:
|
||||
friend class TestCase;
|
||||
friend class TestInfo;
|
||||
friend class internal::DefaultGlobalTestPartResultReporter;
|
||||
friend class internal::NoExecDeathTest;
|
||||
friend class internal::TestEventListenersAccessor;
|
||||
friend class internal::TestInfoImpl;
|
||||
friend class internal::UnitTestImpl;
|
||||
|
||||
// Returns repeater that broadcasts the TestEventListener events to all
|
||||
@ -1206,30 +1281,6 @@ GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
|
||||
|
||||
namespace internal {
|
||||
|
||||
// These overloaded versions handle ::std::string and ::std::wstring.
|
||||
GTEST_API_ inline String FormatForFailureMessage(const ::std::string& str) {
|
||||
return (Message() << '"' << str << '"').GetString();
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
GTEST_API_ inline String FormatForFailureMessage(const ::std::wstring& wstr) {
|
||||
return (Message() << "L\"" << wstr << '"').GetString();
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
// These overloaded versions handle ::string and ::wstring.
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
GTEST_API_ inline String FormatForFailureMessage(const ::string& str) {
|
||||
return (Message() << '"' << str << '"').GetString();
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
#if GTEST_HAS_GLOBAL_WSTRING
|
||||
GTEST_API_ inline String FormatForFailureMessage(const ::wstring& wstr) {
|
||||
return (Message() << "L\"" << wstr << '"').GetString();
|
||||
}
|
||||
#endif // GTEST_HAS_GLOBAL_WSTRING
|
||||
|
||||
// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
|
||||
// operand to be used in a failure message. The type (but not value)
|
||||
// of the other operand may affect the format. This allows us to
|
||||
@ -1245,7 +1296,9 @@ GTEST_API_ inline String FormatForFailureMessage(const ::wstring& wstr) {
|
||||
template <typename T1, typename T2>
|
||||
String FormatForComparisonFailureMessage(const T1& value,
|
||||
const T2& /* other_operand */) {
|
||||
return FormatForFailureMessage(value);
|
||||
// C++Builder compiles this incorrectly if the namespace isn't explicitly
|
||||
// given.
|
||||
return ::testing::PrintToString(value);
|
||||
}
|
||||
|
||||
// The helper function for {ASSERT|EXPECT}_EQ.
|
||||
@ -1255,8 +1308,8 @@ AssertionResult CmpHelperEQ(const char* expected_expression,
|
||||
const T1& expected,
|
||||
const T2& actual) {
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push) // Saves the current warning state.
|
||||
#pragma warning(disable:4389) // Temporarily disables warning on
|
||||
# pragma warning(push) // Saves the current warning state.
|
||||
# pragma warning(disable:4389) // Temporarily disables warning on
|
||||
// signed/unsigned mismatch.
|
||||
#pragma warning(disable:4805) // Temporarily disables warning on
|
||||
// unsafe mix of types
|
||||
@ -1267,7 +1320,7 @@ AssertionResult CmpHelperEQ(const char* expected_expression,
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop) // Restores the warning state.
|
||||
# pragma warning(pop) // Restores the warning state.
|
||||
#endif
|
||||
|
||||
return EqFailure(expected_expression,
|
||||
@ -1318,7 +1371,7 @@ class EqHelper {
|
||||
};
|
||||
|
||||
// This specialization is used when the first argument to ASSERT_EQ()
|
||||
// is a null pointer literal.
|
||||
// is a null pointer literal, like NULL, false, or 0.
|
||||
template <>
|
||||
class EqHelper<true> {
|
||||
public:
|
||||
@ -1327,24 +1380,38 @@ class EqHelper<true> {
|
||||
// NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
|
||||
// EXPECT_EQ(false, a_bool).
|
||||
template <typename T1, typename T2>
|
||||
static AssertionResult Compare(const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
const T1& expected,
|
||||
const T2& actual) {
|
||||
static AssertionResult Compare(
|
||||
const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
const T1& expected,
|
||||
const T2& actual,
|
||||
// The following line prevents this overload from being considered if T2
|
||||
// is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr)
|
||||
// expands to Compare("", "", NULL, my_ptr), which requires a conversion
|
||||
// to match the Secret* in the other overload, which would otherwise make
|
||||
// this template match better.
|
||||
typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
|
||||
return CmpHelperEQ(expected_expression, actual_expression, expected,
|
||||
actual);
|
||||
}
|
||||
|
||||
// This version will be picked when the second argument to
|
||||
// ASSERT_EQ() is a pointer, e.g. ASSERT_EQ(NULL, a_pointer).
|
||||
template <typename T1, typename T2>
|
||||
static AssertionResult Compare(const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
const T1& /* expected */,
|
||||
T2* actual) {
|
||||
// This version will be picked when the second argument to ASSERT_EQ() is a
|
||||
// pointer, e.g. ASSERT_EQ(NULL, a_pointer).
|
||||
template <typename T>
|
||||
static AssertionResult Compare(
|
||||
const char* expected_expression,
|
||||
const char* actual_expression,
|
||||
// We used to have a second template parameter instead of Secret*. That
|
||||
// template parameter would deduce to 'long', making this a better match
|
||||
// than the first overload even without the first overload's EnableIf.
|
||||
// Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
|
||||
// non-pointer argument" (even a deduced integral argument), so the old
|
||||
// implementation caused warnings in user code.
|
||||
Secret* /* expected (NULL) */,
|
||||
T* actual) {
|
||||
// We already know that 'expected' is a null pointer.
|
||||
return CmpHelperEQ(expected_expression, actual_expression,
|
||||
static_cast<T2*>(NULL), actual);
|
||||
static_cast<T*>(NULL), actual);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1365,11 +1432,10 @@ AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
|
||||
if (val1 op val2) {\
|
||||
return AssertionSuccess();\
|
||||
} else {\
|
||||
Message msg;\
|
||||
msg << "Expected: (" << expr1 << ") " #op " (" << expr2\
|
||||
return AssertionFailure() \
|
||||
<< "Expected: (" << expr1 << ") " #op " (" << expr2\
|
||||
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
|
||||
<< " vs " << FormatForComparisonFailureMessage(val2, val1);\
|
||||
return AssertionFailure(msg);\
|
||||
}\
|
||||
}\
|
||||
GTEST_API_ AssertionResult CmpHelper##op_name(\
|
||||
@ -1497,18 +1563,18 @@ AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression,
|
||||
return AssertionSuccess();
|
||||
}
|
||||
|
||||
StrStream expected_ss;
|
||||
::std::stringstream expected_ss;
|
||||
expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
|
||||
<< expected;
|
||||
|
||||
StrStream actual_ss;
|
||||
::std::stringstream actual_ss;
|
||||
actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
|
||||
<< actual;
|
||||
|
||||
return EqFailure(expected_expression,
|
||||
actual_expression,
|
||||
StrStreamToString(&expected_ss),
|
||||
StrStreamToString(&actual_ss),
|
||||
StringStreamToString(&expected_ss),
|
||||
StringStreamToString(&actual_ss),
|
||||
false);
|
||||
}
|
||||
|
||||
@ -1566,9 +1632,13 @@ class GTEST_API_ AssertHelper {
|
||||
} // namespace internal
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
// The abstract base class that all value-parameterized tests inherit from.
|
||||
// The pure interface class that all value-parameterized tests inherit from.
|
||||
// A value-parameterized class must inherit from both ::testing::Test and
|
||||
// ::testing::WithParamInterface. In most cases that just means inheriting
|
||||
// from ::testing::TestWithParam, but more complicated test hierarchies
|
||||
// may need to inherit from Test and WithParamInterface at different levels.
|
||||
//
|
||||
// This class adds support for accessing the test parameter value via
|
||||
// This interface has support for accessing the test parameter value via
|
||||
// the GetParam() method.
|
||||
//
|
||||
// Use it with one of the parameter generator defining functions, like Range(),
|
||||
@ -1597,12 +1667,16 @@ class GTEST_API_ AssertHelper {
|
||||
// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
|
||||
|
||||
template <typename T>
|
||||
class TestWithParam : public Test {
|
||||
class WithParamInterface {
|
||||
public:
|
||||
typedef T ParamType;
|
||||
virtual ~WithParamInterface() {}
|
||||
|
||||
// The current parameter value. Is also available in the test fixture's
|
||||
// constructor.
|
||||
// constructor. This member function is non-static, even though it only
|
||||
// references static data, to reduce the opportunity for incorrect uses
|
||||
// like writing 'WithParamInterface<bool>::GetParam()' for a test that
|
||||
// uses a fixture whose parameter type is int.
|
||||
const ParamType& GetParam() const { return *parameter_; }
|
||||
|
||||
private:
|
||||
@ -1615,12 +1689,19 @@ class TestWithParam : public Test {
|
||||
// Static value used for accessing parameter during a test lifetime.
|
||||
static const ParamType* parameter_;
|
||||
|
||||
// TestClass must be a subclass of TestWithParam<T>.
|
||||
// TestClass must be a subclass of WithParamInterface<T> and Test.
|
||||
template <class TestClass> friend class internal::ParameterizedTestFactory;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
const T* TestWithParam<T>::parameter_ = NULL;
|
||||
const T* WithParamInterface<T>::parameter_ = NULL;
|
||||
|
||||
// Most value-parameterized classes can ignore the existence of
|
||||
// WithParamInterface, and can just inherit from ::testing::TestWithParam.
|
||||
|
||||
template <typename T>
|
||||
class TestWithParam : public Test, public WithParamInterface<T> {
|
||||
};
|
||||
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
||||
@ -1652,13 +1733,19 @@ const T* TestWithParam<T>::parameter_ = NULL;
|
||||
// Generates a nonfatal failure with a generic message.
|
||||
#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
|
||||
|
||||
// Generates a nonfatal failure at the given source file location with
|
||||
// a generic message.
|
||||
#define ADD_FAILURE_AT(file, line) \
|
||||
GTEST_MESSAGE_AT_(file, line, "Failed", \
|
||||
::testing::TestPartResult::kNonFatalFailure)
|
||||
|
||||
// Generates a fatal failure with a generic message.
|
||||
#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
|
||||
|
||||
// Define this macro to 1 to omit the definition of FAIL(), which is a
|
||||
// generic name and clashes with some other libraries.
|
||||
#if !GTEST_DONT_DEFINE_FAIL
|
||||
#define FAIL() GTEST_FAIL()
|
||||
# define FAIL() GTEST_FAIL()
|
||||
#endif
|
||||
|
||||
// Generates a success with a generic message.
|
||||
@ -1667,7 +1754,7 @@ const T* TestWithParam<T>::parameter_ = NULL;
|
||||
// Define this macro to 1 to omit the definition of SUCCEED(), which
|
||||
// is a generic name and clashes with some other libraries.
|
||||
#if !GTEST_DONT_DEFINE_SUCCEED
|
||||
#define SUCCEED() GTEST_SUCCEED()
|
||||
# define SUCCEED() GTEST_SUCCEED()
|
||||
#endif
|
||||
|
||||
// Macros for testing exceptions.
|
||||
@ -1710,7 +1797,7 @@ const T* TestWithParam<T>::parameter_ = NULL;
|
||||
|
||||
// Includes the auto-generated header that implements a family of
|
||||
// generic predicate assertion macros.
|
||||
#include <gtest/gtest_pred_impl.h>
|
||||
#include "gtest/gtest_pred_impl.h"
|
||||
|
||||
// Macros for testing equalities and inequalities.
|
||||
//
|
||||
@ -1773,21 +1860,48 @@ const T* TestWithParam<T>::parameter_ = NULL;
|
||||
#define EXPECT_GT(val1, val2) \
|
||||
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
|
||||
|
||||
#define ASSERT_EQ(expected, actual) \
|
||||
#define GTEST_ASSERT_EQ(expected, actual) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal:: \
|
||||
EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
|
||||
expected, actual)
|
||||
#define ASSERT_NE(val1, val2) \
|
||||
#define GTEST_ASSERT_NE(val1, val2) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
|
||||
#define ASSERT_LE(val1, val2) \
|
||||
#define GTEST_ASSERT_LE(val1, val2) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
|
||||
#define ASSERT_LT(val1, val2) \
|
||||
#define GTEST_ASSERT_LT(val1, val2) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
|
||||
#define ASSERT_GE(val1, val2) \
|
||||
#define GTEST_ASSERT_GE(val1, val2) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
|
||||
#define ASSERT_GT(val1, val2) \
|
||||
#define GTEST_ASSERT_GT(val1, val2) \
|
||||
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
|
||||
|
||||
// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
|
||||
// ASSERT_XY(), which clashes with some users' own code.
|
||||
|
||||
#if !GTEST_DONT_DEFINE_ASSERT_EQ
|
||||
# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
|
||||
#endif
|
||||
|
||||
#if !GTEST_DONT_DEFINE_ASSERT_NE
|
||||
# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
|
||||
#endif
|
||||
|
||||
#if !GTEST_DONT_DEFINE_ASSERT_LE
|
||||
# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
|
||||
#endif
|
||||
|
||||
#if !GTEST_DONT_DEFINE_ASSERT_LT
|
||||
# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
|
||||
#endif
|
||||
|
||||
#if !GTEST_DONT_DEFINE_ASSERT_GE
|
||||
# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
|
||||
#endif
|
||||
|
||||
#if !GTEST_DONT_DEFINE_ASSERT_GT
|
||||
# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
|
||||
#endif
|
||||
|
||||
// C String Comparisons. All tests treat NULL and any non-NULL string
|
||||
// as different. Two NULLs are equal.
|
||||
//
|
||||
@ -1884,16 +1998,16 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
|
||||
// expected result and the actual result with both a human-readable
|
||||
// string representation of the error, if available, as well as the
|
||||
// hex result code.
|
||||
#define EXPECT_HRESULT_SUCCEEDED(expr) \
|
||||
# define EXPECT_HRESULT_SUCCEEDED(expr) \
|
||||
EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
|
||||
|
||||
#define ASSERT_HRESULT_SUCCEEDED(expr) \
|
||||
# define ASSERT_HRESULT_SUCCEEDED(expr) \
|
||||
ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
|
||||
|
||||
#define EXPECT_HRESULT_FAILED(expr) \
|
||||
# define EXPECT_HRESULT_FAILED(expr) \
|
||||
EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
|
||||
|
||||
#define ASSERT_HRESULT_FAILED(expr) \
|
||||
# define ASSERT_HRESULT_FAILED(expr) \
|
||||
ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
|
||||
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
@ -1928,17 +2042,6 @@ GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
|
||||
::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
|
||||
__FILE__, __LINE__, ::testing::Message() << (message))
|
||||
|
||||
namespace internal {
|
||||
|
||||
// This template is declared, but intentionally undefined.
|
||||
template <typename T1, typename T2>
|
||||
struct StaticAssertTypeEqHelper;
|
||||
|
||||
template <typename T>
|
||||
struct StaticAssertTypeEqHelper<T, T> {};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Compile-time assertion for type equality.
|
||||
// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
|
||||
// the same type. The value it returns is not interesting.
|
||||
@ -1971,7 +2074,7 @@ struct StaticAssertTypeEqHelper<T, T> {};
|
||||
// to cause a compiler error.
|
||||
template <typename T1, typename T2>
|
||||
bool StaticAssertTypeEq() {
|
||||
internal::StaticAssertTypeEqHelper<T1, T2>();
|
||||
(void)internal::StaticAssertTypeEqHelper<T1, T2>();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2007,7 +2110,7 @@ bool StaticAssertTypeEq() {
|
||||
// Define this macro to 1 to omit the definition of TEST(), which
|
||||
// is a generic name and clashes with some other libraries.
|
||||
#if !GTEST_DONT_DEFINE_TEST
|
||||
#define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
|
||||
# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
|
||||
#endif
|
||||
|
||||
// Defines a test that uses a test fixture.
|
||||
|
@ -27,7 +27,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file is AUTOMATICALLY GENERATED on 10/02/2008 by command
|
||||
// This file is AUTOMATICALLY GENERATED on 09/24/2010 by command
|
||||
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
||||
//
|
||||
// Implements a family of generic predicate assertion macros.
|
||||
@ -37,7 +37,7 @@
|
||||
|
||||
// Makes sure this header is not included before gtest.h.
|
||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_H_
|
||||
#error Do not include gtest_pred_impl.h directly. Include gtest.h instead.
|
||||
# error Do not include gtest_pred_impl.h directly. Include gtest.h instead.
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_H_
|
||||
|
||||
// This header implements a family of generic predicate assertion
|
||||
@ -90,11 +90,9 @@ AssertionResult AssertPred1Helper(const char* pred_text,
|
||||
const T1& v1) {
|
||||
if (pred(v1)) return AssertionSuccess();
|
||||
|
||||
Message msg;
|
||||
msg << pred_text << "("
|
||||
<< e1 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1;
|
||||
return AssertionFailure(msg);
|
||||
return AssertionFailure() << pred_text << "("
|
||||
<< e1 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1;
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
|
||||
@ -136,13 +134,11 @@ AssertionResult AssertPred2Helper(const char* pred_text,
|
||||
const T2& v2) {
|
||||
if (pred(v1, v2)) return AssertionSuccess();
|
||||
|
||||
Message msg;
|
||||
msg << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2;
|
||||
return AssertionFailure(msg);
|
||||
return AssertionFailure() << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2;
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
|
||||
@ -189,15 +185,13 @@ AssertionResult AssertPred3Helper(const char* pred_text,
|
||||
const T3& v3) {
|
||||
if (pred(v1, v2, v3)) return AssertionSuccess();
|
||||
|
||||
Message msg;
|
||||
msg << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ", "
|
||||
<< e3 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2
|
||||
<< "\n" << e3 << " evaluates to " << v3;
|
||||
return AssertionFailure(msg);
|
||||
return AssertionFailure() << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ", "
|
||||
<< e3 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2
|
||||
<< "\n" << e3 << " evaluates to " << v3;
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
|
||||
@ -249,17 +243,15 @@ AssertionResult AssertPred4Helper(const char* pred_text,
|
||||
const T4& v4) {
|
||||
if (pred(v1, v2, v3, v4)) return AssertionSuccess();
|
||||
|
||||
Message msg;
|
||||
msg << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ", "
|
||||
<< e3 << ", "
|
||||
<< e4 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2
|
||||
<< "\n" << e3 << " evaluates to " << v3
|
||||
<< "\n" << e4 << " evaluates to " << v4;
|
||||
return AssertionFailure(msg);
|
||||
return AssertionFailure() << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ", "
|
||||
<< e3 << ", "
|
||||
<< e4 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2
|
||||
<< "\n" << e3 << " evaluates to " << v3
|
||||
<< "\n" << e4 << " evaluates to " << v4;
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
|
||||
@ -316,19 +308,17 @@ AssertionResult AssertPred5Helper(const char* pred_text,
|
||||
const T5& v5) {
|
||||
if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
|
||||
|
||||
Message msg;
|
||||
msg << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ", "
|
||||
<< e3 << ", "
|
||||
<< e4 << ", "
|
||||
<< e5 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2
|
||||
<< "\n" << e3 << " evaluates to " << v3
|
||||
<< "\n" << e4 << " evaluates to " << v4
|
||||
<< "\n" << e5 << " evaluates to " << v5;
|
||||
return AssertionFailure(msg);
|
||||
return AssertionFailure() << pred_text << "("
|
||||
<< e1 << ", "
|
||||
<< e2 << ", "
|
||||
<< e3 << ", "
|
||||
<< e4 << ", "
|
||||
<< e5 << ") evaluates to false, where"
|
||||
<< "\n" << e1 << " evaluates to " << v1
|
||||
<< "\n" << e2 << " evaluates to " << v2
|
||||
<< "\n" << e3 << " evaluates to " << v3
|
||||
<< "\n" << e4 << " evaluates to " << v4
|
||||
<< "\n" << e5 << " evaluates to " << v5;
|
||||
}
|
||||
|
||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
|
||||
|
@ -37,7 +37,9 @@
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
|
||||
|
||||
#include <gtest/internal/gtest-internal.h>
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
@ -96,8 +98,12 @@ class GTEST_API_ DeathTest {
|
||||
// test, then wait for it to complete.
|
||||
enum TestRole { OVERSEE_TEST, EXECUTE_TEST };
|
||||
|
||||
// An enumeration of the two reasons that a test might be aborted.
|
||||
enum AbortReason { TEST_ENCOUNTERED_RETURN_STATEMENT, TEST_DID_NOT_DIE };
|
||||
// An enumeration of the three reasons that a test might be aborted.
|
||||
enum AbortReason {
|
||||
TEST_ENCOUNTERED_RETURN_STATEMENT,
|
||||
TEST_THREW_EXCEPTION,
|
||||
TEST_DID_NOT_DIE
|
||||
};
|
||||
|
||||
// Assumes one of the above roles.
|
||||
virtual TestRole AssumeRole() = 0;
|
||||
@ -149,9 +155,34 @@ class DefaultDeathTestFactory : public DeathTestFactory {
|
||||
// by a signal, or exited normally with a nonzero exit code.
|
||||
GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
||||
|
||||
// Traps C++ exceptions escaping statement and reports them as test
|
||||
// failures. Note that trapping SEH exceptions is not implemented here.
|
||||
# if GTEST_HAS_EXCEPTIONS
|
||||
# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
|
||||
try { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} catch (const ::std::exception& gtest_exception) { \
|
||||
fprintf(\
|
||||
stderr, \
|
||||
"\n%s: Caught std::exception-derived exception escaping the " \
|
||||
"death test statement. Exception message: %s\n", \
|
||||
::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \
|
||||
gtest_exception.what()); \
|
||||
fflush(stderr); \
|
||||
death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
|
||||
} catch (...) { \
|
||||
death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
|
||||
}
|
||||
|
||||
# else
|
||||
# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
|
||||
|
||||
# endif
|
||||
|
||||
// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
|
||||
// ASSERT_EXIT*, and EXPECT_EXIT*.
|
||||
#define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \
|
||||
# define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
const ::testing::internal::RE& gtest_regex = (regex); \
|
||||
@ -172,10 +203,12 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
|
||||
case ::testing::internal::DeathTest::EXECUTE_TEST: { \
|
||||
::testing::internal::DeathTest::ReturnSentinel \
|
||||
gtest_sentinel(gtest_dt); \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
|
||||
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
|
||||
break; \
|
||||
} \
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} else \
|
||||
@ -254,7 +287,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
|
||||
// statement unconditionally returns or throws. The Message constructor at
|
||||
// the end allows the syntax of streaming additional messages into the
|
||||
// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
|
||||
#define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \
|
||||
# define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
GTEST_LOG_(WARNING) \
|
||||
|
@ -40,7 +40,7 @@
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
|
||||
|
||||
#include <gtest/internal/gtest-string.h>
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
@ -41,12 +41,12 @@
|
||||
// part of Google Test's implementation; otherwise it's undefined.
|
||||
#if !GTEST_IMPLEMENTATION_
|
||||
// A user is trying to include this from his code - just say no.
|
||||
#error "gtest-internal-inl.h is part of Google Test's internal implementation."
|
||||
#error "It must not be included except by Google Test itself."
|
||||
# error "gtest-internal-inl.h is part of Google Test's internal implementation."
|
||||
# error "It must not be included except by Google Test itself."
|
||||
#endif // GTEST_IMPLEMENTATION_
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
#include <errno.h>
|
||||
# include <errno.h>
|
||||
#endif // !_WIN32_WCE
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h> // For strtoll/_strtoul64/malloc/free.
|
||||
@ -56,14 +56,14 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
#include <windows.h> // For DWORD.
|
||||
# include <windows.h> // NOLINT
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
#include <gtest/gtest.h> // NOLINT
|
||||
#include <gtest/gtest-spi.h>
|
||||
#include "gtest/gtest.h" // NOLINT
|
||||
#include "gtest/gtest-spi.h"
|
||||
|
||||
namespace testing {
|
||||
|
||||
@ -93,6 +93,7 @@ const char kRandomSeedFlag[] = "random_seed";
|
||||
const char kRepeatFlag[] = "repeat";
|
||||
const char kShuffleFlag[] = "shuffle";
|
||||
const char kStackTraceDepthFlag[] = "stack_trace_depth";
|
||||
const char kStreamResultToFlag[] = "stream_result_to";
|
||||
const char kThrowOnFailureFlag[] = "throw_on_failure";
|
||||
|
||||
// A valid random seed must be in [1, kMaxRandomSeed].
|
||||
@ -165,6 +166,7 @@ class GTestFlagSaver {
|
||||
repeat_ = GTEST_FLAG(repeat);
|
||||
shuffle_ = GTEST_FLAG(shuffle);
|
||||
stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
|
||||
stream_result_to_ = GTEST_FLAG(stream_result_to);
|
||||
throw_on_failure_ = GTEST_FLAG(throw_on_failure);
|
||||
}
|
||||
|
||||
@ -185,6 +187,7 @@ class GTestFlagSaver {
|
||||
GTEST_FLAG(repeat) = repeat_;
|
||||
GTEST_FLAG(shuffle) = shuffle_;
|
||||
GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
|
||||
GTEST_FLAG(stream_result_to) = stream_result_to_;
|
||||
GTEST_FLAG(throw_on_failure) = throw_on_failure_;
|
||||
}
|
||||
private:
|
||||
@ -205,6 +208,7 @@ class GTestFlagSaver {
|
||||
internal::Int32 repeat_;
|
||||
bool shuffle_;
|
||||
internal::Int32 stack_trace_depth_;
|
||||
String stream_result_to_;
|
||||
bool throw_on_failure_;
|
||||
} GTEST_ATTRIBUTE_UNUSED_;
|
||||
|
||||
@ -267,7 +271,14 @@ GTEST_API_ bool ShouldRunTestOnShard(
|
||||
// the given predicate.
|
||||
template <class Container, typename Predicate>
|
||||
inline int CountIf(const Container& c, Predicate predicate) {
|
||||
return static_cast<int>(std::count_if(c.begin(), c.end(), predicate));
|
||||
// Implemented as an explicit loop since std::count_if() in libCstd on
|
||||
// Solaris has a non-standard signature.
|
||||
int count = 0;
|
||||
for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
|
||||
if (predicate(*it))
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Applies a function/functor to each element in the container.
|
||||
@ -340,85 +351,6 @@ class TestPropertyKeyIs {
|
||||
String key_;
|
||||
};
|
||||
|
||||
class TestInfoImpl {
|
||||
public:
|
||||
TestInfoImpl(TestInfo* parent, const char* test_case_name,
|
||||
const char* name, const char* test_case_comment,
|
||||
const char* comment, TypeId fixture_class_id,
|
||||
internal::TestFactoryBase* factory);
|
||||
~TestInfoImpl();
|
||||
|
||||
// Returns true if this test should run.
|
||||
bool should_run() const { return should_run_; }
|
||||
|
||||
// Sets the should_run member.
|
||||
void set_should_run(bool should) { should_run_ = should; }
|
||||
|
||||
// Returns true if this test is disabled. Disabled tests are not run.
|
||||
bool is_disabled() const { return is_disabled_; }
|
||||
|
||||
// Sets the is_disabled member.
|
||||
void set_is_disabled(bool is) { is_disabled_ = is; }
|
||||
|
||||
// Returns true if this test matches the filter specified by the user.
|
||||
bool matches_filter() const { return matches_filter_; }
|
||||
|
||||
// Sets the matches_filter member.
|
||||
void set_matches_filter(bool matches) { matches_filter_ = matches; }
|
||||
|
||||
// Returns the test case name.
|
||||
const char* test_case_name() const { return test_case_name_.c_str(); }
|
||||
|
||||
// Returns the test name.
|
||||
const char* name() const { return name_.c_str(); }
|
||||
|
||||
// Returns the test case comment.
|
||||
const char* test_case_comment() const { return test_case_comment_.c_str(); }
|
||||
|
||||
// Returns the test comment.
|
||||
const char* comment() const { return comment_.c_str(); }
|
||||
|
||||
// Returns the ID of the test fixture class.
|
||||
TypeId fixture_class_id() const { return fixture_class_id_; }
|
||||
|
||||
// Returns the test result.
|
||||
TestResult* result() { return &result_; }
|
||||
const TestResult* result() const { return &result_; }
|
||||
|
||||
// Creates the test object, runs it, records its result, and then
|
||||
// deletes it.
|
||||
void Run();
|
||||
|
||||
// Clears the test result.
|
||||
void ClearResult() { result_.Clear(); }
|
||||
|
||||
// Clears the test result in the given TestInfo object.
|
||||
static void ClearTestResult(TestInfo * test_info) {
|
||||
test_info->impl()->ClearResult();
|
||||
}
|
||||
|
||||
private:
|
||||
// These fields are immutable properties of the test.
|
||||
TestInfo* const parent_; // The owner of this object
|
||||
const String test_case_name_; // Test case name
|
||||
const String name_; // Test name
|
||||
const String test_case_comment_; // Test case comment
|
||||
const String comment_; // Test comment
|
||||
const TypeId fixture_class_id_; // ID of the test fixture class
|
||||
bool should_run_; // True iff this test should run
|
||||
bool is_disabled_; // True iff this test is disabled
|
||||
bool matches_filter_; // True if this test matches the
|
||||
// user-specified filter.
|
||||
internal::TestFactoryBase* const factory_; // The factory that creates
|
||||
// the test object
|
||||
|
||||
// This field is mutable and needs to be reset before running the
|
||||
// test for the second time.
|
||||
TestResult result_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfoImpl);
|
||||
};
|
||||
|
||||
// Class UnitTestOptions.
|
||||
//
|
||||
// This class contains functions for processing options the user
|
||||
@ -682,10 +614,12 @@ class GTEST_API_ UnitTestImpl {
|
||||
// Arguments:
|
||||
//
|
||||
// test_case_name: name of the test case
|
||||
// type_param: the name of the test's type parameter, or NULL if
|
||||
// this is not a typed or a type-parameterized test.
|
||||
// set_up_tc: pointer to the function that sets up the test case
|
||||
// tear_down_tc: pointer to the function that tears down the test case
|
||||
TestCase* GetTestCase(const char* test_case_name,
|
||||
const char* comment,
|
||||
const char* type_param,
|
||||
Test::SetUpTestCaseFunc set_up_tc,
|
||||
Test::TearDownTestCaseFunc tear_down_tc);
|
||||
|
||||
@ -698,7 +632,7 @@ class GTEST_API_ UnitTestImpl {
|
||||
// test_info: the TestInfo object
|
||||
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
|
||||
Test::TearDownTestCaseFunc tear_down_tc,
|
||||
TestInfo * test_info) {
|
||||
TestInfo* test_info) {
|
||||
// In order to support thread-safe death tests, we need to
|
||||
// remember the original working directory when the test program
|
||||
// was first invoked. We cannot do this in RUN_ALL_TESTS(), as
|
||||
@ -713,7 +647,7 @@ class GTEST_API_ UnitTestImpl {
|
||||
}
|
||||
|
||||
GetTestCase(test_info->test_case_name(),
|
||||
test_info->test_case_comment(),
|
||||
test_info->type_param(),
|
||||
set_up_tc,
|
||||
tear_down_tc)->AddTestInfo(test_info);
|
||||
}
|
||||
@ -739,24 +673,26 @@ class GTEST_API_ UnitTestImpl {
|
||||
}
|
||||
|
||||
// Registers all parameterized tests defined using TEST_P and
|
||||
// INSTANTIATE_TEST_P, creating regular tests for each test/parameter
|
||||
// combination. This method can be called more then once; it has
|
||||
// guards protecting from registering the tests more then once.
|
||||
// If value-parameterized tests are disabled, RegisterParameterizedTests
|
||||
// is present but does nothing.
|
||||
// INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
|
||||
// combination. This method can be called more then once; it has guards
|
||||
// protecting from registering the tests more then once. If
|
||||
// value-parameterized tests are disabled, RegisterParameterizedTests is
|
||||
// present but does nothing.
|
||||
void RegisterParameterizedTests();
|
||||
|
||||
// Runs all tests in this UnitTest object, prints the result, and
|
||||
// returns 0 if all tests are successful, or 1 otherwise. If any
|
||||
// exception is thrown during a test on Windows, this test is
|
||||
// considered to be failed, but the rest of the tests will still be
|
||||
// run. (We disable exceptions on Linux and Mac OS X, so the issue
|
||||
// doesn't apply there.)
|
||||
int RunAllTests();
|
||||
// returns true if all tests are successful. If any exception is
|
||||
// thrown during a test, this test is considered to be failed, but
|
||||
// the rest of the tests will still be run.
|
||||
bool RunAllTests();
|
||||
|
||||
// Clears the results of all tests, including the ad hoc test.
|
||||
void ClearResult() {
|
||||
// Clears the results of all tests, except the ad hoc tests.
|
||||
void ClearNonAdHocTestResult() {
|
||||
ForEach(test_cases_, TestCase::ClearTestCaseResult);
|
||||
}
|
||||
|
||||
// Clears the results of ad-hoc test assertions.
|
||||
void ClearAdHocTestResult() {
|
||||
ad_hoc_test_result_.Clear();
|
||||
}
|
||||
|
||||
@ -818,6 +754,12 @@ class GTEST_API_ UnitTestImpl {
|
||||
// UnitTestOptions. Must not be called before InitGoogleTest.
|
||||
void ConfigureXmlOutput();
|
||||
|
||||
#if GTEST_CAN_STREAM_RESULTS_
|
||||
// Initializes the event listener for streaming test results to a socket.
|
||||
// Must not be called before InitGoogleTest.
|
||||
void ConfigureStreamingOutput();
|
||||
#endif
|
||||
|
||||
// Performs initialization dependent upon flag values obtained in
|
||||
// ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
|
||||
// ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
|
||||
@ -838,9 +780,17 @@ class GTEST_API_ UnitTestImpl {
|
||||
// Restores the test cases and tests to their order before the first shuffle.
|
||||
void UnshuffleTests();
|
||||
|
||||
// Returns the value of GTEST_FLAG(catch_exceptions) at the moment
|
||||
// UnitTest::Run() starts.
|
||||
bool catch_exceptions() const { return catch_exceptions_; }
|
||||
|
||||
private:
|
||||
friend class ::testing::UnitTest;
|
||||
|
||||
// Used by UnitTest::Run() to capture the state of
|
||||
// GTEST_FLAG(catch_exceptions) at the moment it starts.
|
||||
void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
|
||||
|
||||
// The UnitTest object that owns this implementation object.
|
||||
UnitTest* const parent_;
|
||||
|
||||
@ -943,6 +893,10 @@ class GTEST_API_ UnitTestImpl {
|
||||
// A per-thread stack of traces created by the SCOPED_TRACE() macro.
|
||||
internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
|
||||
|
||||
// The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
|
||||
// starts.
|
||||
bool catch_exceptions_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
|
||||
}; // class UnitTestImpl
|
||||
|
||||
@ -952,14 +906,16 @@ inline UnitTestImpl* GetUnitTestImpl() {
|
||||
return UnitTest::GetInstance()->impl();
|
||||
}
|
||||
|
||||
#if GTEST_USES_SIMPLE_RE
|
||||
|
||||
// Internal helper functions for implementing the simple regular
|
||||
// expression matcher.
|
||||
GTEST_API_ bool IsInSet(char ch, const char* str);
|
||||
GTEST_API_ bool IsDigit(char ch);
|
||||
GTEST_API_ bool IsPunct(char ch);
|
||||
GTEST_API_ bool IsAsciiDigit(char ch);
|
||||
GTEST_API_ bool IsAsciiPunct(char ch);
|
||||
GTEST_API_ bool IsRepeat(char ch);
|
||||
GTEST_API_ bool IsWhiteSpace(char ch);
|
||||
GTEST_API_ bool IsWordChar(char ch);
|
||||
GTEST_API_ bool IsAsciiWhiteSpace(char ch);
|
||||
GTEST_API_ bool IsAsciiWordChar(char ch);
|
||||
GTEST_API_ bool IsValidEscape(char ch);
|
||||
GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
|
||||
GTEST_API_ bool ValidateRegex(const char* regex);
|
||||
@ -968,6 +924,8 @@ GTEST_API_ bool MatchRepetitionAndRegexAtHead(
|
||||
bool escaped, char ch, char repeat, const char* regex, const char* str);
|
||||
GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
|
||||
|
||||
#endif // GTEST_USES_SIMPLE_RE
|
||||
|
||||
// Parses the command line for Google Test flags, without initializing
|
||||
// other parts of Google Test.
|
||||
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
|
||||
@ -977,9 +935,9 @@ GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
|
||||
|
||||
// Returns the message describing the last system error, regardless of the
|
||||
// platform.
|
||||
String GetLastErrnoDescription();
|
||||
GTEST_API_ String GetLastErrnoDescription();
|
||||
|
||||
#if GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS
|
||||
// Provides leak-safe Windows kernel handle ownership.
|
||||
class AutoHandle {
|
||||
public:
|
||||
@ -1003,7 +961,7 @@ class AutoHandle {
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
|
||||
};
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
||||
// Attempts to parse a string into a positive integer pointed to by the
|
||||
// number parameter. Returns true if that is possible.
|
||||
@ -1014,7 +972,7 @@ bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
|
||||
// Fail fast if the given string does not begin with a digit;
|
||||
// this bypasses strtoXXX's "optional leading whitespace and plus
|
||||
// or minus sign" semantics, which are undesirable here.
|
||||
if (str.empty() || !isdigit(str[0])) {
|
||||
if (str.empty() || !IsDigit(str[0])) {
|
||||
return false;
|
||||
}
|
||||
errno = 0;
|
||||
@ -1022,14 +980,20 @@ bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
|
||||
char* end;
|
||||
// BiggestConvertible is the largest integer type that system-provided
|
||||
// string-to-number conversion routines can return.
|
||||
#if GTEST_OS_WINDOWS && !defined(__GNUC__)
|
||||
|
||||
# if GTEST_OS_WINDOWS && !defined(__GNUC__)
|
||||
|
||||
// MSVC and C++ Builder define __int64 instead of the standard long long.
|
||||
typedef unsigned __int64 BiggestConvertible;
|
||||
const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
|
||||
#else
|
||||
|
||||
# else
|
||||
|
||||
typedef unsigned long long BiggestConvertible; // NOLINT
|
||||
const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
|
||||
#endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
|
||||
|
||||
# endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
|
||||
|
||||
const bool parse_success = *end == '\0' && errno == 0;
|
||||
|
||||
// TODO(vladl@google.com): Convert this to compile time assertion when it is
|
||||
|
@ -37,13 +37,13 @@
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
|
||||
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_OS_LINUX
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
# include <stdlib.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/wait.h>
|
||||
# include <unistd.h>
|
||||
#endif // GTEST_OS_LINUX
|
||||
|
||||
#include <ctype.h>
|
||||
@ -52,9 +52,9 @@
|
||||
#include <limits>
|
||||
#include <set>
|
||||
|
||||
#include <gtest/internal/gtest-string.h>
|
||||
#include <gtest/internal/gtest-filepath.h>
|
||||
#include <gtest/internal/gtest-type-util.h>
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
#include "gtest/internal/gtest-filepath.h"
|
||||
#include "gtest/internal/gtest-type-util.h"
|
||||
|
||||
#include "llvm/Support/raw_os_ostream.h"
|
||||
|
||||
@ -117,9 +117,12 @@ inline void GTestStreamToHelper(std::ostream* os, const T& val) {
|
||||
cos << val;
|
||||
}
|
||||
|
||||
class ProtocolMessage;
|
||||
namespace proto2 { class Message; }
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Forward declaration of classes.
|
||||
// Forward declarations.
|
||||
|
||||
class AssertionResult; // Result of an assertion.
|
||||
class Message; // Represents a failure message.
|
||||
@ -128,6 +131,9 @@ class TestInfo; // Information about a test.
|
||||
class TestPartResult; // Result of a test part.
|
||||
class UnitTest; // A collection of test cases.
|
||||
|
||||
template <typename T>
|
||||
::std::string PrintToString(const T& value);
|
||||
|
||||
namespace internal {
|
||||
|
||||
struct TraceInfo; // Information about a trace point.
|
||||
@ -170,9 +176,9 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT
|
||||
#ifdef GTEST_ELLIPSIS_NEEDS_POD_
|
||||
// We lose support for NULL detection where the compiler doesn't like
|
||||
// passing non-POD classes through ellipsis (...).
|
||||
#define GTEST_IS_NULL_LITERAL_(x) false
|
||||
# define GTEST_IS_NULL_LITERAL_(x) false
|
||||
#else
|
||||
#define GTEST_IS_NULL_LITERAL_(x) \
|
||||
# define GTEST_IS_NULL_LITERAL_(x) \
|
||||
(sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
|
||||
#endif // GTEST_ELLIPSIS_NEEDS_POD_
|
||||
|
||||
@ -209,72 +215,32 @@ class GTEST_API_ ScopedTrace {
|
||||
template <typename T>
|
||||
String StreamableToString(const T& streamable);
|
||||
|
||||
// Formats a value to be used in a failure message.
|
||||
|
||||
#ifdef GTEST_NEEDS_IS_POINTER_
|
||||
|
||||
// These are needed as the Nokia Symbian and IBM XL C/C++ compilers
|
||||
// cannot decide between const T& and const T* in a function template.
|
||||
// These compilers _can_ decide between class template specializations
|
||||
// for T and T*, so a tr1::type_traits-like is_pointer works, and we
|
||||
// can overload on that.
|
||||
|
||||
// This overload makes sure that all pointers (including
|
||||
// those to char or wchar_t) are printed as raw pointers.
|
||||
template <typename T>
|
||||
inline String FormatValueForFailureMessage(internal::true_type /*dummy*/,
|
||||
T* pointer) {
|
||||
return StreamableToString(static_cast<const void*>(pointer));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline String FormatValueForFailureMessage(internal::false_type /*dummy*/,
|
||||
const T& value) {
|
||||
return StreamableToString(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline String FormatForFailureMessage(const T& value) {
|
||||
return FormatValueForFailureMessage(
|
||||
typename internal::is_pointer<T>::type(), value);
|
||||
}
|
||||
|
||||
// The Symbian compiler has a bug that prevents it from selecting the
|
||||
// correct overload of FormatForComparisonFailureMessage (see below)
|
||||
// unless we pass the first argument by reference. If we do that,
|
||||
// however, Visual Age C++ 10.1 generates a compiler error. Therefore
|
||||
// we only apply the work-around for Symbian.
|
||||
#if defined(__SYMBIAN32__)
|
||||
# define GTEST_CREF_WORKAROUND_ const&
|
||||
#else
|
||||
# define GTEST_CREF_WORKAROUND_
|
||||
#endif
|
||||
|
||||
// These are needed as the above solution using is_pointer has the
|
||||
// limitation that T cannot be a type without external linkage, when
|
||||
// compiled using MSVC.
|
||||
|
||||
template <typename T>
|
||||
inline String FormatForFailureMessage(const T& value) {
|
||||
return StreamableToString(value);
|
||||
}
|
||||
|
||||
// This overload makes sure that all pointers (including
|
||||
// those to char or wchar_t) are printed as raw pointers.
|
||||
template <typename T>
|
||||
inline String FormatForFailureMessage(T* pointer) {
|
||||
return StreamableToString(static_cast<const void*>(pointer));
|
||||
}
|
||||
|
||||
#endif // GTEST_NEEDS_IS_POINTER_
|
||||
|
||||
// These overloaded versions handle narrow and wide characters.
|
||||
GTEST_API_ String FormatForFailureMessage(char ch);
|
||||
GTEST_API_ String FormatForFailureMessage(wchar_t wchar);
|
||||
|
||||
// When this operand is a const char* or char*, and the other operand
|
||||
// When this operand is a const char* or char*, if the other operand
|
||||
// is a ::std::string or ::string, we print this operand as a C string
|
||||
// rather than a pointer. We do the same for wide strings.
|
||||
// rather than a pointer (we do the same for wide strings); otherwise
|
||||
// we print it as a pointer to be safe.
|
||||
|
||||
// This internal macro is used to avoid duplicated code.
|
||||
#define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\
|
||||
inline String FormatForComparisonFailureMessage(\
|
||||
operand2_type::value_type* str, const operand2_type& /*operand2*/) {\
|
||||
operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \
|
||||
const operand2_type& /*operand2*/) {\
|
||||
return operand1_printer(str);\
|
||||
}\
|
||||
inline String FormatForComparisonFailureMessage(\
|
||||
const operand2_type::value_type* str, const operand2_type& /*operand2*/) {\
|
||||
const operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \
|
||||
const operand2_type& /*operand2*/) {\
|
||||
return operand1_printer(str);\
|
||||
}
|
||||
|
||||
@ -292,6 +258,24 @@ GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted)
|
||||
|
||||
#undef GTEST_FORMAT_IMPL_
|
||||
|
||||
// The next four overloads handle the case where the operand being
|
||||
// printed is a char/wchar_t pointer and the other operand is not a
|
||||
// string/wstring object. In such cases, we just print the operand as
|
||||
// a pointer to be safe.
|
||||
#define GTEST_FORMAT_CHAR_PTR_IMPL_(CharType) \
|
||||
template <typename T> \
|
||||
String FormatForComparisonFailureMessage(CharType* GTEST_CREF_WORKAROUND_ p, \
|
||||
const T&) { \
|
||||
return PrintToString(static_cast<const void*>(p)); \
|
||||
}
|
||||
|
||||
GTEST_FORMAT_CHAR_PTR_IMPL_(char)
|
||||
GTEST_FORMAT_CHAR_PTR_IMPL_(const char)
|
||||
GTEST_FORMAT_CHAR_PTR_IMPL_(wchar_t)
|
||||
GTEST_FORMAT_CHAR_PTR_IMPL_(const wchar_t)
|
||||
|
||||
#undef GTEST_FORMAT_CHAR_PTR_IMPL_
|
||||
|
||||
// Constructs and returns the message for an equality assertion
|
||||
// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
|
||||
//
|
||||
@ -578,20 +562,6 @@ GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
|
||||
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
// Formats a source file path and a line number as they would appear
|
||||
// in a compiler error message.
|
||||
inline String FormatFileLocation(const char* file, int line) {
|
||||
const char* const file_name = file == NULL ? "unknown file" : file;
|
||||
if (line < 0) {
|
||||
return String::Format("%s:", file_name);
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
return String::Format("%s(%d):", file_name, line);
|
||||
#else
|
||||
return String::Format("%s:%d:", file_name, line);
|
||||
#endif // _MSC_VER
|
||||
}
|
||||
|
||||
// Types of SetUpTestCase() and TearDownTestCase() functions.
|
||||
typedef void (*SetUpTestCaseFunc)();
|
||||
typedef void (*TearDownTestCaseFunc)();
|
||||
@ -603,10 +573,10 @@ typedef void (*TearDownTestCaseFunc)();
|
||||
//
|
||||
// test_case_name: name of the test case
|
||||
// name: name of the test
|
||||
// test_case_comment: a comment on the test case that will be included in
|
||||
// the test output
|
||||
// comment: a comment on the test that will be included in the
|
||||
// test output
|
||||
// type_param the name of the test's type parameter, or NULL if
|
||||
// this is not a typed or a type-parameterized test.
|
||||
// value_param text representation of the test's value parameter,
|
||||
// or NULL if this is not a type-parameterized test.
|
||||
// fixture_class_id: ID of the test fixture class
|
||||
// set_up_tc: pointer to the function that sets up the test case
|
||||
// tear_down_tc: pointer to the function that tears down the test case
|
||||
@ -615,7 +585,8 @@ typedef void (*TearDownTestCaseFunc)();
|
||||
// ownership of the factory object.
|
||||
GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
|
||||
const char* test_case_name, const char* name,
|
||||
const char* test_case_comment, const char* comment,
|
||||
const char* type_param,
|
||||
const char* value_param,
|
||||
TypeId fixture_class_id,
|
||||
SetUpTestCaseFunc set_up_tc,
|
||||
TearDownTestCaseFunc tear_down_tc,
|
||||
@ -624,7 +595,7 @@ GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
|
||||
// If *pstr starts with the given prefix, modifies *pstr to be right
|
||||
// past the prefix and returns true; otherwise leaves *pstr unchanged
|
||||
// and returns false. None of pstr, *pstr, and prefix can be NULL.
|
||||
bool SkipPrefix(const char* prefix, const char** pstr);
|
||||
GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
@ -667,7 +638,7 @@ inline const char* SkipComma(const char* str) {
|
||||
if (comma == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
while (isspace(*(++comma))) {}
|
||||
while (IsSpace(*(++comma))) {}
|
||||
return comma;
|
||||
}
|
||||
|
||||
@ -704,8 +675,8 @@ class TypeParameterizedTest {
|
||||
String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/",
|
||||
case_name, index).c_str(),
|
||||
GetPrefixUntilComma(test_names).c_str(),
|
||||
String::Format("TypeParam = %s", GetTypeName<Type>().c_str()).c_str(),
|
||||
"",
|
||||
GetTypeName<Type>().c_str(),
|
||||
NULL, // No value parameter.
|
||||
GetTypeId<FixtureClass>(),
|
||||
TestClass::SetUpTestCase,
|
||||
TestClass::TearDownTestCase,
|
||||
@ -782,6 +753,15 @@ GTEST_API_ bool AlwaysTrue();
|
||||
// Always returns false.
|
||||
inline bool AlwaysFalse() { return !AlwaysTrue(); }
|
||||
|
||||
// Helper for suppressing false warning from Clang on a const char*
|
||||
// variable declared in a conditional expression always being NULL in
|
||||
// the else branch.
|
||||
struct GTEST_API_ ConstCharPtr {
|
||||
ConstCharPtr(const char* str) : value(str) {}
|
||||
operator bool() const { return true; }
|
||||
const char* value;
|
||||
};
|
||||
|
||||
// A simple Linear Congruential Generator for generating random
|
||||
// numbers with a uniform distribution. Unlike rand() and srand(), it
|
||||
// doesn't use global state (and therefore can't interfere with user
|
||||
@ -804,13 +784,338 @@ class GTEST_API_ Random {
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
|
||||
};
|
||||
|
||||
// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
|
||||
// compiler error iff T1 and T2 are different types.
|
||||
template <typename T1, typename T2>
|
||||
struct CompileAssertTypesEqual;
|
||||
|
||||
template <typename T>
|
||||
struct CompileAssertTypesEqual<T, T> {
|
||||
};
|
||||
|
||||
// Removes the reference from a type if it is a reference type,
|
||||
// otherwise leaves it unchanged. This is the same as
|
||||
// tr1::remove_reference, which is not widely available yet.
|
||||
template <typename T>
|
||||
struct RemoveReference { typedef T type; }; // NOLINT
|
||||
template <typename T>
|
||||
struct RemoveReference<T&> { typedef T type; }; // NOLINT
|
||||
|
||||
// A handy wrapper around RemoveReference that works when the argument
|
||||
// T depends on template parameters.
|
||||
#define GTEST_REMOVE_REFERENCE_(T) \
|
||||
typename ::testing::internal::RemoveReference<T>::type
|
||||
|
||||
// Removes const from a type if it is a const type, otherwise leaves
|
||||
// it unchanged. This is the same as tr1::remove_const, which is not
|
||||
// widely available yet.
|
||||
template <typename T>
|
||||
struct RemoveConst { typedef T type; }; // NOLINT
|
||||
template <typename T>
|
||||
struct RemoveConst<const T> { typedef T type; }; // NOLINT
|
||||
|
||||
// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above
|
||||
// definition to fail to remove the const in 'const int[3]' and 'const
|
||||
// char[3][4]'. The following specialization works around the bug.
|
||||
// However, it causes trouble with GCC and thus needs to be
|
||||
// conditionally compiled.
|
||||
#if defined(_MSC_VER) || defined(__SUNPRO_CC) || defined(__IBMCPP__)
|
||||
template <typename T, size_t N>
|
||||
struct RemoveConst<const T[N]> {
|
||||
typedef typename RemoveConst<T>::type type[N];
|
||||
};
|
||||
#endif
|
||||
|
||||
// A handy wrapper around RemoveConst that works when the argument
|
||||
// T depends on template parameters.
|
||||
#define GTEST_REMOVE_CONST_(T) \
|
||||
typename ::testing::internal::RemoveConst<T>::type
|
||||
|
||||
// Turns const U&, U&, const U, and U all into U.
|
||||
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
|
||||
GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
|
||||
|
||||
// Adds reference to a type if it is not a reference type,
|
||||
// otherwise leaves it unchanged. This is the same as
|
||||
// tr1::add_reference, which is not widely available yet.
|
||||
template <typename T>
|
||||
struct AddReference { typedef T& type; }; // NOLINT
|
||||
template <typename T>
|
||||
struct AddReference<T&> { typedef T& type; }; // NOLINT
|
||||
|
||||
// A handy wrapper around AddReference that works when the argument T
|
||||
// depends on template parameters.
|
||||
#define GTEST_ADD_REFERENCE_(T) \
|
||||
typename ::testing::internal::AddReference<T>::type
|
||||
|
||||
// Adds a reference to const on top of T as necessary. For example,
|
||||
// it transforms
|
||||
//
|
||||
// char ==> const char&
|
||||
// const char ==> const char&
|
||||
// char& ==> const char&
|
||||
// const char& ==> const char&
|
||||
//
|
||||
// The argument T must depend on some template parameters.
|
||||
#define GTEST_REFERENCE_TO_CONST_(T) \
|
||||
GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
|
||||
|
||||
// ImplicitlyConvertible<From, To>::value is a compile-time bool
|
||||
// constant that's true iff type From can be implicitly converted to
|
||||
// type To.
|
||||
template <typename From, typename To>
|
||||
class ImplicitlyConvertible {
|
||||
private:
|
||||
// We need the following helper functions only for their types.
|
||||
// They have no implementations.
|
||||
|
||||
// MakeFrom() is an expression whose type is From. We cannot simply
|
||||
// use From(), as the type From may not have a public default
|
||||
// constructor.
|
||||
static From MakeFrom();
|
||||
|
||||
// These two functions are overloaded. Given an expression
|
||||
// Helper(x), the compiler will pick the first version if x can be
|
||||
// implicitly converted to type To; otherwise it will pick the
|
||||
// second version.
|
||||
//
|
||||
// The first version returns a value of size 1, and the second
|
||||
// version returns a value of size 2. Therefore, by checking the
|
||||
// size of Helper(x), which can be done at compile time, we can tell
|
||||
// which version of Helper() is used, and hence whether x can be
|
||||
// implicitly converted to type To.
|
||||
static char Helper(To);
|
||||
static char (&Helper(...))[2]; // NOLINT
|
||||
|
||||
// We have to put the 'public' section after the 'private' section,
|
||||
// or MSVC refuses to compile the code.
|
||||
public:
|
||||
// MSVC warns about implicitly converting from double to int for
|
||||
// possible loss of data, so we need to temporarily disable the
|
||||
// warning.
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push) // Saves the current warning state.
|
||||
# pragma warning(disable:4244) // Temporarily disables warning 4244.
|
||||
|
||||
static const bool value =
|
||||
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
|
||||
# pragma warning(pop) // Restores the warning state.
|
||||
#elif defined(__BORLANDC__)
|
||||
// C++Builder cannot use member overload resolution during template
|
||||
// instantiation. The simplest workaround is to use its C++0x type traits
|
||||
// functions (C++Builder 2009 and above only).
|
||||
static const bool value = __is_convertible(From, To);
|
||||
#else
|
||||
static const bool value =
|
||||
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
|
||||
#endif // _MSV_VER
|
||||
};
|
||||
template <typename From, typename To>
|
||||
const bool ImplicitlyConvertible<From, To>::value;
|
||||
|
||||
// IsAProtocolMessage<T>::value is a compile-time bool constant that's
|
||||
// true iff T is type ProtocolMessage, proto2::Message, or a subclass
|
||||
// of those.
|
||||
template <typename T>
|
||||
struct IsAProtocolMessage
|
||||
: public bool_constant<
|
||||
ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
|
||||
ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
|
||||
};
|
||||
|
||||
// When the compiler sees expression IsContainerTest<C>(0), if C is an
|
||||
// STL-style container class, the first overload of IsContainerTest
|
||||
// will be viable (since both C::iterator* and C::const_iterator* are
|
||||
// valid types and NULL can be implicitly converted to them). It will
|
||||
// be picked over the second overload as 'int' is a perfect match for
|
||||
// the type of argument 0. If C::iterator or C::const_iterator is not
|
||||
// a valid type, the first overload is not viable, and the second
|
||||
// overload will be picked. Therefore, we can determine whether C is
|
||||
// a container class by checking the type of IsContainerTest<C>(0).
|
||||
// The value of the expression is insignificant.
|
||||
//
|
||||
// Note that we look for both C::iterator and C::const_iterator. The
|
||||
// reason is that C++ injects the name of a class as a member of the
|
||||
// class itself (e.g. you can refer to class iterator as either
|
||||
// 'iterator' or 'iterator::iterator'). If we look for C::iterator
|
||||
// only, for example, we would mistakenly think that a class named
|
||||
// iterator is an STL container.
|
||||
//
|
||||
// Also note that the simpler approach of overloading
|
||||
// IsContainerTest(typename C::const_iterator*) and
|
||||
// IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++.
|
||||
typedef int IsContainer;
|
||||
template <class C>
|
||||
IsContainer IsContainerTest(int /* dummy */,
|
||||
typename C::iterator* /* it */ = NULL,
|
||||
typename C::const_iterator* /* const_it */ = NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef char IsNotContainer;
|
||||
template <class C>
|
||||
IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; }
|
||||
|
||||
// EnableIf<condition>::type is void when 'Cond' is true, and
|
||||
// undefined when 'Cond' is false. To use SFINAE to make a function
|
||||
// overload only apply when a particular expression is true, add
|
||||
// "typename EnableIf<expression>::type* = 0" as the last parameter.
|
||||
template<bool> struct EnableIf;
|
||||
template<> struct EnableIf<true> { typedef void type; }; // NOLINT
|
||||
|
||||
// Utilities for native arrays.
|
||||
|
||||
// ArrayEq() compares two k-dimensional native arrays using the
|
||||
// elements' operator==, where k can be any integer >= 0. When k is
|
||||
// 0, ArrayEq() degenerates into comparing a single pair of values.
|
||||
|
||||
template <typename T, typename U>
|
||||
bool ArrayEq(const T* lhs, size_t size, const U* rhs);
|
||||
|
||||
// This generic version is used when k is 0.
|
||||
template <typename T, typename U>
|
||||
inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; }
|
||||
|
||||
// This overload is used when k >= 1.
|
||||
template <typename T, typename U, size_t N>
|
||||
inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {
|
||||
return internal::ArrayEq(lhs, N, rhs);
|
||||
}
|
||||
|
||||
// This helper reduces code bloat. If we instead put its logic inside
|
||||
// the previous ArrayEq() function, arrays with different sizes would
|
||||
// lead to different copies of the template code.
|
||||
template <typename T, typename U>
|
||||
bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
|
||||
for (size_t i = 0; i != size; i++) {
|
||||
if (!internal::ArrayEq(lhs[i], rhs[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Finds the first element in the iterator range [begin, end) that
|
||||
// equals elem. Element may be a native array type itself.
|
||||
template <typename Iter, typename Element>
|
||||
Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {
|
||||
for (Iter it = begin; it != end; ++it) {
|
||||
if (internal::ArrayEq(*it, elem))
|
||||
return it;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
// CopyArray() copies a k-dimensional native array using the elements'
|
||||
// operator=, where k can be any integer >= 0. When k is 0,
|
||||
// CopyArray() degenerates into copying a single value.
|
||||
|
||||
template <typename T, typename U>
|
||||
void CopyArray(const T* from, size_t size, U* to);
|
||||
|
||||
// This generic version is used when k is 0.
|
||||
template <typename T, typename U>
|
||||
inline void CopyArray(const T& from, U* to) { *to = from; }
|
||||
|
||||
// This overload is used when k >= 1.
|
||||
template <typename T, typename U, size_t N>
|
||||
inline void CopyArray(const T(&from)[N], U(*to)[N]) {
|
||||
internal::CopyArray(from, N, *to);
|
||||
}
|
||||
|
||||
// This helper reduces code bloat. If we instead put its logic inside
|
||||
// the previous CopyArray() function, arrays with different sizes
|
||||
// would lead to different copies of the template code.
|
||||
template <typename T, typename U>
|
||||
void CopyArray(const T* from, size_t size, U* to) {
|
||||
for (size_t i = 0; i != size; i++) {
|
||||
internal::CopyArray(from[i], to + i);
|
||||
}
|
||||
}
|
||||
|
||||
// The relation between an NativeArray object (see below) and the
|
||||
// native array it represents.
|
||||
enum RelationToSource {
|
||||
kReference, // The NativeArray references the native array.
|
||||
kCopy // The NativeArray makes a copy of the native array and
|
||||
// owns the copy.
|
||||
};
|
||||
|
||||
// Adapts a native array to a read-only STL-style container. Instead
|
||||
// of the complete STL container concept, this adaptor only implements
|
||||
// members useful for Google Mock's container matchers. New members
|
||||
// should be added as needed. To simplify the implementation, we only
|
||||
// support Element being a raw type (i.e. having no top-level const or
|
||||
// reference modifier). It's the client's responsibility to satisfy
|
||||
// this requirement. Element can be an array type itself (hence
|
||||
// multi-dimensional arrays are supported).
|
||||
template <typename Element>
|
||||
class NativeArray {
|
||||
public:
|
||||
// STL-style container typedefs.
|
||||
typedef Element value_type;
|
||||
typedef Element* iterator;
|
||||
typedef const Element* const_iterator;
|
||||
|
||||
// Constructs from a native array.
|
||||
NativeArray(const Element* array, size_t count, RelationToSource relation) {
|
||||
Init(array, count, relation);
|
||||
}
|
||||
|
||||
// Copy constructor.
|
||||
NativeArray(const NativeArray& rhs) {
|
||||
Init(rhs.array_, rhs.size_, rhs.relation_to_source_);
|
||||
}
|
||||
|
||||
~NativeArray() {
|
||||
// Ensures that the user doesn't instantiate NativeArray with a
|
||||
// const or reference type.
|
||||
static_cast<void>(StaticAssertTypeEqHelper<Element,
|
||||
GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>());
|
||||
if (relation_to_source_ == kCopy)
|
||||
delete[] array_;
|
||||
}
|
||||
|
||||
// STL-style container methods.
|
||||
size_t size() const { return size_; }
|
||||
const_iterator begin() const { return array_; }
|
||||
const_iterator end() const { return array_ + size_; }
|
||||
bool operator==(const NativeArray& rhs) const {
|
||||
return size() == rhs.size() &&
|
||||
ArrayEq(begin(), size(), rhs.begin());
|
||||
}
|
||||
|
||||
private:
|
||||
// Initializes this object; makes a copy of the input array if
|
||||
// 'relation' is kCopy.
|
||||
void Init(const Element* array, size_t a_size, RelationToSource relation) {
|
||||
if (relation == kReference) {
|
||||
array_ = array;
|
||||
} else {
|
||||
Element* const copy = new Element[a_size];
|
||||
CopyArray(array, a_size, copy);
|
||||
array_ = copy;
|
||||
}
|
||||
size_ = a_size;
|
||||
relation_to_source_ = relation;
|
||||
}
|
||||
|
||||
const Element* array_;
|
||||
size_t size_;
|
||||
RelationToSource relation_to_source_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(NativeArray);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#define GTEST_MESSAGE_(message, result_type) \
|
||||
::testing::internal::AssertHelper(result_type, __FILE__, __LINE__, message) \
|
||||
#define GTEST_MESSAGE_AT_(file, line, message, result_type) \
|
||||
::testing::internal::AssertHelper(result_type, file, line, message) \
|
||||
= ::testing::Message()
|
||||
|
||||
#define GTEST_MESSAGE_(message, result_type) \
|
||||
GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
|
||||
|
||||
#define GTEST_FATAL_FAILURE_(message) \
|
||||
return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
|
||||
|
||||
@ -828,7 +1133,7 @@ class GTEST_API_ Random {
|
||||
|
||||
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (const char* gtest_msg = "") { \
|
||||
if (::testing::internal::ConstCharPtr gtest_msg = "") { \
|
||||
bool gtest_caught_expected = false; \
|
||||
try { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
@ -837,38 +1142,38 @@ class GTEST_API_ Random {
|
||||
gtest_caught_expected = true; \
|
||||
} \
|
||||
catch (...) { \
|
||||
gtest_msg = "Expected: " #statement " throws an exception of type " \
|
||||
#expected_exception ".\n Actual: it throws a different " \
|
||||
"type."; \
|
||||
gtest_msg.value = \
|
||||
"Expected: " #statement " throws an exception of type " \
|
||||
#expected_exception ".\n Actual: it throws a different type."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||
} \
|
||||
if (!gtest_caught_expected) { \
|
||||
gtest_msg = "Expected: " #statement " throws an exception of type " \
|
||||
#expected_exception ".\n Actual: it throws nothing."; \
|
||||
gtest_msg.value = \
|
||||
"Expected: " #statement " throws an exception of type " \
|
||||
#expected_exception ".\n Actual: it throws nothing."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||
} \
|
||||
} else \
|
||||
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
|
||||
fail(gtest_msg)
|
||||
fail(gtest_msg.value)
|
||||
|
||||
#define GTEST_TEST_NO_THROW_(statement, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (const char* gtest_msg = "") { \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
try { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
} \
|
||||
catch (...) { \
|
||||
gtest_msg = "Expected: " #statement " doesn't throw an exception.\n" \
|
||||
" Actual: it throws."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
|
||||
} \
|
||||
} else \
|
||||
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
|
||||
fail(gtest_msg)
|
||||
fail("Expected: " #statement " doesn't throw an exception.\n" \
|
||||
" Actual: it throws.")
|
||||
|
||||
#define GTEST_TEST_ANY_THROW_(statement, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (const char* gtest_msg = "") { \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
bool gtest_caught_any = false; \
|
||||
try { \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
@ -877,13 +1182,12 @@ class GTEST_API_ Random {
|
||||
gtest_caught_any = true; \
|
||||
} \
|
||||
if (!gtest_caught_any) { \
|
||||
gtest_msg = "Expected: " #statement " throws an exception.\n" \
|
||||
" Actual: it doesn't."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
|
||||
} \
|
||||
} else \
|
||||
GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
|
||||
fail(gtest_msg)
|
||||
fail("Expected: " #statement " throws an exception.\n" \
|
||||
" Actual: it doesn't.")
|
||||
|
||||
|
||||
// Implements Boolean test assertions such as EXPECT_TRUE. expression can be
|
||||
@ -900,18 +1204,17 @@ class GTEST_API_ Random {
|
||||
|
||||
#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
|
||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||
if (const char* gtest_msg = "") { \
|
||||
if (::testing::internal::AlwaysTrue()) { \
|
||||
::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||
if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
|
||||
gtest_msg = "Expected: " #statement " doesn't generate new fatal " \
|
||||
"failures in the current thread.\n" \
|
||||
" Actual: it does."; \
|
||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
|
||||
} \
|
||||
} else \
|
||||
GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
|
||||
fail(gtest_msg)
|
||||
fail("Expected: " #statement " doesn't generate new fatal " \
|
||||
"failures in the current thread.\n" \
|
||||
" Actual: it does.")
|
||||
|
||||
// Expands to the name of the class that implements the given test.
|
||||
#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
||||
@ -924,7 +1227,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
|
||||
private:\
|
||||
virtual void TestBody();\
|
||||
static ::testing::TestInfo* const test_info_;\
|
||||
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
|
||||
};\
|
||||
@ -932,7 +1235,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
|
||||
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
|
||||
::test_info_ =\
|
||||
::testing::internal::MakeAndRegisterTestInfo(\
|
||||
#test_case_name, #test_name, "", "", \
|
||||
#test_case_name, #test_name, NULL, NULL, \
|
||||
(parent_id), \
|
||||
parent_class::SetUpTestCase, \
|
||||
parent_class::TearDownTestCase, \
|
||||
|
@ -71,7 +71,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
@ -172,16 +172,6 @@ class linked_ptr {
|
||||
T* get() const { return value_; }
|
||||
T* operator->() const { return value_; }
|
||||
T& operator*() const { return *value_; }
|
||||
// Release ownership of the pointed object and returns it.
|
||||
// Sole ownership by this linked_ptr object is required.
|
||||
T* release() {
|
||||
bool last = link_.depart();
|
||||
(void) last;
|
||||
assert(last);
|
||||
T* v = value_;
|
||||
value_ = NULL;
|
||||
return v;
|
||||
}
|
||||
|
||||
bool operator==(T* p) const { return value_ == p; }
|
||||
bool operator!=(T* p) const { return value_ != p; }
|
||||
|
@ -1,4 +1,6 @@
|
||||
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
|
||||
// This file was GENERATED by command:
|
||||
// pump.py gtest-param-util-generated.h.pump
|
||||
// DO NOT EDIT BY HAND!!!
|
||||
|
||||
// Copyright 2008 Google Inc.
|
||||
// All Rights Reserved.
|
||||
@ -47,8 +49,8 @@
|
||||
// scripts/fuse_gtest.py depends on gtest's own header being #included
|
||||
// *unconditionally*. Therefore these #includes cannot be moved
|
||||
// inside #if GTEST_HAS_PARAM_TEST.
|
||||
#include <gtest/internal/gtest-param-util.h>
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include "gtest/internal/gtest-param-util.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
|
||||
@ -58,8 +60,8 @@ namespace testing {
|
||||
// include/gtest/gtest-param-test.h.
|
||||
template <typename ForwardIterator>
|
||||
internal::ParamGenerator<
|
||||
typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn(
|
||||
ForwardIterator begin, ForwardIterator end);
|
||||
typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
|
||||
ValuesIn(ForwardIterator begin, ForwardIterator end);
|
||||
|
||||
template <typename T, size_t N>
|
||||
internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
|
||||
@ -2826,7 +2828,7 @@ class ValueArray50 {
|
||||
const T50 v50_;
|
||||
};
|
||||
|
||||
#if GTEST_HAS_COMBINE
|
||||
# if GTEST_HAS_COMBINE
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||
//
|
||||
// Generates values from the Cartesian product of values produced
|
||||
@ -4810,7 +4812,7 @@ CartesianProductHolder10(const Generator1& g1, const Generator2& g2,
|
||||
const Generator10 g10_;
|
||||
}; // class CartesianProductHolder10
|
||||
|
||||
#endif // GTEST_HAS_COMBINE
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
@ -41,9 +41,10 @@
|
||||
// scripts/fuse_gtest.py depends on gtest's own header being #included
|
||||
// *unconditionally*. Therefore these #includes cannot be moved
|
||||
// inside #if GTEST_HAS_PARAM_TEST.
|
||||
#include <gtest/internal/gtest-internal.h>
|
||||
#include <gtest/internal/gtest-linked_ptr.h>
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-linked_ptr.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/gtest-printers.h"
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
|
||||
@ -171,7 +172,7 @@ class ParamGenerator {
|
||||
iterator end() const { return iterator(impl_->End()); }
|
||||
|
||||
private:
|
||||
::testing::internal::linked_ptr<const ParamGeneratorInterface<T> > impl_;
|
||||
linked_ptr<const ParamGeneratorInterface<T> > impl_;
|
||||
};
|
||||
|
||||
// Generates values from a range of two comparable values. Can be used to
|
||||
@ -285,7 +286,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
|
||||
public:
|
||||
Iterator(const ParamGeneratorInterface<T>* base,
|
||||
typename ContainerType::const_iterator iterator)
|
||||
: base_(base), iterator_(iterator) {}
|
||||
: base_(base), iterator_(iterator) {}
|
||||
virtual ~Iterator() {}
|
||||
|
||||
virtual const ParamGeneratorInterface<T>* BaseGenerator() const {
|
||||
@ -416,7 +417,7 @@ class ParameterizedTestCaseInfoBase {
|
||||
virtual ~ParameterizedTestCaseInfoBase() {}
|
||||
|
||||
// Base part of test case name for display purposes.
|
||||
virtual const String& GetTestCaseName() const = 0;
|
||||
virtual const string& GetTestCaseName() const = 0;
|
||||
// Test case id to verify identity.
|
||||
virtual TypeId GetTestCaseTypeId() const = 0;
|
||||
// UnitTest class invokes this method to register tests in this
|
||||
@ -453,7 +454,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
: test_case_name_(name) {}
|
||||
|
||||
// Test case base name for display purposes.
|
||||
virtual const String& GetTestCaseName() const { return test_case_name_; }
|
||||
virtual const string& GetTestCaseName() const { return test_case_name_; }
|
||||
// Test case id to verify identity.
|
||||
virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); }
|
||||
// TEST_P macro uses AddTestPattern() to record information
|
||||
@ -471,7 +472,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
}
|
||||
// INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
|
||||
// about a generator.
|
||||
int AddTestCaseInstantiation(const char* instantiation_name,
|
||||
int AddTestCaseInstantiation(const string& instantiation_name,
|
||||
GeneratorCreationFunc* func,
|
||||
const char* /* file */,
|
||||
int /* line */) {
|
||||
@ -490,26 +491,25 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
for (typename InstantiationContainer::iterator gen_it =
|
||||
instantiations_.begin(); gen_it != instantiations_.end();
|
||||
++gen_it) {
|
||||
const String& instantiation_name = gen_it->first;
|
||||
const string& instantiation_name = gen_it->first;
|
||||
ParamGenerator<ParamType> generator((*gen_it->second)());
|
||||
|
||||
Message test_case_name_stream;
|
||||
if ( !instantiation_name.empty() )
|
||||
test_case_name_stream << instantiation_name.c_str() << "/";
|
||||
test_case_name_stream << test_info->test_case_base_name.c_str();
|
||||
test_case_name_stream << instantiation_name << "/";
|
||||
test_case_name_stream << test_info->test_case_base_name;
|
||||
|
||||
int i = 0;
|
||||
for (typename ParamGenerator<ParamType>::iterator param_it =
|
||||
generator.begin();
|
||||
param_it != generator.end(); ++param_it, ++i) {
|
||||
Message test_name_stream;
|
||||
test_name_stream << test_info->test_base_name.c_str() << "/" << i;
|
||||
::testing::internal::MakeAndRegisterTestInfo(
|
||||
test_name_stream << test_info->test_base_name << "/" << i;
|
||||
MakeAndRegisterTestInfo(
|
||||
test_case_name_stream.GetString().c_str(),
|
||||
test_name_stream.GetString().c_str(),
|
||||
"", // test_case_comment
|
||||
"", // comment; TODO(vladl@google.com): provide parameter value
|
||||
// representation.
|
||||
NULL, // No type parameter.
|
||||
PrintToString(*param_it).c_str(),
|
||||
GetTestCaseTypeId(),
|
||||
TestCase::SetUpTestCase,
|
||||
TestCase::TearDownTestCase,
|
||||
@ -530,17 +530,17 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
||||
test_base_name(a_test_base_name),
|
||||
test_meta_factory(a_test_meta_factory) {}
|
||||
|
||||
const String test_case_base_name;
|
||||
const String test_base_name;
|
||||
const string test_case_base_name;
|
||||
const string test_base_name;
|
||||
const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
|
||||
};
|
||||
typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;
|
||||
// Keeps pairs of <Instantiation name, Sequence generator creation function>
|
||||
// received from INSTANTIATE_TEST_CASE_P macros.
|
||||
typedef ::std::vector<std::pair<String, GeneratorCreationFunc*> >
|
||||
typedef ::std::vector<std::pair<string, GeneratorCreationFunc*> >
|
||||
InstantiationContainer;
|
||||
|
||||
const String test_case_name_;
|
||||
const string test_case_name_;
|
||||
TestInfoContainer tests_;
|
||||
InstantiationContainer instantiations_;
|
||||
|
||||
@ -579,7 +579,7 @@ class ParameterizedTestCaseRegistry {
|
||||
// and terminate the program since we cannot guaranty correct
|
||||
// test case setup and tear-down in this case.
|
||||
ReportInvalidTestCaseType(test_case_name, file, line);
|
||||
abort();
|
||||
posix::Abort();
|
||||
} else {
|
||||
// At this point we are sure that the object we found is of the same
|
||||
// type we are looking for, so we downcast it to that type
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -43,11 +43,11 @@
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
// string.h is not guaranteed to provide strcpy on C++ Builder.
|
||||
#include <mem.h>
|
||||
# include <mem.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -296,7 +296,7 @@ class GTEST_API_ String {
|
||||
|
||||
private:
|
||||
// Constructs a non-NULL String from the given content. This
|
||||
// function can only be called when data_ has not been allocated.
|
||||
// function can only be called when c_str_ has not been allocated.
|
||||
// ConstructNonNull(NULL, 0) results in an empty string ("").
|
||||
// ConstructNonNull(NULL, non_zero) is undefined behavior.
|
||||
void ConstructNonNull(const char* buffer, size_t a_length) {
|
||||
@ -329,9 +329,9 @@ inline ::std::ostream& operator<<(::std::ostream& os, const String& str) {
|
||||
return os;
|
||||
}
|
||||
|
||||
// Gets the content of the StrStream's buffer as a String. Each '\0'
|
||||
// Gets the content of the stringstream's buffer as a String. Each '\0'
|
||||
// character in the buffer is replaced with "\\0".
|
||||
GTEST_API_ String StrStreamToString(StrStream* stream);
|
||||
GTEST_API_ String StringStreamToString(::std::stringstream* stream);
|
||||
|
||||
// Converts a streamable value to a String. A NULL pointer is
|
||||
// converted to "(null)". When the input value is a ::string,
|
||||
|
@ -44,9 +44,9 @@
|
||||
// private as public.
|
||||
// Sun Studio versions < 12 also have the above bug.
|
||||
#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
|
||||
#define GTEST_DECLARE_TUPLE_AS_FRIEND_ public:
|
||||
# define GTEST_DECLARE_TUPLE_AS_FRIEND_ public:
|
||||
#else
|
||||
#define GTEST_DECLARE_TUPLE_AS_FRIEND_ \
|
||||
# define GTEST_DECLARE_TUPLE_AS_FRIEND_ \
|
||||
template <GTEST_10_TYPENAMES_(U)> friend class tuple; \
|
||||
private:
|
||||
#endif
|
||||
|
@ -44,20 +44,52 @@
|
||||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||
|
||||
#include <gtest/internal/gtest-port.h>
|
||||
#include <gtest/internal/gtest-string.h>
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
// #ifdef __GNUC__ is too general here. It is possible to use gcc without using
|
||||
// libstdc++ (which is where cxxabi.h comes from).
|
||||
#ifdef __GLIBCXX__
|
||||
#include <cxxabi.h>
|
||||
#endif // __GLIBCXX__
|
||||
# ifdef __GLIBCXX__
|
||||
# include <cxxabi.h>
|
||||
# elif defined(__HP_aCC)
|
||||
# include <acxx_demangle.h>
|
||||
# endif // __GLIBCXX__
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// GetTypeName<T>() returns a human-readable name of type T.
|
||||
// NB: This function is also used in Google Mock, so don't move it inside of
|
||||
// the typed-test-only section below.
|
||||
template <typename T>
|
||||
String GetTypeName() {
|
||||
# if GTEST_HAS_RTTI
|
||||
|
||||
const char* const name = typeid(T).name();
|
||||
# if defined(__GLIBCXX__) || defined(__HP_aCC)
|
||||
int status = 0;
|
||||
// gcc's implementation of typeid(T).name() mangles the type name,
|
||||
// so we have to demangle it.
|
||||
# ifdef __GLIBCXX__
|
||||
using abi::__cxa_demangle;
|
||||
# endif // __GLIBCXX__
|
||||
char* const readable_name = __cxa_demangle(name, 0, 0, &status);
|
||||
const String name_str(status == 0 ? readable_name : name);
|
||||
free(readable_name);
|
||||
return name_str;
|
||||
# else
|
||||
return name;
|
||||
# endif // __GLIBCXX__ || __HP_aCC
|
||||
|
||||
# else
|
||||
|
||||
return "<type>";
|
||||
|
||||
# endif // GTEST_HAS_RTTI
|
||||
}
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
|
||||
// type. This can be used as a compile-time assertion to ensure that
|
||||
// two types are equal.
|
||||
@ -70,29 +102,6 @@ struct AssertTypeEq<T, T> {
|
||||
typedef bool type;
|
||||
};
|
||||
|
||||
// GetTypeName<T>() returns a human-readable name of type T.
|
||||
template <typename T>
|
||||
String GetTypeName() {
|
||||
#if GTEST_HAS_RTTI
|
||||
|
||||
const char* const name = typeid(T).name();
|
||||
#ifdef __GLIBCXX__
|
||||
int status = 0;
|
||||
// gcc's implementation of typeid(T).name() mangles the type name,
|
||||
// so we have to demangle it.
|
||||
char* const readable_name = abi::__cxa_demangle(name, 0, 0, &status);
|
||||
const String name_str(status == 0 ? readable_name : name);
|
||||
free(readable_name);
|
||||
return name_str;
|
||||
#else
|
||||
return name;
|
||||
#endif // __GLIBCXX__
|
||||
|
||||
#else
|
||||
return "<type>";
|
||||
#endif // GTEST_HAS_RTTI
|
||||
}
|
||||
|
||||
// A unique type used as the default value for the arguments of class
|
||||
// template Types. This allows us to simulate variadic templates
|
||||
// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
|
||||
@ -1611,7 +1620,7 @@ struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
|
||||
|
||||
namespace internal {
|
||||
|
||||
#define GTEST_TEMPLATE_ template <typename T> class
|
||||
# define GTEST_TEMPLATE_ template <typename T> class
|
||||
|
||||
// The template "selector" struct TemplateSel<Tmpl> is used to
|
||||
// represent Tmpl, which must be a class template with one type
|
||||
@ -1629,7 +1638,7 @@ struct TemplateSel {
|
||||
};
|
||||
};
|
||||
|
||||
#define GTEST_BIND_(TmplSel, T) \
|
||||
# define GTEST_BIND_(TmplSel, T) \
|
||||
TmplSel::template Bind<T>::type
|
||||
|
||||
// A unique struct template used as the default value for the
|
||||
@ -3313,9 +3322,9 @@ struct TypeList<Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
|
||||
T41, T42, T43, T44, T45, T46, T47, T48, T49, T50>::type type;
|
||||
};
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user