"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googletest/src/gtest-internal-inl.h" between
googletest-release-1.11.0.tar.gz and googletest-release-1.12.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

gtest-internal-inl.h  (googletest-release-1.11.0):gtest-internal-inl.h  (googletest-release-1.12.0)
skipping to change at line 38 skipping to change at line 38
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Utility functions and classes used by the Google C++ testing framework.// // Utility functions and classes used by the Google C++ testing framework.//
// This file contains purely Google Test's internal implementation. Please // This file contains purely Google Test's internal implementation. Please
// DO NOT #INCLUDE IT IN A USER PROGRAM. // DO NOT #INCLUDE IT IN A USER PROGRAM.
#ifndef GOOGLETEST_SRC_GTEST_INTERNAL_INL_H_ #ifndef GOOGLETEST_SRC_GTEST_INTERNAL_INL_H_
#define GOOGLETEST_SRC_GTEST_INTERNAL_INL_H_ #define GOOGLETEST_SRC_GTEST_INTERNAL_INL_H_
#ifndef _WIN32_WCE #ifndef _WIN32_WCE
# include <errno.h> #include <errno.h>
#endif // !_WIN32_WCE #endif // !_WIN32_WCE
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> // For strtoll/_strtoul64/malloc/free. #include <stdlib.h> // For strtoll/_strtoul64/malloc/free.
#include <string.h> // For memmove. #include <string.h> // For memmove.
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#if GTEST_CAN_STREAM_RESULTS_ #if GTEST_CAN_STREAM_RESULTS_
# include <arpa/inet.h> // NOLINT #include <arpa/inet.h> // NOLINT
# include <netdb.h> // NOLINT #include <netdb.h> // NOLINT
#endif #endif
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
# include <windows.h> // NOLINT #include <windows.h> // NOLINT
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h" #include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */) /* class A needs to have dll-interface to be used by clients of class B */)
namespace testing {
// Declares the flags. // Declares the flags.
// //
// We don't want the users to modify this flag in the code, but want // We don't want the users to modify this flag in the code, but want
// Google Test's own unit tests to be able to access it. Therefore we // Google Test's own unit tests to be able to access it. Therefore we
// declare it here as opposed to in gtest.h. // declare it here as opposed to in gtest.h.
GTEST_DECLARE_bool_(death_test_use_fork); GTEST_DECLARE_bool_(death_test_use_fork);
namespace testing {
namespace internal { namespace internal {
// The value of GetTestTypeId() as seen from within the Google Test // The value of GetTestTypeId() as seen from within the Google Test
// library. This is solely for testing GetTestTypeId(). // library. This is solely for testing GetTestTypeId().
GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest; GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
// Names of the flags (needed for parsing Google Test flags).
const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
const char kBreakOnFailureFlag[] = "break_on_failure";
const char kCatchExceptionsFlag[] = "catch_exceptions";
const char kColorFlag[] = "color";
const char kFailFast[] = "fail_fast";
const char kFilterFlag[] = "filter";
const char kListTestsFlag[] = "list_tests";
const char kOutputFlag[] = "output";
const char kBriefFlag[] = "brief";
const char kPrintTimeFlag[] = "print_time";
const char kPrintUTF8Flag[] = "print_utf8";
const char kRandomSeedFlag[] = "random_seed";
const char kRepeatFlag[] = "repeat";
const char kShuffleFlag[] = "shuffle";
const char kStackTraceDepthFlag[] = "stack_trace_depth";
const char kStreamResultToFlag[] = "stream_result_to";
const char kThrowOnFailureFlag[] = "throw_on_failure";
const char kFlagfileFlag[] = "flagfile";
// A valid random seed must be in [1, kMaxRandomSeed]. // A valid random seed must be in [1, kMaxRandomSeed].
const int kMaxRandomSeed = 99999; const int kMaxRandomSeed = 99999;
// g_help_flag is true if and only if the --help flag or an equivalent form // g_help_flag is true if and only if the --help flag or an equivalent form
// is specified on the command line. // is specified on the command line.
GTEST_API_ extern bool g_help_flag; GTEST_API_ extern bool g_help_flag;
// Returns the current time in milliseconds. // Returns the current time in milliseconds.
GTEST_API_ TimeInMillis GetTimeInMillis(); GTEST_API_ TimeInMillis GetTimeInMillis();
skipping to change at line 128 skipping to change at line 107
// Converts the given time in milliseconds to a date string in the ISO 8601 // Converts the given time in milliseconds to a date string in the ISO 8601
// format, without the timezone information. N.B.: due to the use the // format, without the timezone information. N.B.: due to the use the
// non-reentrant localtime() function, this function is not thread safe. Do // non-reentrant localtime() function, this function is not thread safe. Do
// not use it in any code that can be called from multiple threads. // not use it in any code that can be called from multiple threads.
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms); GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms);
// Parses a string for an Int32 flag, in the form of "--flag=value". // Parses a string for an Int32 flag, in the form of "--flag=value".
// //
// On success, stores the value of the flag in *value, and returns // On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value. // true. On failure, returns false without changing *value.
GTEST_API_ bool ParseInt32Flag( GTEST_API_ bool ParseFlag(const char* str, const char* flag, int32_t* value);
const char* str, const char* flag, int32_t* value);
// Returns a random seed in range [1, kMaxRandomSeed] based on the // Returns a random seed in range [1, kMaxRandomSeed] based on the
// given --gtest_random_seed flag value. // given --gtest_random_seed flag value.
inline int GetRandomSeedFromFlag(int32_t random_seed_flag) { inline int GetRandomSeedFromFlag(int32_t random_seed_flag) {
const unsigned int raw_seed = (random_seed_flag == 0) ? const unsigned int raw_seed =
static_cast<unsigned int>(GetTimeInMillis()) : (random_seed_flag == 0) ? static_cast<unsigned int>(GetTimeInMillis())
static_cast<unsigned int>(random_seed_flag); : static_cast<unsigned int>(random_seed_flag);
// Normalizes the actual seed to range [1, kMaxRandomSeed] such that // Normalizes the actual seed to range [1, kMaxRandomSeed] such that
// it's easy to type. // it's easy to type.
const int normalized_seed = const int normalized_seed =
static_cast<int>((raw_seed - 1U) % static_cast<int>((raw_seed - 1U) %
static_cast<unsigned int>(kMaxRandomSeed)) + 1; static_cast<unsigned int>(kMaxRandomSeed)) +
1;
return normalized_seed; return normalized_seed;
} }
// Returns the first valid random seed after 'seed'. The behavior is // Returns the first valid random seed after 'seed'. The behavior is
// undefined if 'seed' is invalid. The seed after kMaxRandomSeed is // undefined if 'seed' is invalid. The seed after kMaxRandomSeed is
// considered to be 1. // considered to be 1.
inline int GetNextRandomSeed(int seed) { inline int GetNextRandomSeed(int seed) {
GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed) GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
<< "Invalid random seed " << seed << " - must be in [1, " << "Invalid random seed " << seed << " - must be in [1, "
<< kMaxRandomSeed << "]."; << kMaxRandomSeed << "].";
const int next_seed = seed + 1; const int next_seed = seed + 1;
return (next_seed > kMaxRandomSeed) ? 1 : next_seed; return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
} }
// This class saves the values of all Google Test flags in its c'tor, and // This class saves the values of all Google Test flags in its c'tor, and
// restores them in its d'tor. // restores them in its d'tor.
class GTestFlagSaver { class GTestFlagSaver {
public: public:
// The c'tor. // The c'tor.
GTestFlagSaver() { GTestFlagSaver() {
also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests); also_run_disabled_tests_ = GTEST_FLAG_GET(also_run_disabled_tests);
break_on_failure_ = GTEST_FLAG(break_on_failure); break_on_failure_ = GTEST_FLAG_GET(break_on_failure);
catch_exceptions_ = GTEST_FLAG(catch_exceptions); catch_exceptions_ = GTEST_FLAG_GET(catch_exceptions);
color_ = GTEST_FLAG(color); color_ = GTEST_FLAG_GET(color);
death_test_style_ = GTEST_FLAG(death_test_style); death_test_style_ = GTEST_FLAG_GET(death_test_style);
death_test_use_fork_ = GTEST_FLAG(death_test_use_fork); death_test_use_fork_ = GTEST_FLAG_GET(death_test_use_fork);
fail_fast_ = GTEST_FLAG(fail_fast); fail_fast_ = GTEST_FLAG_GET(fail_fast);
filter_ = GTEST_FLAG(filter); filter_ = GTEST_FLAG_GET(filter);
internal_run_death_test_ = GTEST_FLAG(internal_run_death_test); internal_run_death_test_ = GTEST_FLAG_GET(internal_run_death_test);
list_tests_ = GTEST_FLAG(list_tests); list_tests_ = GTEST_FLAG_GET(list_tests);
output_ = GTEST_FLAG(output); output_ = GTEST_FLAG_GET(output);
brief_ = GTEST_FLAG(brief); brief_ = GTEST_FLAG_GET(brief);
print_time_ = GTEST_FLAG(print_time); print_time_ = GTEST_FLAG_GET(print_time);
print_utf8_ = GTEST_FLAG(print_utf8); print_utf8_ = GTEST_FLAG_GET(print_utf8);
random_seed_ = GTEST_FLAG(random_seed); random_seed_ = GTEST_FLAG_GET(random_seed);
repeat_ = GTEST_FLAG(repeat); repeat_ = GTEST_FLAG_GET(repeat);
shuffle_ = GTEST_FLAG(shuffle); recreate_environments_when_repeating_ =
stack_trace_depth_ = GTEST_FLAG(stack_trace_depth); GTEST_FLAG_GET(recreate_environments_when_repeating);
stream_result_to_ = GTEST_FLAG(stream_result_to); shuffle_ = GTEST_FLAG_GET(shuffle);
throw_on_failure_ = GTEST_FLAG(throw_on_failure); stack_trace_depth_ = GTEST_FLAG_GET(stack_trace_depth);
stream_result_to_ = GTEST_FLAG_GET(stream_result_to);
throw_on_failure_ = GTEST_FLAG_GET(throw_on_failure);
} }
// The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS. // The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
~GTestFlagSaver() { ~GTestFlagSaver() {
GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_; GTEST_FLAG_SET(also_run_disabled_tests, also_run_disabled_tests_);
GTEST_FLAG(break_on_failure) = break_on_failure_; GTEST_FLAG_SET(break_on_failure, break_on_failure_);
GTEST_FLAG(catch_exceptions) = catch_exceptions_; GTEST_FLAG_SET(catch_exceptions, catch_exceptions_);
GTEST_FLAG(color) = color_; GTEST_FLAG_SET(color, color_);
GTEST_FLAG(death_test_style) = death_test_style_; GTEST_FLAG_SET(death_test_style, death_test_style_);
GTEST_FLAG(death_test_use_fork) = death_test_use_fork_; GTEST_FLAG_SET(death_test_use_fork, death_test_use_fork_);
GTEST_FLAG(filter) = filter_; GTEST_FLAG_SET(filter, filter_);
GTEST_FLAG(fail_fast) = fail_fast_; GTEST_FLAG_SET(fail_fast, fail_fast_);
GTEST_FLAG(internal_run_death_test) = internal_run_death_test_; GTEST_FLAG_SET(internal_run_death_test, internal_run_death_test_);
GTEST_FLAG(list_tests) = list_tests_; GTEST_FLAG_SET(list_tests, list_tests_);
GTEST_FLAG(output) = output_; GTEST_FLAG_SET(output, output_);
GTEST_FLAG(brief) = brief_; GTEST_FLAG_SET(brief, brief_);
GTEST_FLAG(print_time) = print_time_; GTEST_FLAG_SET(print_time, print_time_);
GTEST_FLAG(print_utf8) = print_utf8_; GTEST_FLAG_SET(print_utf8, print_utf8_);
GTEST_FLAG(random_seed) = random_seed_; GTEST_FLAG_SET(random_seed, random_seed_);
GTEST_FLAG(repeat) = repeat_; GTEST_FLAG_SET(repeat, repeat_);
GTEST_FLAG(shuffle) = shuffle_; GTEST_FLAG_SET(recreate_environments_when_repeating,
GTEST_FLAG(stack_trace_depth) = stack_trace_depth_; recreate_environments_when_repeating_);
GTEST_FLAG(stream_result_to) = stream_result_to_; GTEST_FLAG_SET(shuffle, shuffle_);
GTEST_FLAG(throw_on_failure) = throw_on_failure_; GTEST_FLAG_SET(stack_trace_depth, stack_trace_depth_);
GTEST_FLAG_SET(stream_result_to, stream_result_to_);
GTEST_FLAG_SET(throw_on_failure, throw_on_failure_);
} }
private: private:
// Fields for saving the original values of flags. // Fields for saving the original values of flags.
bool also_run_disabled_tests_; bool also_run_disabled_tests_;
bool break_on_failure_; bool break_on_failure_;
bool catch_exceptions_; bool catch_exceptions_;
std::string color_; std::string color_;
std::string death_test_style_; std::string death_test_style_;
bool death_test_use_fork_; bool death_test_use_fork_;
bool fail_fast_; bool fail_fast_;
std::string filter_; std::string filter_;
std::string internal_run_death_test_; std::string internal_run_death_test_;
bool list_tests_; bool list_tests_;
std::string output_; std::string output_;
bool brief_; bool brief_;
bool print_time_; bool print_time_;
bool print_utf8_; bool print_utf8_;
int32_t random_seed_; int32_t random_seed_;
int32_t repeat_; int32_t repeat_;
bool recreate_environments_when_repeating_;
bool shuffle_; bool shuffle_;
int32_t stack_trace_depth_; int32_t stack_trace_depth_;
std::string stream_result_to_; std::string stream_result_to_;
bool throw_on_failure_; bool throw_on_failure_;
} GTEST_ATTRIBUTE_UNUSED_; } GTEST_ATTRIBUTE_UNUSED_;
// Converts a Unicode code point to a narrow string in UTF-8 encoding. // 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 // code_point parameter is of type UInt32 because wchar_t may not be
// wide enough to contain a code point. // wide enough to contain a code point.
// If the code_point is not a valid Unicode code point // If the code_point is not a valid Unicode code point
skipping to change at line 281 skipping to change at line 265
// Parses the environment variable var as a 32-bit integer. If it is unset, // Parses the environment variable var as a 32-bit integer. If it is unset,
// returns default_val. If it is not a 32-bit integer, prints an error and // returns default_val. If it is not a 32-bit integer, prints an error and
// and aborts. // and aborts.
GTEST_API_ int32_t Int32FromEnvOrDie(const char* env_var, int32_t default_val); GTEST_API_ int32_t Int32FromEnvOrDie(const char* env_var, int32_t default_val);
// Given the total number of shards, the shard index, and the test id, // Given the total number of shards, the shard index, and the test id,
// returns true if and only if the test should be run on this shard. The test id // returns true if and only if the test should be run on this shard. The test id
// is some arbitrary but unique non-negative integer assigned to each test // is some arbitrary but unique non-negative integer assigned to each test
// method. Assumes that 0 <= shard_index < total_shards. // method. Assumes that 0 <= shard_index < total_shards.
GTEST_API_ bool ShouldRunTestOnShard( GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index,
int total_shards, int shard_index, int test_id); int test_id);
// STL container utilities. // STL container utilities.
// Returns the number of elements in the given container that satisfy // Returns the number of elements in the given container that satisfy
// the given predicate. // the given predicate.
template <class Container, typename Predicate> template <class Container, typename Predicate>
inline int CountIf(const Container& c, Predicate predicate) { inline int CountIf(const Container& c, Predicate predicate) {
// Implemented as an explicit loop since std::count_if() in libCstd on // Implemented as an explicit loop since std::count_if() in libCstd on
// Solaris has a non-standard signature. // Solaris has a non-standard signature.
int count = 0; int count = 0;
for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) { for (auto it = c.begin(); it != c.end(); ++it) {
if (predicate(*it)) if (predicate(*it)) ++count;
++count;
} }
return count; return count;
} }
// Applies a function/functor to each element in the container. // Applies a function/functor to each element in the container.
template <class Container, typename Functor> template <class Container, typename Functor>
void ForEach(const Container& c, Functor functor) { void ForEach(const Container& c, Functor functor) {
std::for_each(c.begin(), c.end(), functor); std::for_each(c.begin(), c.end(), functor);
} }
skipping to change at line 444 skipping to change at line 427
// UponLeavingGTest() should be called immediately before Google Test calls // UponLeavingGTest() should be called immediately before Google Test calls
// user code. It saves some information about the current stack that // user code. It saves some information about the current stack that
// CurrentStackTrace() will use to find and hide Google Test stack frames. // CurrentStackTrace() will use to find and hide Google Test stack frames.
virtual void UponLeavingGTest() = 0; virtual void UponLeavingGTest() = 0;
// This string is inserted in place of stack frames that are part of // This string is inserted in place of stack frames that are part of
// Google Test's implementation. // Google Test's implementation.
static const char* const kElidedFramesMarker; static const char* const kElidedFramesMarker;
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface); OsStackTraceGetterInterface(const OsStackTraceGetterInterface&) = delete;
OsStackTraceGetterInterface& operator=(const OsStackTraceGetterInterface&) =
delete;
}; };
// A working implementation of the OsStackTraceGetterInterface interface. // A working implementation of the OsStackTraceGetterInterface interface.
class OsStackTraceGetter : public OsStackTraceGetterInterface { class OsStackTraceGetter : public OsStackTraceGetterInterface {
public: public:
OsStackTraceGetter() {} OsStackTraceGetter() {}
std::string CurrentStackTrace(int max_depth, int skip_count) override; std::string CurrentStackTrace(int max_depth, int skip_count) override;
void UponLeavingGTest() override; void UponLeavingGTest() override;
skipping to change at line 466 skipping to change at line 451
#if GTEST_HAS_ABSL #if GTEST_HAS_ABSL
Mutex mutex_; // Protects all internal state. Mutex mutex_; // Protects all internal state.
// We save the stack frame below the frame that calls user code. // We save the stack frame below the frame that calls user code.
// We do this because the address of the frame immediately below // We do this because the address of the frame immediately below
// the user code changes between the call to UponLeavingGTest() // the user code changes between the call to UponLeavingGTest()
// and any calls to the stack trace code from within the user code. // and any calls to the stack trace code from within the user code.
void* caller_frame_ = nullptr; void* caller_frame_ = nullptr;
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter); OsStackTraceGetter(const OsStackTraceGetter&) = delete;
OsStackTraceGetter& operator=(const OsStackTraceGetter&) = delete;
}; };
// Information about a Google Test trace point. // Information about a Google Test trace point.
struct TraceInfo { struct TraceInfo {
const char* file; const char* file;
int line; int line;
std::string message; std::string message;
}; };
// This is the default global test part result reporter used in UnitTestImpl. // This is the default global test part result reporter used in UnitTestImpl.
// This class should only be used by UnitTestImpl. // This class should only be used by UnitTestImpl.
class DefaultGlobalTestPartResultReporter class DefaultGlobalTestPartResultReporter
: public TestPartResultReporterInterface { : public TestPartResultReporterInterface {
public: public:
explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test); explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
// Implements the TestPartResultReporterInterface. Reports the test part // Implements the TestPartResultReporterInterface. Reports the test part
// result in the current test. // result in the current test.
void ReportTestPartResult(const TestPartResult& result) override; void ReportTestPartResult(const TestPartResult& result) override;
private: private:
UnitTestImpl* const unit_test_; UnitTestImpl* const unit_test_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter); DefaultGlobalTestPartResultReporter(
const DefaultGlobalTestPartResultReporter&) = delete;
DefaultGlobalTestPartResultReporter& operator=(
const DefaultGlobalTestPartResultReporter&) = delete;
}; };
// This is the default per thread test part result reporter used in // This is the default per thread test part result reporter used in
// UnitTestImpl. This class should only be used by UnitTestImpl. // UnitTestImpl. This class should only be used by UnitTestImpl.
class DefaultPerThreadTestPartResultReporter class DefaultPerThreadTestPartResultReporter
: public TestPartResultReporterInterface { : public TestPartResultReporterInterface {
public: public:
explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test); explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
// Implements the TestPartResultReporterInterface. The implementation just // Implements the TestPartResultReporterInterface. The implementation just
// delegates to the current global test part result reporter of *unit_test_. // delegates to the current global test part result reporter of *unit_test_.
void ReportTestPartResult(const TestPartResult& result) override; void ReportTestPartResult(const TestPartResult& result) override;
private: private:
UnitTestImpl* const unit_test_; UnitTestImpl* const unit_test_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter); DefaultPerThreadTestPartResultReporter(
const DefaultPerThreadTestPartResultReporter&) = delete;
DefaultPerThreadTestPartResultReporter& operator=(
const DefaultPerThreadTestPartResultReporter&) = delete;
}; };
// The private implementation of the UnitTest class. We don't protect // The private implementation of the UnitTest class. We don't protect
// the methods under a mutex, as this class is not accessible by a // 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 // user and the UnitTest class that delegates work to this class does
// proper locking. // proper locking.
class GTEST_API_ UnitTestImpl { class GTEST_API_ UnitTestImpl {
public: public:
explicit UnitTestImpl(UnitTest* parent); explicit UnitTestImpl(UnitTest* parent);
virtual ~UnitTestImpl(); virtual ~UnitTestImpl();
skipping to change at line 643 skipping to change at line 635
// Returns the current OS stack trace as an std::string. // Returns the current OS stack trace as an std::string.
// //
// The maximum number of stack frames to be included is specified by // The maximum number of stack frames to be included is specified by
// the gtest_stack_trace_depth flag. The skip_count parameter // the gtest_stack_trace_depth flag. The skip_count parameter
// specifies the number of top frames to be skipped, which doesn't // specifies the number of top frames to be skipped, which doesn't
// count against the number of frames to be included. // count against the number of frames to be included.
// //
// For example, if Foo() calls Bar(), which in turn calls // For example, if Foo() calls Bar(), which in turn calls
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
// trace but Bar() and CurrentOsStackTraceExceptTop() won't. // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_; std::string CurrentOsStackTraceExceptTop(int skip_count)
GTEST_NO_INLINE_ GTEST_NO_TAIL_CALL_;
// Finds and returns a TestSuite with the given name. If one doesn't // Finds and returns a TestSuite with the given name. If one doesn't
// exist, creates one and returns it. // exist, creates one and returns it.
// //
// Arguments: // Arguments:
// //
// test_suite_name: name of the test suite // test_suite_name: name of the test suite
// type_param: the name of the test's type parameter, or NULL if // type_param: the name of the test's type parameter, or NULL if
// this is not a typed or a type-parameterized test. // this is not a typed or a type-parameterized test.
// set_up_tc: pointer to the function that sets up the test suite // set_up_tc: pointer to the function that sets up the test suite
skipping to change at line 747 skipping to change at line 740
// thrown during a test, this test is considered to be failed, but // thrown during a test, this test is considered to be failed, but
// the rest of the tests will still be run. // the rest of the tests will still be run.
bool RunAllTests(); bool RunAllTests();
// Clears the results of all tests, except the ad hoc tests. // Clears the results of all tests, except the ad hoc tests.
void ClearNonAdHocTestResult() { void ClearNonAdHocTestResult() {
ForEach(test_suites_, TestSuite::ClearTestSuiteResult); ForEach(test_suites_, TestSuite::ClearTestSuiteResult);
} }
// Clears the results of ad-hoc test assertions. // Clears the results of ad-hoc test assertions.
void ClearAdHocTestResult() { void ClearAdHocTestResult() { ad_hoc_test_result_.Clear(); }
ad_hoc_test_result_.Clear();
}
// Adds a TestProperty to the current TestResult object when invoked in a // Adds a TestProperty to the current TestResult object when invoked in a
// context of a test or a test suite, or to the global property set. If the // context of a test or a test suite, or to the global property set. If the
// result already contains a property with the same key, the value will be // result already contains a property with the same key, the value will be
// updated. // updated.
void RecordProperty(const TestProperty& test_property); void RecordProperty(const TestProperty& test_property);
enum ReactionToSharding { enum ReactionToSharding { HONOR_SHARDING_PROTOCOL, IGNORE_SHARDING_PROTOCOL };
HONOR_SHARDING_PROTOCOL,
IGNORE_SHARDING_PROTOCOL
};
// Matches the full name of each test against the user-specified // Matches the full name of each test against the user-specified
// filter to decide whether the test should run, then records the // filter to decide whether the test should run, then records the
// result in each TestSuite and TestInfo object. // result in each TestSuite and TestInfo object.
// If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests // If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
// based on sharding variables in the environment. // based on sharding variables in the environment.
// Returns the number of tests that should run. // Returns the number of tests that should run.
int FilterTests(ReactionToSharding shard_tests); int FilterTests(ReactionToSharding shard_tests);
// Prints the names of the tests matching the user-specified filter flag. // Prints the names of the tests matching the user-specified filter flag.
skipping to change at line 966 skipping to change at line 954
std::unique_ptr<internal::DeathTestFactory> death_test_factory_; std::unique_ptr<internal::DeathTestFactory> death_test_factory_;
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
// A per-thread stack of traces created by the SCOPED_TRACE() macro. // A per-thread stack of traces created by the SCOPED_TRACE() macro.
internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_; internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
// The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests() // The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
// starts. // starts.
bool catch_exceptions_; bool catch_exceptions_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl); UnitTestImpl(const UnitTestImpl&) = delete;
UnitTestImpl& operator=(const UnitTestImpl&) = delete;
}; // class UnitTestImpl }; // class UnitTestImpl
// Convenience function for accessing the global UnitTest // Convenience function for accessing the global UnitTest
// implementation object. // implementation object.
inline UnitTestImpl* GetUnitTestImpl() { inline UnitTestImpl* GetUnitTestImpl() {
return UnitTest::GetInstance()->impl(); return UnitTest::GetInstance()->impl();
} }
#if GTEST_USES_SIMPLE_RE #if GTEST_USES_SIMPLE_RE
skipping to change at line 989 skipping to change at line 978
GTEST_API_ bool IsInSet(char ch, const char* str); GTEST_API_ bool IsInSet(char ch, const char* str);
GTEST_API_ bool IsAsciiDigit(char ch); GTEST_API_ bool IsAsciiDigit(char ch);
GTEST_API_ bool IsAsciiPunct(char ch); GTEST_API_ bool IsAsciiPunct(char ch);
GTEST_API_ bool IsRepeat(char ch); GTEST_API_ bool IsRepeat(char ch);
GTEST_API_ bool IsAsciiWhiteSpace(char ch); GTEST_API_ bool IsAsciiWhiteSpace(char ch);
GTEST_API_ bool IsAsciiWordChar(char ch); GTEST_API_ bool IsAsciiWordChar(char ch);
GTEST_API_ bool IsValidEscape(char ch); GTEST_API_ bool IsValidEscape(char ch);
GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch); GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
GTEST_API_ bool ValidateRegex(const char* regex); GTEST_API_ bool ValidateRegex(const char* regex);
GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str); GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
GTEST_API_ bool MatchRepetitionAndRegexAtHead( GTEST_API_ bool MatchRepetitionAndRegexAtHead(bool escaped, char ch,
bool escaped, char ch, char repeat, const char* regex, const char* str); char repeat, const char* regex,
const char* str);
GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str); GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
#endif // GTEST_USES_SIMPLE_RE #endif // GTEST_USES_SIMPLE_RE
// Parses the command line for Google Test flags, without initializing // Parses the command line for Google Test flags, without initializing
// other parts of Google Test. // other parts of Google Test.
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv); GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv); GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
skipping to change at line 1092 skipping to change at line 1082
// Concrete class for actually writing strings to a socket. // Concrete class for actually writing strings to a socket.
class SocketWriter : public AbstractSocketWriter { class SocketWriter : public AbstractSocketWriter {
public: public:
SocketWriter(const std::string& host, const std::string& port) SocketWriter(const std::string& host, const std::string& port)
: sockfd_(-1), host_name_(host), port_num_(port) { : sockfd_(-1), host_name_(host), port_num_(port) {
MakeConnection(); MakeConnection();
} }
~SocketWriter() override { ~SocketWriter() override {
if (sockfd_ != -1) if (sockfd_ != -1) CloseConnection();
CloseConnection();
} }
// Sends a string to the socket. // Sends a string to the socket.
void Send(const std::string& message) override { void Send(const std::string& message) override {
GTEST_CHECK_(sockfd_ != -1) GTEST_CHECK_(sockfd_ != -1)
<< "Send() can be called only when there is a connection."; << "Send() can be called only when there is a connection.";
const auto len = static_cast<size_t>(message.length()); const auto len = static_cast<size_t>(message.length());
if (write(sockfd_, message.c_str(), len) != static_cast<ssize_t>(len)) { if (write(sockfd_, message.c_str(), len) != static_cast<ssize_t>(len)) {
GTEST_LOG_(WARNING) GTEST_LOG_(WARNING) << "stream_result_to: failed to stream to "
<< "stream_result_to: failed to stream to " << host_name_ << ":" << port_num_;
<< host_name_ << ":" << port_num_;
} }
} }
private: private:
// Creates a client socket and connects to the server. // Creates a client socket and connects to the server.
void MakeConnection(); void MakeConnection();
// Closes the socket. // Closes the socket.
void CloseConnection() override { void CloseConnection() override {
GTEST_CHECK_(sockfd_ != -1) GTEST_CHECK_(sockfd_ != -1)
<< "CloseConnection() can be called only when there is a connection."; << "CloseConnection() can be called only when there is a connection.";
close(sockfd_); close(sockfd_);
sockfd_ = -1; sockfd_ = -1;
} }
int sockfd_; // socket file descriptor int sockfd_; // socket file descriptor
const std::string host_name_; const std::string host_name_;
const std::string port_num_; const std::string port_num_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter); SocketWriter(const SocketWriter&) = delete;
SocketWriter& operator=(const SocketWriter&) = delete;
}; // class SocketWriter }; // class SocketWriter
// Escapes '=', '&', '%', and '\n' characters in str as "%xx". // Escapes '=', '&', '%', and '\n' characters in str as "%xx".
static std::string UrlEncode(const char* str); static std::string UrlEncode(const char* str);
StreamingListener(const std::string& host, const std::string& port) StreamingListener(const std::string& host, const std::string& port)
: socket_writer_(new SocketWriter(host, port)) { : socket_writer_(new SocketWriter(host, port)) {
Start(); Start();
} }
explicit StreamingListener(AbstractSocketWriter* socket_writer) explicit StreamingListener(AbstractSocketWriter* socket_writer)
: socket_writer_(socket_writer) { Start(); } : socket_writer_(socket_writer) {
Start();
}
void OnTestProgramStart(const UnitTest& /* unit_test */) override { void OnTestProgramStart(const UnitTest& /* unit_test */) override {
SendLn("event=TestProgramStart"); SendLn("event=TestProgramStart");
} }
void OnTestProgramEnd(const UnitTest& unit_test) override { void OnTestProgramEnd(const UnitTest& unit_test) override {
// Note that Google Test current only report elapsed time for each // Note that Google Test current only report elapsed time for each
// test iteration, not for the entire test program. // test iteration, not for the entire test program.
SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed())); SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
skipping to change at line 1161 skipping to change at line 1152
} }
void OnTestIterationStart(const UnitTest& /* unit_test */, void OnTestIterationStart(const UnitTest& /* unit_test */,
int iteration) override { int iteration) override {
SendLn("event=TestIterationStart&iteration=" + SendLn("event=TestIterationStart&iteration=" +
StreamableToString(iteration)); StreamableToString(iteration));
} }
void OnTestIterationEnd(const UnitTest& unit_test, void OnTestIterationEnd(const UnitTest& unit_test,
int /* iteration */) override { int /* iteration */) override {
SendLn("event=TestIterationEnd&passed=" + SendLn("event=TestIterationEnd&passed=" + FormatBool(unit_test.Passed()) +
FormatBool(unit_test.Passed()) + "&elapsed_time=" + "&elapsed_time=" + StreamableToString(unit_test.elapsed_time()) +
StreamableToString(unit_test.elapsed_time()) + "ms"); "ms");
} }
// Note that "event=TestCaseStart" is a wire format and has to remain // Note that "event=TestCaseStart" is a wire format and has to remain
// "case" for compatibility // "case" for compatibility
void OnTestCaseStart(const TestCase& test_case) override { void OnTestSuiteStart(const TestSuite& test_suite) override {
SendLn(std::string("event=TestCaseStart&name=") + test_case.name()); SendLn(std::string("event=TestCaseStart&name=") + test_suite.name());
} }
// Note that "event=TestCaseEnd" is a wire format and has to remain // Note that "event=TestCaseEnd" is a wire format and has to remain
// "case" for compatibility // "case" for compatibility
void OnTestCaseEnd(const TestCase& test_case) override { void OnTestSuiteEnd(const TestSuite& test_suite) override {
SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed()) + SendLn("event=TestCaseEnd&passed=" + FormatBool(test_suite.Passed()) +
"&elapsed_time=" + StreamableToString(test_case.elapsed_time()) + "&elapsed_time=" + StreamableToString(test_suite.elapsed_time()) +
"ms"); "ms");
} }
void OnTestStart(const TestInfo& test_info) override { void OnTestStart(const TestInfo& test_info) override {
SendLn(std::string("event=TestStart&name=") + test_info.name()); SendLn(std::string("event=TestStart&name=") + test_info.name());
} }
void OnTestEnd(const TestInfo& test_info) override { void OnTestEnd(const TestInfo& test_info) override {
SendLn("event=TestEnd&passed=" + SendLn("event=TestEnd&passed=" +
FormatBool((test_info.result())->Passed()) + FormatBool((test_info.result())->Passed()) + "&elapsed_time=" +
"&elapsed_time=" +
StreamableToString((test_info.result())->elapsed_time()) + "ms"); StreamableToString((test_info.result())->elapsed_time()) + "ms");
} }
void OnTestPartResult(const TestPartResult& test_part_result) override { void OnTestPartResult(const TestPartResult& test_part_result) override {
const char* file_name = test_part_result.file_name(); const char* file_name = test_part_result.file_name();
if (file_name == nullptr) file_name = ""; if (file_name == nullptr) file_name = "";
SendLn("event=TestPartResult&file=" + UrlEncode(file_name) + SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
"&line=" + StreamableToString(test_part_result.line_number()) + "&line=" + StreamableToString(test_part_result.line_number()) +
"&message=" + UrlEncode(test_part_result.message())); "&message=" + UrlEncode(test_part_result.message()));
} }
skipping to change at line 1211 skipping to change at line 1201
void SendLn(const std::string& message) { socket_writer_->SendLn(message); } void SendLn(const std::string& message) { socket_writer_->SendLn(message); }
// Called at the start of streaming to notify the receiver what // Called at the start of streaming to notify the receiver what
// protocol we are using. // protocol we are using.
void Start() { SendLn("gtest_streaming_protocol_version=1.0"); } void Start() { SendLn("gtest_streaming_protocol_version=1.0"); }
std::string FormatBool(bool value) { return value ? "1" : "0"; } std::string FormatBool(bool value) { return value ? "1" : "0"; }
const std::unique_ptr<AbstractSocketWriter> socket_writer_; const std::unique_ptr<AbstractSocketWriter> socket_writer_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener); StreamingListener(const StreamingListener&) = delete;
StreamingListener& operator=(const StreamingListener&) = delete;
}; // class StreamingListener }; // class StreamingListener
#endif // GTEST_CAN_STREAM_RESULTS_ #endif // GTEST_CAN_STREAM_RESULTS_
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
#endif // GOOGLETEST_SRC_GTEST_INTERNAL_INL_H_ #endif // GOOGLETEST_SRC_GTEST_INTERNAL_INL_H_
 End of changes. 35 change blocks. 
113 lines changed or deleted 104 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)