Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
KWSys
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sylvain Joubert
KWSys
Commits
3f3d9eb5
Commit
3f3d9eb5
authored
9 years ago
by
Rolf Eike Beer
Browse files
Options
Downloads
Patches
Plain Diff
SystemTools: add basic tests for SystemTools::FindFile()
Change-Id: I59c150ef46c87bea36bab2822ebd0643aa7b7c2b
parent
9e9c8ae3
Branches
viame/master-old
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testSystemTools.cxx
+140
-0
140 additions, 0 deletions
testSystemTools.cxx
with
140 additions
and
0 deletions
testSystemTools.cxx
+
140
−
0
View file @
3f3d9eb5
...
...
@@ -196,6 +196,14 @@ static bool CheckFileOperations()
<<
std
::
endl
;
res
=
false
;
}
// check existence
if
(
!
kwsys
::
SystemTools
::
FileExists
(
testNewDir
.
c_str
(),
false
))
{
std
::
cerr
<<
"Problem with FileExists as C string and not file for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
// remove it
if
(
!
kwsys
::
SystemTools
::
RemoveADirectory
(
testNewDir
))
{
...
...
@@ -204,6 +212,15 @@ static bool CheckFileOperations()
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
// check existence
if
(
kwsys
::
SystemTools
::
FileExists
(
testNewDir
.
c_str
(),
false
))
{
std
::
cerr
<<
"After RemoveADirectory: "
<<
"Problem with FileExists as C string and not file for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
// create it using the char* version
if
(
!
kwsys
::
SystemTools
::
MakeDirectory
(
testNewDir
.
c_str
()))
{
...
...
@@ -229,6 +246,89 @@ static bool CheckFileOperations()
res
=
false
;
}
// calling with 0 pointer should return false
if
(
kwsys
::
SystemTools
::
FileExists
(
0
))
{
std
::
cerr
<<
"Problem with FileExists(0)"
<<
std
::
endl
;
res
=
false
;
}
if
(
kwsys
::
SystemTools
::
FileExists
(
0
,
true
))
{
std
::
cerr
<<
"Problem with FileExists(0) as file"
<<
std
::
endl
;
res
=
false
;
}
// calling with an empty string should return false
if
(
kwsys
::
SystemTools
::
FileExists
(
std
::
string
()))
{
std
::
cerr
<<
"Problem with FileExists(std::string())"
<<
std
::
endl
;
res
=
false
;
}
// FileExists(x, true) should return false on a directory
if
(
kwsys
::
SystemTools
::
FileExists
(
testNewDir
,
true
))
{
std
::
cerr
<<
"Problem with FileExists as file for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
if
(
kwsys
::
SystemTools
::
FileExists
(
testNewDir
.
c_str
(),
true
))
{
std
::
cerr
<<
"Problem with FileExists as C string and file for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
// FileExists(x, false) should return true even on a directory
if
(
!
kwsys
::
SystemTools
::
FileExists
(
testNewDir
,
false
))
{
std
::
cerr
<<
"Problem with FileExists as not file for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
if
(
!
kwsys
::
SystemTools
::
FileExists
(
testNewDir
.
c_str
(),
false
))
{
std
::
cerr
<<
"Problem with FileExists as C string and not file for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
// should work, was created as new file before
if
(
!
kwsys
::
SystemTools
::
FileExists
(
testNewFile
))
{
std
::
cerr
<<
"Problem with FileExists for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
if
(
!
kwsys
::
SystemTools
::
FileExists
(
testNewFile
.
c_str
()))
{
std
::
cerr
<<
"Problem with FileExists as C string for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
if
(
!
kwsys
::
SystemTools
::
FileExists
(
testNewFile
,
true
))
{
std
::
cerr
<<
"Problem with FileExists as file for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
if
(
!
kwsys
::
SystemTools
::
FileExists
(
testNewFile
.
c_str
(),
true
))
{
std
::
cerr
<<
"Problem with FileExists as C string and file for: "
<<
testNewDir
<<
std
::
endl
;
res
=
false
;
}
// Reset umask
#if defined(_WIN32) && !defined(__CYGWIN__)
// NOTE: Windows doesn't support toggling _S_IREAD.
...
...
@@ -899,6 +999,44 @@ static bool CheckGetPath()
return
res
;
}
static
bool
CheckFind
()
{
bool
res
=
true
;
const
std
::
string
testFindFileName
(
"testFindFile.txt"
);
const
std
::
string
testFindFile
(
TEST_SYSTEMTOOLS_BINARY_DIR
"/"
+
testFindFileName
);
if
(
!
kwsys
::
SystemTools
::
Touch
(
testFindFile
.
c_str
(),
true
))
{
std
::
cerr
<<
"Problem with Touch for: "
<<
testFindFile
<<
std
::
endl
;
// abort here as the existence of the file only makes the test meaningful
return
false
;
}
std
::
vector
<
std
::
string
>
searchPaths
;
searchPaths
.
push_back
(
TEST_SYSTEMTOOLS_BINARY_DIR
);
if
(
kwsys
::
SystemTools
::
FindFile
(
testFindFileName
,
searchPaths
,
true
).
empty
())
{
std
::
cerr
<<
"Problem with FindFile without system paths for: "
<<
testFindFileName
<<
std
::
endl
;
res
=
false
;
}
if
(
kwsys
::
SystemTools
::
FindFile
(
testFindFileName
,
searchPaths
,
false
).
empty
())
{
std
::
cerr
<<
"Problem with FindFile with system paths for: "
<<
testFindFileName
<<
std
::
endl
;
res
=
false
;
}
return
res
;
}
//----------------------------------------------------------------------------
int
testSystemTools
(
int
,
char
*
[])
{
...
...
@@ -936,5 +1074,7 @@ int testSystemTools(int, char*[])
res
&=
CheckGetPath
();
res
&=
CheckFind
();
return
res
?
0
:
1
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment