Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
0fbeac8f
Commit
0fbeac8f
authored
Mar 22, 2014
by
Jesse Beder
Browse files
Add more ostream_wrapper tests
parent
396a9705
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
7 deletions
+58
-7
include/yaml-cpp/ostream_wrapper.h
include/yaml-cpp/ostream_wrapper.h
+1
-1
test/ostream_wrapper_test.cpp
test/ostream_wrapper_test.cpp
+57
-6
No files found.
include/yaml-cpp/ostream_wrapper.h
View file @
0fbeac8f
...
@@ -41,7 +41,7 @@ class ostream_wrapper {
...
@@ -41,7 +41,7 @@ class ostream_wrapper {
private:
private:
mutable
std
::
vector
<
char
>
m_buffer
;
mutable
std
::
vector
<
char
>
m_buffer
;
std
::
ostream
*
m_pStream
;
std
::
ostream
*
const
m_pStream
;
std
::
size_t
m_pos
;
std
::
size_t
m_pos
;
std
::
size_t
m_row
,
m_col
;
std
::
size_t
m_row
,
m_col
;
...
...
test/ostream_wrapper_test.cpp
View file @
0fbeac8f
#include "yaml-cpp/ostream_wrapper.h"
#include "yaml-cpp/ostream_wrapper.h"
#include <sstream>
#include "gtest/gtest.h"
#include "gtest/gtest.h"
namespace
{
namespace
{
class
OstreamWrapperTest
:
public
::
testing
::
Test
{
TEST
(
OstreamWrapperTest
,
BufferNoWrite
)
{
protected:
};
// Tests that the Foo::Bar() method does Abc.
TEST_F
(
OstreamWrapperTest
,
ConstructNoWrite
)
{
YAML
::
ostream_wrapper
wrapper
;
YAML
::
ostream_wrapper
wrapper
;
EXPECT_STREQ
(
""
,
wrapper
.
str
());
EXPECT_STREQ
(
""
,
wrapper
.
str
());
}
}
TEST
(
OstreamWrapperTest
,
BufferWriteStr
)
{
YAML
::
ostream_wrapper
wrapper
;
wrapper
.
write
(
std
::
string
(
"Hello, world"
));
EXPECT_STREQ
(
"Hello, world"
,
wrapper
.
str
());
}
TEST
(
OstreamWrapperTest
,
BufferWriteCStr
)
{
YAML
::
ostream_wrapper
wrapper
;
wrapper
.
write
(
"Hello, world"
);
EXPECT_STREQ
(
"Hello, world"
,
wrapper
.
str
());
}
TEST
(
OstreamWrapperTest
,
StreamNoWrite
)
{
std
::
stringstream
stream
;
YAML
::
ostream_wrapper
wrapper
(
stream
);
EXPECT_STREQ
(
NULL
,
wrapper
.
str
());
EXPECT_EQ
(
""
,
stream
.
str
());
}
TEST
(
OstreamWrapperTest
,
StreamWriteStr
)
{
std
::
stringstream
stream
;
YAML
::
ostream_wrapper
wrapper
(
stream
);
wrapper
.
write
(
std
::
string
(
"Hello, world"
));
EXPECT_STREQ
(
NULL
,
wrapper
.
str
());
EXPECT_EQ
(
"Hello, world"
,
stream
.
str
());
}
TEST
(
OstreamWrapperTest
,
StreamWriteCStr
)
{
std
::
stringstream
stream
;
YAML
::
ostream_wrapper
wrapper
(
stream
);
wrapper
.
write
(
"Hello, world"
);
EXPECT_STREQ
(
NULL
,
wrapper
.
str
());
EXPECT_EQ
(
"Hello, world"
,
stream
.
str
());
}
TEST
(
OstreamWrapperTest
,
Position
)
{
YAML
::
ostream_wrapper
wrapper
;
wrapper
.
write
(
"Hello, world
\n
"
);
EXPECT_EQ
(
1
,
wrapper
.
row
());
EXPECT_EQ
(
0
,
wrapper
.
col
());
EXPECT_EQ
(
13
,
wrapper
.
pos
());
}
TEST
(
OstreamWrapperTest
,
Comment
)
{
YAML
::
ostream_wrapper
wrapper
;
wrapper
.
write
(
"Hello, world "
);
wrapper
.
set_comment
();
EXPECT_TRUE
(
wrapper
.
comment
());
wrapper
.
write
(
"foo"
);
EXPECT_TRUE
(
wrapper
.
comment
());
wrapper
.
write
(
"
\n
"
);
EXPECT_FALSE
(
wrapper
.
comment
());
}
}
}
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