Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
f516fb9c
Commit
f516fb9c
authored
May 03, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests.
parent
7b2568a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
9 deletions
+16
-9
test/gtest-extra-test.cc
test/gtest-extra-test.cc
+16
-9
No files found.
test/gtest-extra-test.cc
View file @
f516fb9c
...
...
@@ -152,20 +152,24 @@ TEST(FileTest, DefaultCtor) {
}
// Checks if the file is open by reading one character from it.
// Note that IsOpen is not equivalent to !IsClosed.
bool
IsOpen
(
int
fd
)
{
char
buffer
;
return
read
(
fd
,
&
buffer
,
1
)
==
1
;
}
// Checks if the file is closed.
// Note that IsClosed is not equivalent to !IsOpen.
bool
IsClosed
(
int
fd
)
{
bool
IsClosedInternal
(
int
fd
)
{
char
buffer
;
std
::
streamsize
result
=
read
(
fd
,
&
buffer
,
1
);
return
result
==
-
1
&&
errno
==
EBADF
;
}
#ifndef _WIN32
// Checks if the file is closed.
# define EXPECT_CLOSED(fd) EXPECT_TRUE(IsClosedInternal(fd))
#else
# define EXPECT_CLOSED(fd) EXPECT_DEATH(IsClosedInternal(fd))
#endif
TEST
(
FileTest
,
OpenFileInCtor
)
{
int
fd
=
0
;
{
...
...
@@ -173,7 +177,7 @@ TEST(FileTest, OpenFileInCtor) {
fd
=
f
.
get
();
ASSERT_TRUE
(
IsOpen
(
fd
));
}
ASSERT_TRUE
(
IsClosed
(
fd
)
);
EXPECT_CLOSED
(
fd
);
}
TEST
(
FileTest
,
OpenFileError
)
{
...
...
@@ -205,7 +209,7 @@ TEST(FileTest, MoveAssignmentClosesFile) {
File
f2
(
"CMakeLists.txt"
,
File
::
RDONLY
);
int
old_fd
=
f2
.
get
();
f2
=
std
::
move
(
f
);
EXPECT_
TRUE
(
IsClosed
(
old_fd
)
);
EXPECT_
CLOSED
(
old_fd
);
}
File
OpenFile
(
int
&
fd
)
{
...
...
@@ -232,7 +236,7 @@ TEST(FileTest, MoveFromTemporaryInAssignmentClosesFile) {
File
f
(
".travis.yml"
,
File
::
RDONLY
);
int
old_fd
=
f
.
get
();
f
=
OpenFile
(
fd
);
EXPECT_
TRUE
(
IsClosed
(
old_fd
)
);
EXPECT_
CLOSED
(
old_fd
);
}
TEST
(
FileTest
,
CloseFileInDtor
)
{
...
...
@@ -297,6 +301,11 @@ TEST(FileTest, Write) {
EXPECT_READ
(
read_end
,
MESSAGE
);
}
TEST
(
FileTest
,
WriteError
)
{
File
f
;
EXPECT_SYSTEM_ERROR
(
f
.
write
(
" "
,
1
),
EBADF
,
"cannot write to file"
);
}
TEST
(
FileTest
,
Dup
)
{
File
f
(
".travis.yml"
,
File
::
RDONLY
);
File
dup
=
File
::
dup
(
f
.
get
());
...
...
@@ -351,8 +360,6 @@ TEST(FileTest, Pipe) {
// TODO: test pipe
// TODO: test File::read
// TODO: compile both with C++11 & C++98 mode
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment