Merge branch 'master' into josh/fix_scoped_class2
This commit is contained in:
commit
a6e7ba27c7
|
@ -19,6 +19,11 @@ Follow either of the two links above to access the appropriate CLA and
|
|||
instructions for how to sign and return it. Once we receive it, we'll be able to
|
||||
accept your pull requests.
|
||||
|
||||
## Are you a Googler?
|
||||
If you are a Googler, please create an internal change and
|
||||
have it reviewed and submitted. The maintainers will normally be in position to upstream the changes.
|
||||
|
||||
|
||||
## Contributing A Patch
|
||||
|
||||
1. Submit an issue describing your proposed change to the
|
||||
|
@ -39,10 +44,6 @@ accept your pull requests.
|
|||
1. Ensure that your code has an appropriate set of unit tests which all pass.
|
||||
1. Submit a pull request.
|
||||
|
||||
If you are a Googler, it is preferable to first create an internal change and
|
||||
have it reviewed and submitted, and then create an upstreaming pull
|
||||
request here.
|
||||
|
||||
## The Google Test and Google Mock Communities ##
|
||||
|
||||
The Google Test community exists primarily through the
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
# ctest. You can select which tests to run using 'ctest -R regex'.
|
||||
# For more options, run 'ctest --help'.
|
||||
|
||||
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
|
||||
# make it prominent in the GUI.
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
|
||||
|
||||
option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
|
||||
|
||||
# A directory to find Google Test sources.
|
||||
|
@ -55,6 +51,20 @@ endif()
|
|||
# if they are the same (the default).
|
||||
add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest")
|
||||
|
||||
|
||||
# These commands only run if this is the main project
|
||||
if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
|
||||
|
||||
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
|
||||
# make it prominent in the GUI.
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
|
||||
|
||||
else()
|
||||
|
||||
mark_as_advanced(gmock_build_tests)
|
||||
|
||||
endif()
|
||||
|
||||
# Although Google Test's CMakeLists.txt calls this function, the
|
||||
# changes there don't affect the current scope. Therefore we have to
|
||||
# call it again here.
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// To implement a cardinality Foo, define:
|
||||
|
@ -145,4 +148,6 @@ inline Cardinality MakeCardinality(const CardinalityInterface* c) {
|
|||
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
|
||||
|
|
|
@ -56,6 +56,9 @@
|
|||
# include <initializer_list> // NOLINT -- must be after gtest.h
|
||||
#endif
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// To implement a matcher Foo for type T, define:
|
||||
|
@ -5266,6 +5269,8 @@ PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T> > VariantWith(
|
|||
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// Include any custom callback matchers added by the local installation.
|
||||
// We must include this header at the end to make sure it can use the
|
||||
// declarations from this file.
|
||||
|
|
|
@ -77,6 +77,9 @@
|
|||
# include <stdexcept> // NOLINT
|
||||
#endif
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// An abstract handle of an expectation.
|
||||
|
@ -1357,11 +1360,7 @@ class ReferenceOrValueWrapper<T&> {
|
|||
// we need to temporarily disable the warning. We have to do it for
|
||||
// the entire class to suppress the warning, even though it's about
|
||||
// the constructor only.
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push) // Saves the current warning state.
|
||||
# pragma warning(disable:4355) // Temporarily disables warning 4355.
|
||||
#endif // _MSV_VER
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355)
|
||||
|
||||
// C++ treats the void type specially. For example, you cannot define
|
||||
// a void-typed variable or pass a void value to a function.
|
||||
|
@ -1797,9 +1796,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase);
|
||||
}; // class FunctionMockerBase
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop) // Restores the warning state.
|
||||
#endif // _MSV_VER
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4355
|
||||
|
||||
// Implements methods of FunctionMockerBase.
|
||||
|
||||
|
@ -1844,6 +1841,8 @@ inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT
|
|||
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// Implementation for ON_CALL and EXPECT_CALL macros. A separate macro is
|
||||
// required to avoid compile errors when the name of the method used in call is
|
||||
// a result of macro expansion. See CompilesWithMethodNameExpandedFromMacro
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
# ctest. You can select which tests to run using 'ctest -R regex'.
|
||||
# For more options, run 'ctest --help'.
|
||||
|
||||
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
|
||||
# make it prominent in the GUI.
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
|
||||
|
||||
# When other libraries are using a shared version of runtime libraries,
|
||||
# Google Test also has to use one.
|
||||
option(
|
||||
|
@ -60,6 +56,25 @@ if (COMMAND set_up_hermetic_build)
|
|||
set_up_hermetic_build()
|
||||
endif()
|
||||
|
||||
# These commands only run if this is the main project
|
||||
if(CMAKE_PROJECT_NAME STREQUAL "gtest" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
|
||||
|
||||
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
|
||||
# make it prominent in the GUI.
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
|
||||
|
||||
else()
|
||||
|
||||
mark_as_advanced(
|
||||
gtest_force_shared_crt
|
||||
gtest_build_tests
|
||||
gtest_build_samples
|
||||
gtest_disable_pthreads
|
||||
gtest_hide_internal_symbols)
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
if (gtest_hide_internal_symbols)
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
|
||||
|
|
|
@ -38,6 +38,11 @@ macro(fix_default_compiler_settings_)
|
|||
# We prefer more strict warning checking for building Google Test.
|
||||
# Replaces /W3 with /W4 in defaults.
|
||||
string(REPLACE "/W3" "/W4" ${flag_var} "${${flag_var}}")
|
||||
|
||||
# Prevent D9025 warning for targets that have exception handling
|
||||
# turned off (/EHs-c- flag). Where required, exceptions are explicitly
|
||||
# re-enabled using the cxx_exception_flags variable.
|
||||
string(REPLACE "/EHsc" "" ${flag_var} "${${flag_var}}")
|
||||
endforeach()
|
||||
endif()
|
||||
endmacro()
|
||||
|
|
|
@ -572,7 +572,7 @@ namespace foo {
|
|||
class Bar { // We want googletest to be able to print instances of this.
|
||||
...
|
||||
// Create a free inline friend function.
|
||||
friend ::std::ostream& operator<<(::std::ostream& os, const Bar& bar) {
|
||||
friend std::ostream& operator<<(std::ostream& os, const Bar& bar) {
|
||||
return os << bar.DebugString(); // whatever needed to print bar to os
|
||||
}
|
||||
};
|
||||
|
@ -580,7 +580,7 @@ class Bar { // We want googletest to be able to print instances of this.
|
|||
// If you can't declare the function in the class it's important that the
|
||||
// << operator is defined in the SAME namespace that defines Bar. C++'s look-up
|
||||
// rules rely on that.
|
||||
::std::ostream& operator<<(::std::ostream& os, const Bar& bar) {
|
||||
std::ostream& operator<<(std::ostream& os, const Bar& bar) {
|
||||
return os << bar.DebugString(); // whatever needed to print bar to os
|
||||
}
|
||||
|
||||
|
@ -601,7 +601,7 @@ namespace foo {
|
|||
|
||||
class Bar {
|
||||
...
|
||||
friend void PrintTo(const Bar& bar, ::std::ostream* os) {
|
||||
friend void PrintTo(const Bar& bar, std::ostream* os) {
|
||||
*os << bar.DebugString(); // whatever needed to print bar to os
|
||||
}
|
||||
};
|
||||
|
@ -609,7 +609,7 @@ class Bar {
|
|||
// If you can't declare the function in the class it's important that PrintTo()
|
||||
// is defined in the SAME namespace that defines Bar. C++'s look-up rules rely
|
||||
// on that.
|
||||
void PrintTo(const Bar& bar, ::std::ostream* os) {
|
||||
void PrintTo(const Bar& bar, std::ostream* os) {
|
||||
*os << bar.DebugString(); // whatever needed to print bar to os
|
||||
}
|
||||
|
||||
|
@ -649,7 +649,7 @@ _death tests_. More generally, any test that checks that a program terminates
|
|||
Note that if a piece of code throws an exception, we don't consider it "death"
|
||||
for the purpose of death tests, as the caller of the code could catch the
|
||||
exception and avoid the crash. If you want to verify exceptions thrown by your
|
||||
code, see [Exception Assertions](#ExceptionAssertions).
|
||||
code, see [Exception Assertions](#exception-assertions).
|
||||
|
||||
If you want to test `EXPECT_*()/ASSERT_*()` failures in your test code, see
|
||||
Catching Failures
|
||||
|
@ -1147,7 +1147,7 @@ test has at least one failure of either kind.
|
|||
|
||||
In your test code, you can call `RecordProperty("key", value)` to log additional
|
||||
information, where `value` can be either a string or an `int`. The *last* value
|
||||
recorded for a key will be emitted to the [XML output](#XmlReport) if you
|
||||
recorded for a key will be emitted to the [XML output](#generating-an-xml-report) if you
|
||||
specify one. For example, the test
|
||||
|
||||
```c++
|
||||
|
@ -1424,7 +1424,7 @@ will have these names:
|
|||
* `InstantiationName/FooTest.HasBlahBlah/1` for `"miny"`
|
||||
* `InstantiationName/FooTest.HasBlahBlah/2` for `"moe"`
|
||||
|
||||
You can use these names in [`--gtest_filter`](#TestFilter).
|
||||
You can use these names in [`--gtest_filter`](#running-a-subset-of-the-tests).
|
||||
|
||||
This statement will instantiate all tests from `FooTest` again, each with
|
||||
parameter values `"cat"` and `"dog"`:
|
||||
|
@ -1674,7 +1674,7 @@ To test them, we use the following special techniques:
|
|||
* Both static functions and definitions/declarations in an unnamed namespace
|
||||
are only visible within the same translation unit. To test them, you can
|
||||
`#include` the entire `.cc` file being tested in your `*_test.cc` file.
|
||||
(#including `.cc` files is not a good way to reuse code - you should not do
|
||||
(including `.cc` files is not a good way to reuse code - you should not do
|
||||
this in production code!)
|
||||
|
||||
However, a better approach is to move the private code into the
|
||||
|
@ -2120,7 +2120,7 @@ $ foo_test --gtest_repeat=1000 --gtest_filter=FooBar.*
|
|||
Repeat the tests whose name matches the filter 1000 times.
|
||||
```
|
||||
|
||||
If your test program contains [global set-up/tear-down](#GlobalSetUp) code, it
|
||||
If your test program contains [global set-up/tear-down](#global-set-up-and-tear-down) code, it
|
||||
will be repeated in each iteration as well, as the flakiness may be in it. You
|
||||
can also specify the repeat count by setting the `GTEST_REPEAT` environment
|
||||
variable.
|
||||
|
|
|
@ -51,6 +51,9 @@
|
|||
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// Ensures that there is at least one operator<< in the global namespace.
|
||||
// See Message& operator<<(...) below for why.
|
||||
void operator<<(const testing::internal::Secret&, int);
|
||||
|
@ -247,4 +250,6 @@ std::string StreamableToString(const T& streamable) {
|
|||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
|
||||
|
|
|
@ -978,12 +978,13 @@ struct TuplePolicy {
|
|||
static const size_t tuple_size = ::std::tr1::tuple_size<Tuple>::value;
|
||||
|
||||
template <size_t I>
|
||||
struct tuple_element : ::std::tr1::tuple_element<I, Tuple> {};
|
||||
struct tuple_element : ::std::tr1::tuple_element<static_cast<int>(I), Tuple> {
|
||||
};
|
||||
|
||||
template <size_t I>
|
||||
static typename AddReference<
|
||||
const typename ::std::tr1::tuple_element<I, Tuple>::type>::type get(
|
||||
const Tuple& tuple) {
|
||||
static typename AddReference<const typename ::std::tr1::tuple_element<
|
||||
static_cast<int>(I), Tuple>::type>::type
|
||||
get(const Tuple& tuple) {
|
||||
return ::std::tr1::get<I>(tuple);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -38,6 +38,9 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// This helper class can be used to mock out Google Test failure reporting
|
||||
|
@ -112,6 +115,8 @@ class GTEST_API_ SingleFailureChecker {
|
|||
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// A set of macros for testing Google Test assertions or code that's expected
|
||||
// to generate Google Test fatal failures. It verifies that the given
|
||||
// statement will cause exactly one fatal Google Test failure with 'substr'
|
||||
|
|
|
@ -37,6 +37,9 @@
|
|||
#include "gtest/internal/gtest-internal.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// A copyable object representing the result of a test part (i.e. an
|
||||
|
@ -142,7 +145,7 @@ class GTEST_API_ TestPartResultArray {
|
|||
};
|
||||
|
||||
// This interface knows how to report a test part result.
|
||||
class TestPartResultReporterInterface {
|
||||
class GTEST_API_ TestPartResultReporterInterface {
|
||||
public:
|
||||
virtual ~TestPartResultReporterInterface() {}
|
||||
|
||||
|
@ -175,4 +178,6 @@ class GTEST_API_ HasNewFatalFailureHelper
|
|||
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
|
||||
|
|
|
@ -66,6 +66,9 @@
|
|||
#include "gtest/gtest-test-part.h"
|
||||
#include "gtest/gtest-typed-test.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// Depending on the platform, different string classes are available.
|
||||
// On Linux, in addition to ::std::string, Google also makes use of
|
||||
// class ::string, which has the same interface as ::std::string, but
|
||||
|
@ -2330,4 +2333,6 @@ inline int RUN_ALL_TESTS() {
|
|||
return ::testing::UnitTest::GetInstance()->Run();
|
||||
}
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_GTEST_H_
|
||||
|
|
|
@ -52,6 +52,9 @@ const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
|
|||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// DeathTest is a class that hides much of the complexity of the
|
||||
// GTEST_DEATH_TEST_ macro. It is abstract; its static Create method
|
||||
// returns a concrete class that depends on the prevailing death test
|
||||
|
@ -135,6 +138,8 @@ class GTEST_API_ DeathTest {
|
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
|
||||
};
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// Factory interface for death tests. May be mocked out for testing.
|
||||
class DeathTestFactory {
|
||||
public:
|
||||
|
|
|
@ -42,6 +42,9 @@
|
|||
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
|
@ -203,4 +206,6 @@ class GTEST_API_ FilePath {
|
|||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
|
||||
|
|
|
@ -141,6 +141,9 @@ GTEST_API_ std::string AppendUserMessage(
|
|||
|
||||
#if GTEST_HAS_EXCEPTIONS
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4275 \
|
||||
/* an exported class was derived from a class that was not exported */)
|
||||
|
||||
// This exception is thrown by (and only by) a failed Google Test
|
||||
// assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions
|
||||
// are enabled). We derive it from std::runtime_error, which is for
|
||||
|
@ -152,6 +155,8 @@ class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error {
|
|||
explicit GoogleTestFailureException(const TestPartResult& failure);
|
||||
};
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4275
|
||||
|
||||
#endif // GTEST_HAS_EXCEPTIONS
|
||||
|
||||
namespace edit_distance {
|
||||
|
@ -528,6 +533,9 @@ GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
|
|||
|
||||
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
// State of the definition of a type-parameterized test case.
|
||||
class GTEST_API_ TypedTestCasePState {
|
||||
public:
|
||||
|
@ -573,6 +581,8 @@ class GTEST_API_ TypedTestCasePState {
|
|||
RegisteredTestsMap registered_tests_;
|
||||
};
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
// Skips to the first non-space char after the first comma in 'str';
|
||||
// returns NULL if no comma is found in 'str'.
|
||||
inline const char* SkipComma(const char* str) {
|
||||
|
|
|
@ -2107,8 +2107,8 @@ class MutexBase {
|
|||
// particular, the owner_ field (a pthread_t) is not explicitly initialized.
|
||||
// This allows initialization to work whether pthread_t is a scalar or struct.
|
||||
// The flag -Wmissing-field-initializers must not be specified for this to work.
|
||||
# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
|
||||
::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }
|
||||
#define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
|
||||
::testing::internal::MutexBase mutex = {PTHREAD_MUTEX_INITIALIZER, false, 0}
|
||||
|
||||
// The Mutex class can only be used for mutexes created at runtime. It
|
||||
// shares its API with MutexBase otherwise.
|
||||
|
|
|
@ -38,6 +38,16 @@ int Counter::Increment() {
|
|||
return counter_++;
|
||||
}
|
||||
|
||||
// Returns the current counter value, and decrements it.
|
||||
// counter can not be less than 0, return 0 in this case
|
||||
int Counter::Decrement() {
|
||||
if (counter_ == 0) {
|
||||
return counter_;
|
||||
} else {
|
||||
return counter_--;
|
||||
}
|
||||
}
|
||||
|
||||
// Prints the current counter value to STDOUT.
|
||||
void Counter::Print() const {
|
||||
printf("%d", counter_);
|
||||
|
|
|
@ -43,6 +43,9 @@ class Counter {
|
|||
// Returns the current counter value, and increments it.
|
||||
int Increment();
|
||||
|
||||
// Returns the current counter value, and decrements it.
|
||||
int Decrement();
|
||||
|
||||
// Prints the current counter value to STDOUT.
|
||||
void Print() const;
|
||||
};
|
||||
|
|
|
@ -37,12 +37,17 @@ namespace {
|
|||
TEST(Counter, Increment) {
|
||||
Counter c;
|
||||
|
||||
// Test that counter 0 returns 0
|
||||
EXPECT_EQ(0, c.Decrement());
|
||||
|
||||
// EXPECT_EQ() evaluates its arguments exactly once, so they
|
||||
// can have side effects.
|
||||
|
||||
EXPECT_EQ(0, c.Increment());
|
||||
EXPECT_EQ(1, c.Increment());
|
||||
EXPECT_EQ(2, c.Increment());
|
||||
|
||||
EXPECT_EQ(3, c.Decrement());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -59,6 +59,9 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest-spi.h"
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||
|
||||
namespace testing {
|
||||
|
||||
// Declares the flags.
|
||||
|
@ -1179,4 +1182,6 @@ class StreamingListener : public EmptyTestEventListener {
|
|||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||
|
||||
#endif // GTEST_SRC_GTEST_INTERNAL_INL_H_
|
||||
|
|
|
@ -294,6 +294,43 @@ void Mutex::AssertHeld() {
|
|||
<< "The current thread is not holding the mutex @" << this;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Use the RAII idiom to flag mem allocs that are intentionally never
|
||||
// deallocated. The motivation is to silence the false positive mem leaks
|
||||
// that are reported by the debug version of MS's CRT which can only detect
|
||||
// if an alloc is missing a matching deallocation.
|
||||
// Example:
|
||||
// MemoryIsNotDeallocated memory_is_not_deallocated;
|
||||
// critical_section_ = new CRITICAL_SECTION;
|
||||
//
|
||||
class MemoryIsNotDeallocated
|
||||
{
|
||||
public:
|
||||
MemoryIsNotDeallocated() : old_crtdbg_flag_(0) {
|
||||
#ifdef _MSC_VER
|
||||
old_crtdbg_flag_ = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||||
// Set heap allocation block type to _IGNORE_BLOCK so that MS debug CRT
|
||||
// doesn't report mem leak if there's no matching deallocation.
|
||||
_CrtSetDbgFlag(old_crtdbg_flag_ & ~_CRTDBG_ALLOC_MEM_DF);
|
||||
#endif // _MSC_VER
|
||||
}
|
||||
|
||||
~MemoryIsNotDeallocated() {
|
||||
#ifdef _MSC_VER
|
||||
// Restore the original _CRTDBG_ALLOC_MEM_DF flag
|
||||
_CrtSetDbgFlag(old_crtdbg_flag_);
|
||||
#endif // _MSC_VER
|
||||
}
|
||||
|
||||
private:
|
||||
int old_crtdbg_flag_;
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MemoryIsNotDeallocated);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Initializes owner_thread_id_ and critical_section_ in static mutexes.
|
||||
void Mutex::ThreadSafeLazyInit() {
|
||||
// Dynamic mutexes are initialized in the constructor.
|
||||
|
@ -304,7 +341,11 @@ void Mutex::ThreadSafeLazyInit() {
|
|||
// If critical_section_init_phase_ was 0 before the exchange, we
|
||||
// are the first to test it and need to perform the initialization.
|
||||
owner_thread_id_ = 0;
|
||||
critical_section_ = new CRITICAL_SECTION;
|
||||
{
|
||||
// Use RAII to flag that following mem alloc is never deallocated.
|
||||
MemoryIsNotDeallocated memory_is_not_deallocated;
|
||||
critical_section_ = new CRITICAL_SECTION;
|
||||
}
|
||||
::InitializeCriticalSection(critical_section_);
|
||||
// Updates the critical_section_init_phase_ to 2 to signal
|
||||
// initialization complete.
|
||||
|
@ -546,7 +587,8 @@ class ThreadLocalRegistryImpl {
|
|||
// Returns map of thread local instances.
|
||||
static ThreadIdToThreadLocals* GetThreadLocalsMapLocked() {
|
||||
mutex_.AssertHeld();
|
||||
static ThreadIdToThreadLocals* map = new ThreadIdToThreadLocals;
|
||||
MemoryIsNotDeallocated memory_is_not_deallocated;
|
||||
static ThreadIdToThreadLocals* map = new ThreadIdToThreadLocals();
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,6 +138,12 @@
|
|||
# define vsnprintf _vsnprintf
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
#if GTEST_OS_MAC
|
||||
#ifndef GTEST_OS_IOS
|
||||
#include <crt_externs.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
#include "absl/debugging/failure_signal_handler.h"
|
||||
#include "absl/debugging/stacktrace.h"
|
||||
|
@ -4692,7 +4698,7 @@ int UnitTest::Run() {
|
|||
// used for the duration of the program.
|
||||
impl()->set_catch_exceptions(GTEST_FLAG(catch_exceptions));
|
||||
|
||||
#if GTEST_HAS_SEH
|
||||
#if GTEST_OS_WINDOWS
|
||||
// Either the user wants Google Test to catch exceptions thrown by the
|
||||
// tests or this is executing in the context of death test child
|
||||
// process. In either case the user does not want to see pop-up dialogs
|
||||
|
@ -4729,7 +4735,7 @@ int UnitTest::Run() {
|
|||
_WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump.
|
||||
# endif
|
||||
}
|
||||
#endif // GTEST_HAS_SEH
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
return internal::HandleExceptionsInMethodIfSupported(
|
||||
impl(),
|
||||
|
@ -5825,6 +5831,17 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
|
|||
// other parts of Google Test.
|
||||
void ParseGoogleTestFlagsOnly(int* argc, char** argv) {
|
||||
ParseGoogleTestFlagsOnlyImpl(argc, argv);
|
||||
|
||||
// Fix the value of *_NSGetArgc() on macOS, but iff
|
||||
// *_NSGetArgv() == argv
|
||||
// Only applicable to char** version of argv
|
||||
#if GTEST_OS_MAC
|
||||
#ifndef GTEST_OS_IOS
|
||||
if (*_NSGetArgv() == argv) {
|
||||
*_NSGetArgc() = *argc;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv) {
|
||||
ParseGoogleTestFlagsOnlyImpl(argc, argv);
|
||||
|
|
Loading…
Reference in New Issue
Block a user