Commit a8ce8d27 authored by xiabo's avatar xiabo
Browse files

修改googletest版本

parent 0a21fff9
...@@ -249,7 +249,7 @@ static std::string DeathTestThreadWarning(size_t thread_count) { ...@@ -249,7 +249,7 @@ static std::string DeathTestThreadWarning(size_t thread_count) {
msg << "detected " << thread_count << " threads."; msg << "detected " << thread_count << " threads.";
} }
msg << " See " msg << " See "
"https://github.com/google/googletest/blob/main/docs/" "https://github.com/google/googletest/blob/master/docs/"
"advanced.md#death-tests-and-threads" "advanced.md#death-tests-and-threads"
<< " for more explanation and suggested solutions, especially if" << " for more explanation and suggested solutions, especially if"
<< " this is the last message you see before your test times out."; << " this is the last message you see before your test times out.";
...@@ -284,7 +284,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW }; ...@@ -284,7 +284,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
// message is propagated back to the parent process. Otherwise, the // message is propagated back to the parent process. Otherwise, the
// message is simply printed to stderr. In either case, the program // message is simply printed to stderr. In either case, the program
// then exits with status 1. // then exits with status 1.
[[noreturn]] static void DeathTestAbort(const std::string& message) { static void DeathTestAbort(const std::string& message) {
// On a POSIX system, this function may be called from a threadsafe-style // 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 // death test child process, which operates on a very small stack. Use
// the heap for any additional non-minuscule memory requirements. // the heap for any additional non-minuscule memory requirements.
......
...@@ -57,8 +57,6 @@ ...@@ -57,8 +57,6 @@
#define GTEST_PATH_MAX_ _POSIX_PATH_MAX #define GTEST_PATH_MAX_ _POSIX_PATH_MAX
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_HAS_FILE_SYSTEM
namespace testing { namespace testing {
namespace internal { namespace internal {
...@@ -98,7 +96,7 @@ static bool IsPathSeparator(char c) { ...@@ -98,7 +96,7 @@ static bool IsPathSeparator(char c) {
FilePath FilePath::GetCurrentDir() { FilePath FilePath::GetCurrentDir() {
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \ GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \
GTEST_OS_XTENSA || GTEST_OS_QURT GTEST_OS_XTENSA
// These platforms do not have a current directory, so we just return // These platforms do not have a current directory, so we just return
// something reasonable. // something reasonable.
return FilePath(kCurrentDirectoryString); return FilePath(kCurrentDirectoryString);
...@@ -147,45 +145,6 @@ const char* FilePath::FindLastPathSeparator() const { ...@@ -147,45 +145,6 @@ const char* FilePath::FindLastPathSeparator() const {
return last_sep; return last_sep;
} }
size_t FilePath::CalculateRootLength() const {
const auto &path = pathname_;
auto s = path.begin();
auto end = path.end();
#if GTEST_OS_WINDOWS
if (end - s >= 2 && s[1] == ':' &&
(end - s == 2 || IsPathSeparator(s[2])) &&
(('A' <= s[0] && s[0] <= 'Z') || ('a' <= s[0] && s[0] <= 'z'))) {
// A typical absolute path like "C:\Windows" or "D:"
s += 2;
if (s != end) {
++s;
}
} else if (end - s >= 3 && IsPathSeparator(*s) && IsPathSeparator(*(s + 1))
&& !IsPathSeparator(*(s + 2))) {
// Move past the "\\" prefix in a UNC path like "\\Server\Share\Folder"
s += 2;
// Skip 2 components and their following separators ("Server\" and "Share\")
for (int i = 0; i < 2; ++i) {
while (s != end) {
bool stop = IsPathSeparator(*s);
++s;
if (stop) {
break;
}
}
}
} else if (s != end && IsPathSeparator(*s)) {
// A drive-rooted path like "\Windows"
++s;
}
#else
if (s != end && IsPathSeparator(*s)) {
++s;
}
#endif
return static_cast<size_t>(s - path.begin());
}
// Returns a copy of the FilePath with the directory part removed. // Returns a copy of the FilePath with the directory part removed.
// Example: FilePath("path/to/file").RemoveDirectoryName() returns // Example: FilePath("path/to/file").RemoveDirectoryName() returns
// FilePath("file"). If there is no directory part ("just_a_file"), it returns // FilePath("file"). If there is no directory part ("just_a_file"), it returns
...@@ -287,16 +246,26 @@ bool FilePath::DirectoryExists() const { ...@@ -287,16 +246,26 @@ bool FilePath::DirectoryExists() const {
} }
// Returns true if pathname describes a root directory. (Windows has one // Returns true if pathname describes a root directory. (Windows has one
// root directory per disk drive. UNC share roots are also included.) // root directory per disk drive.)
bool FilePath::IsRootDirectory() const { bool FilePath::IsRootDirectory() const {
size_t root_length = CalculateRootLength(); #if GTEST_OS_WINDOWS
return root_length > 0 && root_length == pathname_.size() && return pathname_.length() == 3 && IsAbsolutePath();
IsPathSeparator(pathname_[root_length - 1]); #else
return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
#endif
} }
// Returns true if pathname describes an absolute path. // Returns true if pathname describes an absolute path.
bool FilePath::IsAbsolutePath() const { bool FilePath::IsAbsolutePath() const {
return CalculateRootLength() > 0; const char* const name = pathname_.c_str();
#if GTEST_OS_WINDOWS
return pathname_.length() >= 3 &&
((name[0] >= 'a' && name[0] <= 'z') ||
(name[0] >= 'A' && name[0] <= 'Z')) &&
name[1] == ':' && IsPathSeparator(name[2]);
#else
return IsPathSeparator(name[0]);
#endif
} }
// Returns a pathname for a file that does not currently exist. The pathname // Returns a pathname for a file that does not currently exist. The pathname
...@@ -354,7 +323,7 @@ bool FilePath::CreateFolder() const { ...@@ -354,7 +323,7 @@ bool FilePath::CreateFolder() const {
delete[] unicode; delete[] unicode;
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
int result = _mkdir(pathname_.c_str()); int result = _mkdir(pathname_.c_str());
#elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA || GTEST_OS_QURT #elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA
// do nothing // do nothing
int result = 0; int result = 0;
#else #else
...@@ -378,27 +347,17 @@ FilePath FilePath::RemoveTrailingPathSeparator() const { ...@@ -378,27 +347,17 @@ FilePath FilePath::RemoveTrailingPathSeparator() const {
// Removes any redundant separators that might be in the pathname. // Removes any redundant separators that might be in the pathname.
// For example, "bar///foo" becomes "bar/foo". Does not eliminate other // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
// redundancies that might be in a pathname involving "." or "..". // redundancies that might be in a pathname involving "." or "..".
// Note that "\\Host\Share" does not contain a redundancy on Windows!
void FilePath::Normalize() { void FilePath::Normalize() {
auto out = pathname_.begin(); auto out = pathname_.begin();
auto i = pathname_.cbegin(); for (const char character : pathname_) {
#if GTEST_OS_WINDOWS
// UNC paths are treated specially
if (pathname_.end() - i >= 3 && IsPathSeparator(*i) &&
IsPathSeparator(*(i + 1)) && !IsPathSeparator(*(i + 2))) {
*(out++) = kPathSeparator;
*(out++) = kPathSeparator;
}
#endif
while (i != pathname_.end()) {
const char character = *i;
if (!IsPathSeparator(character)) { if (!IsPathSeparator(character)) {
*(out++) = character; *(out++) = character;
} else if (out == pathname_.begin() || *std::prev(out) != kPathSeparator) { } else if (out == pathname_.begin() || *std::prev(out) != kPathSeparator) {
*(out++) = kPathSeparator; *(out++) = kPathSeparator;
} else {
continue;
} }
++i;
} }
pathname_.erase(out, pathname_.end()); pathname_.erase(out, pathname_.end());
...@@ -406,5 +365,3 @@ void FilePath::Normalize() { ...@@ -406,5 +365,3 @@ void FilePath::Normalize() {
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
#endif // GTEST_HAS_FILE_SYSTEM
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <set>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -213,7 +212,7 @@ class GTestFlagSaver { ...@@ -213,7 +212,7 @@ class GTestFlagSaver {
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_;
// 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
...@@ -397,11 +396,9 @@ class GTEST_API_ UnitTestOptions { ...@@ -397,11 +396,9 @@ class GTEST_API_ UnitTestOptions {
static bool MatchesFilter(const std::string& name, const char* filter); static bool MatchesFilter(const std::string& name, const char* filter);
}; };
#if GTEST_HAS_FILE_SYSTEM
// Returns the current application's name, removing directory path if that // Returns the current application's name, removing directory path if that
// is present. Used by UnitTestOptions::GetOutputFile. // is present. Used by UnitTestOptions::GetOutputFile.
GTEST_API_ FilePath GetCurrentExecutableName(); GTEST_API_ FilePath GetCurrentExecutableName();
#endif // GTEST_HAS_FILE_SYSTEM
// The role interface for getting the OS stack trace as a string. // The role interface for getting the OS stack trace as a string.
class OsStackTraceGetterInterface { class OsStackTraceGetterInterface {
...@@ -510,9 +507,9 @@ class GTEST_API_ UnitTestImpl { ...@@ -510,9 +507,9 @@ class GTEST_API_ UnitTestImpl {
virtual ~UnitTestImpl(); virtual ~UnitTestImpl();
// There are two different ways to register your own TestPartResultReporter. // There are two different ways to register your own TestPartResultReporter.
// You can register your own reporter to listen either only for test results // You can register your own repoter to listen either only for test results
// from the current thread or for results from all threads. // from the current thread or for results from all threads.
// By default, each per-thread test result reporter just passes a new // By default, each per-thread test result repoter just passes a new
// TestPartResult to the global test result reporter, which registers the // TestPartResult to the global test result reporter, which registers the
// test part result for the currently running test. // test part result for the currently running test.
...@@ -843,11 +840,9 @@ class GTEST_API_ UnitTestImpl { ...@@ -843,11 +840,9 @@ class GTEST_API_ UnitTestImpl {
// The UnitTest object that owns this implementation object. // The UnitTest object that owns this implementation object.
UnitTest* const parent_; UnitTest* const parent_;
#if GTEST_HAS_FILE_SYSTEM
// The working directory when the first TEST() or TEST_F() was // The working directory when the first TEST() or TEST_F() was
// executed. // executed.
internal::FilePath original_working_dir_; internal::FilePath original_working_dir_;
#endif // GTEST_HAS_FILE_SYSTEM
// The default test part result reporters. // The default test part result reporters.
DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_; DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
...@@ -855,7 +850,7 @@ class GTEST_API_ UnitTestImpl { ...@@ -855,7 +850,7 @@ class GTEST_API_ UnitTestImpl {
default_per_thread_test_part_result_reporter_; default_per_thread_test_part_result_reporter_;
// Points to (but doesn't own) the global test part result reporter. // Points to (but doesn't own) the global test part result reporter.
TestPartResultReporterInterface* global_test_part_result_reporter_; TestPartResultReporterInterface* global_test_part_result_repoter_;
// Protects read and write access to global_test_part_result_reporter_. // Protects read and write access to global_test_part_result_reporter_.
internal::Mutex global_test_part_result_reporter_mutex_; internal::Mutex global_test_part_result_reporter_mutex_;
......
...@@ -315,7 +315,7 @@ void PrintTo(__uint128_t v, ::std::ostream* os) { ...@@ -315,7 +315,7 @@ void PrintTo(__uint128_t v, ::std::ostream* os) {
low = low / 10 + high_mod * 1844674407370955161 + carry / 10; low = low / 10 + high_mod * 1844674407370955161 + carry / 10;
char digit = static_cast<char>(carry % 10); char digit = static_cast<char>(carry % 10);
*--p = static_cast<char>('0' + digit); *--p = '0' + digit;
} }
*os << p; *os << p;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment