Push upstream to SVN.

This commit is contained in:
billydonahue 2014-05-15 19:42:15 +00:00
parent 5df87d70b6
commit 8120f66c32
11 changed files with 241 additions and 203 deletions

View File

@ -593,10 +593,7 @@ 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
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
// Note: we deliberately don't call this PrintTo(), as that name
// conflicts with ::testing::internal::PrintTo in the body of the
@ -613,9 +610,7 @@ class UniversalPrinter {
PrintTo(value, os);
}
#ifdef _MSC_VER
# pragma warning(pop) // Restores the warning state.
#endif // _MSC_VER
GTEST_DISABLE_MSC_WARNINGS_POP_()
};
// UniversalPrintArray(begin, len, os) prints an array of 'len'
@ -667,10 +662,7 @@ 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
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180)
static void Print(const T& value, ::std::ostream* os) {
// Prints the address of the value. We use reinterpret_cast here
@ -681,9 +673,7 @@ class UniversalPrinter<T&> {
UniversalPrint(value, os);
}
#ifdef _MSC_VER
# pragma warning(pop) // Restores the warning state.
#endif // _MSC_VER
GTEST_DISABLE_MSC_WARNINGS_POP_()
};
// Prints a value tersely: for a reference type, the referenced value
@ -835,9 +825,9 @@ struct TuplePrefixPrinter {
template <typename Tuple>
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
GTEST_INTENTIONAL_CONST_COND_PUSH_
GTEST_INTENTIONAL_CONST_COND_PUSH_()
if (N > 1) {
GTEST_INTENTIONAL_CONST_COND_POP_
GTEST_INTENTIONAL_CONST_COND_POP_()
*os << ", ";
}
UniversalPrinter<

View File

@ -258,8 +258,31 @@ class GTEST_API_ AssertionResult {
// Copy constructor.
// Used in EXPECT_TRUE/FALSE(assertion_result).
AssertionResult(const AssertionResult& other);
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */)
// Used in the EXPECT_TRUE/FALSE(bool_expression).
explicit AssertionResult(bool success) : success_(success) {}
//
// T must be contextually convertible to bool.
//
// The second parameter prevents this overload from being considered if
// the argument is implicitly convertible to AssertionResult. In that case
// we want AssertionResult's copy constructor to be used.
template <typename T>
explicit AssertionResult(
const T& success,
typename internal::EnableIf<
!internal::ImplicitlyConvertible<T, AssertionResult>::value>::type*
/*enabler*/ = NULL)
: success_(success) {}
GTEST_DISABLE_MSC_WARNINGS_POP_()
// Assignment operator.
AssertionResult& operator=(AssertionResult other) {
swap(other);
return *this;
}
// Returns true iff the assertion succeeded.
operator bool() const { return success_; } // NOLINT
@ -300,6 +323,9 @@ class GTEST_API_ AssertionResult {
message_->append(a_message.GetString().c_str());
}
// Swap the contents of this AssertionResult with other.
void swap(AssertionResult& other);
// Stores result of the assertion predicate.
bool success_;
// Stores the message describing the condition in case the expectation
@ -307,8 +333,6 @@ class GTEST_API_ AssertionResult {
// Referenced via a pointer to avoid taking too much stack frame space
// with test assertions.
internal::scoped_ptr< ::std::string> message_;
GTEST_DISALLOW_ASSIGN_(AssertionResult);
};
// Makes a successful assertion result.
@ -1439,19 +1463,11 @@ AssertionResult CmpHelperEQ(const char* expected_expression,
const char* actual_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
// signed/unsigned mismatch.
#endif
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 /* signed/unsigned mismatch */)
if (expected == actual) {
return AssertionSuccess();
}
#ifdef _MSC_VER
# pragma warning(pop) // Restores the warning state.
#endif
GTEST_DISABLE_MSC_WARNINGS_POP_()
return EqFailure(expected_expression,
actual_expression,

View File

@ -802,25 +802,20 @@ class ImplicitlyConvertible {
// 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__)
#if 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
// MSVC warns about implicitly converting from double to int for
// possible loss of data, so we need to temporarily disable the
// warning.
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244)
static const bool value =
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
#endif // _MSV_VER
GTEST_DISABLE_MSC_WARNINGS_POP_()
#endif // __BORLANDC__
};
template <typename From, typename To>
const bool ImplicitlyConvertible<From, To>::value;
@ -946,11 +941,10 @@ void CopyArray(const T* from, size_t size, U* to) {
// 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.
};
// We use 2 different structs to allow non-copyable types to be used, as long
// as RelationToSourceReference() is passed.
struct RelationToSourceReference {};
struct RelationToSourceCopy {};
// Adapts a native array to a read-only STL-style container. Instead
// of the complete STL container concept, this adaptor only implements
@ -968,22 +962,23 @@ class NativeArray {
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);
// Constructs from a native array. References the source.
NativeArray(const Element* array, size_t count, RelationToSourceReference) {
InitRef(array, count);
}
// Constructs from a native array. Copies the source.
NativeArray(const Element* array, size_t count, RelationToSourceCopy) {
InitCopy(array, count);
}
// Copy constructor.
NativeArray(const NativeArray& rhs) {
Init(rhs.array_, rhs.size_, rhs.relation_to_source_);
(this->*rhs.clone_)(rhs.array_, rhs.size_);
}
~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)
if (clone_ != &NativeArray::InitRef)
delete[] array_;
}
@ -997,23 +992,30 @@ class NativeArray {
}
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;
}
enum {
kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper<
Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value,
};
// Initializes this object with a copy of the input.
void InitCopy(const Element* array, size_t a_size) {
Element* const copy = new Element[a_size];
CopyArray(array, a_size, copy);
array_ = copy;
size_ = a_size;
relation_to_source_ = relation;
clone_ = &NativeArray::InitCopy;
}
// Initializes this object with a reference of the input.
void InitRef(const Element* array, size_t a_size) {
array_ = array;
size_ = a_size;
clone_ = &NativeArray::InitRef;
}
const Element* array_;
size_t size_;
RelationToSource relation_to_source_;
void (NativeArray::*clone_)(const Element*, size_t);
GTEST_DISALLOW_ASSIGN_(NativeArray);
};
@ -1156,3 +1158,4 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_

