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
0867c1b4
Commit
0867c1b4
authored
Mar 04, 2016
by
vitaut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test writing to ostream
parent
6883d6e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
cppformat/format.cc
cppformat/format.cc
+1
-1
test/format-impl-test.cc
test/format-impl-test.cc
+55
-0
No files found.
cppformat/format.cc
View file @
0867c1b4
...
...
@@ -364,7 +364,7 @@ class CharConverter : public fmt::internal::ArgVisitor<CharConverter, void> {
};
// Write the content of w to os.
void
write
(
std
::
ostream
&
os
,
fmt
::
Memory
Writer
&
w
)
{
void
write
(
std
::
ostream
&
os
,
fmt
::
Writer
&
w
)
{
const
char
*
data
=
w
.
data
();
typedef
internal
::
MakeUnsigned
<
std
::
streamsize
>::
Type
UnsignedStreamSize
;
UnsignedStreamSize
size
=
w
.
size
();
...
...
test/format-impl-test.cc
View file @
0867c1b4
...
...
@@ -31,11 +31,14 @@
// Include format.cc instead of format.h to test implementation-specific stuff.
#include "cppformat/format.cc"
#include <algorithm>
#include <cstring>
#include "gmock/gmock.h"
#include "gtest-extra.h"
#include "util.h"
#undef min
#undef max
TEST
(
FormatTest
,
ArgConverter
)
{
...
...
@@ -119,3 +122,55 @@ TEST(FormatTest, FormatErrorCode) {
EXPECT_EQ
(
msg
,
w
.
str
());
}
}
TEST
(
FormatTest
,
WriteToOStream
)
{
std
::
ostringstream
os
;
fmt
::
MemoryWriter
w
;
w
<<
"foo"
;
fmt
::
write
(
os
,
w
);
EXPECT_EQ
(
"foo"
,
os
.
str
());
}
TEST
(
FormatTest
,
WriteToOStreamMaxSize
)
{
std
::
size_t
max_size
=
std
::
numeric_limits
<
std
::
size_t
>::
max
();
std
::
streamsize
max_streamsize
=
std
::
numeric_limits
<
std
::
streamsize
>::
max
();
if
(
max_size
<=
fmt
::
internal
::
to_unsigned
(
max_streamsize
))
return
;
class
TestWriter
:
public
fmt
::
BasicWriter
<
char
>
{
private:
struct
TestBuffer
:
fmt
::
Buffer
<
char
>
{
explicit
TestBuffer
(
std
::
size_t
size
)
{
size_
=
size
;
}
void
grow
(
std
::
size_t
)
{}
}
buffer_
;
public:
explicit
TestWriter
(
std
::
size_t
size
)
:
fmt
::
BasicWriter
<
char
>
(
buffer_
),
buffer_
(
size
)
{}
}
w
(
max_size
);
struct
MockStreamBuf
:
std
::
streambuf
{
MOCK_METHOD2
(
xsputn
,
std
::
streamsize
(
const
void
*
s
,
std
::
streamsize
n
));
std
::
streamsize
xsputn
(
const
char
*
s
,
std
::
streamsize
n
)
{
const
void
*
v
=
s
;
return
xsputn
(
v
,
n
);
}
}
buffer
;
struct
TestOStream
:
std
::
ostream
{
explicit
TestOStream
(
MockStreamBuf
&
buffer
)
:
std
::
ostream
(
&
buffer
)
{}
}
os
(
buffer
);
testing
::
InSequence
sequence
;
const
char
*
data
=
0
;
std
::
size_t
size
=
max_size
;
do
{
typedef
fmt
::
internal
::
MakeUnsigned
<
std
::
streamsize
>::
Type
UStreamSize
;
UStreamSize
n
=
std
::
min
<
UStreamSize
>
(
size
,
fmt
::
internal
::
to_unsigned
(
max_streamsize
));
EXPECT_CALL
(
buffer
,
xsputn
(
data
,
static_cast
<
std
::
streamsize
>
(
n
)))
.
WillOnce
(
testing
::
Return
(
max_streamsize
));
data
+=
n
;
size
-=
n
;
}
while
(
size
!=
0
);
fmt
::
write
(
os
,
w
);
}
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