Commit e0865dd9 by shiqian

Many changes:

- appends "_" to internal macro names (by Markus Heule). - makes Google Test work with newer versions of tools on Symbian and Windows CE (by Mika Raento). - adds the (ASSERT|EXPECT)_NO_FATAL_FAILURE macros (by Markus Heule). - changes EXPECT_(NON|)FATAL_FAILURE to catch failures in the current thread only (by Markus Heule). - adds the EXPECT_(NON|)FATAL_FAILURE_ON_ALL_THREADS macros (by Markus Heule). - adds GTEST_HAS_PTHREAD and GTEST_IS_THREADSAFE to indicate the availability of <pthread.h> and Google Test's thread-safety (by Zhanyong Wan). - adds scons/SConscript for building with scons (by Joi Sigurdsson). - adds src/gtest-all.cc for building Google Test from a single file (by Markus Heule). - updates the xcode project to include new tests (by Preston Jackson).
parent 0cbe322d
......@@ -10,6 +10,7 @@ Chandler Carruth <chandlerc@google.com>
Chris Prince <cprince@google.com>
Chris Taylor <taylorc@google.com>
Jeffrey Yasskin <jyasskin@google.com>
Jói Sigurðsson <joi@google.com>
Keir Mierle <mierle@gmail.com>
Keith Ray <keith.ray@gmail.com>
Kenton Varda <kenton@google.com>
......
......@@ -7,7 +7,8 @@ EXTRA_DIST = \
CHANGES \
CONTRIBUTORS \
include/gtest/internal/gtest-type-util.h.pump \
scripts/gen_gtest_pred_impl.py
scripts/gen_gtest_pred_impl.py \
src/gtest-all.cc
# MSVC project files
EXTRA_DIST += \
......@@ -69,6 +70,7 @@ lib_libgtest_la_SOURCES = src/gtest.cc \
src/gtest-filepath.cc \
src/gtest-internal-inl.h \
src/gtest-port.cc \
src/gtest-test-part.cc \
src/gtest-typed-test.cc
pkginclude_HEADERS = include/gtest/gtest.h \
......@@ -77,6 +79,7 @@ pkginclude_HEADERS = include/gtest/gtest.h \
include/gtest/gtest-spi.h \
include/gtest/gtest_pred_impl.h \
include/gtest/gtest_prod.h \
include/gtest/gtest-test-part.h \
include/gtest/gtest-typed-test.h
pkginclude_internaldir = $(pkgincludedir)/internal
......@@ -207,11 +210,21 @@ check_PROGRAMS += test/gtest_repeat_test
test_gtest_repeat_test_SOURCES = test/gtest_repeat_test.cc
test_gtest_repeat_test_LDADD = lib/libgtest.la
TESTS += test/gtest_sole_header_test
check_PROGRAMS += test/gtest_sole_header_test
test_gtest_sole_header_test_SOURCES = test/gtest_sole_header_test.cc
test_gtest_sole_header_test_LDADD = lib/libgtest_main.la
TESTS += test/gtest_stress_test
check_PROGRAMS += test/gtest_stress_test
test_gtest_stress_test_SOURCES = test/gtest_stress_test.cc
test_gtest_stress_test_LDADD = lib/libgtest.la
TESTS += test/gtest-test-part_test
check_PROGRAMS += test/gtest-test-part_test
test_gtest_test_part_test_SOURCES = test/gtest-test-part_test.cc
test_gtest_test_part_test_LDADD = lib/libgtest_main.la
TESTS += test/gtest-typed-test_test
check_PROGRAMS += test/gtest-typed-test_test
test_gtest_typed_test_test_SOURCES = test/gtest-typed-test_test.cc \
......
......@@ -47,7 +47,7 @@ namespace testing {
// from the start, running only a single death test, or "fast",
// meaning that the child process will execute the test logic immediately
// after forking.
GTEST_DECLARE_string(death_test_style);
GTEST_DECLARE_string_(death_test_style);
#ifdef GTEST_HAS_DEATH_TEST
......@@ -104,12 +104,12 @@ GTEST_DECLARE_string(death_test_style);
// 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)
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)
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
......
......@@ -102,7 +102,7 @@ class Message {
}
~Message() { delete ss_; }
#ifdef __SYMBIAN32__
#ifdef GTEST_OS_SYMBIAN
// Streams a value (either a pointer or not) to this object.
template <typename T>
inline Message& operator <<(const T& value) {
......@@ -139,7 +139,7 @@ class Message {
}
return *this;
}
#endif // __SYMBIAN32__
#endif // GTEST_OS_SYMBIAN
// Since the basic IO manipulators are overloaded for both narrow
// and wide streams, we have to provide this specialized definition
......@@ -187,7 +187,7 @@ class Message {
}
private:
#ifdef __SYMBIAN32__
#ifdef 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_
// decide between class template specializations for T and T*, so a
......@@ -204,7 +204,7 @@ class Message {
inline void StreamHelper(internal::false_type dummy, const T& value) {
::GTestStreamToHelper(ss_, value);
}
#endif // __SYMBIAN32__
#endif // GTEST_OS_SYMBIAN
// We'll hold the text streamed to this object here.
internal::StrStream* const ss_;
......
// Copyright 2008, 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: mheule@google.com (Markus Heule)
//
#ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
#define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
#include <iosfwd>
#include <gtest/internal/gtest-internal.h>
#include <gtest/internal/gtest-string.h>
namespace testing {
// The possible outcomes of a test part (i.e. an assertion or an
// explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
enum TestPartResultType {
TPRT_SUCCESS, // Succeeded.
TPRT_NONFATAL_FAILURE, // Failed but the test can continue.
TPRT_FATAL_FAILURE // Failed and the test should be terminated.
};
// A copyable object representing the result of a test part (i.e. an
// assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
//
// Don't inherit from TestPartResult as its destructor is not virtual.
class TestPartResult {
public:
// C'tor. TestPartResult does NOT have a default constructor.
// Always use this constructor (with parameters) to create a
// TestPartResult object.
TestPartResult(TestPartResultType type,
const char* file_name,
int line_number,
const char* message)
: type_(type),
file_name_(file_name),
line_number_(line_number),
summary_(ExtractSummary(message)),
message_(message) {
}
// Gets the outcome of the test part.
TestPartResultType type() const { return type_; }
// Gets the name of the source file where the test part took place, or
// NULL if it's unknown.
const char* file_name() const { return file_name_.c_str(); }
// Gets the line in the source file where the test part took place,
// or -1 if it's unknown.
int line_number() const { return line_number_; }
// Gets the summary of the failure message.
const char* summary() const { return summary_.c_str(); }
// Gets the message associated with the test part.
const char* message() const { return message_.c_str(); }
// Returns true iff the test part passed.
bool passed() const { return type_ == TPRT_SUCCESS; }
// Returns true iff the test part failed.
bool failed() const { return type_ != TPRT_SUCCESS; }
// Returns true iff the test part non-fatally failed.
bool nonfatally_failed() const { return type_ == TPRT_NONFATAL_FAILURE; }
// Returns true iff the test part fatally failed.
bool fatally_failed() const { return type_ == TPRT_FATAL_FAILURE; }
private:
TestPartResultType type_;
// Gets the summary of the failure message by omitting the stack
// trace in it.
static internal::String ExtractSummary(const char* message);
// The name of the source file where the test part took place, or
// NULL if the source file is unknown.
internal::String file_name_;
// The line in the source file where the test part took place, or -1
// if the line number is unknown.
int line_number_;
internal::String summary_; // The test failure summary.
internal::String message_; // The test failure message.
};
// Prints a TestPartResult object.
std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
// An array of TestPartResult objects.
//
// We define this class as we cannot use STL containers when compiling
// Google Test with MSVC 7.1 and exceptions disabled.
//
// Don't inherit from TestPartResultArray as its destructor is not
// virtual.
class TestPartResultArray {
public:
TestPartResultArray();
~TestPartResultArray();
// Appends the given TestPartResult to the array.
void Append(const TestPartResult& result);
// Returns the TestPartResult at the given index (0-based).
const TestPartResult& GetTestPartResult(int index) const;
// Returns the number of TestPartResult objects in the array.
int size() const;
private:
// Internally we use a list to simulate the array. Yes, this means
// that random access is O(N) in time, but it's OK for its purpose.
internal::List<TestPartResult>* const list_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray);
};
// This interface knows how to report a test part result.
class TestPartResultReporterInterface {
public:
virtual ~TestPartResultReporterInterface() {}
virtual void ReportTestPartResult(const TestPartResult& result) = 0;
};
namespace internal {
// This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a
// statement generates new fatal failures. To do so it registers itself as the
// current test part result reporter. Besides checking if fatal failures were
// reported, it only delegates the reporting to the former result reporter.
// The original result reporter is restored in the destructor.
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
class HasNewFatalFailureHelper : public TestPartResultReporterInterface {
public:
HasNewFatalFailureHelper();
virtual ~HasNewFatalFailureHelper();
virtual void ReportTestPartResult(const TestPartResult& result);
bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
private:
bool has_new_fatal_failure_;
TestPartResultReporterInterface* original_reporter_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper);
};
} // namespace internal
} // namespace testing
#endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
......@@ -53,7 +53,6 @@
// The following platform macros are used throughout Google Test:
// _WIN32_WCE Windows CE (set in project files)
// __SYMBIAN32__ Symbian (set by Symbian tool chain)
//
// Note that even though _MSC_VER and _WIN32_WCE really indicate a compiler
// and a Win32 implementation, respectively, we use them to indicate the
......@@ -68,6 +67,7 @@
#include <gtest/gtest-death-test.h>
#include <gtest/gtest-message.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.
......@@ -97,19 +97,11 @@ const int kMaxStackTraceDepth = 100;
// This flag specifies the maximum number of stack frames to be
// printed in a failure message.
GTEST_DECLARE_int32(stack_trace_depth);
GTEST_DECLARE_int32_(stack_trace_depth);
// This flag controls whether Google Test includes Google Test internal
// stack frames in failure stack traces.
GTEST_DECLARE_bool(show_internal_stack_frames);
// The possible outcomes of a test part (i.e. an assertion or an
// explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
enum TestPartResultType {
TPRT_SUCCESS, // Succeeded.
TPRT_NONFATAL_FAILURE, // Failed but the test can continue.
TPRT_FATAL_FAILURE // Failed and the test should be terminated.
};
GTEST_DECLARE_bool_(show_internal_stack_frames);
namespace internal {
......@@ -308,7 +300,7 @@ class Test {
virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
// We disallow copying Tests.
GTEST_DISALLOW_COPY_AND_ASSIGN(Test);
GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
};
......@@ -393,7 +385,7 @@ class TestInfo {
// An opaque implementation object.
internal::TestInfoImpl* impl_;
GTEST_DISALLOW_COPY_AND_ASSIGN(TestInfo);
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
};
// An Environment object is capable of setting up and tearing down an
......@@ -477,7 +469,7 @@ class UnitTest {
// This method can only be called from the main thread.
//
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
int Run() GTEST_MUST_USE_RESULT;
int Run() GTEST_MUST_USE_RESULT_;
// Returns the working directory when the first TEST() or TEST_F()
// was executed. The UnitTest object owns the string.
......@@ -523,7 +515,7 @@ class UnitTest {
internal::UnitTestImpl* impl_;
// We disallow copying UnitTest.
GTEST_DISALLOW_COPY_AND_ASSIGN(UnitTest);
GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);
};
// A convenient wrapper for adding an environment for the test
......@@ -707,7 +699,7 @@ class EqHelper<true> {
// with gcc 4.
//
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
#define GTEST_IMPL_CMP_HELPER(op_name, op)\
#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
template <typename T1, typename T2>\
AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
const T1& val1, const T2& val2) {\
......@@ -727,17 +719,17 @@ AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
// Implements the helper function for {ASSERT|EXPECT}_NE
GTEST_IMPL_CMP_HELPER(NE, !=)
GTEST_IMPL_CMP_HELPER_(NE, !=)
// Implements the helper function for {ASSERT|EXPECT}_LE
GTEST_IMPL_CMP_HELPER(LE, <=)
GTEST_IMPL_CMP_HELPER_(LE, <=)
// Implements the helper function for {ASSERT|EXPECT}_LT
GTEST_IMPL_CMP_HELPER(LT, < )
GTEST_IMPL_CMP_HELPER_(LT, < )
// Implements the helper function for {ASSERT|EXPECT}_GE
GTEST_IMPL_CMP_HELPER(GE, >=)
GTEST_IMPL_CMP_HELPER_(GE, >=)
// Implements the helper function for {ASSERT|EXPECT}_GT
GTEST_IMPL_CMP_HELPER(GT, > )
GTEST_IMPL_CMP_HELPER_(GT, > )
#undef GTEST_IMPL_CMP_HELPER
#undef GTEST_IMPL_CMP_HELPER_
// The helper function for {ASSERT|EXPECT}_STREQ.
//
......@@ -881,7 +873,7 @@ class AssertHelper {
AssertHelper(TestPartResultType type, const char* file, int line,
const char* message);
// Message assignment is a semantic trick to enable assertion
// streaming; see the GTEST_MESSAGE macro below.
// streaming; see the GTEST_MESSAGE_ macro below.
void operator=(const Message& message) const;
private:
TestPartResultType const type_;
......@@ -889,7 +881,7 @@ class AssertHelper {
int const line_;
String const message_;
GTEST_DISALLOW_COPY_AND_ASSIGN(AssertHelper);
GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
};
} // namespace internal
......@@ -920,13 +912,13 @@ class AssertHelper {
// << "There are still pending requests " << "on port " << port;
// Generates a nonfatal failure with a generic message.
#define ADD_FAILURE() GTEST_NONFATAL_FAILURE("Failed")
#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
// Generates a fatal failure with a generic message.
#define FAIL() GTEST_FATAL_FAILURE("Failed")
#define FAIL() GTEST_FATAL_FAILURE_("Failed")
// Generates a success with a generic message.
#define SUCCEED() GTEST_SUCCESS("Succeeded")
#define SUCCEED() GTEST_SUCCESS_("Succeeded")
// Macros for testing exceptions.
//
......@@ -938,31 +930,31 @@ class AssertHelper {
// Tests that the statement throws an exception.
#define EXPECT_THROW(statement, expected_exception) \
GTEST_TEST_THROW(statement, expected_exception, GTEST_NONFATAL_FAILURE)
GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
#define EXPECT_NO_THROW(statement) \
GTEST_TEST_NO_THROW(statement, GTEST_NONFATAL_FAILURE)
GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
#define EXPECT_ANY_THROW(statement) \
GTEST_TEST_ANY_THROW(statement, GTEST_NONFATAL_FAILURE)
GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
#define ASSERT_THROW(statement, expected_exception) \
GTEST_TEST_THROW(statement, expected_exception, GTEST_FATAL_FAILURE)
GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
#define ASSERT_NO_THROW(statement) \
GTEST_TEST_NO_THROW(statement, GTEST_FATAL_FAILURE)
GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
#define ASSERT_ANY_THROW(statement) \
GTEST_TEST_ANY_THROW(statement, GTEST_FATAL_FAILURE)
GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
// Boolean assertions.
#define EXPECT_TRUE(condition) \
GTEST_TEST_BOOLEAN(condition, #condition, false, true, \
GTEST_NONFATAL_FAILURE)
GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
GTEST_NONFATAL_FAILURE_)
#define EXPECT_FALSE(condition) \
GTEST_TEST_BOOLEAN(!(condition), #condition, true, false, \
GTEST_NONFATAL_FAILURE)
GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
GTEST_NONFATAL_FAILURE_)
#define ASSERT_TRUE(condition) \
GTEST_TEST_BOOLEAN(condition, #condition, false, true, \
GTEST_FATAL_FAILURE)
GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
GTEST_FATAL_FAILURE_)
#define ASSERT_FALSE(condition) \
GTEST_TEST_BOOLEAN(!(condition), #condition, true, false, \
GTEST_FATAL_FAILURE)
GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
GTEST_FATAL_FAILURE_)
// Includes the auto-generated header that implements a family of
// generic predicate assertion macros.
......@@ -1016,7 +1008,7 @@ class AssertHelper {
#define EXPECT_EQ(expected, actual) \
EXPECT_PRED_FORMAT2(::testing::internal:: \
EqHelper<GTEST_IS_NULL_LITERAL(expected)>::Compare, \
EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
expected, actual)
#define EXPECT_NE(expected, actual) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual)
......@@ -1031,7 +1023,7 @@ class AssertHelper {
#define ASSERT_EQ(expected, actual) \
ASSERT_PRED_FORMAT2(::testing::internal:: \
EqHelper<GTEST_IS_NULL_LITERAL(expected)>::Compare, \
EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
expected, actual)
#define ASSERT_NE(val1, val2) \
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
......@@ -1154,6 +1146,20 @@ AssertionResult DoubleLE(const char* expr1, const char* expr2,
#endif // GTEST_OS_WINDOWS
// Macros that execute statement and check that it doesn't generate new fatal
// failures in the current thread.
//
// * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
//
// Examples:
//
// EXPECT_NO_FATAL_FAILURE(Process());
// ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
//
#define ASSERT_NO_FATAL_FAILURE(statement) \
GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
#define EXPECT_NO_FATAL_FAILURE(statement) \
GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
// Causes a trace (including the source file path, the current line
// number, and the given message) to be included in every test failure
......@@ -1167,7 +1173,7 @@ AssertionResult DoubleLE(const char* expr1, const char* expr2,
// to appear in the same block - as long as they are on different
// lines.
#define SCOPED_TRACE(message) \
::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN(gtest_trace_, __LINE__)(\
::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
__FILE__, __LINE__, ::testing::Message() << (message))
......@@ -1188,7 +1194,7 @@ AssertionResult DoubleLE(const char* expr1, const char* expr2,
// }
#define TEST(test_case_name, test_name)\
GTEST_TEST(test_case_name, test_name, ::testing::Test)
GTEST_TEST_(test_case_name, test_name, ::testing::Test)
// Defines a test that uses a test fixture.
......@@ -1218,7 +1224,7 @@ AssertionResult DoubleLE(const char* expr1, const char* expr2,
// }
#define TEST_F(test_fixture, test_name)\
GTEST_TEST(test_fixture, test_name, test_fixture)
GTEST_TEST_(test_fixture, test_name, test_fixture)
// Use this macro in main() to run all tests. It returns 0 if all
// tests are successful, or 1 otherwise.
......
......@@ -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 06/22/2008 by command
// This file is AUTOMATICALLY GENERATED on 10/02/2008 by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
//
// Implements a family of generic predicate assertion macros.
......@@ -69,11 +69,11 @@
// Please email googletestframework@googlegroups.com if you need
// support for higher arities.
// GTEST_ASSERT is the basic statement to which all of the assertions
// GTEST_ASSERT_ is the basic statement to which all of the assertions
// in this file reduce. Don't use this in your code.
#define GTEST_ASSERT(expression, on_failure) \
GTEST_AMBIGUOUS_ELSE_BLOCKER \
#define GTEST_ASSERT_(expression, on_failure) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const ::testing::AssertionResult gtest_ar = (expression)) \
; \
else \
......@@ -99,27 +99,27 @@ AssertionResult AssertPred1Helper(const char* pred_text,
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
// Don't use this in your code.
#define GTEST_PRED_FORMAT1(pred_format, v1, on_failure)\
GTEST_ASSERT(pred_format(#v1, v1),\
#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
GTEST_ASSERT_(pred_format(#v1, v1),\
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
// this in your code.
#define GTEST_PRED1(pred, v1, on_failure)\
GTEST_ASSERT(::testing::AssertPred1Helper(#pred, \
#define GTEST_PRED1_(pred, v1, on_failure)\
GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \
#v1, \
pred, \
v1), on_failure)
// Unary predicate assertion macros.
#define EXPECT_PRED_FORMAT1(pred_format, v1) \
GTEST_PRED_FORMAT1(pred_format, v1, GTEST_NONFATAL_FAILURE)
GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
#define EXPECT_PRED1(pred, v1) \
GTEST_PRED1(pred, v1, GTEST_NONFATAL_FAILURE)
GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
#define ASSERT_PRED_FORMAT1(pred_format, v1) \
GTEST_PRED_FORMAT1(pred_format, v1, GTEST_FATAL_FAILURE)
GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
#define ASSERT_PRED1(pred, v1) \
GTEST_PRED1(pred, v1, GTEST_FATAL_FAILURE)
GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
......@@ -147,14 +147,14 @@ AssertionResult AssertPred2Helper(const char* pred_text,
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
// Don't use this in your code.
#define GTEST_PRED_FORMAT2(pred_format, v1, v2, on_failure)\
GTEST_ASSERT(pred_format(#v1, #v2, v1, v2),\
#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2),\
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
// this in your code.
#define GTEST_PRED2(pred, v1, v2, on_failure)\
GTEST_ASSERT(::testing::AssertPred2Helper(#pred, \
#define GTEST_PRED2_(pred, v1, v2, on_failure)\
GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
#v1, \
#v2, \
pred, \
......@@ -163,13 +163,13 @@ AssertionResult AssertPred2Helper(const char* pred_text,
// Binary predicate assertion macros.
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
GTEST_PRED_FORMAT2(pred_format, v1, v2, GTEST_NONFATAL_FAILURE)
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
#define EXPECT_PRED2(pred, v1, v2) \
GTEST_PRED2(pred, v1, v2, GTEST_NONFATAL_FAILURE)
GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
GTEST_PRED_FORMAT2(pred_format, v1, v2, GTEST_FATAL_FAILURE)
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
#define ASSERT_PRED2(pred, v1, v2) \
GTEST_PRED2(pred, v1, v2, GTEST_FATAL_FAILURE)
GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
......@@ -202,14 +202,14 @@ AssertionResult AssertPred3Helper(const char* pred_text,
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
// Don't use this in your code.
#define GTEST_PRED_FORMAT3(pred_format, v1, v2, v3, on_failure)\
GTEST_ASSERT(pred_format(#v1, #v2, #v3, v1, v2, v3),\
#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3),\
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
// this in your code.
#define GTEST_PRED3(pred, v1, v2, v3, on_failure)\
GTEST_ASSERT(::testing::AssertPred3Helper(#pred, \
#define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
#v1, \
#v2, \
#v3, \
......@@ -220,13 +220,13 @@ AssertionResult AssertPred3Helper(const char* pred_text,
// Ternary predicate assertion macros.
#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
GTEST_PRED_FORMAT3(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE)
GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
#define EXPECT_PRED3(pred, v1, v2, v3) \
GTEST_PRED3(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE)
GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
#define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
GTEST_PRED_FORMAT3(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE)
GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
#define ASSERT_PRED3(pred, v1, v2, v3) \
GTEST_PRED3(pred, v1, v2, v3, GTEST_FATAL_FAILURE)
GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
......@@ -264,14 +264,14 @@ AssertionResult AssertPred4Helper(const char* pred_text,
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
// Don't use this in your code.
#define GTEST_PRED_FORMAT4(pred_format, v1, v2, v3, v4, on_failure)\
GTEST_ASSERT(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4),\
#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4),\
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
// this in your code.
#define GTEST_PRED4(pred, v1, v2, v3, v4, on_failure)\
GTEST_ASSERT(::testing::AssertPred4Helper(#pred, \
#define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\
GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \
#v1, \
#v2, \
#v3, \
......@@ -284,13 +284,13 @@ AssertionResult AssertPred4Helper(const char* pred_text,
// 4-ary predicate assertion macros.
#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
GTEST_PRED_FORMAT4(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE)
GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
#define EXPECT_PRED4(pred, v1, v2, v3, v4) \
GTEST_PRED4(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE)
GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
GTEST_PRED_FORMAT4(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE)
GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
#define ASSERT_PRED4(pred, v1, v2, v3, v4) \
GTEST_PRED4(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE)
GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
......@@ -333,14 +333,14 @@ AssertionResult AssertPred5Helper(const char* pred_text,
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
// Don't use this in your code.
#define GTEST_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5, on_failure)\
GTEST_ASSERT(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5),\
#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5),\
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
// this in your code.
#define GTEST_PRED5(pred, v1, v2, v3, v4, v5, on_failure)\
GTEST_ASSERT(::testing::AssertPred5Helper(#pred, \
#define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
#v1, \
#v2, \
#v3, \
......@@ -355,13 +355,13 @@ AssertionResult AssertPred5Helper(const char* pred_text,
// 5-ary predicate assertion macros.
#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
GTEST_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE)
GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
#define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
GTEST_PRED5(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE)
GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
GTEST_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE)
GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
#define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
GTEST_PRED5(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE)
GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
......
......@@ -42,7 +42,7 @@
namespace testing {
namespace internal {
GTEST_DECLARE_string(internal_run_death_test);
GTEST_DECLARE_string_(internal_run_death_test);
// Names of the flags (needed for parsing Google Test flags).
const char kDeathTestStyleFlag[] = "death_test_style";
......@@ -51,7 +51,7 @@ const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
#ifdef GTEST_HAS_DEATH_TEST
// DeathTest is a class that hides much of the complexity of the
// GTEST_DEATH_TEST macro. It is abstract; its static Create method
// GTEST_DEATH_TEST_ macro. It is abstract; its static Create method
// returns a concrete class that depends on the prevailing death test
// style, as defined by the --gtest_death_test_style and/or
// --gtest_internal_run_death_test flags.
......@@ -85,8 +85,8 @@ class DeathTest {
~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
private:
DeathTest* const test_;
GTEST_DISALLOW_COPY_AND_ASSIGN(ReturnSentinel);
} GTEST_ATTRIBUTE_UNUSED;
GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel);
} GTEST_ATTRIBUTE_UNUSED_;
// An enumeration of possible roles that may be taken when a death
// test is encountered. EXECUTE means that the death test logic should
......@@ -121,7 +121,7 @@ class DeathTest {
static const char* LastMessage();
private:
GTEST_DISALLOW_COPY_AND_ASSIGN(DeathTest);
GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
};
// Factory interface for death tests. May be mocked out for testing.
......@@ -145,14 +145,14 @@ bool ExitedUnsuccessfully(int exit_status);
// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
// ASSERT_EXIT*, and EXPECT_EXIT*.
#define GTEST_DEATH_TEST(statement, predicate, regex, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER \
#define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (true) { \
const ::testing::internal::RE& gtest_regex = (regex); \
::testing::internal::DeathTest* gtest_dt; \
if (!::testing::internal::DeathTest::Create(#statement, &gtest_regex, \
__FILE__, __LINE__, &gtest_dt)) { \
goto GTEST_CONCAT_TOKEN(gtest_label_, __LINE__); \
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
} \
if (gtest_dt != NULL) { \
::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \
......@@ -160,7 +160,7 @@ bool ExitedUnsuccessfully(int exit_status);
switch (gtest_dt->AssumeRole()) { \
case ::testing::internal::DeathTest::OVERSEE_TEST: \
if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \
goto GTEST_CONCAT_TOKEN(gtest_label_, __LINE__); \
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
} \
break; \
case ::testing::internal::DeathTest::EXECUTE_TEST: { \
......@@ -173,7 +173,7 @@ bool ExitedUnsuccessfully(int exit_status);
} \
} \
} else \
GTEST_CONCAT_TOKEN(gtest_label_, __LINE__): \
GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \
fail(::testing::internal::DeathTest::LastMessage())
// The symbol "fail" here expands to something into which a message
// can be streamed.
......
......@@ -37,27 +37,25 @@
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
// The user can define the following macros in the build script to
// control Google Test's behavior:
// control Google Test's behavior. If the user doesn't define a macro
// in this list, Google Test will define it.
//
// GTEST_HAS_STD_STRING - Define it to 1/0 to indicate that
// std::string does/doesn't work (Google Test can
// be used where std::string is unavailable).
// Leave it undefined to let Google Test define it.
// GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string
// is/isn't available (some systems define
// ::string, which is different to std::string).
// Leave it undefined to let Google Test define it.
// GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that
// std::wstring does/doesn't work (Google Test can
// be used where std::wstring is unavailable).
// Leave it undefined to let Google Test define it.
// GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
// is/isn't available (some systems define
// ::wstring, which is different to std::wstring).
// Leave it undefined to let Google Test define it.
// GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't
// enabled. Leave it undefined to let Google
// Test define it.
// enabled.
// GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h>
// is/isn't available.
// This header defines the following utilities:
//
......@@ -72,6 +70,7 @@
// GTEST_OS_CYGWIN - defined iff compiled on Cygwin.
// GTEST_OS_LINUX - defined iff compiled on Linux.
// GTEST_OS_MAC - defined iff compiled on Mac OS X.
// GTEST_OS_SYMBIAN - defined iff compiled for Symbian.
// GTEST_OS_WINDOWS - defined iff compiled on Windows.
// Note that it is possible that none of the GTEST_OS_ macros are defined.
//
......@@ -82,15 +81,18 @@
// supported.
//
// Macros for basic C++ coding:
// GTEST_AMBIGUOUS_ELSE_BLOCKER - for disabling a gcc warning.
// GTEST_ATTRIBUTE_UNUSED - declares that a class' instances don't have to
// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
// GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances don't have to
// be used.
// GTEST_DISALLOW_COPY_AND_ASSIGN() - disables copy ctor and operator=.
// GTEST_MUST_USE_RESULT - declares that a function's result must be used.
// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used.
//
// Synchronization:
// Mutex, MutexLock, ThreadLocal, GetThreadCount()
// - synchronization primitives.
// GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
// synchronization primitives have real implementations
// and Google Test is thread-safe; or 0 otherwise.
//
// Template meta programming:
// is_pointer - as in TR1; needed on Symbian only.
......@@ -104,7 +106,7 @@
// Windows.
//
// Logging:
// GTEST_LOG() - logs messages at the specified severity level.
// GTEST_LOG_() - logs messages at the specified severity level.
// LogToStderr() - directs all log messages to stderr.
// FlushInfoLog() - flushes informational log messages.
//
......@@ -148,6 +150,8 @@
// Determines the platform on which Google Test is compiled.
#ifdef __CYGWIN__
#define GTEST_OS_CYGWIN
#elif __SYMBIAN32__
#define GTEST_OS_SYMBIAN
#elif defined _MSC_VER
// TODO(kenton@google.com): GTEST_OS_WINDOWS is currently used to mean
// both "The OS is Windows" and "The compiler is MSVC". These
......@@ -261,6 +265,18 @@
#endif // GTEST_HAS_RTTI
// Determines whether <pthread.h> is available.
#ifndef GTEST_HAS_PTHREAD
// The user didn't tell us, so we need to figure it out.
#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC)
#define GTEST_HAS_PTHREAD 1
#else
#define GTEST_HAS_PTHREAD 0
#endif // GTEST_OS_LINUX || GTEST_OS_MAC
#endif // GTEST_HAS_PTHREAD
// Determines whether to support death tests.
#if GTEST_HAS_STD_STRING && defined(GTEST_OS_LINUX)
#define GTEST_HAS_DEATH_TEST
......@@ -285,7 +301,7 @@
// Determines whether the system compiler uses UTF-16 for encoding wide strings.
#if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_CYGWIN) || \
defined(__SYMBIAN32__)
defined(GTEST_OS_SYMBIAN)
#define GTEST_WIDE_STRING_USES_UTF16_ 1
#endif
......@@ -300,9 +316,9 @@
//
// The "switch (0) case 0:" idiom is used to suppress this.
#ifdef __INTEL_COMPILER
#define GTEST_AMBIGUOUS_ELSE_BLOCKER
#define GTEST_AMBIGUOUS_ELSE_BLOCKER_
#else
#define GTEST_AMBIGUOUS_ELSE_BLOCKER switch (0) case 0: // NOLINT
#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: // NOLINT
#endif
// Use this annotation at the end of a struct / class definition to
......@@ -312,16 +328,16 @@
//
// struct Foo {
// Foo() { ... }
// } GTEST_ATTRIBUTE_UNUSED;
// } GTEST_ATTRIBUTE_UNUSED_;
#if defined(__GNUC__) && !defined(COMPILER_ICC)
#define GTEST_ATTRIBUTE_UNUSED __attribute__ ((unused))
#define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
#else
#define GTEST_ATTRIBUTE_UNUSED
#define GTEST_ATTRIBUTE_UNUSED_
#endif
// A macro to disallow the evil copy constructor and operator= functions
// This should be used in the private: declarations for a class.
#define GTEST_DISALLOW_COPY_AND_ASSIGN(type)\
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
type(const type &);\
void operator=(const type &)
......@@ -329,11 +345,11 @@
// with this macro. The macro should be used on function declarations
// following the argument list:
//
// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT;
// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
#define GTEST_MUST_USE_RESULT __attribute__ ((warn_unused_result))
#define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
#else
#define GTEST_MUST_USE_RESULT
#define GTEST_MUST_USE_RESULT_
#endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
namespace testing {
......@@ -385,7 +401,7 @@ class scoped_ptr {
private:
T* ptr_;
GTEST_DISALLOW_COPY_AND_ASSIGN(scoped_ptr);
GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
};
#ifdef GTEST_HAS_DEATH_TEST
......@@ -444,7 +460,7 @@ class RE {
#endif // GTEST_HAS_DEATH_TEST
// Defines logging utilities:
// GTEST_LOG() - logs messages at the specified severity level.
// GTEST_LOG_() - logs messages at the specified severity level.
// LogToStderr() - directs all log messages to stderr.
// FlushInfoLog() - flushes informational log messages.
......@@ -458,7 +474,7 @@ enum GTestLogSeverity {
void GTestLog(GTestLogSeverity severity, const char* file,
int line, const char* msg);
#define GTEST_LOG(severity, msg)\
#define GTEST_LOG_(severity, msg)\
::testing::internal::GTestLog(\
::testing::internal::GTEST_##severity, __FILE__, __LINE__, \
(::testing::Message() << (msg)).GetString().c_str())
......@@ -510,6 +526,8 @@ typedef GTestMutexLock MutexLock;
template <typename T>
class ThreadLocal {
public:
ThreadLocal() : value_() {}
explicit ThreadLocal(const T& value) : value_(value) {}
T* pointer() { return &value_; }
const T* pointer() const { return &value_; }
const T& get() const { return value_; }
......@@ -522,6 +540,10 @@ class ThreadLocal {
// return 0 to indicate that we cannot detect it.
inline size_t GetThreadCount() { return 0; }
// The above synchronization primitives have dummy implementations.
// Therefore Google Test is not thread-safe.
#define GTEST_IS_THREADSAFE 0
// Defines tr1::is_pointer (only needed for Symbian).
#ifdef __SYMBIAN32__
......@@ -657,18 +679,18 @@ inline void abort() { ::abort(); }
#define GTEST_FLAG(name) FLAGS_gtest_##name
// Macros for declaring flags.
#define GTEST_DECLARE_bool(name) extern bool GTEST_FLAG(name)
#define GTEST_DECLARE_int32(name) \
#define GTEST_DECLARE_bool_(name) extern bool GTEST_FLAG(name)
#define GTEST_DECLARE_int32_(name) \
extern ::testing::internal::Int32 GTEST_FLAG(name)
#define GTEST_DECLARE_string(name) \
#define GTEST_DECLARE_string_(name) \
extern ::testing::internal::String GTEST_FLAG(name)
// Macros for defining flags.
#define GTEST_DEFINE_bool(name, default_val, doc) \
#define GTEST_DEFINE_bool_(name, default_val, doc) \
bool GTEST_FLAG(name) = (default_val)
#define GTEST_DEFINE_int32(name, default_val, doc) \
#define GTEST_DEFINE_int32_(name, default_val, doc) \
::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
#define GTEST_DEFINE_string(name, default_val, doc) \
#define GTEST_DEFINE_string_(name, default_val, doc) \
::testing::internal::String GTEST_FLAG(name) = (default_val)
// Parses 'str' for a 32-bit signed integer. If successful, writes the result
......
#!/usr/bin/python2.4
#
# Copyright 2008, 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.
"""Builds the Google Test (gtest) lib; this is for Windows projects
using SCons and can probably be easily extended for cross-platform
SCons builds. The compilation settings from your project will be used,
with some specific flags required for gtest added.
You should be able to call this file from more or less any SConscript
file.
You can optionally set a variable on the construction environment to
have the unit test executables copied to your output directory. The
variable should be env['EXE_OUTPUT'].
Another optional variable is env['LIB_OUTPUT']. If set, the generated
libraries are copied to the folder indicated by the variable.
If you place the gtest sources within your own project's source
directory, you should be able to call this SConscript file simply as
follows:
# -- cut here --
# Build gtest library; first tell it where to copy executables.
env['EXE_OUTPUT'] = '#/mybuilddir/mybuildmode' # example, optional
env['LIB_OUTPUT'] = '#/mybuilddir/mybuildmode/lib'
env.SConscript('whateverpath/gtest/scons/SConscript')
# -- cut here --
If on the other hand you place the gtest sources in a directory
outside of your project's source tree, you would use a snippet similar
to the following:
# -- cut here --
# The following assumes that $BUILD_DIR refers to the root of the
# directory for your current build mode, e.g. "#/mybuilddir/mybuildmode"
# Build gtest library; as it is outside of our source root, we need to
# tell SCons that the directory it will refer to as
# e.g. $BUIlD_DIR/gtest is actually on disk in original form as
# ../../gtest (relative to your project root directory). Recall that
# SCons by default copies all source files into the build directory
# before building.
gtest_dir = env.Dir('$BUILD_DIR/gtest')
# Modify this part to point to gtest relative to the current
# SConscript or SConstruct file's directory. The ../.. path would
# be different per project, to locate the base directory for gtest.
gtest_dir.addRepository(env.Dir('../../gtest'))
# Tell the gtest SCons file where to copy executables.
env['EXE_OUTPUT'] = '$BUILD_DIR' # example, optional
# Call the gtest SConscript to build gtest.lib and unit tests. The
# location of the library should end up as
# '$BUILD_DIR/gtest/scons/gtest.lib'
env.SConscript(env.File('scons/SConscript', gtest_dir))
# -- cut here --
"""
__author__ = 'joi@google.com (Joi Sigurdsson)'
Import('env')
env = env.Clone()
# Include paths to gtest headers are relative to a directory two above
# the gtest directory itself, and this SConscript file is one
# directory deeper than the gtest directory.
env.Prepend(CPPPATH = ['../../..'])
# TODO(joi@google.com) Fix the code that causes this warning so that
# we see all warnings from the compiler about possible 64-bit porting
# issues.
env.Append(CCFLAGS=['-wd4267'])
# Sources shared by base library and library that includes main.
gtest_sources = ['../src/gtest-all.cc']
# gtest.lib to be used by most apps (if you have your own main
# function)
gtest = env.StaticLibrary(target='gtest',
source=gtest_sources)
# gtest_main.lib can be used if you just want a basic main function;
# it is also used by the tests for Google Test itself.
gtest_main = env.StaticLibrary(target='gtest_main',
source=gtest_sources + ['../src/gtest_main.cc'])
# Install the libraries if needed.
if 'LIB_OUTPUT' in env.Dictionary():
env.Install('$LIB_OUTPUT', source=[gtest, gtest_main])
def GtestUnitTest(env, target, gtest_lib, additional_sources=None):
"""Helper to create gtest unit tests.
Args:
env: The SCons construction environment to use to build.
target: The basename of the target unit test .cc file.
gtest_lib: The gtest lib to use.
"""
source = [env.File('%s.cc' % target, env.Dir('../test'))]
if additional_sources:
source += additional_sources
unit_test = env.Program(target=target,
source=source,
LIBS=[gtest_lib, 'kernel32.lib', 'user32.lib'])
if 'EXE_OUTPUT' in env.Dictionary():
env.Install('$EXE_OUTPUT', source=[unit_test])
GtestUnitTest(env, 'gtest-filepath_test', gtest_main)
GtestUnitTest(env, 'gtest-message_test', gtest_main)
GtestUnitTest(env, 'gtest-options_test', gtest_main)
GtestUnitTest(env, 'gtest_environment_test', gtest)
GtestUnitTest(env, 'gtest_main_unittest', gtest_main)
GtestUnitTest(env, 'gtest_no_test_unittest', gtest)
GtestUnitTest(env, 'gtest_pred_impl_unittest', gtest_main)
GtestUnitTest(env, 'gtest_prod_test', gtest_main,
additional_sources=['../test/production.cc'])
GtestUnitTest(env, 'gtest_repeat_test', gtest)
GtestUnitTest(env, 'gtest_sole_header_test', gtest_main)
GtestUnitTest(env, 'gtest-test-part_test', gtest_main)
GtestUnitTest(env, 'gtest-typed-test_test', gtest_main,
additional_sources=['../test/gtest-typed-test2_test.cc'])
GtestUnitTest(env, 'gtest_unittest', gtest)
GtestUnitTest(env, 'gtest_output_test_', gtest)
GtestUnitTest(env, 'gtest_color_test_', gtest)
# TODO(wan@google.com) Add these unit tests:
# - gtest_break_on_failure_unittest_
# - gtest_filter_unittest_
# - gtest_list_tests_unittest_
# - gtest_xml_outfile1_test_
# - gtest_xml_outfile2_test_
# - gtest_xml_output_unittest_
# We need to disable some optimization flags for a couple of tests,
# otherwise the redirection of stdout does not work (apparently
# because of a compiler bug).
special_env = env.Clone()
linker_flags = special_env['LINKFLAGS']
for flag in ["/O1", "/Os", "/Og", "/Oy"]:
if flag in linker_flags:
linker_flags.remove(flag)
GtestUnitTest(special_env, 'gtest_env_var_test_', gtest)
GtestUnitTest(special_env, 'gtest_uninitialized_test_', gtest)
......@@ -149,11 +149,11 @@ def HeaderPreamble(n):
// Please email googletestframework@googlegroups.com if you need
// support for higher arities.
// GTEST_ASSERT is the basic statement to which all of the assertions
// GTEST_ASSERT_ is the basic statement to which all of the assertions
// in this file reduce. Don't use this in your code.
#define GTEST_ASSERT(expression, on_failure) \\
GTEST_AMBIGUOUS_ELSE_BLOCKER \\
#define GTEST_ASSERT_(expression, on_failure) \\
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \\
if (const ::testing::AssertionResult gtest_ar = (expression)) \\
; \\
else \\
......@@ -257,14 +257,14 @@ AssertionResult AssertPred%(n)sHelper(const char* pred_text""" % DEFS
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT%(n)s.
// Don't use this in your code.
#define GTEST_PRED_FORMAT%(n)s(pred_format, %(vs)s, on_failure)\\
GTEST_ASSERT(pred_format(%(vts)s, %(vs)s),\\
#define GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, on_failure)\\
GTEST_ASSERT_(pred_format(%(vts)s, %(vs)s),\\
on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED%(n)s. Don't use
// this in your code.
#define GTEST_PRED%(n)s(pred, %(vs)s, on_failure)\\
GTEST_ASSERT(::testing::AssertPred%(n)sHelper(#pred""" % DEFS
#define GTEST_PRED%(n)s_(pred, %(vs)s, on_failure)\\
GTEST_ASSERT_(::testing::AssertPred%(n)sHelper(#pred""" % DEFS
impl += Iter(n, """, \\
#v%s""")
......@@ -279,13 +279,13 @@ AssertionResult AssertPred%(n)sHelper(const char* pred_text""" % DEFS
// %(Arity)s predicate assertion macros.
#define EXPECT_PRED_FORMAT%(n)s(pred_format, %(vs)s) \\
GTEST_PRED_FORMAT%(n)s(pred_format, %(vs)s, GTEST_NONFATAL_FAILURE)
GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, GTEST_NONFATAL_FAILURE_)
#define EXPECT_PRED%(n)s(pred, %(vs)s) \\
GTEST_PRED%(n)s(pred, %(vs)s, GTEST_NONFATAL_FAILURE)
GTEST_PRED%(n)s_(pred, %(vs)s, GTEST_NONFATAL_FAILURE_)
#define ASSERT_PRED_FORMAT%(n)s(pred_format, %(vs)s) \\
GTEST_PRED_FORMAT%(n)s(pred_format, %(vs)s, GTEST_FATAL_FAILURE)
GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, GTEST_FATAL_FAILURE_)
#define ASSERT_PRED%(n)s(pred, %(vs)s) \\
GTEST_PRED%(n)s(pred, %(vs)s, GTEST_FATAL_FAILURE)
GTEST_PRED%(n)s_(pred, %(vs)s, GTEST_FATAL_FAILURE_)
""" % DEFS
......
// Copyright 2008, 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: mheule@google.com (Markus Heule)
//
// Google C++ Testing Framework (Google Test)
//
// Sometimes it's desirable to build Google Test by compiling a single file.
// This file serves this purpose.
#include "src/gtest.cc"
#include "src/gtest-death-test.cc"
#include "src/gtest-filepath.cc"
#include "src/gtest-port.cc"
#include "src/gtest-test-part.cc"
#include "src/gtest-typed-test.cc"
......@@ -59,7 +59,7 @@ namespace testing {
// The default death test style.
static const char kDefaultDeathTestStyle[] = "fast";
GTEST_DEFINE_string(
GTEST_DEFINE_string_(
death_test_style,
internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle),
"Indicates how to run a death test in a forked child process: "
......@@ -69,7 +69,7 @@ GTEST_DEFINE_string(
"after forking).");
namespace internal {
GTEST_DEFINE_string(
GTEST_DEFINE_string_(
internal_run_death_test, "",
"Indicates the file, line number, temporal index of "
"the single death test to run, and a file descriptor to "
......@@ -188,7 +188,7 @@ void DeathTestAbort(const char* format, ...) {
// 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 (!(expression)) { \
DeathTestAbort("CHECK failed: File %s, line %d: %s", \
......@@ -196,14 +196,14 @@ void DeathTestAbort(const char* format, ...) {
} \
} while (0)
// This macro is similar to GTEST_DEATH_TEST_CHECK, but it is meant for
// This macro is similar to GTEST_DEATH_TEST_CHECK_, but it is meant for
// evaluating any system call that fulfills two conditions: it must return
// -1 on failure, and set errno to EINTR when it is interrupted and
// should be tried again. The macro expands to a loop that repeatedly
// 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 retval; \
do { \
......@@ -303,9 +303,9 @@ static void FailFromInternalError(int fd) {
// TODO(smcafee): Maybe just FAIL the test instead?
if (num_read == 0) {
GTEST_LOG(FATAL, error);
GTEST_LOG_(FATAL, error);
} else {
GTEST_LOG(FATAL,
GTEST_LOG_(FATAL,
Message() << "Error while reading death test internal: "
<< strerror(errno) << " [" << errno << "]");
}
......@@ -343,19 +343,19 @@ int ForkingDeathTest::Wait() {
FailFromInternalError(read_fd_); // Does not return.
break;
default:
GTEST_LOG(FATAL,
GTEST_LOG_(FATAL,
Message() << "Death test child process reported unexpected "
<< "status byte (" << static_cast<unsigned int>(flag)
<< ")");
}
} else {
GTEST_LOG(FATAL,
GTEST_LOG_(FATAL,
Message() << "Read from death test child process failed: "
<< strerror(errno));
}
GTEST_DEATH_TEST_CHECK_SYSCALL(close(read_fd_));
GTEST_DEATH_TEST_CHECK_SYSCALL(waitpid(child_pid_, &status_, 0));
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(read_fd_));
GTEST_DEATH_TEST_CHECK_SYSCALL_(waitpid(child_pid_, &status_, 0));
return status_;
}
......@@ -418,7 +418,7 @@ bool ForkingDeathTest::Passed(bool status_ok) {
break;
case IN_PROGRESS:
default:
GTEST_LOG(FATAL,
GTEST_LOG_(FATAL,
"DeathTest::Passed somehow called before conclusion of test");
}
......@@ -436,8 +436,8 @@ void ForkingDeathTest::Abort(AbortReason reason) {
// to the pipe, then exit.
const char flag =
reason == TEST_DID_NOT_DIE ? kDeathTestLived : kDeathTestReturned;
GTEST_DEATH_TEST_CHECK_SYSCALL(write(write_fd_, &flag, 1));
GTEST_DEATH_TEST_CHECK_SYSCALL(close(write_fd_));
GTEST_DEATH_TEST_CHECK_SYSCALL_(write(write_fd_, &flag, 1));
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(write_fd_));
_exit(1); // Exits w/o any normal exit hooks (we were supposed to crash)
}
......@@ -455,11 +455,11 @@ class NoExecDeathTest : public ForkingDeathTest {
DeathTest::TestRole NoExecDeathTest::AssumeRole() {
const size_t thread_count = GetThreadCount();
if (thread_count != 1) {
GTEST_LOG(WARNING, DeathTestThreadWarning(thread_count));
GTEST_LOG_(WARNING, DeathTestThreadWarning(thread_count));
}
int pipe_fd[2];
GTEST_DEATH_TEST_CHECK(pipe(pipe_fd) != -1);
GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
last_death_test_message = "";
CaptureStderr();
......@@ -473,10 +473,10 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() {
FlushInfoLog();
const pid_t child_pid = fork();
GTEST_DEATH_TEST_CHECK(child_pid != -1);
GTEST_DEATH_TEST_CHECK_(child_pid != -1);
set_child_pid(child_pid);
if (child_pid == 0) {
GTEST_DEATH_TEST_CHECK_SYSCALL(close(pipe_fd[0]));
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[0]));
set_write_fd(pipe_fd[1]);
// Redirects all logging to stderr in the child process to prevent
// concurrent writes to the log files. We capture stderr in the parent
......@@ -484,7 +484,7 @@ DeathTest::TestRole NoExecDeathTest::AssumeRole() {
LogToStderr();
return EXECUTE_TEST;
} else {
GTEST_DEATH_TEST_CHECK_SYSCALL(close(pipe_fd[1]));
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
set_read_fd(pipe_fd[0]);
set_forked(true);
return OVERSEE_TEST;
......@@ -551,7 +551,7 @@ struct ExecDeathTestArgs {
// any potentially unsafe operations like malloc or libc functions.
static int ExecDeathTestChildMain(void* child_arg) {
ExecDeathTestArgs* const args = static_cast<ExecDeathTestArgs*>(child_arg);
GTEST_DEATH_TEST_CHECK_SYSCALL(close(args->close_fd));
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd));
// We need to execute the test program in the same environment where
// it was originally invoked. Therefore we change to the original
......@@ -599,14 +599,14 @@ static pid_t ExecDeathTestFork(char* const* argv, int close_fd) {
const size_t stack_size = getpagesize();
void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
GTEST_DEATH_TEST_CHECK(stack != MAP_FAILED);
GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
void* const stack_top =
static_cast<char*>(stack) + (stack_grows_down ? stack_size : 0);
ExecDeathTestArgs args = { argv, close_fd };
const pid_t child_pid = clone(&ExecDeathTestChildMain, stack_top,
SIGCHLD, &args);
GTEST_DEATH_TEST_CHECK(child_pid != -1);
GTEST_DEATH_TEST_CHECK(munmap(stack, stack_size) != -1);
GTEST_DEATH_TEST_CHECK_(child_pid != -1);
GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
return child_pid;
}
......@@ -627,10 +627,10 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
}
int pipe_fd[2];
GTEST_DEATH_TEST_CHECK(pipe(pipe_fd) != -1);
GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
// Clear the close-on-exec flag on the write end of the pipe, lest
// it be closed when the child process does an exec:
GTEST_DEATH_TEST_CHECK(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
const String filter_flag =
String::Format("--%s%s=%s.%s",
......@@ -654,7 +654,7 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
FlushInfoLog();
const pid_t child_pid = ExecDeathTestFork(args.Argv(), pipe_fd[0]);
GTEST_DEATH_TEST_CHECK_SYSCALL(close(pipe_fd[1]));
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
set_child_pid(child_pid);
set_read_fd(pipe_fd[0]);
set_forked(true);
......
......@@ -36,10 +36,14 @@
#ifdef _WIN32_WCE
#include <windows.h>
#elif defined(_WIN32)
#elif defined(GTEST_OS_WINDOWS)
#include <direct.h>
#include <io.h>
#include <sys/stat.h>
#elif defined(GTEST_OS_SYMBIAN)
// Symbian OpenC has PATH_MAX in sys/syslimits.h
#include <sys/syslimits.h>
#include <unistd.h>
#else
#include <sys/stat.h>
#include <unistd.h>
......@@ -249,7 +253,7 @@ bool FilePath::CreateDirectoriesRecursively() const {
// directory for any reason, including if the parent directory does not
// exist. Not named "CreateDirectory" because that's a macro on Windows.
bool FilePath::CreateFolder() const {
#ifdef _WIN32
#ifdef GTEST_OS_WINDOWS
#ifdef _WIN32_WCE
FilePath removed_sep(this->RemoveTrailingPathSeparator());
LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
......
......@@ -64,16 +64,16 @@ namespace testing {
// We don't want the users to modify these flags in the code, but want
// Google Test's own unit tests to be able to access them. Therefore we
// declare them here as opposed to in gtest.h.
GTEST_DECLARE_bool(break_on_failure);
GTEST_DECLARE_bool(catch_exceptions);
GTEST_DECLARE_string(color);
GTEST_DECLARE_string(filter);
GTEST_DECLARE_bool(list_tests);
GTEST_DECLARE_string(output);
GTEST_DECLARE_bool(print_time);
GTEST_DECLARE_int32(repeat);
GTEST_DECLARE_int32(stack_trace_depth);
GTEST_DECLARE_bool(show_internal_stack_frames);
GTEST_DECLARE_bool_(break_on_failure);
GTEST_DECLARE_bool_(catch_exceptions);
GTEST_DECLARE_string_(color);
GTEST_DECLARE_string_(filter);
GTEST_DECLARE_bool_(list_tests);
GTEST_DECLARE_string_(output);
GTEST_DECLARE_bool_(print_time);
GTEST_DECLARE_int32_(repeat);
GTEST_DECLARE_int32_(stack_trace_depth);
GTEST_DECLARE_bool_(show_internal_stack_frames);
namespace internal {
......@@ -131,7 +131,7 @@ class GTestFlagSaver {
bool print_time_;
bool pretty_;
internal::Int32 repeat_;
} GTEST_ATTRIBUTE_UNUSED;
} GTEST_ATTRIBUTE_UNUSED_;
// Converts a Unicode code point to a narrow string in UTF-8 encoding.
// code_point parameter is of type UInt32 because wchar_t may not be
......@@ -200,7 +200,7 @@ class ListNode {
explicit ListNode(const E & element) : element_(element), next_(NULL) {}
// We disallow copying ListNode
GTEST_DISALLOW_COPY_AND_ASSIGN(ListNode);
GTEST_DISALLOW_COPY_AND_ASSIGN_(ListNode);
public:
......@@ -399,7 +399,7 @@ class List {
int size_; // The number of elements in the list.
// We disallow copying List.
GTEST_DISALLOW_COPY_AND_ASSIGN(List);
GTEST_DISALLOW_COPY_AND_ASSIGN_(List);
};
// The virtual destructor of List.
......@@ -557,7 +557,7 @@ class TestResult {
TimeInMillis elapsed_time_;
// We disallow copying TestResult.
GTEST_DISALLOW_COPY_AND_ASSIGN(TestResult);
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
}; // class TestResult
class TestInfoImpl {
......@@ -633,7 +633,7 @@ class TestInfoImpl {
// test for the second time.
internal::TestResult result_;
GTEST_DISALLOW_COPY_AND_ASSIGN(TestInfoImpl);
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfoImpl);
};
} // namespace internal
......@@ -765,7 +765,7 @@ class TestCase {
internal::TimeInMillis elapsed_time_;
// We disallow copying TestCases.
GTEST_DISALLOW_COPY_AND_ASSIGN(TestCase);
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
};
namespace internal {
......@@ -843,7 +843,7 @@ class OsStackTraceGetterInterface {
virtual void UponLeavingGTest() = 0;
private:
GTEST_DISALLOW_COPY_AND_ASSIGN(OsStackTraceGetterInterface);
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
};
// A working implemenation of the OsStackTraceGetterInterface interface.
......@@ -866,7 +866,7 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface {
// and any calls to CurrentStackTrace() from within the user code.
void* caller_frame_;
GTEST_DISALLOW_COPY_AND_ASSIGN(OsStackTraceGetter);
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
};
// Information about a Google Test trace point.
......@@ -876,24 +876,63 @@ struct TraceInfo {
String message;
};
// This is the default global test part result reporter used in UnitTestImpl.
// This class should only be used by UnitTestImpl.
class DefaultGlobalTestPartResultReporter
: public TestPartResultReporterInterface {
public:
explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
// Implements the TestPartResultReporterInterface. Reports the test part
// result in the current test.
virtual void ReportTestPartResult(const TestPartResult& result);
private:
UnitTestImpl* const unit_test_;
};
// This is the default per thread test part result reporter used in
// UnitTestImpl. This class should only be used by UnitTestImpl.
class DefaultPerThreadTestPartResultReporter
: public TestPartResultReporterInterface {
public:
explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
// Implements the TestPartResultReporterInterface. The implementation just
// delegates to the current global test part result reporter of *unit_test_.
virtual void ReportTestPartResult(const TestPartResult& result);
private:
UnitTestImpl* const unit_test_;
};
// The private implementation of the UnitTest class. We don't protect
// the methods under a mutex, as this class is not accessible by a
// user and the UnitTest class that delegates work to this class does
// proper locking.
class UnitTestImpl : public TestPartResultReporterInterface {
class UnitTestImpl {
public:
explicit UnitTestImpl(UnitTest* parent);
virtual ~UnitTestImpl();
// Reports a test part result. This method is from the
// TestPartResultReporterInterface interface.
virtual void ReportTestPartResult(const TestPartResult& result);
// There are two different ways to register your own TestPartResultReporter.
// You can register your own repoter to listen either only for test results
// from the current thread or for results from all threads.
// By default, each per-thread test result repoter just passes a new
// TestPartResult to the global test result reporter, which registers the
// test part result for the currently running test.
// Returns the global test part result reporter.
TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
// Returns the current test part result reporter.
TestPartResultReporterInterface* test_part_result_reporter();
// Sets the global test part result reporter.
void SetGlobalTestPartResultReporter(
TestPartResultReporterInterface* reporter);
// Sets the current test part result reporter.
void set_test_part_result_reporter(TestPartResultReporterInterface* reporter);
// Returns the test part result reporter for the current thread.
TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
// Sets the test part result reporter for the current thread.
void SetTestPartResultReporterForCurrentThread(
TestPartResultReporterInterface* reporter);
// Gets the number of successful test cases.
int successful_test_case_count() const;
......@@ -1107,8 +1146,20 @@ class UnitTestImpl : public TestPartResultReporterInterface {
// executed.
internal::FilePath original_working_dir_;
// Points to (but doesn't own) the test part result reporter.
TestPartResultReporterInterface* test_part_result_reporter_;
// The default test part result reporters.
DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
DefaultPerThreadTestPartResultReporter
default_per_thread_test_part_result_reporter_;
// Points to (but doesn't own) the global test part result reporter.
TestPartResultReporterInterface* global_test_part_result_repoter_;
// Protects read and write access to global_test_part_result_reporter_.
internal::Mutex global_test_part_result_reporter_mutex_;
// Points to (but doesn't own) the per-thread test part result reporter.
internal::ThreadLocal<TestPartResultReporterInterface*>
per_thread_test_part_result_reporter_;
// The list of environments that need to be set-up/torn-down
// before/after the tests are run. environments_in_reverse_order_
......@@ -1168,7 +1219,7 @@ class UnitTestImpl : public TestPartResultReporterInterface {
// A per-thread stack of traces created by the SCOPED_TRACE() macro.
internal::ThreadLocal<internal::List<TraceInfo> > gtest_trace_stack_;
GTEST_DISALLOW_COPY_AND_ASSIGN(UnitTestImpl);
GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
}; // class UnitTestImpl
// Convenience function for accessing the global UnitTest
......
......@@ -172,7 +172,7 @@ static ::std::string ReadEntireFile(FILE * file) {
// Starts capturing stderr.
void CaptureStderr() {
if (g_captured_stderr != NULL) {
GTEST_LOG(FATAL, "Only one stderr capturer can exist at one time.");
GTEST_LOG_(FATAL, "Only one stderr capturer can exist at one time.");
}
g_captured_stderr = new CapturedStderr;
}
......
// Copyright 2008, 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: mheule@google.com (Markus Heule)
//
// The Google C++ Testing Framework (Google Test)
#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
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// his code.
#define GTEST_IMPLEMENTATION
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION
namespace testing {
// Gets the summary of the failure message by omitting the stack trace
// in it.
internal::String TestPartResult::ExtractSummary(const char* message) {
const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
return stack_trace == NULL ? internal::String(message) :
internal::String(message, stack_trace - message);
}
// Prints a TestPartResult object.
std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
return os << result.file_name() << ":"
<< result.line_number() << ": "
<< (result.type() == TPRT_SUCCESS ? "Success" :
result.type() == TPRT_FATAL_FAILURE ? "Fatal failure" :
"Non-fatal failure") << ":\n"
<< result.message() << std::endl;
}
// Constructs an empty TestPartResultArray.
TestPartResultArray::TestPartResultArray()
: list_(new internal::List<TestPartResult>) {
}
// Destructs a TestPartResultArray.
TestPartResultArray::~TestPartResultArray() {
delete list_;
}
// Appends a TestPartResult to the array.
void TestPartResultArray::Append(const TestPartResult& result) {
list_->PushBack(result);
}
// Returns the TestPartResult at the given index (0-based).
const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {
if (index < 0 || index >= size()) {
printf("\nInvalid index (%d) into TestPartResultArray.\n", index);
internal::abort();
}
const internal::ListNode<TestPartResult>* p = list_->Head();
for (int i = 0; i < index; i++) {
p = p->next();
}
return p->element();
}
// Returns the number of TestPartResult objects in the array.
int TestPartResultArray::size() const {
return list_->size();
}
namespace internal {
HasNewFatalFailureHelper::HasNewFatalFailureHelper()
: has_new_fatal_failure_(false),
original_reporter_(UnitTest::GetInstance()->impl()->
GetTestPartResultReporterForCurrentThread()) {
UnitTest::GetInstance()->impl()->SetTestPartResultReporterForCurrentThread(
this);
}
HasNewFatalFailureHelper::~HasNewFatalFailureHelper() {
UnitTest::GetInstance()->impl()->SetTestPartResultReporterForCurrentThread(
original_reporter_);
}
void HasNewFatalFailureHelper::ReportTestPartResult(
const TestPartResult& result) {
if (result.fatally_failed())
has_new_fatal_failure_ = true;
original_reporter_->ReportTestPartResult(result);
}
} // namespace internal
} // namespace testing
......@@ -115,7 +115,7 @@ class MayDie {
// A member function that may die.
void MemberFunction() const {
if (should_die_) {
GTEST_LOG(FATAL, "death inside MayDie::MemberFunction().");
GTEST_LOG_(FATAL, "death inside MayDie::MemberFunction().");
}
}
......@@ -126,26 +126,26 @@ class MayDie {
// A global function that's expected to die.
void GlobalFunction() {
GTEST_LOG(FATAL, "death inside GlobalFunction().");
GTEST_LOG_(FATAL, "death inside GlobalFunction().");
}
// A non-void function that's expected to die.
int NonVoidFunction() {
GTEST_LOG(FATAL, "death inside NonVoidFunction().");
GTEST_LOG_(FATAL, "death inside NonVoidFunction().");
return 1;
}
// A unary function that may die.
void DieIf(bool should_die) {
if (should_die) {
GTEST_LOG(FATAL, "death inside DieIf().");
GTEST_LOG_(FATAL, "death inside DieIf().");
}
}
// A binary function that may die.
bool DieIfLessThan(int x, int y) {
if (x < y) {
GTEST_LOG(FATAL, "death inside DieIfLessThan().");
GTEST_LOG_(FATAL, "death inside DieIfLessThan().");
}
return true;
}
......@@ -160,7 +160,7 @@ void DeathTestSubroutine() {
int DieInDebugElse12(int* sideeffect) {
if (sideeffect) *sideeffect = 12;
#ifndef NDEBUG
GTEST_LOG(FATAL, "debug death inside DieInDebugElse12()");
GTEST_LOG_(FATAL, "debug death inside DieInDebugElse12()");
#endif // NDEBUG
return 12;
}
......@@ -717,7 +717,7 @@ bool MockDeathTestFactory::Create(const char* statement,
return true;
}
// A test fixture for testing the logic of the GTEST_DEATH_TEST macro.
// A test fixture for testing the logic of the GTEST_DEATH_TEST_ macro.
// It installs a MockDeathTestFactory that is used for the duration
// of the test case.
class MacroLogicDeathTest : public testing::Test {
......
......@@ -286,9 +286,12 @@ TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
}
#endif // GTEST_OS_WINDOWS
#ifndef _WIN32_WCE
// Windows CE _does_ consider an empty directory to exist.
TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
EXPECT_FALSE(FilePath("").DirectoryExists());
}
#endif // ! _WIN32_WCE
TEST(DirectoryTest, CurrentDirectoryExists) {
#ifdef GTEST_OS_WINDOWS // We are on Windows.
......
// Copyright 2008 Google Inc. All Rights Reserved.
// Author: mheule@google.com (Markus Heule)
#include <gtest/gtest-test-part.h>
#include <gtest/gtest.h>
using testing::Test;
using testing::TestPartResult;
using testing::TestPartResultArray;
using testing::TPRT_FATAL_FAILURE;
using testing::TPRT_NONFATAL_FAILURE;
using testing::TPRT_SUCCESS;
namespace {
// Tests the TestPartResult class.
// The test fixture for testing TestPartResult.
class TestPartResultTest : public Test {
protected:
TestPartResultTest()
: r1_(TPRT_SUCCESS, "foo/bar.cc", 10, "Success!"),
r2_(TPRT_NONFATAL_FAILURE, "foo/bar.cc", -1, "Failure!"),
r3_(TPRT_FATAL_FAILURE, NULL, -1, "Failure!") {}
TestPartResult r1_, r2_, r3_;
};
// Tests TestPartResult::type().
TEST_F(TestPartResultTest, type) {
EXPECT_EQ(TPRT_SUCCESS, r1_.type());
EXPECT_EQ(TPRT_NONFATAL_FAILURE, r2_.type());
EXPECT_EQ(TPRT_FATAL_FAILURE, r3_.type());
}
// Tests TestPartResult::file_name().
TEST_F(TestPartResultTest, file_name) {
EXPECT_STREQ("foo/bar.cc", r1_.file_name());
EXPECT_STREQ(NULL, r3_.file_name());
}
// Tests TestPartResult::line_number().
TEST_F(TestPartResultTest, line_number) {
EXPECT_EQ(10, r1_.line_number());
EXPECT_EQ(-1, r2_.line_number());
}
// Tests TestPartResult::message().
TEST_F(TestPartResultTest, message) {
EXPECT_STREQ("Success!", r1_.message());
}
// Tests TestPartResult::passed().
TEST_F(TestPartResultTest, Passed) {
EXPECT_TRUE(r1_.passed());
EXPECT_FALSE(r2_.passed());
EXPECT_FALSE(r3_.passed());
}
// Tests TestPartResult::failed().
TEST_F(TestPartResultTest, Failed) {
EXPECT_FALSE(r1_.failed());
EXPECT_TRUE(r2_.failed());
EXPECT_TRUE(r3_.failed());
}
// Tests TestPartResult::fatally_failed().
TEST_F(TestPartResultTest, FatallyFailed) {
EXPECT_FALSE(r1_.fatally_failed());
EXPECT_FALSE(r2_.fatally_failed());
EXPECT_TRUE(r3_.fatally_failed());
}
// Tests TestPartResult::nonfatally_failed().
TEST_F(TestPartResultTest, NonfatallyFailed) {
EXPECT_FALSE(r1_.nonfatally_failed());
EXPECT_TRUE(r2_.nonfatally_failed());
EXPECT_FALSE(r3_.nonfatally_failed());
}
// Tests the TestPartResultArray class.
class TestPartResultArrayTest : public Test {
protected:
TestPartResultArrayTest()
: r1_(TPRT_NONFATAL_FAILURE, "foo/bar.cc", -1, "Failure 1"),
r2_(TPRT_FATAL_FAILURE, "foo/bar.cc", -1, "Failure 2") {}
const TestPartResult r1_, r2_;
};
// Tests that TestPartResultArray initially has size 0.
TEST_F(TestPartResultArrayTest, InitialSizeIsZero) {
TestPartResultArray results;
EXPECT_EQ(0, results.size());
}
// Tests that TestPartResultArray contains the given TestPartResult
// after one Append() operation.
TEST_F(TestPartResultArrayTest, ContainsGivenResultAfterAppend) {
TestPartResultArray results;
results.Append(r1_);
EXPECT_EQ(1, results.size());
EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
}
// Tests that TestPartResultArray contains the given TestPartResults
// after two Append() operations.
TEST_F(TestPartResultArrayTest, ContainsGivenResultsAfterTwoAppends) {
TestPartResultArray results;
results.Append(r1_);
results.Append(r2_);
EXPECT_EQ(2, results.size());
EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
EXPECT_STREQ("Failure 2", results.GetTestPartResult(1).message());
}
#ifdef GTEST_HAS_DEATH_TEST
typedef TestPartResultArrayTest TestPartResultArrayDeathTest;
// Tests that the program dies when GetTestPartResult() is called with
// an invalid index.
TEST_F(TestPartResultArrayDeathTest, DiesWhenIndexIsOutOfBound) {
TestPartResultArray results;
results.Append(r1_);
EXPECT_DEATH(results.GetTestPartResult(-1), "");
EXPECT_DEATH(results.GetTestPartResult(1), "");
}
#endif // GTEST_HAS_DEATH_TEST
// TODO(mheule@google.com): Add a test for the class HasNewFatalFailureHelper.
} // namespace
......@@ -36,7 +36,7 @@
#include <gtest/gtest.h>
namespace testing {
GTEST_DECLARE_string(filter);
GTEST_DECLARE_string_(filter);
}
namespace {
......
......@@ -46,14 +46,20 @@
#include <stdlib.h>
#if GTEST_HAS_PTHREAD
#include <pthread.h>
#endif // GTEST_HAS_PTHREAD
#ifdef GTEST_OS_LINUX
#include <string.h>
#include <signal.h>
#include <pthread.h>
#include <string>
#include <vector>
#endif // GTEST_OS_LINUX
using testing::ScopedFakeTestPartResultReporter;
using testing::TestPartResultArray;
// Tests catching fatal failures.
// A subroutine used by the following test.
......@@ -790,6 +796,134 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, ATypeParamDeathTest, NumericTypes);
#endif // GTEST_HAS_DEATH_TEST
// Tests various failure conditions of
// EXPECT_{,NON}FATAL_FAILURE{,_ON_ALL_THREADS}.
class ExpectFailureTest : public testing::Test {
protected:
enum FailureMode {
FATAL_FAILURE,
NONFATAL_FAILURE
};
static void AddFailure(FailureMode failure) {
if (failure == FATAL_FAILURE) {
FAIL() << "Expected fatal failure.";
} else {
ADD_FAILURE() << "Expected non-fatal failure.";
}
}
};
TEST_F(ExpectFailureTest, ExpectFatalFailure) {
// Expected fatal failure, but succeeds.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE(SUCCEED(), "Expected fatal failure.");
// Expected fatal failure, but got a non-fatal failure.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE(AddFailure(NONFATAL_FAILURE), "Expected non-fatal "
"failure.");
// Wrong message.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE(AddFailure(FATAL_FAILURE), "Some other fatal failure "
"expected.");
}
TEST_F(ExpectFailureTest, ExpectNonFatalFailure) {
// Expected non-fatal failure, but succeeds.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE(SUCCEED(), "Expected non-fatal failure.");
// Expected non-fatal failure, but got a fatal failure.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE(AddFailure(FATAL_FAILURE), "Expected fatal failure.");
// Wrong message.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE(AddFailure(NONFATAL_FAILURE), "Some other non-fatal "
"failure.");
}
#if GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD
class ExpectFailureWithThreadsTest : public ExpectFailureTest {
protected:
static void AddFailureInOtherThread(FailureMode failure) {
pthread_t tid;
pthread_create(&tid,
NULL,
ExpectFailureWithThreadsTest::FailureThread,
&failure);
pthread_join(tid, NULL);
}
private:
static void* FailureThread(void* attr) {
FailureMode* failure = static_cast<FailureMode*>(attr);
AddFailure(*failure);
return NULL;
}
};
TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailure) {
// We only intercept the current thread.
printf("(expecting 2 failures)\n");
EXPECT_FATAL_FAILURE(AddFailureInOtherThread(FATAL_FAILURE),
"Expected fatal failure.");
}
TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailure) {
// We only intercept the current thread.
printf("(expecting 2 failures)\n");
EXPECT_NONFATAL_FAILURE(AddFailureInOtherThread(NONFATAL_FAILURE),
"Expected non-fatal failure.");
}
typedef ExpectFailureWithThreadsTest ScopedFakeTestPartResultReporterTest;
// Tests that the ScopedFakeTestPartResultReporter only catches failures from
// the current thread if it is instantiated with INTERCEPT_ONLY_CURRENT_THREAD.
TEST_F(ScopedFakeTestPartResultReporterTest, InterceptOnlyCurrentThread) {
printf("(expecting 2 failures)\n");
TestPartResultArray results;
{
ScopedFakeTestPartResultReporter reporter(
ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
&results);
AddFailureInOtherThread(FATAL_FAILURE);
AddFailureInOtherThread(NONFATAL_FAILURE);
}
// The two failures should not have been intercepted.
EXPECT_EQ(0, results.size()) << "This shouldn't fail.";
}
#endif // GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD
TEST_F(ExpectFailureTest, ExpectFatalFailureOnAllThreads) {
// Expected fatal failure, but succeeds.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE_ON_ALL_THREADS(SUCCEED(), "Expected fatal failure.");
// Expected fatal failure, but got a non-fatal failure.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailure(NONFATAL_FAILURE),
"Expected non-fatal failure.");
// Wrong message.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailure(FATAL_FAILURE),
"Some other fatal failure expected.");
}
TEST_F(ExpectFailureTest, ExpectNonFatalFailureOnAllThreads) {
// Expected non-fatal failure, but succeeds.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(SUCCEED(), "Expected non-fatal "
"failure.");
// Expected non-fatal failure, but got a fatal failure.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(AddFailure(FATAL_FAILURE),
"Expected fatal failure.");
// Wrong message.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(AddFailure(NONFATAL_FAILURE),
"Some other non-fatal failure.");
}
// Two test environments for testing testing::AddGlobalTestEnvironment().
class FooEnvironment : public testing::Environment {
......
......@@ -7,7 +7,7 @@ Expected: true
gtest_output_test_.cc:#: Failure
Value of: 3
Expected: 2
[==========] Running 48 tests from 21 test cases.
[==========] Running 52 tests from 22 test cases.
[----------] Global test environment set-up.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
......@@ -386,6 +386,107 @@ Value of: TypeParam()
Expected: 1
Expected failure
[ FAILED ] Unsigned/TypedTestP/1.Failure
[----------] 4 tests from ExpectFailureTest
[ RUN ] ExpectFailureTest.ExpectFatalFailure
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure containing "Some other fatal failure expected."
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
[ FAILED ] ExpectFailureTest.ExpectFatalFailure
[ RUN ] ExpectFailureTest.ExpectNonFatalFailure
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure containing "Some other non-fatal failure."
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailure
[ RUN ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure containing "Some other fatal failure expected."
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
[ FAILED ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
[ RUN ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure containing "Some other non-fatal failure."
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
[----------] Global test environment tear-down
BarEnvironment::TearDown() called.
gtest_output_test_.cc:#: Failure
......@@ -395,9 +496,9 @@ FooEnvironment::TearDown() called.
gtest_output_test_.cc:#: Failure
Failed
Expected fatal failure.
[==========] 48 tests from 21 test cases ran.
[==========] 52 tests from 22 test cases ran.
[ PASSED ] 19 tests.
[ FAILED ] 29 tests, listed below:
[ FAILED ] 33 tests, listed below:
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
[ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine
[ FAILED ] FatalFailureTest.NonfatalFailureInSubroutine
......@@ -427,8 +528,12 @@ Expected fatal failure.
[ FAILED ] TypedTest/0.Failure, where TypeParam = int
[ FAILED ] Unsigned/TypedTestP/0.Failure, where TypeParam = unsigned char
[ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int
[ FAILED ] ExpectFailureTest.ExpectFatalFailure
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailure
[ FAILED ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
29 FAILED TESTS
33 FAILED TESTS
The non-test part of the code is expected to have 2 failures.
gtest_output_test_.cc:#: Failure
......
......@@ -5,7 +5,7 @@ gtest_output_test_.cc:#: error: Value of: false
Expected: true
gtest_output_test_.cc:#: error: Value of: 3
Expected: 2
[==========] Running 46 tests from 19 test cases.
[==========] Running 50 tests from 20 test cases.
[----------] Global test environment set-up.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
......@@ -344,6 +344,95 @@ gtest_output_test_.cc:#: error: Value of: TypeParam()
Expected: 1
Expected failure
[ FAILED ] Unsigned/TypedTestP/1.Failure
[----------] 4 tests from ExpectFailureTest
[ RUN ] ExpectFailureTest.ExpectFatalFailure
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure containing "Some other fatal failure expected."
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
[ FAILED ] ExpectFailureTest.ExpectFatalFailure
[ RUN ] ExpectFailureTest.ExpectNonFatalFailure
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure containing "Some other non-fatal failure."
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailure
[ RUN ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure containing "Some other fatal failure expected."
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
[ FAILED ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
[ RUN ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure containing "Some other non-fatal failure."
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
[----------] Global test environment tear-down
BarEnvironment::TearDown() called.
gtest_output_test_.cc:#: error: Failed
......@@ -351,9 +440,9 @@ Expected non-fatal failure.
FooEnvironment::TearDown() called.
gtest_output_test_.cc:#: error: Failed
Expected fatal failure.
[==========] 46 tests from 19 test cases ran.
[==========] 50 tests from 20 test cases ran.
[ PASSED ] 14 tests.
[ FAILED ] 32 tests, listed below:
[ FAILED ] 36 tests, listed below:
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
[ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine
[ FAILED ] FatalFailureTest.NonfatalFailureInSubroutine
......@@ -386,8 +475,12 @@ Expected fatal failure.
[ FAILED ] TypedTest/0.Failure, where TypeParam = int
[ FAILED ] Unsigned/TypedTestP/0.Failure, where TypeParam = unsigned char
[ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int
[ FAILED ] ExpectFailureTest.ExpectFatalFailure
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailure
[ FAILED ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
32 FAILED TESTS
36 FAILED TESTS
The non-test part of the code is expected to have 2 failures.
gtest_output_test_.cc:#: error: Value of: false
......
......@@ -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 06/11/2008 by command
// This file is AUTOMATICALLY GENERATED on 10/02/2008 by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
// Regression test for gtest_pred_impl.h
......
......@@ -46,9 +46,9 @@
namespace testing {
GTEST_DECLARE_string(death_test_style);
GTEST_DECLARE_string(filter);
GTEST_DECLARE_int32(repeat);
GTEST_DECLARE_string_(death_test_style);
GTEST_DECLARE_string_(filter);
GTEST_DECLARE_int32_(repeat);
} // namespace testing
......
// Copyright 2008, 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: mheule@google.com (Markus Heule)
//
// This test verifies that it's possible to use Google Test by including
// the gtest.h header file alone.
#include <gtest/gtest.h>
namespace {
void Subroutine() {
EXPECT_EQ(42, 42);
}
TEST(NoFatalFailureTest, ExpectNoFatalFailure) {
EXPECT_NO_FATAL_FAILURE(;);
EXPECT_NO_FATAL_FAILURE(SUCCEED());
EXPECT_NO_FATAL_FAILURE(Subroutine());
EXPECT_NO_FATAL_FAILURE({ SUCCEED(); });
}
TEST(NoFatalFailureTest, AssertNoFatalFailure) {
ASSERT_NO_FATAL_FAILURE(;);
ASSERT_NO_FATAL_FAILURE(SUCCEED());
ASSERT_NO_FATAL_FAILURE(Subroutine());
ASSERT_NO_FATAL_FAILURE({ SUCCEED(); });
}
} // namespace
......@@ -112,6 +112,36 @@ TEST(StressTest, CanUseScopedTraceAndAssertionsInManyThreads) {
// ManyAsserts() in many threads here.
}
TEST(NoFatalFailureTest, ExpectNoFatalFailureIgnoresFailuresInOtherThreads) {
// TODO(mheule@google.com): Test this works correctly when Google
// Test is made thread-safe.
}
TEST(NoFatalFailureTest, AssertNoFatalFailureIgnoresFailuresInOtherThreads) {
// TODO(mheule@google.com): Test this works correctly when Google
// Test is made thread-safe.
}
TEST(FatalFailureTest, ExpectFatalFailureIgnoresFailuresInOtherThreads) {
// TODO(mheule@google.com): Test this works correctly when Google
// Test is made thread-safe.
}
TEST(FatalFailureOnAllThreadsTest, ExpectFatalFailureOnAllThreads) {
// TODO(wan@google.com): Test this works correctly when Google Test
// is made thread-safe.
}
TEST(NonFatalFailureTest, ExpectNonFatalFailureIgnoresFailuresInOtherThreads) {
// TODO(mheule@google.com): Test this works correctly when Google
// Test is made thread-safe.
}
TEST(NonFatalFailureOnAllThreadsTest, ExpectNonFatalFailureOnAllThreads) {
// TODO(wan@google.com): Test this works correctly when Google Test
// is made thread-safe.
}
} // namespace
} // namespace testing
......
......@@ -24,7 +24,9 @@ test_executables=("$BUILT_PRODUCTS_DIR/sample1_unittest"
"$BUILT_PRODUCTS_DIR/gtest_main_unittest"
"$BUILT_PRODUCTS_DIR/gtest_prod_test"
"$BUILT_PRODUCTS_DIR/gtest_repeat_test"
"$BUILT_PRODUCTS_DIR/gtest_sole_header_test"
"$BUILT_PRODUCTS_DIR/gtest_stress_test"
"$BUILT_PRODUCTS_DIR/gtest_test_part_test"
"$BUILT_PRODUCTS_DIR/gtest-typed-test_test"
"$BUILT_PRODUCTS_DIR/gtest_output_test.py"
......@@ -41,6 +43,7 @@ test_executables=("$BUILT_PRODUCTS_DIR/sample1_unittest"
# Now execute each one in turn keeping track of how many succeeded and failed.
succeeded=0
failed=0
failed_list=()
for test in ${test_executables[*]}; do
"$test"
result=$?
......@@ -48,9 +51,14 @@ for test in ${test_executables[*]}; do
succeeded=$(( $succeeded + 1 ))
else
failed=$(( failed + 1 ))
failed_list="$failed_list $test"
fi
done
# Report the successes and failures to the console
echo "Tests complete with $succeeded successes and $failed failures."
if [ $failed -ne 0 ]; then
echo "The following tests failed:"
echo $failed_list
fi
exit $failed
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment