1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

ts: restore Google Test 1.8.0 (capture OpenCV specific patch)

This commit is contained in:
Alexander Alekhin
2018-09-02 12:07:15 +00:00
parent 5eb295adf3
commit 546fcd990e
2 changed files with 125 additions and 278 deletions
+54 -98
View File
@@ -36,15 +36,7 @@
// This line ensures that gtest.h can be compiled on its own, even
// when it's fused.
#include "precomp.hpp"
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wmissing-declarations"
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
# if __GNUC__ >= 5
# pragma GCC diagnostic ignored "-Wsuggest-override"
# endif
#endif
#include "gtest/gtest.h"
// The following lines pull in the real gtest *.cc files.
// Copyright 2005, Google Inc.
@@ -506,7 +498,6 @@ const char kBreakOnFailureFlag[] = "break_on_failure";
const char kCatchExceptionsFlag[] = "catch_exceptions";
const char kColorFlag[] = "color";
const char kFilterFlag[] = "filter";
const char kParamFilterFlag[] = "param_filter";
const char kListTestsFlag[] = "list_tests";
const char kOutputFlag[] = "output";
const char kPrintTimeFlag[] = "print_time";
@@ -586,7 +577,6 @@ class GTestFlagSaver {
death_test_style_ = GTEST_FLAG(death_test_style);
death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
filter_ = GTEST_FLAG(filter);
param_filter_ = GTEST_FLAG(param_filter);
internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
list_tests_ = GTEST_FLAG(list_tests);
output_ = GTEST_FLAG(output);
@@ -608,7 +598,6 @@ class GTestFlagSaver {
GTEST_FLAG(death_test_style) = death_test_style_;
GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
GTEST_FLAG(filter) = filter_;
GTEST_FLAG(param_filter) = param_filter_;
GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
GTEST_FLAG(list_tests) = list_tests_;
GTEST_FLAG(output) = output_;
@@ -630,7 +619,6 @@ class GTestFlagSaver {
std::string death_test_style_;
bool death_test_use_fork_;
std::string filter_;
std::string param_filter_;
std::string internal_run_death_test_;
bool list_tests_;
std::string output_;
@@ -1359,7 +1347,6 @@ GTEST_API_ bool IsAsciiWhiteSpace(char ch);
GTEST_API_ bool IsAsciiWordChar(char ch);
GTEST_API_ bool IsValidEscape(char ch);
GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
GTEST_API_ std::string FormatRegexSyntaxError(const char* regex, int index);
GTEST_API_ bool ValidateRegex(const char* regex);
GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
GTEST_API_ bool MatchRepetitionAndRegexAtHead(
@@ -1693,12 +1680,6 @@ GTEST_DEFINE_string_(
"exclude). A test is run if it matches one of the positive "
"patterns and does not match any of the negative patterns.");
GTEST_DEFINE_string_(
param_filter,
internal::StringFromGTestEnv("param_filter", GetDefaultFilter()),
"Same syntax and semantics as for param, but these patterns "
"have to match the test's parameters.");
GTEST_DEFINE_bool_(list_tests, false,
"List all tests without running them.");
@@ -2095,7 +2076,7 @@ extern const TypeId kTestTypeIdInGoogleTest = GetTestTypeId();
// This predicate-formatter checks that 'results' contains a test part
// failure of the given type and that the failure message contains the
// given substring.
static AssertionResult HasOneFailure(const char* /* results_expr */,
AssertionResult HasOneFailure(const char* /* results_expr */,
const char* /* type_expr */,
const char* /* substr_expr */,
const TestPartResultArray& results,
@@ -2638,7 +2619,7 @@ class Hunk {
// Print a unified diff header for one hunk.
// The format is
// "@@ -<left_start>,<left_length> +<right_start>,<right_length> @@"
// where the left/right parts are omitted if unnecessary.
// where the left/right parts are ommitted if unnecessary.
void PrintHeader(std::ostream* ss) const {
*ss << "@@ ";
if (removes_) {
@@ -3605,7 +3586,7 @@ static std::string FormatWordList(const std::vector<std::string>& words) {
return word_list.GetString();
}
static bool ValidateTestPropertyName(const std::string& property_name,
bool ValidateTestPropertyName(const std::string& property_name,
const std::vector<std::string>& reserved_names) {
if (std::find(reserved_names.begin(), reserved_names.end(), property_name) !=
reserved_names.end()) {
@@ -3834,7 +3815,7 @@ static std::string PrintTestPartResultToString(
GoogleTestFailureException::GoogleTestFailureException(
const TestPartResult& failure)
: ::std::runtime_error(PrintTestPartResultToString(failure).c_str()) {}
: ::std::runtime_error(PrintTestPartResultToString(failure).c_str()) {}
#endif // GTEST_HAS_EXCEPTIONS
@@ -4368,7 +4349,7 @@ WORD GetColorAttribute(GTestColor color) {
// Returns the ANSI color code for the given color. COLOR_DEFAULT is
// an invalid input.
static const char* GetAnsiColorCode(GTestColor color) {
const char* GetAnsiColorCode(GTestColor color) {
switch (color) {
case COLOR_RED: return "1";
case COLOR_GREEN: return "2";
@@ -4420,7 +4401,7 @@ bool ShouldUseColor(bool stdout_is_tty) {
// cannot simply emit special characters and have the terminal change colors.
// This routine must actually emit the characters rather than return a string
// that would be colored when printed, as can be done on Linux.
static void ColoredPrintf(GTestColor color, const char* fmt, ...) {
void ColoredPrintf(GTestColor color, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
@@ -4473,7 +4454,7 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) {
static const char kTypeParamLabel[] = "TypeParam";
static const char kValueParamLabel[] = "GetParam()";
static void PrintFullTestCommentIfPresent(const TestInfo& test_info) {
void PrintFullTestCommentIfPresent(const TestInfo& test_info) {
const char* const type_param = test_info.type_param();
const char* const value_param = test_info.value_param();
@@ -4534,14 +4515,6 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart(
"Note: %s filter = %s\n", GTEST_NAME_, filter);
}
const char* const param_filter = GTEST_FLAG(param_filter).c_str();
// Ditto.
if (!String::CStringEquals(param_filter, kUniversalFilter)) {
ColoredPrintf(COLOR_YELLOW,
"Note: %s parameter filter = %s\n", GTEST_NAME_, param_filter);
}
if (internal::ShouldShard(kTestTotalShards, kTestShardIndex, false)) {
const Int32 shard_index = Int32FromEnvOrDie(kTestShardIndex, -1);
ColoredPrintf(COLOR_YELLOW,
@@ -4586,7 +4559,6 @@ void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) {
void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {
ColoredPrintf(COLOR_GREEN, "[ RUN ] ");
PrintTestName(test_info.test_case_name(), test_info.name());
PrintFullTestCommentIfPresent(test_info);
printf("\n");
fflush(stdout);
}
@@ -4956,38 +4928,38 @@ std::string XmlUnitTestResultPrinter::EscapeXml(
for (size_t i = 0; i < str.size(); ++i) {
const char ch = str[i];
switch (ch) {
case '<':
m << "&lt;";
break;
case '>':
m << "&gt;";
break;
case '&':
m << "&amp;";
break;
case '\'':
if (is_attribute)
m << "&apos;";
else
m << '\'';
break;
case '"':
if (is_attribute)
m << "&quot;";
else
m << '"';
break;
default:
case '<':
m << "&lt;";
break;
case '>':
m << "&gt;";
break;
case '&':
m << "&amp;";
break;
case '\'':
if (is_attribute)
m << "&apos;";
else
m << '\'';
break;
case '"':
if (is_attribute)
m << "&quot;";
else
m << '"';
break;
default:
if (IsValidXmlCharacter(ch)) {
if (is_attribute && IsNormalizableWhitespace(ch))
m << "&#x" << String::FormatByte(static_cast<unsigned char>(ch))
<< ";";
else
else
m << ch;
}
break;
}
}
break;
}
}
return m.GetString();
}
@@ -5445,7 +5417,7 @@ void TestEventListeners::SuppressEventForwarding() {
// We don't protect this under mutex_ as a user is not supposed to
// call this before main() starts, from which point on the return
// value will never change.
UnitTest * UnitTest::GetInstance() {
UnitTest* UnitTest::GetInstance() {
// When compiled with MSVC 7.1 in optimized mode, destroying the
// UnitTest object upon exiting the program messes up the exit code,
// causing successful tests to appear failed. We have to use a
@@ -5457,13 +5429,13 @@ UnitTest * UnitTest::GetInstance() {
// default implementation. Use this implementation to keep good OO
// design with private destructor.
#if (defined(_MSC_VER) && _MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
#if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
static UnitTest* const instance = new UnitTest;
return instance;
#else
static UnitTest instance;
return &instance;
#endif // (defined(_MSC_VER) && _MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
#endif // (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
}
// Gets the number of successful test cases.
@@ -6291,15 +6263,9 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
kDisableTestFilter);
test_info->is_disabled_ = is_disabled;
const std::string value_param(test_info->value_param() == NULL ?
"" : test_info->value_param());
const bool matches_filter =
internal::UnitTestOptions::FilterMatchesTest(test_case_name,
test_name) &&
internal::UnitTestOptions::MatchesFilter(value_param,
GTEST_FLAG(param_filter).c_str());
test_name);
test_info->matches_filter_ = matches_filter;
const bool is_runnable =
@@ -6364,7 +6330,7 @@ void UnitTestImpl::ListTestsMatchingFilter() {
// We print the type parameter on a single line to make
// the output easy to parse by a program.
PrintOnOneLine(test_case->type_param(), kMaxParamLength);
}
}
printf("\n");
}
printf(" %s", test_info->name());
@@ -6494,7 +6460,7 @@ bool SkipPrefix(const char* prefix, const char** pstr) {
// part can be omitted.
//
// Returns the value of the flag, or NULL if the parsing failed.
static const char* ParseFlagValue(const char* str,
const char* ParseFlagValue(const char* str,
const char* flag,
bool def_optional) {
// str and flag must not be NULL.
@@ -6532,7 +6498,7 @@ static const char* ParseFlagValue(const char* str,
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
static bool ParseBoolFlag(const char* str, const char* flag, bool* value) {
bool ParseBoolFlag(const char* str, const char* flag, bool* value) {
// Gets the value of the flag as a string.
const char* const value_str = ParseFlagValue(str, flag, true);
@@ -6566,7 +6532,7 @@ bool ParseInt32Flag(const char* str, const char* flag, Int32* value) {
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
static bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
// Gets the value of the flag as a string.
const char* const value_str = ParseFlagValue(str, flag, false);
@@ -6651,12 +6617,6 @@ static const char kColorEncodedHelpMessage[] =
" Run only the tests whose name matches one of the positive patterns but\n"
" none of the negative patterns. '?' matches any single character; '*'\n"
" matches any substring; ':' separates two patterns.\n"
" @G--" GTEST_FLAG_PREFIX_ "param_filter=@YPOSITIVE_PATTERNS"
"[@G-@YNEGATIVE_PATTERNS]@D\n"
" Like @G--" GTEST_FLAG_PREFIX_
"filter@D, but applies to the test's parameter. If a\n"
" test is not parameterized, its parameter is considered to be the\n"
" empty string.\n"
" @G--" GTEST_FLAG_PREFIX_ "also_run_disabled_tests@D\n"
" Run all disabled tests too.\n"
"\n"
@@ -6708,7 +6668,7 @@ static const char kColorEncodedHelpMessage[] =
"(not one in your own code or tests), please report it to\n"
"@G<" GTEST_DEV_EMAIL_ ">@D.\n";
static bool ParseGoogleTestFlag(const char* const arg) {
bool ParseGoogleTestFlag(const char* const arg) {
return ParseBoolFlag(arg, kAlsoRunDisabledTestsFlag,
&GTEST_FLAG(also_run_disabled_tests)) ||
ParseBoolFlag(arg, kBreakOnFailureFlag,
@@ -6721,7 +6681,6 @@ static bool ParseGoogleTestFlag(const char* const arg) {
ParseBoolFlag(arg, kDeathTestUseFork,
&GTEST_FLAG(death_test_use_fork)) ||
ParseStringFlag(arg, kFilterFlag, &GTEST_FLAG(filter)) ||
ParseStringFlag(arg, kParamFilterFlag, &GTEST_FLAG(param_filter)) ||
ParseStringFlag(arg, kInternalRunDeathTestFlag,
&GTEST_FLAG(internal_run_death_test)) ||
ParseBoolFlag(arg, kListTestsFlag, &GTEST_FLAG(list_tests)) ||
@@ -6739,7 +6698,7 @@ static bool ParseGoogleTestFlag(const char* const arg) {
}
#if GTEST_USE_OWN_FLAGFILE_FLAG_
static void LoadFlagsFromFile(const std::string& path) {
void LoadFlagsFromFile(const std::string& path) {
FILE* flagfile = posix::FOpen(path.c_str(), "r");
if (!flagfile) {
fprintf(stderr,
@@ -7130,7 +7089,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
// message is propagated back to the parent process. Otherwise, the
// message is simply printed to stderr. In either case, the program
// then exits with status 1.
static void DeathTestAbort(const std::string& message) {
void DeathTestAbort(const std::string& message) {
// On a POSIX system, this function may be called from a threadsafe-style
// death test child process, which operates on a very small stack. Use
// the heap for any additional non-minuscule memory requirements.
@@ -7872,15 +7831,14 @@ void StackLowerThanAddress(const void* ptr, bool* result) {
*result = (&dummy < ptr);
}
#if GTEST_HAS_CLONE
// Make sure AddressSanitizer does not tamper with the stack here.
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
static bool StackGrowsDown() {
bool StackGrowsDown() {
int dummy;
bool result;
StackLowerThanAddress(&dummy, &result);
return result;
}
#endif
// Spawns a child process with the same executable as the current process in
// a thread-safe manner and instructs it to run the death test. The
@@ -8066,6 +8024,7 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
}
# if GTEST_OS_WINDOWS
if (GTEST_FLAG(death_test_style) == "threadsafe" ||
GTEST_FLAG(death_test_style) == "fast") {
*test = new WindowsDeathTest(statement, regex, file, line);
@@ -8174,6 +8133,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
int write_fd = -1;
# if GTEST_OS_WINDOWS
unsigned int parent_process_id = 0;
size_t write_handle_as_size_t = 0;
size_t event_handle_as_size_t = 0;
@@ -8278,7 +8238,6 @@ namespace internal {
// of them.
const char kPathSeparator = '\\';
const char kAlternatePathSeparator = '/';
//const char kPathSeparatorString[] = "\\";
const char kAlternatePathSeparatorString[] = "/";
# if GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have a current directory. You should not use
@@ -8292,7 +8251,6 @@ const char kCurrentDirectoryString[] = ".\\";
# endif // GTEST_OS_WINDOWS_MOBILE
#else
const char kPathSeparator = '/';
//const char kPathSeparatorString[] = "/";
const char kCurrentDirectoryString[] = "./";
#endif // GTEST_OS_WINDOWS
@@ -8340,7 +8298,7 @@ FilePath FilePath::RemoveExtension(const char* extension) const {
return *this;
}
// Returns a pointer to the last occurrence of a valid path separator in
// Returns a pointer to the last occurence of a valid path separator in
// the FilePath. On Windows, for example, both '/' and '\' are valid path
// separators. Returns NULL if no path separator was found.
const char* FilePath::FindLastPathSeparator() const {
@@ -9606,7 +9564,7 @@ static CapturedStream* g_captured_stderr = NULL;
static CapturedStream* g_captured_stdout = NULL;
// Starts capturing an output stream (stdout/stderr).
static void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) {
void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) {
if (*stream != NULL) {
GTEST_LOG_(FATAL) << "Only one " << stream_name
<< " capturer can exist at a time.";
@@ -9615,7 +9573,7 @@ static void CaptureStream(int fd, const char* stream_name, CapturedStream** stre
}
// Stops capturing the output stream and returns the captured string.
static std::string GetCapturedStream(CapturedStream** captured_stream) {
std::string GetCapturedStream(CapturedStream** captured_stream) {
const std::string content = (*captured_stream)->GetCapturedString();
delete *captured_stream;
@@ -9971,7 +9929,7 @@ namespace internal {
// Depending on the value of a char (or wchar_t), we print it in one
// of three formats:
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
// - as a hexadecimal escape sequence (e.g. '\x7F'), or
// - as a hexidecimal escape sequence (e.g. '\x7F'), or
// - as a special escape sequence (e.g. '\r', '\n').
enum CharFormat {
kAsIs,
@@ -10075,7 +10033,7 @@ void PrintCharAndCodeTo(Char c, ostream* os) {
return;
*os << " (" << static_cast<int>(c);
// For more convenience, we print c's code again in hexadecimal,
// For more convenience, we print c's code again in hexidecimal,
// unless c was already printed in the form '\x##' or the code is in
// [1, 9].
if (format == kHexEscape || (1 <= c && c <= 9)) {
@@ -10441,7 +10399,5 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
#endif // GTEST_HAS_TYPED_TEST_P
void* g_parameter_ = NULL;
} // namespace internal
} // namespace testing