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
5c639eb4
Commit
5c639eb4
authored
May 01, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test system error reporting.
parent
6ec1389d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
24 deletions
+52
-24
format-test.cc
format-test.cc
+52
-24
No files found.
format-test.cc
View file @
5c639eb4
...
@@ -310,12 +310,13 @@ TEST(UtilTest, SystemError) {
...
@@ -310,12 +310,13 @@ TEST(UtilTest, SystemError) {
EXPECT_EQ
(
42
,
e
.
error_code
());
EXPECT_EQ
(
42
,
e
.
error_code
());
}
}
// TODO: test WinErrorSink, FormatSystemErrorMessage, FormatWinErrorMessage
typedef
void
(
*
FormatErrorMessage
)(
fmt
::
Writer
&
out
,
int
error_code
,
fmt
::
StringRef
message
);
TEST
(
UtilTest
,
SystemErrorSink
)
{
template
<
typename
Sink
>
const
int
TEST_ERROR
=
EDOM
;
void
CheckErrorSink
(
int
error_code
,
FormatErrorMessage
format
)
{
fmt
::
SystemError
error
(
""
,
0
);
fmt
::
SystemError
error
(
""
,
0
);
fmt
::
SystemErrorSink
sink
(
TEST_ERROR
);
Sink
sink
(
error_code
);
fmt
::
Writer
w
;
fmt
::
Writer
w
;
w
<<
"test"
;
w
<<
"test"
;
try
{
try
{
...
@@ -323,32 +324,46 @@ TEST(UtilTest, SystemErrorSink) {
...
@@ -323,32 +324,46 @@ TEST(UtilTest, SystemErrorSink) {
}
catch
(
const
fmt
::
SystemError
&
e
)
{
}
catch
(
const
fmt
::
SystemError
&
e
)
{
error
=
e
;
error
=
e
;
}
}
EXPECT_EQ
(
str
(
fmt
::
Format
(
"test: {}"
)
<<
strerror
(
TEST_ERROR
)),
error
.
what
());
fmt
::
Writer
message
;
EXPECT_EQ
(
TEST_ERROR
,
error
.
error_code
());
format
(
message
,
error_code
,
"test"
);
EXPECT_EQ
(
str
(
message
),
error
.
what
());
EXPECT_EQ
(
error_code
,
error
.
error_code
());
}
}
TEST
(
UtilTest
,
ThrowSystemError
)
{
template
<
typename
Sink
>
const
int
TEST_ERROR
=
EDOM
;
void
CheckThrowError
(
int
error_code
,
FormatErrorMessage
format
,
fmt
::
Formatter
<
Sink
>
(
*
throw_error
)(
int
error_code
,
StringRef
format
))
{
fmt
::
SystemError
error
(
""
,
0
);
fmt
::
SystemError
error
(
""
,
0
);
try
{
try
{
fmt
::
ThrowSystemError
(
TEST_ERROR
,
"test {}"
)
<<
"error"
;
throw_error
(
error_code
,
"test {}"
)
<<
"error"
;
}
catch
(
const
fmt
::
SystemError
&
e
)
{
}
catch
(
const
fmt
::
SystemError
&
e
)
{
error
=
e
;
error
=
e
;
}
}
EXPECT_EQ
(
str
(
fmt
::
Format
(
"test error: {}"
)
<<
strerror
(
TEST_ERROR
)),
fmt
::
Writer
message
;
error
.
what
());
format
(
message
,
error_code
,
"test error"
);
EXPECT_EQ
(
TEST_ERROR
,
error
.
error_code
());
EXPECT_EQ
(
str
(
message
),
error
.
what
());
EXPECT_EQ
(
error_code
,
error
.
error_code
());
}
TEST
(
UtilTest
,
FormatSystemErrorMessage
)
{
fmt
::
Writer
message
;
fmt
::
internal
::
FormatSystemErrorMessage
(
message
,
EDOM
,
"test"
);
EXPECT_EQ
(
str
(
fmt
::
Format
(
"test: {}"
)
<<
strerror
(
EDOM
)),
fmt
::
str
(
message
));
}
TEST
(
UtilTest
,
SystemErrorSink
)
{
CheckErrorSink
<
fmt
::
SystemErrorSink
>
(
EDOM
,
fmt
::
internal
::
FormatSystemErrorMessage
);
}
TEST
(
UtilTest
,
ThrowSystemError
)
{
CheckThrowError
(
EDOM
,
fmt
::
internal
::
FormatSystemErrorMessage
,
fmt
::
ThrowSystemError
);
}
}
#ifdef _WIN32
#ifdef _WIN32
TEST
(
UtilTest
,
ThrowWinError
)
{
const
int
TEST_ERROR
=
ERROR_FILE_EXISTS
;
TEST
(
UtilTest
,
FormatWinErrorMessage
)
{
fmt
::
SystemError
error
(
""
,
0
);
try
{
fmt
::
ThrowWinError
(
TEST_ERROR
,
"test {}"
)
<<
"error"
;
}
catch
(
const
fmt
::
SystemError
&
e
)
{
error
=
e
;
}
LPWSTR
message
=
0
;
LPWSTR
message
=
0
;
FormatMessageW
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FormatMessageW
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
0
,
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
0
,
...
@@ -356,11 +371,24 @@ TEST(UtilTest, ThrowWinError) {
...
@@ -356,11 +371,24 @@ TEST(UtilTest, ThrowWinError) {
reinterpret_cast
<
LPWSTR
>
(
&
message
),
0
,
0
);
reinterpret_cast
<
LPWSTR
>
(
&
message
),
0
,
0
);
fmt
::
internal
::
UTF16ToUTF8
utf8_message
(
message
);
fmt
::
internal
::
UTF16ToUTF8
utf8_message
(
message
);
LocalFree
(
message
);
LocalFree
(
message
);
EXPECT_EQ
(
str
(
fmt
::
Format
(
"test error: {}"
)
<<
fmt
::
str
(
utf8_message
)),
fmt
::
Writer
actual_message
;
error
.
what
());
fmt
::
internal
::
FormatWinErrorMessage
(
EXPECT_EQ
(
TEST_ERROR
,
error
.
error_code
());
actual_message
,
ERROR_FILE_EXISTS
,
"test"
);
EXPECT_EQ
(
str
(
fmt
::
Format
(
"test: {}"
)
<<
fmt
::
str
(
utf8_message
)),
fmt
::
str
(
actual_message
));
}
}
#endif
TEST
(
UtilTest
,
WinErrorSink
)
{
CheckErrorSink
<
fmt
::
WinErrorSink
>
(
ERROR_FILE_EXISTS
,
fmt
::
internal
::
FormatWinErrorMessage
);
}
TEST
(
UtilTest
,
ThrowWinError
)
{
CheckThrowError
(
ERROR_FILE_EXISTS
,
fmt
::
internal
::
FormatWinErrorMessage
,
fmt
::
ThrowWinError
);
}
#endif // _WIN32
class
TestString
{
class
TestString
{
private:
private:
...
...
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