gtest-internal-inl.h (googletest-release-1.10.0) | : | gtest-internal-inl.h (googletest-release-1.11.0) | ||
---|---|---|---|---|
skipping to change at line 34 | skipping to change at line 34 | |||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
// 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 GTEST_SRC_GTEST_INTERNAL_INL_H_ | #ifndef GOOGLETEST_SRC_GTEST_INTERNAL_INL_H_ | |||
#define GTEST_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 <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 | |||
skipping to change at line 86 | skipping to change at line 87 | |||
// 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). | // Names of the flags (needed for parsing Google Test flags). | |||
const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests"; | const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests"; | |||
const char kBreakOnFailureFlag[] = "break_on_failure"; | const char kBreakOnFailureFlag[] = "break_on_failure"; | |||
const char kCatchExceptionsFlag[] = "catch_exceptions"; | const char kCatchExceptionsFlag[] = "catch_exceptions"; | |||
const char kColorFlag[] = "color"; | const char kColorFlag[] = "color"; | |||
const char kFailFast[] = "fail_fast"; | ||||
const char kFilterFlag[] = "filter"; | const char kFilterFlag[] = "filter"; | |||
const char kListTestsFlag[] = "list_tests"; | const char kListTestsFlag[] = "list_tests"; | |||
const char kOutputFlag[] = "output"; | const char kOutputFlag[] = "output"; | |||
const char kBriefFlag[] = "brief"; | ||||
const char kPrintTimeFlag[] = "print_time"; | const char kPrintTimeFlag[] = "print_time"; | |||
const char kPrintUTF8Flag[] = "print_utf8"; | const char kPrintUTF8Flag[] = "print_utf8"; | |||
const char kRandomSeedFlag[] = "random_seed"; | const char kRandomSeedFlag[] = "random_seed"; | |||
const char kRepeatFlag[] = "repeat"; | const char kRepeatFlag[] = "repeat"; | |||
const char kShuffleFlag[] = "shuffle"; | const char kShuffleFlag[] = "shuffle"; | |||
const char kStackTraceDepthFlag[] = "stack_trace_depth"; | const char kStackTraceDepthFlag[] = "stack_trace_depth"; | |||
const char kStreamResultToFlag[] = "stream_result_to"; | const char kStreamResultToFlag[] = "stream_result_to"; | |||
const char kThrowOnFailureFlag[] = "throw_on_failure"; | const char kThrowOnFailureFlag[] = "throw_on_failure"; | |||
const char kFlagfileFlag[] = "flagfile"; | const char kFlagfileFlag[] = "flagfile"; | |||
skipping to change at line 126 | skipping to change at line 129 | |||
// 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 ParseInt32Flag( | |||
const char* str, const char* flag, Int32* 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 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 = (random_seed_flag == 0) ? | |||
static_cast<unsigned int>(GetTimeInMillis()) : | 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; | |||
skipping to change at line 166 | skipping to change at line 169 | |||
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(also_run_disabled_tests); | |||
break_on_failure_ = GTEST_FLAG(break_on_failure); | break_on_failure_ = GTEST_FLAG(break_on_failure); | |||
catch_exceptions_ = GTEST_FLAG(catch_exceptions); | catch_exceptions_ = GTEST_FLAG(catch_exceptions); | |||
color_ = GTEST_FLAG(color); | color_ = GTEST_FLAG(color); | |||
death_test_style_ = GTEST_FLAG(death_test_style); | death_test_style_ = GTEST_FLAG(death_test_style); | |||
death_test_use_fork_ = GTEST_FLAG(death_test_use_fork); | death_test_use_fork_ = GTEST_FLAG(death_test_use_fork); | |||
fail_fast_ = GTEST_FLAG(fail_fast); | ||||
filter_ = GTEST_FLAG(filter); | filter_ = GTEST_FLAG(filter); | |||
internal_run_death_test_ = GTEST_FLAG(internal_run_death_test); | internal_run_death_test_ = GTEST_FLAG(internal_run_death_test); | |||
list_tests_ = GTEST_FLAG(list_tests); | list_tests_ = GTEST_FLAG(list_tests); | |||
output_ = GTEST_FLAG(output); | output_ = GTEST_FLAG(output); | |||
brief_ = GTEST_FLAG(brief); | ||||
print_time_ = GTEST_FLAG(print_time); | print_time_ = GTEST_FLAG(print_time); | |||
print_utf8_ = GTEST_FLAG(print_utf8); | print_utf8_ = GTEST_FLAG(print_utf8); | |||
random_seed_ = GTEST_FLAG(random_seed); | random_seed_ = GTEST_FLAG(random_seed); | |||
repeat_ = GTEST_FLAG(repeat); | repeat_ = GTEST_FLAG(repeat); | |||
shuffle_ = GTEST_FLAG(shuffle); | shuffle_ = GTEST_FLAG(shuffle); | |||
stack_trace_depth_ = GTEST_FLAG(stack_trace_depth); | stack_trace_depth_ = GTEST_FLAG(stack_trace_depth); | |||
stream_result_to_ = GTEST_FLAG(stream_result_to); | stream_result_to_ = GTEST_FLAG(stream_result_to); | |||
throw_on_failure_ = GTEST_FLAG(throw_on_failure); | throw_on_failure_ = GTEST_FLAG(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(also_run_disabled_tests) = also_run_disabled_tests_; | |||
GTEST_FLAG(break_on_failure) = break_on_failure_; | GTEST_FLAG(break_on_failure) = break_on_failure_; | |||
GTEST_FLAG(catch_exceptions) = catch_exceptions_; | GTEST_FLAG(catch_exceptions) = catch_exceptions_; | |||
GTEST_FLAG(color) = color_; | GTEST_FLAG(color) = color_; | |||
GTEST_FLAG(death_test_style) = death_test_style_; | GTEST_FLAG(death_test_style) = death_test_style_; | |||
GTEST_FLAG(death_test_use_fork) = death_test_use_fork_; | GTEST_FLAG(death_test_use_fork) = death_test_use_fork_; | |||
GTEST_FLAG(filter) = filter_; | GTEST_FLAG(filter) = filter_; | |||
GTEST_FLAG(fail_fast) = fail_fast_; | ||||
GTEST_FLAG(internal_run_death_test) = internal_run_death_test_; | GTEST_FLAG(internal_run_death_test) = internal_run_death_test_; | |||
GTEST_FLAG(list_tests) = list_tests_; | GTEST_FLAG(list_tests) = list_tests_; | |||
GTEST_FLAG(output) = output_; | GTEST_FLAG(output) = output_; | |||
GTEST_FLAG(brief) = brief_; | ||||
GTEST_FLAG(print_time) = print_time_; | GTEST_FLAG(print_time) = print_time_; | |||
GTEST_FLAG(print_utf8) = print_utf8_; | GTEST_FLAG(print_utf8) = print_utf8_; | |||
GTEST_FLAG(random_seed) = random_seed_; | GTEST_FLAG(random_seed) = random_seed_; | |||
GTEST_FLAG(repeat) = repeat_; | GTEST_FLAG(repeat) = repeat_; | |||
GTEST_FLAG(shuffle) = shuffle_; | GTEST_FLAG(shuffle) = shuffle_; | |||
GTEST_FLAG(stack_trace_depth) = stack_trace_depth_; | GTEST_FLAG(stack_trace_depth) = stack_trace_depth_; | |||
GTEST_FLAG(stream_result_to) = stream_result_to_; | GTEST_FLAG(stream_result_to) = stream_result_to_; | |||
GTEST_FLAG(throw_on_failure) = throw_on_failure_; | GTEST_FLAG(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_; | ||||
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 print_time_; | bool print_time_; | |||
bool print_utf8_; | bool print_utf8_; | |||
internal::Int32 random_seed_; | int32_t random_seed_; | |||
internal::Int32 repeat_; | int32_t repeat_; | |||
bool shuffle_; | bool shuffle_; | |||
internal::Int32 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 | |||
// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted | // (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted | |||
// to "(Invalid Unicode 0xXXXXXXXX)". | // to "(Invalid Unicode 0xXXXXXXXX)". | |||
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point); | GTEST_API_ std::string CodePointToUtf8(uint32_t code_point); | |||
// Converts a wide string to a narrow string in UTF-8 encoding. | // Converts a wide string to a narrow string in UTF-8 encoding. | |||
// The wide string is assumed to have the following encoding: | // The wide string is assumed to have the following encoding: | |||
// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin) | // UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin) | |||
// UTF-32 if sizeof(wchar_t) == 4 (on Linux) | // UTF-32 if sizeof(wchar_t) == 4 (on Linux) | |||
// Parameter str points to a null-terminated wide string. | // Parameter str points to a null-terminated wide string. | |||
// Parameter num_chars may additionally limit the number | // Parameter num_chars may additionally limit the number | |||
// of wchar_t characters processed. -1 is used when the entire string | // of wchar_t characters processed. -1 is used when the entire string | |||
// should be processed. | // should be processed. | |||
// If the string contains code points that are not valid Unicode code points | // If the string contains code points that are not valid Unicode code points | |||
skipping to change at line 263 | skipping to change at line 272 | |||
// Checks whether sharding is enabled by examining the relevant | // Checks whether sharding is enabled by examining the relevant | |||
// environment variable values. If the variables are present, | // environment variable values. If the variables are present, | |||
// but inconsistent (e.g., shard_index >= total_shards), prints | // but inconsistent (e.g., shard_index >= total_shards), prints | |||
// an error and exits. If in_subprocess_for_death_test, sharding is | // an error and exits. If in_subprocess_for_death_test, sharding is | |||
// disabled because it must only be applied to the original test | // disabled because it must only be applied to the original test | |||
// process. Otherwise, we could filter out death tests we intended to execute. | // process. Otherwise, we could filter out death tests we intended to execute. | |||
GTEST_API_ bool ShouldShard(const char* total_shards_str, | GTEST_API_ bool ShouldShard(const char* total_shards_str, | |||
const char* shard_index_str, | const char* shard_index_str, | |||
bool in_subprocess_for_death_test); | bool in_subprocess_for_death_test); | |||
// Parses the environment variable var as an Int32. 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 an Int32, 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 Int32FromEnvOrDie(const char* env_var, Int32 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 test_id); | int total_shards, int shard_index, int test_id); | |||
// STL container utilities. | // STL container utilities. | |||
skipping to change at line 326 | skipping to change at line 335 | |||
GTEST_CHECK_(begin <= end && end <= size) | GTEST_CHECK_(begin <= end && end <= size) | |||
<< "Invalid shuffle range finish " << end << ": must be in range [" | << "Invalid shuffle range finish " << end << ": must be in range [" | |||
<< begin << ", " << size << "]."; | << begin << ", " << size << "]."; | |||
// Fisher-Yates shuffle, from | // Fisher-Yates shuffle, from | |||
// http://en.wikipedia.org/wiki/Fisher-Yates_shuffle | // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle | |||
for (int range_width = end - begin; range_width >= 2; range_width--) { | for (int range_width = end - begin; range_width >= 2; range_width--) { | |||
const int last_in_range = begin + range_width - 1; | const int last_in_range = begin + range_width - 1; | |||
const int selected = | const int selected = | |||
begin + | begin + | |||
static_cast<int>(random->Generate(static_cast<UInt32>(range_width))); | static_cast<int>(random->Generate(static_cast<uint32_t>(range_width))); | |||
std::swap((*v)[static_cast<size_t>(selected)], | std::swap((*v)[static_cast<size_t>(selected)], | |||
(*v)[static_cast<size_t>(last_in_range)]); | (*v)[static_cast<size_t>(last_in_range)]); | |||
} | } | |||
} | } | |||
// Performs an in-place shuffle of the vector's elements. | // Performs an in-place shuffle of the vector's elements. | |||
template <typename E> | template <typename E> | |||
inline void Shuffle(internal::Random* random, std::vector<E>* v) { | inline void Shuffle(internal::Random* random, std::vector<E>* v) { | |||
ShuffleRange(random, 0, static_cast<int>(v->size()), v); | ShuffleRange(random, 0, static_cast<int>(v->size()), v); | |||
} | } | |||
skipping to change at line 388 | skipping to change at line 397 | |||
// Returns the output format, or "" for normal printed output. | // Returns the output format, or "" for normal printed output. | |||
static std::string GetOutputFormat(); | static std::string GetOutputFormat(); | |||
// Returns the absolute path of the requested output file, or the | // Returns the absolute path of the requested output file, or the | |||
// default (test_detail.xml in the original working directory) if | // default (test_detail.xml in the original working directory) if | |||
// none was explicitly specified. | // none was explicitly specified. | |||
static std::string GetAbsolutePathToOutputFile(); | static std::string GetAbsolutePathToOutputFile(); | |||
// Functions for processing the gtest_filter flag. | // Functions for processing the gtest_filter flag. | |||
// Returns true if and only if the wildcard pattern matches the string. | ||||
// The first ':' or '\0' character in pattern marks the end of it. | ||||
// | ||||
// This recursive algorithm isn't very efficient, but is clear and | ||||
// works well enough for matching test names, which are short. | ||||
static bool PatternMatchesString(const char *pattern, const char *str); | ||||
// Returns true if and only if the user-specified filter matches the test | // Returns true if and only if the user-specified filter matches the test | |||
// suite name and the test name. | // suite name and the test name. | |||
static bool FilterMatchesTest(const std::string& test_suite_name, | static bool FilterMatchesTest(const std::string& test_suite_name, | |||
const std::string& test_name); | const std::string& test_name); | |||
#if GTEST_OS_WINDOWS | #if GTEST_OS_WINDOWS | |||
// Function for supporting the gtest_catch_exception flag. | // Function for supporting the gtest_catch_exception flag. | |||
// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the | // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the | |||
// given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise. | // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise. | |||
skipping to change at line 649 | skipping to change at line 651 | |||
// 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_; | |||
// 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 | |||
// tear_down_tc: pointer to the function that tears down the test suite | // tear_down_tc: pointer to the function that tears down the test suite | |||
TestSuite* GetTestSuite(const char* test_suite_name, const char* type_param, | TestSuite* GetTestSuite(const char* test_suite_name, const char* type_param, | |||
internal::SetUpTestSuiteFunc set_up_tc, | internal::SetUpTestSuiteFunc set_up_tc, | |||
internal::TearDownTestSuiteFunc tear_down_tc); | internal::TearDownTestSuiteFunc tear_down_tc); | |||
// Legacy API is deprecated but still available | // Legacy API is deprecated but still available | |||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
TestCase* GetTestCase(const char* test_case_name, const char* type_param, | TestCase* GetTestCase(const char* test_case_name, const char* type_param, | |||
internal::SetUpTestSuiteFunc set_up_tc, | internal::SetUpTestSuiteFunc set_up_tc, | |||
internal::TearDownTestSuiteFunc tear_down_tc) { | internal::TearDownTestSuiteFunc tear_down_tc) { | |||
return GetTestSuite(test_case_name, type_param, set_up_tc, tear_down_tc); | return GetTestSuite(test_case_name, type_param, set_up_tc, tear_down_tc); | |||
skipping to change at line 676 | skipping to change at line 678 | |||
// Adds a TestInfo to the unit test. | // Adds a TestInfo to the unit test. | |||
// | // | |||
// Arguments: | // Arguments: | |||
// | // | |||
// 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 | |||
// tear_down_tc: pointer to the function that tears down the test suite | // tear_down_tc: pointer to the function that tears down the test suite | |||
// test_info: the TestInfo object | // test_info: the TestInfo object | |||
void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc, | void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc, | |||
internal::TearDownTestSuiteFunc tear_down_tc, | internal::TearDownTestSuiteFunc tear_down_tc, | |||
TestInfo* test_info) { | TestInfo* test_info) { | |||
#if GTEST_HAS_DEATH_TEST | ||||
// In order to support thread-safe death tests, we need to | // In order to support thread-safe death tests, we need to | |||
// remember the original working directory when the test program | // remember the original working directory when the test program | |||
// was first invoked. We cannot do this in RUN_ALL_TESTS(), as | // was first invoked. We cannot do this in RUN_ALL_TESTS(), as | |||
// the user may have changed the current directory before calling | // the user may have changed the current directory before calling | |||
// RUN_ALL_TESTS(). Therefore we capture the current directory in | // RUN_ALL_TESTS(). Therefore we capture the current directory in | |||
// AddTestInfo(), which is called to register a TEST or TEST_F | // AddTestInfo(), which is called to register a TEST or TEST_F | |||
// before main() is reached. | // before main() is reached. | |||
if (original_working_dir_.IsEmpty()) { | if (original_working_dir_.IsEmpty()) { | |||
original_working_dir_.Set(FilePath::GetCurrentDir()); | original_working_dir_.Set(FilePath::GetCurrentDir()); | |||
GTEST_CHECK_(!original_working_dir_.IsEmpty()) | GTEST_CHECK_(!original_working_dir_.IsEmpty()) | |||
<< "Failed to get the current working directory."; | << "Failed to get the current working directory."; | |||
} | } | |||
#endif // GTEST_HAS_DEATH_TEST | ||||
GetTestSuite(test_info->test_suite_name(), test_info->type_param(), | GetTestSuite(test_info->test_suite_name(), test_info->type_param(), | |||
set_up_tc, tear_down_tc) | set_up_tc, tear_down_tc) | |||
->AddTestInfo(test_info); | ->AddTestInfo(test_info); | |||
} | } | |||
// Returns ParameterizedTestSuiteRegistry object used to keep track of | // Returns ParameterizedTestSuiteRegistry object used to keep track of | |||
// value-parameterized tests and instantiate and register them. | // value-parameterized tests and instantiate and register them. | |||
internal::ParameterizedTestSuiteRegistry& parameterized_test_registry() { | internal::ParameterizedTestSuiteRegistry& parameterized_test_registry() { | |||
return parameterized_test_registry_; | return parameterized_test_registry_; | |||
} | } | |||
std::set<std::string>* ignored_parameterized_test_suites() { | ||||
return &ignored_parameterized_test_suites_; | ||||
} | ||||
// Returns TypeParameterizedTestSuiteRegistry object used to keep track of | ||||
// type-parameterized tests and instantiations of them. | ||||
internal::TypeParameterizedTestSuiteRegistry& | ||||
type_parameterized_test_registry() { | ||||
return type_parameterized_test_registry_; | ||||
} | ||||
// Sets the TestSuite object for the test that's currently running. | // Sets the TestSuite object for the test that's currently running. | |||
void set_current_test_suite(TestSuite* a_current_test_suite) { | void set_current_test_suite(TestSuite* a_current_test_suite) { | |||
current_test_suite_ = a_current_test_suite; | current_test_suite_ = a_current_test_suite; | |||
} | } | |||
// Sets the TestInfo object for the test that's currently running. If | // Sets the TestInfo object for the test that's currently running. If | |||
// current_test_info is NULL, the assertion results will be stored in | // current_test_info is NULL, the assertion results will be stored in | |||
// ad_hoc_test_result_. | // ad_hoc_test_result_. | |||
void set_current_test_info(TestInfo* a_current_test_info) { | void set_current_test_info(TestInfo* a_current_test_info) { | |||
current_test_info_ = a_current_test_info; | current_test_info_ = a_current_test_info; | |||
skipping to change at line 876 | skipping to change at line 891 | |||
// Provides a level of indirection for the test suite list to allow | // Provides a level of indirection for the test suite list to allow | |||
// easy shuffling and restoring the test suite order. The i-th | // easy shuffling and restoring the test suite order. The i-th | |||
// element of this vector is the index of the i-th test suite in the | // element of this vector is the index of the i-th test suite in the | |||
// shuffled order. | // shuffled order. | |||
std::vector<int> test_suite_indices_; | std::vector<int> test_suite_indices_; | |||
// ParameterizedTestRegistry object used to register value-parameterized | // ParameterizedTestRegistry object used to register value-parameterized | |||
// tests. | // tests. | |||
internal::ParameterizedTestSuiteRegistry parameterized_test_registry_; | internal::ParameterizedTestSuiteRegistry parameterized_test_registry_; | |||
internal::TypeParameterizedTestSuiteRegistry | ||||
type_parameterized_test_registry_; | ||||
// The set holding the name of parameterized | ||||
// test suites that may go uninstantiated. | ||||
std::set<std::string> ignored_parameterized_test_suites_; | ||||
// Indicates whether RegisterParameterizedTests() has been called already. | // Indicates whether RegisterParameterizedTests() has been called already. | |||
bool parameterized_tests_registered_; | bool parameterized_tests_registered_; | |||
// Index of the last death test suite registered. Initially -1. | // Index of the last death test suite registered. Initially -1. | |||
int last_death_test_suite_; | int last_death_test_suite_; | |||
// This points to the TestSuite for the currently running test. It | // This points to the TestSuite for the currently running test. It | |||
// changes as Google Test goes through one test suite after another. | // changes as Google Test goes through one test suite after another. | |||
// When no test is running, this is set to NULL and Google Test | // When no test is running, this is set to NULL and Google Test | |||
skipping to change at line 1002 | skipping to change at line 1023 | |||
// this bypasses strtoXXX's "optional leading whitespace and plus | // this bypasses strtoXXX's "optional leading whitespace and plus | |||
// or minus sign" semantics, which are undesirable here. | // or minus sign" semantics, which are undesirable here. | |||
if (str.empty() || !IsDigit(str[0])) { | if (str.empty() || !IsDigit(str[0])) { | |||
return false; | return false; | |||
} | } | |||
errno = 0; | errno = 0; | |||
char* end; | char* end; | |||
// BiggestConvertible is the largest integer type that system-provided | // BiggestConvertible is the largest integer type that system-provided | |||
// string-to-number conversion routines can return. | // string-to-number conversion routines can return. | |||
using BiggestConvertible = unsigned long long; // NOLINT | ||||
# if GTEST_OS_WINDOWS && !defined(__GNUC__) | const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10); // NOLINT | |||
// MSVC and C++ Builder define __int64 instead of the standard long long. | ||||
typedef unsigned __int64 BiggestConvertible; | ||||
const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10); | ||||
# else | ||||
typedef unsigned long long BiggestConvertible; // NOLINT | ||||
const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10); | ||||
# endif // GTEST_OS_WINDOWS && !defined(__GNUC__) | ||||
const bool parse_success = *end == '\0' && errno == 0; | const bool parse_success = *end == '\0' && errno == 0; | |||
GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed)); | GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed)); | |||
const Integer result = static_cast<Integer>(parsed); | const Integer result = static_cast<Integer>(parsed); | |||
if (parse_success && static_cast<BiggestConvertible>(result) == parsed) { | if (parse_success && static_cast<BiggestConvertible>(result) == parsed) { | |||
*number = result; | *number = result; | |||
return true; | return true; | |||
} | } | |||
return false; | return false; | |||
skipping to change at line 1157 | skipping to change at line 1167 | |||
} | } | |||
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()) + "&elapsed_time=" + | FormatBool(unit_test.Passed()) + "&elapsed_time=" + | |||
StreamableToString(unit_test.elapsed_time()) + "ms"); | StreamableToString(unit_test.elapsed_time()) + "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 compatibilty | // "case" for compatibility | |||
void OnTestCaseStart(const TestCase& test_case) override { | void OnTestCaseStart(const TestCase& test_case) override { | |||
SendLn(std::string("event=TestCaseStart&name=") + test_case.name()); | SendLn(std::string("event=TestCaseStart&name=") + test_case.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 compatibilty | // "case" for compatibility | |||
void OnTestCaseEnd(const TestCase& test_case) override { | void OnTestCaseEnd(const TestCase& test_case) override { | |||
SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed()) + | SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed()) + | |||
"&elapsed_time=" + StreamableToString(test_case.elapsed_time()) + | "&elapsed_time=" + StreamableToString(test_case.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()); | |||
} | } | |||
skipping to change at line 1211 | skipping to change at line 1221 | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener); | GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener); | |||
}; // 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 // GTEST_SRC_GTEST_INTERNAL_INL_H_ | #endif // GOOGLETEST_SRC_GTEST_INTERNAL_INL_H_ | |||
End of changes. 29 change blocks. | ||||
38 lines changed or deleted | 48 lines changed or added |