Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
testing::internal::FilePath Class Reference

#include <gtest-filepath.h>

Public Member Functions

 FilePath ()
 
 FilePath (const FilePath &rhs)
 
 FilePath (const std::string &pathname)
 
FilePathoperator= (const FilePath &rhs)
 
void Set (const FilePath &rhs)
 
const std::string & string () const
 
const char * c_str () const
 
bool IsEmpty () const
 
FilePath RemoveTrailingPathSeparator () const
 
FilePath RemoveDirectoryName () const
 
FilePath RemoveFileName () const
 
FilePath RemoveExtension (const char *extension) const
 
bool CreateDirectoriesRecursively () const
 
bool CreateFolder () const
 
bool FileOrDirectoryExists () const
 
bool DirectoryExists () const
 
bool IsDirectory () const
 
bool IsRootDirectory () const
 
bool IsAbsolutePath () const
 

Static Public Member Functions

static FilePath GetCurrentDir ()
 
static FilePath MakeFileName (const FilePath &directory, const FilePath &base_name, int number, const char *extension)
 
static FilePath ConcatPaths (const FilePath &directory, const FilePath &relative_path)
 
static FilePath GenerateUniqueFileName (const FilePath &directory, const FilePath &base_name, const char *extension)
 

Detailed Description

Definition at line 58 of file gtest-filepath.h.

Constructor & Destructor Documentation

◆ FilePath() [1/3]

testing::internal::FilePath::FilePath ( )
inline

Definition at line 60 of file gtest-filepath.h.

60: pathname_("") { }
Here is the caller graph for this function:

◆ FilePath() [2/3]

testing::internal::FilePath::FilePath ( const FilePath & rhs)
inline

Definition at line 61 of file gtest-filepath.h.

61: pathname_(rhs.pathname_) { }

◆ FilePath() [3/3]

testing::internal::FilePath::FilePath ( const std::string & pathname)
inlineexplicit

Definition at line 63 of file gtest-filepath.h.

63 : pathname_(pathname) {
64 Normalize();
65 }

Member Function Documentation

◆ c_str()

const char * testing::internal::FilePath::c_str ( ) const
inline

Definition at line 77 of file gtest-filepath.h.

77{ return pathname_.c_str(); }
Here is the caller graph for this function:

◆ ConcatPaths()

FilePath testing::internal::FilePath::ConcatPaths ( const FilePath & directory,
const FilePath & relative_path )
static

Definition at line 197 of file gtest-filepath.cc.

198 {
199 if (directory.IsEmpty())
200 return relative_path;
201 const FilePath dir(directory.RemoveTrailingPathSeparator());
202 return FilePath(dir.string() + kPathSeparator + relative_path.string());
203}
const char kPathSeparator
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateDirectoriesRecursively()

bool testing::internal::FilePath::CreateDirectoriesRecursively ( ) const

Definition at line 306 of file gtest-filepath.cc.

306 {
307 if (!this->IsDirectory()) {
308 return false;
309 }
310
311 if (pathname_.length() == 0 || this->DirectoryExists()) {
312 return true;
313 }
314
316 return parent.CreateDirectoriesRecursively() && this->CreateFolder();
317}
FilePath RemoveTrailingPathSeparator() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateFolder()

bool testing::internal::FilePath::CreateFolder ( ) const

Definition at line 323 of file gtest-filepath.cc.

323 {
324#if GTEST_OS_WINDOWS_MOBILE
325 FilePath removed_sep(this->RemoveTrailingPathSeparator());
326 LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
327 int result = CreateDirectory(unicode, NULL) ? 0 : -1;
328 delete [] unicode;
329#elif GTEST_OS_WINDOWS
330 int result = _mkdir(pathname_.c_str());
331#else
332 int result = mkdir(pathname_.c_str(), 0777);
333#endif // GTEST_OS_WINDOWS_MOBILE
334
335 if (result == -1) {
336 return this->DirectoryExists(); // An error is OK if the directory exists.
337 }
338 return true; // No error.
339}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DirectoryExists()

