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
2ecce39c
Commit
2ecce39c
authored
May 05, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More tests.
parent
0aacd0cf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
11 deletions
+38
-11
test/gtest-extra-test.cc
test/gtest-extra-test.cc
+38
-11
No files found.
test/gtest-extra-test.cc
View file @
2ecce39c
...
@@ -98,7 +98,7 @@ const char* SingleEvaluationTest::p_;
...
@@ -98,7 +98,7 @@ const char* SingleEvaluationTest::p_;
int
SingleEvaluationTest
::
a_
;
int
SingleEvaluationTest
::
a_
;
int
SingleEvaluationTest
::
b_
;
int
SingleEvaluationTest
::
b_
;
void
Throw
Nothing
()
{}
void
Do
Nothing
()
{}
void
ThrowException
()
{
void
ThrowException
()
{
throw
std
::
runtime_error
(
"test"
);
throw
std
::
runtime_error
(
"test"
);
...
@@ -173,8 +173,6 @@ TEST_F(SingleEvaluationTest, WriteTests) {
...
@@ -173,8 +173,6 @@ TEST_F(SingleEvaluationTest, WriteTests) {
EXPECT_EQ
(
2
,
b_
);
EXPECT_EQ
(
2
,
b_
);
}
}
// TODO: test EXPECT_STD*
// Tests that the compiler will not complain about unreachable code in the
// Tests that the compiler will not complain about unreachable code in the
// EXPECT_THROW_MSG macro.
// EXPECT_THROW_MSG macro.
TEST
(
ExpectThrowTest
,
DoesNotGenerateUnreachableCodeWarning
)
{
TEST
(
ExpectThrowTest
,
DoesNotGenerateUnreachableCodeWarning
)
{
...
@@ -187,9 +185,9 @@ TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
...
@@ -187,9 +185,9 @@ TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
throw
runtime_error
(
"a"
),
runtime_error
,
"b"
),
""
);
throw
runtime_error
(
"a"
),
runtime_error
,
"b"
),
""
);
}
}
TEST
(
AssertionSyntaxTest
,
ExceptionAssertion
s
BehavesLikeSingleStatement
)
{
TEST
(
AssertionSyntaxTest
,
ExceptionAssertionBehavesLikeSingleStatement
)
{
if
(
::
testing
::
internal
::
AlwaysFalse
())
if
(
::
testing
::
internal
::
AlwaysFalse
())
EXPECT_THROW_MSG
(
Throw
Nothing
(),
std
::
exception
,
""
);
EXPECT_THROW_MSG
(
Do
Nothing
(),
std
::
exception
,
""
);
if
(
::
testing
::
internal
::
AlwaysTrue
())
if
(
::
testing
::
internal
::
AlwaysTrue
())
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"test"
);
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"test"
);
...
@@ -197,6 +195,16 @@ TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
...
@@ -197,6 +195,16 @@ TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
;
// NOLINT
;
// NOLINT
}
}
TEST
(
AssertionSyntaxTest
,
WriteAssertionBehavesLikeSingleStatement
)
{
if
(
::
testing
::
internal
::
AlwaysFalse
())
EXPECT_WRITE
(
stdout
,
std
::
printf
(
"x"
),
"x"
);
if
(
::
testing
::
internal
::
AlwaysTrue
())
EXPECT_WRITE
(
stdout
,
std
::
printf
(
"x"
),
"x"
);
else
;
// NOLINT
}
// Tests EXPECT_THROW_MSG.
// Tests EXPECT_THROW_MSG.
TEST
(
ExpectTest
,
EXPECT_THROW_MSG
)
{
TEST
(
ExpectTest
,
EXPECT_THROW_MSG
)
{
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"test"
);
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"test"
);
...
@@ -205,8 +213,8 @@ TEST(ExpectTest, EXPECT_THROW_MSG) {
...
@@ -205,8 +213,8 @@ TEST(ExpectTest, EXPECT_THROW_MSG) {
"Expected: ThrowException() throws an exception of "
"Expected: ThrowException() throws an exception of "
"type std::logic_error.
\n
Actual: it throws a different type."
);
"type std::logic_error.
\n
Actual: it throws a different type."
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW_MSG
(
Throw
Nothing
(),
std
::
exception
,
"test"
),
EXPECT_THROW_MSG
(
Do
Nothing
(),
std
::
exception
,
"test"
),
"Expected:
Throw
Nothing() throws an exception of type std::exception.
\n
"
"Expected:
Do
Nothing() throws an exception of type std::exception.
\n
"
" Actual: it throws nothing."
);
" Actual: it throws nothing."
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"other"
),
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"other"
),
...
@@ -215,7 +223,20 @@ TEST(ExpectTest, EXPECT_THROW_MSG) {
...
@@ -215,7 +223,20 @@ TEST(ExpectTest, EXPECT_THROW_MSG) {
" Actual: test"
);
" Actual: test"
);
}
}
TEST
(
StreamingAssertionsTest
,
ThrowMsg
)
{
// Tests EXPECT_WRITE.
TEST
(
ExpectTest
,
EXPECT_WRITE
)
{
EXPECT_WRITE
(
stdout
,
DoNothing
(),
""
);
EXPECT_WRITE
(
stdout
,
std
::
printf
(
"test"
),
"test"
);
EXPECT_WRITE
(
stderr
,
std
::
fprintf
(
stderr
,
"test"
),
"test"
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_WRITE
(
stdout
,
std
::
printf
(
"that"
),
"this"
),
"Expected: this
\n
"
" Actual: that"
);
}
// TODO: test EXPECT_WRITE
TEST
(
StreamingAssertionsTest
,
EXPECT_THROW_MSG
)
{
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"test"
)
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"test"
)
<<
"unexpected failure"
;
<<
"unexpected failure"
;
EXPECT_NONFATAL_FAILURE
(
EXPECT_NONFATAL_FAILURE
(
...
@@ -230,7 +251,9 @@ TEST(ErrorCodeTest, Ctor) {
...
@@ -230,7 +251,9 @@ TEST(ErrorCodeTest, Ctor) {
EXPECT_EQ
(
42
,
ErrorCode
(
42
).
get
());
EXPECT_EQ
(
42
,
ErrorCode
(
42
).
get
());
}
}
class
BufferedFileTest
:
public
::
testing
::
Test
{
// Enables standard POSIX mode of handling errors, making functions return
// proper error codes instead of crashing on Windows.
class
ScopedPOSIXMode
{
#ifdef _WIN32
#ifdef _WIN32
private:
private:
_invalid_parameter_handler
original_handler_
;
_invalid_parameter_handler
original_handler_
;
...
@@ -240,17 +263,21 @@ class BufferedFileTest : public ::testing::Test {
...
@@ -240,17 +263,21 @@ class BufferedFileTest : public ::testing::Test {
const
wchar_t
*
,
const
wchar_t
*
,
unsigned
,
uintptr_t
)
{}
const
wchar_t
*
,
const
wchar_t
*
,
unsigned
,
uintptr_t
)
{}
public:
public:
BufferedFileTest
()
ScopedPOSIXMode
()
:
original_handler_
(
_set_invalid_parameter_handler
(
InvalidParameterHandler
)),
:
original_handler_
(
_set_invalid_parameter_handler
(
InvalidParameterHandler
)),
original_report_mode_
(
_CrtSetReportMode
(
_CRT_ASSERT
,
0
))
{
original_report_mode_
(
_CrtSetReportMode
(
_CRT_ASSERT
,
0
))
{
}
}
~
BufferedFileTest
()
{
~
ScopedPOSIXMode
()
{
_set_invalid_parameter_handler
(
original_handler_
);
_set_invalid_parameter_handler
(
original_handler_
);
_CrtSetReportMode
(
_CRT_ASSERT
,
original_report_mode_
);
_CrtSetReportMode
(
_CRT_ASSERT
,
original_report_mode_
);
}
}
#endif // _WIN32
#endif // _WIN32
};
};
class
BufferedFileTest
:
public
::
testing
::
Test
{
ScopedPOSIXMode
mode_
;
};
BufferedFile
OpenFile
(
const
char
*
name
,
FILE
**
fp
=
0
)
{
BufferedFile
OpenFile
(
const
char
*
name
,
FILE
**
fp
=
0
)
{
BufferedFile
f
=
File
(
".travis.yml"
,
File
::
RDONLY
).
fdopen
(
"r"
);
BufferedFile
f
=
File
(
".travis.yml"
,
File
::
RDONLY
).
fdopen
(
"r"
);
if
(
fp
)
if
(
fp
)
...
...
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