View File

@ -136,6 +136,8 @@
// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop
// GTEST_OS_WINDOWS_MINGW - MinGW
// GTEST_OS_WINDOWS_MOBILE - Windows Mobile
// GTEST_OS_WINDOWS_PHONE - Windows Phone
// GTEST_OS_WINDOWS_RT - Windows Store App/WinRT
// GTEST_OS_ZOS - z/OS
//
// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
@ -269,6 +271,7 @@
# include <TargetConditionals.h>
#endif
#include <algorithm> // NOLINT
#include <iostream> // NOLINT
#include <sstream> // NOLINT
#include <string> // NOLINT
@ -299,6 +302,19 @@
# define GTEST_OS_WINDOWS_MOBILE 1
# elif defined(__MINGW__) || defined(__MINGW32__)
# define GTEST_OS_WINDOWS_MINGW 1
# elif defined(WINAPI_FAMILY)
# include <winapifamily.h>
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# define GTEST_OS_WINDOWS_DESKTOP 1
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
# define GTEST_OS_WINDOWS_PHONE 1
# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
# define GTEST_OS_WINDOWS_RT 1
# else
// WINAPI_FAMILY defined but no known partition matched.
// Default to desktop.
# define GTEST_OS_WINDOWS_DESKTOP 1
# endif
# else
# define GTEST_OS_WINDOWS_DESKTOP 1
# endif // _WIN32_WCE
@ -331,6 +347,23 @@
# define GTEST_OS_QNX 1
#endif // __CYGWIN__
// Macros for disabling Microsoft Visual C++ warnings.
//
// GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385)
// /* code that triggers warnings C4800 and C4385 */
// GTEST_DISABLE_MSC_WARNINGS_POP_()
#if _MSC_VER >= 1500
# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
__pragma(warning(push)) \
__pragma(warning(disable: warnings))
# define GTEST_DISABLE_MSC_WARNINGS_POP_() \
__pragma(warning(pop))
#else
// Older versions of MSVC don't have __pragma.
# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
# define GTEST_DISABLE_MSC_WARNINGS_POP_()
#endif
#ifndef GTEST_LANG_CXX11
// gcc and clang define __GXX_EXPERIMENTAL_CXX0X__ when
// -std={c,gnu}++{0x,11} is passed. The C++11 standard specifies a
@ -641,20 +674,20 @@ struct _RTL_CRITICAL_SECTION;
// To avoid conditional compilation everywhere, we make it
// gtest-port.h's responsibility to #include the header implementing
// tuple.
// TODO(sbenza): Enable this block to start using std::tuple instead of
// std::tr1::tuple.
#if 0 && GTEST_HAS_STD_TUPLE_
# include <tuple>
#if GTEST_HAS_STD_TUPLE_
# include <tuple> // IWYU pragma: export
# define GTEST_TUPLE_NAMESPACE_ ::std
#endif
#endif // GTEST_HAS_STD_TUPLE_
// We include tr1::tuple even if std::tuple is available to define printers for
// them.
#if GTEST_HAS_TR1_TUPLE
# ifndef GTEST_TUPLE_NAMESPACE_
# define GTEST_TUPLE_NAMESPACE_ ::std::tr1
# endif // GTEST_TUPLE_NAMESPACE_
# if GTEST_USE_OWN_TR1_TUPLE
# include "gtest/internal/gtest-tuple.h"
# include "gtest/internal/gtest-tuple.h" // IWYU pragma: export // NOLINT
# elif GTEST_ENV_HAS_STD_TUPLE_
# include <tuple>
// C++11 puts its tuple into the ::std namespace rather than
@ -685,7 +718,7 @@ using ::std::tuple_size;
// This prevents <boost/tr1/detail/config.hpp>, which defines
// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
# define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
# include <tuple>
# include <tuple> // IWYU pragma: export // NOLINT
# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does
@ -708,7 +741,7 @@ using ::std::tuple_size;
# else
// If the compiler is not GCC 4.0+, we assume the user is using a
// spec-conforming TR1 implementation.
# include <tuple> // NOLINT
# include <tuple> // IWYU pragma: export // NOLINT
# endif // GTEST_USE_OWN_TR1_TUPLE
#endif // GTEST_HAS_TR1_TUPLE
@ -742,7 +775,8 @@ using ::std::tuple_size;
#ifndef GTEST_HAS_STREAM_REDIRECTION
// By default, we assume that stream redirection is supported on all
// platforms except known mobile ones.
# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN
# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || \
GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
# define GTEST_HAS_STREAM_REDIRECTION 0
# else
# define GTEST_HAS_STREAM_REDIRECTION 1
@ -859,20 +893,14 @@ using ::std::tuple_size;
// constant. In some contexts this warning is false positive and needs to be
// suppressed. Use the following two macros in such cases:
//
// GTEST_INTENTIONAL_CONST_COND_PUSH_
// GTEST_INTENTIONAL_CONST_COND_PUSH_()
// while (true) {
// GTEST_INTENTIONAL_CONST_COND_POP_
// GTEST_INTENTIONAL_CONST_COND_POP_()
// }
#if defined(_MSC_VER)
# define GTEST_INTENTIONAL_CONST_COND_PUSH_ \
__pragma(warning(push)) \
__pragma(warning(disable: 4127))
# define GTEST_INTENTIONAL_CONST_COND_POP_ \
__pragma(warning(pop))
#else
# define GTEST_INTENTIONAL_CONST_COND_PUSH_
# define GTEST_INTENTIONAL_CONST_COND_POP_
#endif
# define GTEST_INTENTIONAL_CONST_COND_PUSH_() \
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127)
# define GTEST_INTENTIONAL_CONST_COND_POP_() \
GTEST_DISABLE_MSC_WARNINGS_POP_()
// Determine whether the compiler supports Microsoft's Structured Exception
// Handling. This is supported by several Windows compilers but generally
@ -962,6 +990,7 @@ namespace testing {
class Message;
#if defined(GTEST_TUPLE_NAMESPACE_)
// Import tuple and friends into the ::testing namespace.
// It is part of our interface, having them in ::testing allows us to change
// their types as needed.
@ -970,6 +999,7 @@ using GTEST_TUPLE_NAMESPACE_::make_tuple;
using GTEST_TUPLE_NAMESPACE_::tuple;
using GTEST_TUPLE_NAMESPACE_::tuple_size;
using GTEST_TUPLE_NAMESPACE_::tuple_element;
#endif // defined(GTEST_TUPLE_NAMESPACE_)
namespace internal {
@ -1049,7 +1079,9 @@ template <typename T1, typename T2>
struct StaticAssertTypeEqHelper;
template <typename T>
struct StaticAssertTypeEqHelper<T, T> {};
struct StaticAssertTypeEqHelper<T, T> {
enum { value = true };
};
// Evaluates to the number of elements in 'array'.
#define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))
@ -1101,6 +1133,11 @@ class scoped_ptr {
}
}
friend void swap(scoped_ptr& a, scoped_ptr& b) {
using std::swap;
swap(a.ptr_, b.ptr_);
}
private:
T* ptr_;
@ -1312,9 +1349,9 @@ inline To DownCast_(From* f) { // so we only accept pointers
// for compile-time type checking, and has no overhead in an
// optimized build at run-time, as it will be optimized away
// completely.
GTEST_INTENTIONAL_CONST_COND_PUSH_
GTEST_INTENTIONAL_CONST_COND_PUSH_()
if (false) {
GTEST_INTENTIONAL_CONST_COND_POP_
GTEST_INTENTIONAL_CONST_COND_POP_()
const To to = NULL;
::testing::internal::ImplicitCast_<From*>(to);
}
@ -2203,11 +2240,7 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
// Functions deprecated by MSVC 8.0.
#ifdef _MSC_VER
// Temporarily disable warning 4996 (deprecated function).
# pragma warning(push)
# pragma warning(disable:4996)
#endif
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */)
inline const char* StrNCpy(char* dest, const char* src, size_t n) {
return strncpy(dest, src, n);
@ -2217,7 +2250,7 @@ inline const char* StrNCpy(char* dest, const char* src, size_t n) {
// StrError() aren't needed on Windows CE at this time and thus not
// defined there.
#if !GTEST_OS_WINDOWS_MOBILE
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
inline int ChDir(const char* dir) { return chdir(dir); }
#endif
inline FILE* FOpen(const char* path, const char* mode) {
@ -2241,7 +2274,7 @@ inline int Close(int fd) { return close(fd); }
inline const char* StrError(int errnum) { return strerror(errnum); }
#endif
inline const char* GetEnv(const char* name) {
#if GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE | GTEST_OS_WINDOWS_RT
// We are on Windows CE, which has no environment variables.
return NULL;
#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
@ -2254,9 +2287,7 @@ inline const char* GetEnv(const char* name) {
#endif
}
#ifdef _MSC_VER
# pragma warning(pop) // Restores the warning state.
#endif
GTEST_DISABLE_MSC_WARNINGS_POP_()
#if GTEST_OS_WINDOWS_MOBILE
// Windows CE has no C library. The abort() function is used in
@ -2396,3 +2427,4 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val);
} // namespace testing
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_

View File

@ -97,7 +97,7 @@ static bool IsPathSeparator(char c) {
// Returns the current working directory, or "" if unsuccessful.
FilePath FilePath::GetCurrentDir() {
#if GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
// Windows CE doesn't have a current directory, so we just return
// something reasonable.
return FilePath(kCurrentDirectoryString);

View File

@ -886,10 +886,7 @@ 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)
#endif // _MSC_VER
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
#if GTEST_HAS_STREAM_REDIRECTION
@ -1008,9 +1005,7 @@ std::string CapturedStream::ReadEntireFile(FILE* file) {
return content;
}
# ifdef _MSC_VER
# pragma warning(pop)
# endif // _MSC_VER
GTEST_DISABLE_MSC_WARNINGS_POP_()
static CapturedStream* g_captured_stderr = NULL;
static CapturedStream* g_captured_stdout = NULL;

View File

@ -802,21 +802,13 @@ TimeInMillis GetTimeInMillis() {
#elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_
__timeb64 now;
# ifdef _MSC_VER
// MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996
// (deprecated function) there.
// TODO(kenton@google.com): Use GetTickCount()? Or use
// SystemTimeToFileTime()
# pragma warning(push) // Saves the current warning state.
# pragma warning(disable:4996) // Temporarily disables warning 4996.
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
_ftime64(&now);
# pragma warning(pop) // Restores the warning state.
# else
_ftime64(&now);
# endif // _MSC_VER
GTEST_DISABLE_MSC_WARNINGS_POP_()
return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;
#elif GTEST_HAS_GETTIMEOFDAY_
@ -956,6 +948,13 @@ AssertionResult::AssertionResult(const AssertionResult& other)
static_cast< ::std::string*>(NULL)) {
}
// Swaps two AssertionResults.
void AssertionResult::swap(AssertionResult& other) {
using std::swap;
swap(success_, other.success_);
swap(message_, other.message_);
}
// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
AssertionResult AssertionResult::operator!() const {
AssertionResult negation(!success_);
@ -2554,7 +2553,8 @@ enum GTestColor {
COLOR_YELLOW
};
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
!GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
// Returns the character attribute for the given color.
WORD GetColorAttribute(GTestColor color) {
@ -2622,7 +2622,8 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS || GTEST_OS_IOS
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS || \
GTEST_OS_IOS || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
const bool use_color = false;
#else
static const bool in_color_mode =
@ -2637,7 +2638,8 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) {
return;
}
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
!GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
// Gets the current text color.
@ -3808,7 +3810,7 @@ void UnitTest::AddTestPartResult(
// with another testing framework) and specify the former on the
// command line for debugging.
if (GTEST_FLAG(break_on_failure)) {
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
// Using DebugBreak on Windows allows gtest to still break into a debugger
// when a failure happens and both the --gtest_break_on_failure and
// the --gtest_catch_exceptions flags are specified.
@ -3886,7 +3888,7 @@ int UnitTest::Run() {
// process. In either case the user does not want to see pop-up dialogs
// about crashes - they are expected.
if (impl()->catch_exceptions() || in_death_test_child_process) {
# if !GTEST_OS_WINDOWS_MOBILE
# if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
// SetErrorMode doesn't exist on CE.
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
@ -3989,17 +3991,10 @@ namespace internal {
UnitTestImpl::UnitTestImpl(UnitTest* parent)
: parent_(parent),
#ifdef _MSC_VER
# pragma warning(push) // Saves the current warning state.
# pragma warning(disable:4355) // Temporarily disables warning 4355
// (using this in initializer).
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355 /* using this in initializer */)
default_global_test_part_result_reporter_(this),
default_per_thread_test_part_result_reporter_(this),
# pragma warning(pop) // Restores the warning state again.
#else
default_global_test_part_result_reporter_(this),
default_per_thread_test_part_result_reporter_(this),
#endif // _MSC_VER
GTEST_DISABLE_MSC_WARNINGS_POP_()
global_test_part_result_repoter_(
&default_global_test_part_result_reporter_),
per_thread_test_part_result_reporter_(

View File

@ -326,12 +326,9 @@ TEST_F(TestForDeathTest, EmbeddedNulInMessage) {
// Tests that death test macros expand to code which interacts well with switch
// statements.
TEST_F(TestForDeathTest, SwitchStatement) {
// Microsoft compiler usually complains about switch statements without
// case labels. We suppress that warning for this test.
# ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable: 4065)
# endif // _MSC_VER
// Microsoft compiler usually complains about switch statements without
// case labels. We suppress that warning for this test.
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4065)
switch (0)
default:
@ -341,9 +338,7 @@ TEST_F(TestForDeathTest, SwitchStatement) {
case 0:
EXPECT_DEATH(_exit(1), "") << "exit in switch case";
# ifdef _MSC_VER
# pragma warning(pop)
# endif // _MSC_VER
GTEST_DISABLE_MSC_WARNINGS_POP_()
}
// Tests that a static member function can be used in a "fast" style
@ -1304,7 +1299,27 @@ TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
EXPECT_FATAL_FAILURE(ASSERT_DEATH_IF_SUPPORTED(;, ""), "");
}
#else
TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
testing::GTEST_FLAG(death_test_style) = "fast";
EXPECT_FALSE(InDeathTestChild());
EXPECT_DEATH({
fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
fflush(stderr);
_exit(1);
}, "Inside");
}
TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
EXPECT_FALSE(InDeathTestChild());
EXPECT_DEATH({
fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
fflush(stderr);
_exit(1);
}, "Inside");
}
#else // !GTEST_HAS_DEATH_TEST follows
using testing::internal::CaptureStderr;
using testing::internal::GetCapturedStderr;
@ -1354,27 +1369,7 @@ TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
EXPECT_EQ(1, n);
}
TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
testing::GTEST_FLAG(death_test_style) = "fast";
EXPECT_FALSE(InDeathTestChild());
EXPECT_DEATH({
fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
fflush(stderr);
_exit(1);
}, "Inside");
}
TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
EXPECT_FALSE(InDeathTestChild());
EXPECT_DEATH({
fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
fflush(stderr);
_exit(1);
}, "Inside");
}
#endif // GTEST_HAS_DEATH_TEST
#endif // !GTEST_HAS_DEATH_TEST
// Tests that the death test macros expand to code which may or may not
// be followed by operator<<, and that in either case the complete text
@ -1405,12 +1400,9 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
// Tests that conditional death test macros expand to code which interacts
// well with switch statements.
TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
// Microsoft compiler usually complains about switch statements without
// case labels. We suppress that warning for this test.
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable: 4065)
#endif // _MSC_VER
// Microsoft compiler usually complains about switch statements without
// case labels. We suppress that warning for this test.
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4065)
switch (0)
default:
@ -1421,9 +1413,7 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
case 0:
EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << "exit in switch case";
#ifdef _MSC_VER
# pragma warning(pop)
#endif // _MSC_VER
GTEST_DISABLE_MSC_WARNINGS_POP_()
}
// Tests that a test case whose name ends with "DeathTest" works fine

View File

@ -202,12 +202,12 @@ using ::testing::internal::FormatForComparisonFailureMessage;
using ::testing::internal::ImplicitCast_;
using ::testing::internal::NativeArray;
using ::testing::internal::RE;
using ::testing::internal::RelationToSourceReference;
using ::testing::internal::Strings;
using ::testing::internal::UniversalPrint;
using ::testing::internal::UniversalPrinter;
using ::testing::internal::UniversalTersePrint;
using ::testing::internal::UniversalTersePrintTupleFieldsToStrings;
using ::testing::internal::kReference;
using ::testing::internal::string;
// The hash_* classes are not part of the C++ standard. STLport
@ -946,13 +946,13 @@ TEST(PrintStlContainerTest, NestedContainer) {
TEST(PrintStlContainerTest, OneDimensionalNativeArray) {
const int a[3] = { 1, 2, 3 };
NativeArray<int> b(a, 3, kReference);
NativeArray<int> b(a, 3, RelationToSourceReference());
EXPECT_EQ("{ 1, 2, 3 }", Print(b));
}
TEST(PrintStlContainerTest, TwoDimensionalNativeArray) {
const int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
NativeArray<int[3]> b(a, 2, kReference);
NativeArray<int[3]> b(a, 2, RelationToSourceReference());
EXPECT_EQ("{ { 1, 2, 3 }, { 4, 5, 6 } }", Print(b));
}
@ -1648,3 +1648,4 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
} // namespace gtest_printers_test
} // namespace testing

View File

@ -100,9 +100,9 @@ TEST_F(PrematureExitDeathTest, FileExistsDuringExecutionOfDeathTest) {
// Tests that TEST_PREMATURE_EXIT_FILE is set where it's expected to
// be set.
TEST_F(PrematureExitTest, TestPrematureExitFileEnvVarIsSet) {
GTEST_INTENTIONAL_CONST_COND_PUSH_
GTEST_INTENTIONAL_CONST_COND_PUSH_()
if (kTestPrematureExitFileEnvVarShouldBeSet) {
GTEST_INTENTIONAL_CONST_COND_POP_
GTEST_INTENTIONAL_CONST_COND_POP_()
const char* const filepath = GetEnv("TEST_PREMATURE_EXIT_FILE");
ASSERT_TRUE(filepath != NULL);
ASSERT_NE(*filepath, '\0');

View File

@ -233,7 +233,6 @@ using testing::TestProperty;
using testing::TestResult;
using testing::TimeInMillis;
using testing::UnitTest;
using testing::kMaxStackTraceDepth;
using testing::internal::AddReference;
using testing::internal::AlwaysFalse;
using testing::internal::AlwaysTrue;
@ -267,6 +266,8 @@ using testing::internal::IsContainerTest;
using testing::internal::IsNotContainer;
using testing::internal::NativeArray;
using testing::internal::ParseInt32Flag;
using testing::internal::RelationToSourceCopy;
using testing::internal::RelationToSourceReference;
using testing::internal::RemoveConst;
using testing::internal::RemoveReference;
using testing::internal::ShouldRunTestOnShard;
@ -281,11 +282,10 @@ using testing::internal::TestEventListenersAccessor;
using testing::internal::TestResultAccessor;
using testing::internal::UInt32;
using testing::internal::WideStringToUtf8;
using testing::internal::kCopy;
using testing::internal::kMaxRandomSeed;
using testing::internal::kReference;
using testing::internal::kTestTypeIdInGoogleTest;
using testing::internal::scoped_ptr;
using testing::kMaxStackTraceDepth;
#if GTEST_HAS_STREAM_REDIRECTION
using testing::internal::CaptureStdout;
@ -417,19 +417,11 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
private:
virtual void SetUp() {
saved_tz_ = NULL;
#if _MSC_VER
# pragma warning(push) // Saves the current warning state.
# pragma warning(disable:4996) // Temporarily disables warning 4996
// (function or variable may be unsafe
// for getenv, function is deprecated for
// strdup).
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* getenv, strdup: deprecated */)
if (getenv("TZ"))
saved_tz_ = strdup(getenv("TZ"));
# pragma warning(pop) // Restores the warning state again.
#else
if (getenv("TZ"))
saved_tz_ = strdup(getenv("TZ"));
#endif
GTEST_DISABLE_MSC_WARNINGS_POP_()
// Set up the time zone for FormatEpochTimeInMillisAsIso8601 to use. We
// cannot use the local time zone because the function's output depends
@ -453,11 +445,9 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
const std::string env_var =
std::string("TZ=") + (time_zone ? time_zone : "");
_putenv(env_var.c_str());
# pragma warning(push) // Saves the current warning state.
# pragma warning(disable:4996) // Temporarily disables warning 4996
// (function is deprecated).
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */)
tzset();
# pragma warning(pop) // Restores the warning state again.
GTEST_DISABLE_MSC_WARNINGS_POP_()
#else
if (time_zone) {
setenv(("TZ"), time_zone, 1);
@ -5026,6 +5016,31 @@ TEST(AssertionResultTest, CanStreamOstreamManipulators) {
EXPECT_STREQ("Data\n\\0Will be visible", r.message());
}
// The next test uses explicit conversion operators -- a C++11 feature.
#if GTEST_LANG_CXX11
TEST(AssertionResultTest, ConstructibleFromContextuallyConvertibleToBool) {
struct ExplicitlyConvertibleToBool {
explicit operator bool() const { return value; }
bool value;
};
ExplicitlyConvertibleToBool v1 = {false};
ExplicitlyConvertibleToBool v2 = {true};
EXPECT_FALSE(v1);
EXPECT_TRUE(v2);
}
#endif // GTEST_LANG_CXX11
struct ConvertibleToAssertionResult {
operator AssertionResult() const { return AssertionResult(true); }
};
TEST(AssertionResultTest, ConstructibleFromImplicitlyConvertible) {
ConvertibleToAssertionResult obj;
EXPECT_TRUE(obj);
}
// Tests streaming a user type whose definition and operator << are
// both in the global namespace.
class Base {
@ -7327,7 +7342,7 @@ TEST(CopyArrayTest, WorksForTwoDimensionalArrays) {
TEST(NativeArrayTest, ConstructorFromArrayWorks) {
const int a[3] = { 0, 1, 2 };
NativeArray<int> na(a, 3, kReference);
NativeArray<int> na(a, 3, RelationToSourceReference());
EXPECT_EQ(3U, na.size());
EXPECT_EQ(a, na.begin());
}
@ -7337,7 +7352,7 @@ TEST(NativeArrayTest, CreatesAndDeletesCopyOfArrayWhenAskedTo) {
Array* a = new Array[1];
(*a)[0] = 0;
(*a)[1] = 1;
NativeArray<int> na(*a, 2, kCopy);
NativeArray<int> na(*a, 2, RelationToSourceCopy());
EXPECT_NE(*a, na.begin());
delete[] a;
EXPECT_EQ(0, na.begin()[0]);
@ -7357,7 +7372,7 @@ TEST(NativeArrayTest, TypeMembersAreCorrect) {
TEST(NativeArrayTest, MethodsWork) {
const int a[3] = { 0, 1, 2 };
NativeArray<int> na(a, 3, kCopy);
NativeArray<int> na(a, 3, RelationToSourceCopy());
ASSERT_EQ(3U, na.size());
EXPECT_EQ(3, na.end() - na.begin());
@ -7372,18 +7387,18 @@ TEST(NativeArrayTest, MethodsWork) {
EXPECT_TRUE(na == na);
NativeArray<int> na2(a, 3, kReference);
NativeArray<int> na2(a, 3, RelationToSourceReference());
EXPECT_TRUE(na == na2);
const int b1[3] = { 0, 1, 1 };
const int b2[4] = { 0, 1, 2, 3 };
EXPECT_FALSE(na == NativeArray<int>(b1, 3, kReference));
EXPECT_FALSE(na == NativeArray<int>(b2, 4, kCopy));
EXPECT_FALSE(na == NativeArray<int>(b1, 3, RelationToSourceReference()));
EXPECT_FALSE(na == NativeArray<int>(b2, 4, RelationToSourceCopy()));
}
TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
const char a[2][3] = { "hi", "lo" };
NativeArray<char[3]> na(a, 2, kReference);
NativeArray<char[3]> na(a, 2, RelationToSourceReference());
ASSERT_EQ(2U, na.size());
EXPECT_EQ(a, na.begin());
}
@ -7413,3 +7428,4 @@ TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) {
EXPECT_FALSE(SkipPrefix("world!", &p));
EXPECT_EQ(str, p);
}