bool testing::internal::FilePath::DirectoryExists ( ) const

Definition at line 221 of file gtest-filepath.cc.

221 {
222 bool result = false;
223#if GTEST_OS_WINDOWS
224 // Don't strip off trailing separator if path is a root directory on
225 // Windows (like "C:\\").
226 const FilePath& path(IsRootDirectory() ? *this :
228#else
229 const FilePath& path(*this);
230#endif
231
232#if GTEST_OS_WINDOWS_MOBILE
233 LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
234 const DWORD attributes = GetFileAttributes(unicode);
235 delete [] unicode;
236 if ((attributes != kInvalidFileAttributes) &&
237 (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
238 result = true;
239 }
240#else
241 posix::StatStruct file_stat;
242 result = posix::Stat(path.c_str(), &file_stat) == 0 &&
243 posix::IsDir(file_stat);
244#endif // GTEST_OS_WINDOWS_MOBILE
245
246 return result;
247}
int Stat(const char *path, StatStruct *buf)
bool IsDir(const StatStruct &st)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileOrDirectoryExists()

bool testing::internal::FilePath::FileOrDirectoryExists ( ) const

Definition at line 207 of file gtest-filepath.cc.

207 {
208#if GTEST_OS_WINDOWS_MOBILE
209 LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
210 const DWORD attributes = GetFileAttributes(unicode);
211 delete [] unicode;
212 return attributes != kInvalidFileAttributes;
213#else
214 posix::StatStruct file_stat;
215 return posix::Stat(pathname_.c_str(), &file_stat) == 0;
216#endif // GTEST_OS_WINDOWS_MOBILE
217}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GenerateUniqueFileName()

FilePath testing::internal::FilePath::GenerateUniqueFileName ( const FilePath & directory,
const FilePath & base_name,
const char * extension )
static

Definition at line 284 of file gtest-filepath.cc.

286 {
287 FilePath full_pathname;
288 int number = 0;
289 do {
290 full_pathname.Set(MakeFileName(directory, base_name, number++, extension));
291 } while (full_pathname.FileOrDirectoryExists());
292 return full_pathname;
293}
static FilePath MakeFileName(const FilePath &directory, const FilePath &base_name, int number, const char *extension)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCurrentDir()

FilePath testing::internal::FilePath::GetCurrentDir ( )
static

Definition at line 97 of file gtest-filepath.cc.

97 {
98#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
99 // Windows CE doesn't have a current directory, so we just return
100 // something reasonable.
102#elif GTEST_OS_WINDOWS
103 char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
104 return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
105#else
106 char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
107 char* result = getcwd(cwd, sizeof(cwd));
108# if GTEST_OS_NACL
109 // getcwd will likely fail in NaCl due to the sandbox, so return something
110 // reasonable. The user may have provided a shim implementation for getcwd,
111 // however, so fallback only when failure is detected.
112 return FilePath(result == NULL ? kCurrentDirectoryString : cwd);
113# endif // GTEST_OS_NACL
114 return FilePath(result == NULL ? "" : cwd);
115#endif // GTEST_OS_WINDOWS_MOBILE
116}
#define GTEST_PATH_MAX_
const char kCurrentDirectoryString[]
void cwd()
Here is the call graph for this function:

◆ IsAbsolutePath()

bool testing::internal::FilePath::IsAbsolutePath ( ) const

Definition at line 263 of file gtest-filepath.cc.

263 {
264 const char* const name = pathname_.c_str();
265#if GTEST_OS_WINDOWS
266 return pathname_.length() >= 3 &&
267 ((name[0] >= 'a' && name[0] <= 'z') ||
268 (name[0] >= 'A' && name[0] <= 'Z')) &&
269 name[1] == ':' &&
270 IsPathSeparator(name[2]);
271#else
272 return IsPathSeparator(name[0]);
273#endif
274}
std::string name
Here is the caller graph for this function:

◆ IsDirectory()

bool testing::internal::FilePath::IsDirectory ( ) const

Definition at line 298 of file gtest-filepath.cc.

298 {
299 return !pathname_.empty() &&
300 IsPathSeparator(pathname_.c_str()[pathname_.length() - 1]);
301}
Here is the caller graph for this function:

◆ IsEmpty()

bool testing::internal::FilePath::IsEmpty ( ) const
inline

Definition at line 110 of file gtest-filepath.h.

110{ return pathname_.empty(); }

◆ IsRootDirectory()

bool testing::internal::FilePath::IsRootDirectory ( ) const

Definition at line 251 of file gtest-filepath.cc.

251 {
252#if GTEST_OS_WINDOWS
253 // TODO(wan@google.com): on Windows a network share like
254 // \\server\share can be a root directory, although it cannot be the
255 // current directory. Handle this properly.
256 return pathname_.length() == 3 && IsAbsolutePath();
257#else
258 return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
259#endif
260}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeFileName()

FilePath testing::internal::FilePath::MakeFileName ( const FilePath & directory,
const FilePath & base_name,
int number,
const char * extension )
static

Definition at line 181 of file gtest-filepath.cc.

184 {
185 std::string file;
186 if (number == 0) {
187 file = base_name.string() + "." + extension;
188 } else {
189 file = base_name.string() + "_" + StreamableToString(number)
190 + "." + extension;
191 }
192 return ConcatPaths(directory, FilePath(file));
193}
static FilePath ConcatPaths(const FilePath &directory, const FilePath &relative_path)
std::string StreamableToString(const T &streamable)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

FilePath & testing::internal::FilePath::operator= ( const FilePath & rhs)
inline

Definition at line 67 of file gtest-filepath.h.

67 {
68 Set(rhs);
69 return *this;
70 }
void Set(const FilePath &rhs)

◆ RemoveDirectoryName()

FilePath testing::internal::FilePath::RemoveDirectoryName ( ) const

Definition at line 153 of file gtest-filepath.cc.

153 {
154 const char* const last_sep = FindLastPathSeparator();
155 return last_sep ? FilePath(last_sep + 1) : *this;
156}
Here is the call graph for this function:

◆ RemoveExtension()

FilePath testing::internal::FilePath::RemoveExtension ( const char * extension) const

Definition at line 122 of file gtest-filepath.cc.

122 {
123 const std::string dot_extension = std::string(".") + extension;
124 if (String::EndsWithCaseInsensitive(pathname_, dot_extension)) {
125 return FilePath(pathname_.substr(
126 0, pathname_.length() - dot_extension.length()));
127 }
128 return *this;
129}
static bool EndsWithCaseInsensitive(const std::string &str, const std::string &suffix)
Definition gtest.cc:1964
Here is the call graph for this function:

◆ RemoveFileName()

FilePath testing::internal::FilePath::RemoveFileName ( ) const

Definition at line 164 of file gtest-filepath.cc.

164 {
165 const char* const last_sep = FindLastPathSeparator();
166 std::string dir;
167 if (last_sep) {
168 dir = std::string(c_str(), last_sep + 1 - c_str());
169 } else {
171 }
172 return FilePath(dir);
173}
const char * c_str() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveTrailingPathSeparator()

FilePath testing::internal::FilePath::RemoveTrailingPathSeparator ( ) const

Definition at line 344 of file gtest-filepath.cc.

344 {
345 return IsDirectory()
346 ? FilePath(pathname_.substr(0, pathname_.length() - 1))
347 : *this;
348}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Set()

void testing::internal::FilePath::Set ( const FilePath & rhs)
inline

Definition at line 72 of file gtest-filepath.h.

72 {
73 pathname_ = rhs.pathname_;
74 }
Here is the caller graph for this function:

◆ string()

const std::string & testing::internal::FilePath::string ( ) const
inline

Definition at line 76 of file gtest-filepath.h.

76{ return pathname_; }
Here is the caller graph for this function:

The documentation for this class was generated from the following files: