diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2017-06-27 10:15:48 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-27 14:50:01 +0000 |
commit | 44dd818b4df46ca9a6b6aae96b20b606253196eb (patch) | |
tree | 5c4f065955df6cfff29dcab6e652e3c67ac43af0 /core/fxcrt/cfx_bytestring_unittest.cpp | |
parent | 3bcabf323f096156545d279c6381317fbc7fbd5a (diff) | |
download | pdfium-44dd818b4df46ca9a6b6aae96b20b606253196eb.tar.xz |
Adding overload for ostream << CFX_ByteString
Bug: pdfium:731
Change-Id: I285332c8f9d988327e8633cb0746af2b76c401e5
Reviewed-on: https://pdfium-review.googlesource.com/6911
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_bytestring_unittest.cpp')
-rw-r--r-- | core/fxcrt/cfx_bytestring_unittest.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_bytestring_unittest.cpp b/core/fxcrt/cfx_bytestring_unittest.cpp index 609f89201b..86fa3830c2 100644 --- a/core/fxcrt/cfx_bytestring_unittest.cpp +++ b/core/fxcrt/cfx_bytestring_unittest.cpp @@ -1259,3 +1259,45 @@ TEST(fxcrt, EqualNoCase) { EXPECT_FALSE(str.EqualNoCase("a")); EXPECT_FALSE(str.EqualNoCase("")); } + +TEST(fxcrt, OStreamByteStringOverload) { + // Basic case + std::ostringstream stream; + CFX_ByteString str("def"); + stream << "abc" << str << "ghi"; + EXPECT_EQ("abcdefghi", stream.str()); + + // Changing the CFX_ByteString does not change the stream it was written to. + str = "123"; + EXPECT_EQ("abcdefghi", stream.str()); + + // Writing it again to the stream will use the latest value. + stream.str(""); + stream << "abc" << str << "ghi"; + EXPECT_EQ("abc123ghi", stream.str()); + + char stringWithNulls[]{'x', 'y', '\0', 'z'}; + + // Writing a CFX_ByteString with nulls and no specified length treats it as + // a C-style null-terminated string. + str = CFX_ByteString(stringWithNulls); + EXPECT_EQ(2, str.GetLength()); + stream.str(""); + stream << str; + EXPECT_EQ(2u, stream.tellp()); + + // Writing a CFX_ByteString with nulls but specifying its length treats it as + // a C++-style string. + str = CFX_ByteString(stringWithNulls, 4); + EXPECT_EQ(4, str.GetLength()); + stream.str(""); + stream << str; + EXPECT_EQ(4u, stream.tellp()); + + // << operators can be chained. + CFX_ByteString str1("abc"); + CFX_ByteString str2("def"); + stream.str(""); + stream << str1 << str2; + EXPECT_EQ("abcdef", stream.str()); +} |