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
6e1d142a
Commit
6e1d142a
authored
Dec 13, 2012
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make tests more portable.
parent
e4ada5bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
60 deletions
+63
-60
format_test.cc
format_test.cc
+63
-60
No files found.
format_test.cc
View file @
6e1d142a
...
@@ -73,6 +73,32 @@ using fmt::FormatError;
...
@@ -73,6 +73,32 @@ using fmt::FormatError;
FORMAT_TEST_THROW_(statement, expected_exception, expected_message, \
FORMAT_TEST_THROW_(statement, expected_exception, expected_message, \
GTEST_NONFATAL_FAILURE_)
GTEST_NONFATAL_FAILURE_)
// Increment a number in a string.
void
Increment
(
char
*
s
)
{
for
(
int
i
=
static_cast
<
int
>
(
std
::
strlen
(
s
))
-
1
;
i
>=
0
;
--
i
)
{
if
(
s
[
i
]
!=
'9'
)
{
++
s
[
i
];
break
;
}
s
[
i
]
=
'0'
;
}
}
TEST
(
UtilTest
,
Increment
)
{
char
s
[
10
]
=
"123"
;
Increment
(
s
);
EXPECT_STREQ
(
"124"
,
s
);
s
[
2
]
=
'8'
;
Increment
(
s
);
EXPECT_STREQ
(
"129"
,
s
);
Increment
(
s
);
EXPECT_STREQ
(
"130"
,
s
);
EXPECT_STREQ
(
"130"
,
s
);
s
[
1
]
=
s
[
2
]
=
'9'
;
Increment
(
s
);
EXPECT_STREQ
(
"200"
,
s
);
}
class
TestString
{
class
TestString
{
private:
private:
std
::
string
value_
;
std
::
string
value_
;
...
@@ -205,25 +231,21 @@ TEST(FormatterTest, ArgErrors) {
...
@@ -205,25 +231,21 @@ TEST(FormatterTest, ArgErrors) {
EXPECT_THROW_MSG
(
Format
(
"{0"
),
FormatError
,
"unmatched '{' in format"
);
EXPECT_THROW_MSG
(
Format
(
"{0"
),
FormatError
,
"unmatched '{' in format"
);
EXPECT_THROW_MSG
(
Format
(
"{0}"
),
FormatError
,
EXPECT_THROW_MSG
(
Format
(
"{0}"
),
FormatError
,
"argument index is out of range in format"
);
"argument index is out of range in format"
);
char
format
[
256
];
char
format
[
256
];
std
::
sprintf
(
format
,
"{%u"
,
UINT_MAX
);
std
::
sprintf
(
format
,
"{%u"
,
UINT_MAX
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
std
::
sprintf
(
format
,
"{%u}"
,
UINT_MAX
);
std
::
sprintf
(
format
,
"{%u}"
,
UINT_MAX
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"argument index is out of range in format"
);
"argument index is out of range in format"
);
if
(
ULONG_MAX
>
UINT_MAX
)
{
std
::
sprintf
(
format
,
"{%lu"
,
UINT_MAX
+
1l
);
std
::
sprintf
(
format
,
"{%u"
,
UINT_MAX
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
Increment
(
format
+
1
);
std
::
sprintf
(
format
,
"{%lu}"
,
UINT_MAX
+
1l
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
EXPECT_THROW_MSG
(
Format
(
format
),
std
::
size_t
size
=
std
::
strlen
(
format
);
FormatError
,
"number is too big in format"
);
format
[
size
]
=
'}'
;
}
else
{
format
[
size
+
1
]
=
0
;
std
::
sprintf
(
format
,
"{%u0"
,
UINT_MAX
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"number is too big in format"
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
std
::
sprintf
(
format
,
"{%u0}"
,
UINT_MAX
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"number is too big in format"
);
}
}
}
TEST
(
FormatterTest
,
EmptySpecs
)
{
TEST
(
FormatterTest
,
EmptySpecs
)
{
...
@@ -275,19 +297,15 @@ TEST(FormatterTest, ZeroFlag) {
...
@@ -275,19 +297,15 @@ TEST(FormatterTest, ZeroFlag) {
TEST
(
FormatterTest
,
Width
)
{
TEST
(
FormatterTest
,
Width
)
{
char
format
[
256
];
char
format
[
256
];
if
(
ULONG_MAX
>
UINT_MAX
)
{
std
::
sprintf
(
format
,
"{0:%u"
,
UINT_MAX
);
std
::
sprintf
(
format
,
"{0:%lu"
,
INT_MAX
+
1l
);
Increment
(
format
+
3
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
std
::
sprintf
(
format
,
"{0:%lu}"
,
UINT_MAX
+
1l
);
std
::
size_t
size
=
std
::
strlen
(
format
);
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
format
[
size
]
=
'}'
;
FormatError
,
"number is too big in format"
);
format
[
size
+
1
]
=
0
;
}
else
{
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
std
::
sprintf
(
format
,
"{0:%u0"
,
UINT_MAX
);
FormatError
,
"number is too big in format"
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
std
::
sprintf
(
format
,
"{0:%u0}"
,
UINT_MAX
);
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
FormatError
,
"number is too big in format"
);
}
std
::
sprintf
(
format
,
"{0:%u"
,
INT_MAX
+
1u
);
std
::
sprintf
(
format
,
"{0:%u"
,
INT_MAX
+
1u
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
std
::
sprintf
(
format
,
"{0:%u}"
,
INT_MAX
+
1u
);
std
::
sprintf
(
format
,
"{0:%u}"
,
INT_MAX
+
1u
);
...
@@ -308,19 +326,14 @@ TEST(FormatterTest, Width) {
...
@@ -308,19 +326,14 @@ TEST(FormatterTest, Width) {
TEST
(
FormatterTest
,
Precision
)
{
TEST
(
FormatterTest
,
Precision
)
{
char
format
[
256
];
char
format
[
256
];
if
(
ULONG_MAX
>
UINT_MAX
)
{
std
::
sprintf
(
format
,
"{0:.%u"
,
UINT_MAX
);
std
::
sprintf
(
format
,
"{0:.%lu"
,
INT_MAX
+
1l
);
Increment
(
format
+
4
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
std
::
sprintf
(
format
,
"{0:.%lu}"
,
UINT_MAX
+
1l
);
std
::
size_t
size
=
std
::
strlen
(
format
);
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
format
[
size
]
=
'}'
;
FormatError
,
"number is too big in format"
);
format
[
size
+
1
]
=
0
;
}
else
{
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
std
::
sprintf
(
format
,
"{0:.%u0"
,
UINT_MAX
);
FormatError
,
"number is too big in format"
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
std
::
sprintf
(
format
,
"{0:.%u0}"
,
UINT_MAX
);
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
FormatError
,
"number is too big in format"
);
}
std
::
sprintf
(
format
,
"{0:.%u"
,
INT_MAX
+
1u
);
std
::
sprintf
(
format
,
"{0:.%u"
,
INT_MAX
+
1u
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
...
@@ -377,27 +390,17 @@ TEST(FormatterTest, Precision) {
...
@@ -377,27 +390,17 @@ TEST(FormatterTest, Precision) {
TEST
(
FormatterTest
,
RuntimePrecision
)
{
TEST
(
FormatterTest
,
RuntimePrecision
)
{
char
format
[
256
];
char
format
[
256
];
if
(
ULONG_MAX
>
UINT_MAX
)
{
std
::
sprintf
(
format
,
"{0:.{%u"
,
UINT_MAX
);
std
::
sprintf
(
format
,
"{0:.{%lu"
,
INT_MAX
+
1l
);
Increment
(
format
+
4
);
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
EXPECT_THROW_MSG
(
Format
(
format
),
FormatError
,
"unmatched '{' in format"
);
FormatError
,
"unmatched '{' in format"
);
std
::
size_t
size
=
std
::
strlen
(
format
);
std
::
sprintf
(
format
,
"{0:.{%lu}"
,
INT_MAX
+
1l
);
format
[
size
]
=
'}'
;
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
format
[
size
+
1
]
=
0
;
FormatError
,
"unmatched '{' in format"
);
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
FormatError
,
"unmatched '{' in format"
);
std
::
sprintf
(
format
,
"{0:.{%lu}}"
,
UINT_MAX
+
1l
);
format
[
size
+
1
]
=
'}'
;
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
format
[
size
+
2
]
=
0
;
FormatError
,
"number is too big in format"
);
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
}
else
{
FormatError
,
"number is too big in format"
);
std
::
sprintf
(
format
,
"{0:.{%u0"
,
UINT_MAX
);
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
FormatError
,
"unmatched '{' in format"
);
std
::
sprintf
(
format
,
"{0:.{%u0}"
,
UINT_MAX
);
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
FormatError
,
"unmatched '{' in format"
);
std
::
sprintf
(
format
,
"{0:.{%u0}}"
,
UINT_MAX
);
EXPECT_THROW_MSG
(
Format
(
format
)
<<
0
,
FormatError
,
"number is too big in format"
);
}
EXPECT_THROW_MSG
(
Format
(
"{0:.{"
)
<<
0
,
EXPECT_THROW_MSG
(
Format
(
"{0:.{"
)
<<
0
,
FormatError
,
"unmatched '{' in format"
);
FormatError
,
"unmatched '{' in format"
);
...
...
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