"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googletest/src/gtest-filepath.cc" between
googletest-release-1.10.0.tar.gz and googletest-release-1.11.0.tar.gz

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

gtest-filepath.cc  (googletest-release-1.10.0):gtest-filepath.cc  (googletest-release-1.11.0)
skipping to change at line 95 skipping to change at line 95
static bool IsPathSeparator(char c) { static bool IsPathSeparator(char c) {
#if GTEST_HAS_ALT_PATH_SEP_ #if GTEST_HAS_ALT_PATH_SEP_
return (c == kPathSeparator) || (c == kAlternatePathSeparator); return (c == kPathSeparator) || (c == kAlternatePathSeparator);
#else #else
return c == kPathSeparator; return c == kPathSeparator;
#endif #endif
} }
// Returns the current working directory, or "" if unsuccessful. // Returns the current working directory, or "" if unsuccessful.
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 || ARDUINO || defined(ESP_PLATFORM) GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \
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);
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd); return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd);
#else #else
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
char* result = getcwd(cwd, sizeof(cwd)); char* result = getcwd(cwd, sizeof(cwd));
# if GTEST_OS_NACL # if GTEST_OS_NACL
skipping to change at line 212 skipping to change at line 213
// Returns true if pathname describes something findable in the file-system, // Returns true if pathname describes something findable in the file-system,
// either a file, directory, or whatever. // either a file, directory, or whatever.
bool FilePath::FileOrDirectoryExists() const { bool FilePath::FileOrDirectoryExists() const {
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str()); LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
const DWORD attributes = GetFileAttributes(unicode); const DWORD attributes = GetFileAttributes(unicode);
delete [] unicode; delete [] unicode;
return attributes != kInvalidFileAttributes; return attributes != kInvalidFileAttributes;
#else #else
posix::StatStruct file_stat; posix::StatStruct file_stat{};
return posix::Stat(pathname_.c_str(), &file_stat) == 0; return posix::Stat(pathname_.c_str(), &file_stat) == 0;
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
} }
// Returns true if pathname describes a directory in the file-system // Returns true if pathname describes a directory in the file-system
// that exists. // that exists.
bool FilePath::DirectoryExists() const { bool FilePath::DirectoryExists() const {
bool result = false; bool result = false;
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// Don't strip off trailing separator if path is a root directory on // Don't strip off trailing separator if path is a root directory on
skipping to change at line 239 skipping to change at line 240
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
LPCWSTR unicode = String::AnsiToUtf16(path.c_str()); LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
const DWORD attributes = GetFileAttributes(unicode); const DWORD attributes = GetFileAttributes(unicode);
delete [] unicode; delete [] unicode;
if ((attributes != kInvalidFileAttributes) && if ((attributes != kInvalidFileAttributes) &&
(attributes & FILE_ATTRIBUTE_DIRECTORY)) { (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
result = true; result = true;
} }
#else #else
posix::StatStruct file_stat; posix::StatStruct file_stat{};
result = posix::Stat(path.c_str(), &file_stat) == 0 && result = posix::Stat(path.c_str(), &file_stat) == 0 &&
posix::IsDir(file_stat); posix::IsDir(file_stat);
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
return result; return result;
} }
// 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.) // root directory per disk drive.)
bool FilePath::IsRootDirectory() const { bool FilePath::IsRootDirectory() const {
skipping to change at line 326 skipping to change at line 327
// directory for any reason, including if the parent directory does not // directory for any reason, including if the parent directory does not
// exist. Not named "CreateDirectory" because that's a macro on Windows. // exist. Not named "CreateDirectory" because that's a macro on Windows.
bool FilePath::CreateFolder() const { bool FilePath::CreateFolder() const {
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
FilePath removed_sep(this->RemoveTrailingPathSeparator()); FilePath removed_sep(this->RemoveTrailingPathSeparator());
LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str()); LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
int result = CreateDirectory(unicode, nullptr) ? 0 : -1; int result = CreateDirectory(unicode, nullptr) ? 0 : -1;
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
// do nothing
int result = 0;
#else #else
int result = mkdir(pathname_.c_str(), 0777); int result = mkdir(pathname_.c_str(), 0777);
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
if (result == -1) { if (result == -1) {
return this->DirectoryExists(); // An error is OK if the directory exists. return this->DirectoryExists(); // An error is OK if the directory exists.
} }
return true; // No error. return true; // No error.
} }
skipping to change at line 349 skipping to change at line 353
FilePath FilePath::RemoveTrailingPathSeparator() const { FilePath FilePath::RemoveTrailingPathSeparator() const {
return IsDirectory() return IsDirectory()
? FilePath(pathname_.substr(0, pathname_.length() - 1)) ? FilePath(pathname_.substr(0, pathname_.length() - 1))
: *this; : *this;
} }
// 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 "..".
void FilePath::Normalize() { void FilePath::Normalize() {
if (pathname_.c_str() == nullptr) { auto out = pathname_.begin();
pathname_ = "";
return; for (const char character : pathname_) {
} if (!IsPathSeparator(character)) {
const char* src = pathname_.c_str(); *(out++) = character;
char* const dest = new char[pathname_.length() + 1]; } else if (out == pathname_.begin() || *std::prev(out) != kPathSeparator) {
char* dest_ptr = dest; *(out++) = kPathSeparator;
memset(dest_ptr, 0, pathname_.length() + 1);
while (*src != '\0') {
*dest_ptr = *src;
if (!IsPathSeparator(*src)) {
src++;
} else { } else {
#if GTEST_HAS_ALT_PATH_SEP_ continue;
if (*dest_ptr == kAlternatePathSeparator) {
*dest_ptr = kPathSeparator;
}
#endif
while (IsPathSeparator(*src))
src++;
} }
dest_ptr++;
} }
*dest_ptr = '\0';
pathname_ = dest; pathname_.erase(out, pathname_.end());
delete[] dest;
} }
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
 End of changes. 8 change blocks. 
28 lines changed or deleted 18 lines changed or added

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