| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/spdy/platform/api/spdy_string_utils.h" | 5 #include "net/spdy/platform/api/spdy_string_utils.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 | 8 |
| 9 #include "net/spdy/platform/api/spdy_string_piece.h" | 9 #include "net/spdy/platform/api/spdy_string_piece.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 namespace test { | 13 namespace test { |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 TEST(SpdyStrUtilsTest, StrCat) { | 16 TEST(SpdyStrUtilsTest, SpdyStrCat) { |
| 17 // No arguments. | 17 // No arguments. |
| 18 EXPECT_EQ("", SpdyStrCat()); | 18 EXPECT_EQ("", SpdyStrCat()); |
| 19 | 19 |
| 20 // Single string-like argument. | 20 // Single string-like argument. |
| 21 const char kFoo[] = "foo"; | 21 const char kFoo[] = "foo"; |
| 22 const std::string string_foo(kFoo); | 22 const std::string string_foo(kFoo); |
| 23 const SpdyStringPiece stringpiece_foo(string_foo); | 23 const SpdyStringPiece stringpiece_foo(string_foo); |
| 24 EXPECT_EQ("foo", SpdyStrCat(kFoo)); | 24 EXPECT_EQ("foo", SpdyStrCat(kFoo)); |
| 25 EXPECT_EQ("foo", SpdyStrCat(string_foo)); | 25 EXPECT_EQ("foo", SpdyStrCat(string_foo)); |
| 26 EXPECT_EQ("foo", SpdyStrCat(stringpiece_foo)); | 26 EXPECT_EQ("foo", SpdyStrCat(stringpiece_foo)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 EXPECT_EQ("0", SpdyStrCat(f)); | 63 EXPECT_EQ("0", SpdyStrCat(f)); |
| 64 EXPECT_EQ("0110", SpdyStrCat(f, t, t, f)); | 64 EXPECT_EQ("0110", SpdyStrCat(f, t, t, f)); |
| 65 | 65 |
| 66 // Mixed string-like, numerical, and Boolean arguments. | 66 // Mixed string-like, numerical, and Boolean arguments. |
| 67 EXPECT_EQ("foo1foo081bar3.14151", | 67 EXPECT_EQ("foo1foo081bar3.14151", |
| 68 SpdyStrCat(kFoo, i, string_foo, f, u, t, stringpiece_bar, d, t)); | 68 SpdyStrCat(kFoo, i, string_foo, f, u, t, stringpiece_bar, d, t)); |
| 69 EXPECT_EQ("3.141511bar18bar13.14150", | 69 EXPECT_EQ("3.141511bar18bar13.14150", |
| 70 SpdyStrCat(d, t, t, string_bar, i, u, kBar, t, d, f)); | 70 SpdyStrCat(d, t, t, string_bar, i, u, kBar, t, d, f)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 TEST(SpdyStrUtilsTest, StrAppend) { | 73 TEST(SpdyStrUtilsTest, SpdyStrAppend) { |
| 74 // No arguments on empty string. | 74 // No arguments on empty string. |
| 75 std::string output; | 75 std::string output; |
| 76 SpdyStrAppend(&output); | 76 SpdyStrAppend(&output); |
| 77 EXPECT_TRUE(output.empty()); | 77 EXPECT_TRUE(output.empty()); |
| 78 | 78 |
| 79 // Single string-like argument. | 79 // Single string-like argument. |
| 80 const char kFoo[] = "foo"; | 80 const char kFoo[] = "foo"; |
| 81 const std::string string_foo(kFoo); | 81 const std::string string_foo(kFoo); |
| 82 const SpdyStringPiece stringpiece_foo(string_foo); | 82 const SpdyStringPiece stringpiece_foo(string_foo); |
| 83 SpdyStrAppend(&output, kFoo); | 83 SpdyStrAppend(&output, kFoo); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 output.clear(); | 159 output.clear(); |
| 160 | 160 |
| 161 // Mixed string-like, numerical, and Boolean arguments. | 161 // Mixed string-like, numerical, and Boolean arguments. |
| 162 SpdyStrAppend(&output, kFoo, i, string_foo, f, u, t, stringpiece_bar, d, t); | 162 SpdyStrAppend(&output, kFoo, i, string_foo, f, u, t, stringpiece_bar, d, t); |
| 163 EXPECT_EQ("foo1foo081bar3.14151", output); | 163 EXPECT_EQ("foo1foo081bar3.14151", output); |
| 164 SpdyStrAppend(&output, d, t, t, string_bar, i, u, kBar, t, d, f); | 164 SpdyStrAppend(&output, d, t, t, string_bar, i, u, kBar, t, d, f); |
| 165 EXPECT_EQ("foo1foo081bar3.141513.141511bar18bar13.14150", output); | 165 EXPECT_EQ("foo1foo081bar3.141513.141511bar18bar13.14150", output); |
| 166 } | 166 } |
| 167 | 167 |
| 168 TEST(SpdyStrUtilsTest, StringPrintf) { | 168 TEST(SpdyStrUtilsTest, SpdyStringPrintf) { |
| 169 EXPECT_EQ("", SpdyStringPrintf("%s", "")); | 169 EXPECT_EQ("", SpdyStringPrintf("%s", "")); |
| 170 EXPECT_EQ("foobar", SpdyStringPrintf("%sbar", "foo")); | 170 EXPECT_EQ("foobar", SpdyStringPrintf("%sbar", "foo")); |
| 171 EXPECT_EQ("foobar", SpdyStringPrintf("%s%s", "foo", "bar")); | 171 EXPECT_EQ("foobar", SpdyStringPrintf("%s%s", "foo", "bar")); |
| 172 EXPECT_EQ("foo: 1, bar: 2.0", SpdyStringPrintf("foo: %d, bar: %.1f", 1, 2.0)); | 172 EXPECT_EQ("foo: 1, bar: 2.0", SpdyStringPrintf("foo: %d, bar: %.1f", 1, 2.0)); |
| 173 } | 173 } |
| 174 | 174 |
| 175 TEST(SpdyStrUtilsTest, SpdyStringAppendF) { |
| 176 std::string output; |
| 177 |
| 178 SpdyStringAppendF(&output, "%s", ""); |
| 179 EXPECT_TRUE(output.empty()); |
| 180 |
| 181 SpdyStringAppendF(&output, "%sbar", "foo"); |
| 182 EXPECT_EQ("foobar", output); |
| 183 |
| 184 SpdyStringAppendF(&output, "%s%s", "foo", "bar"); |
| 185 EXPECT_EQ("foobarfoobar", output); |
| 186 |
| 187 SpdyStringAppendF(&output, "foo: %d, bar: %.1f", 1, 2.0); |
| 188 EXPECT_EQ("foobarfoobarfoo: 1, bar: 2.0", output); |
| 189 } |
| 190 |
| 175 } // namespace | 191 } // namespace |
| 176 } // namespace test | 192 } // namespace test |
| 177 } // namespace net | 193 } // namespace net |
| OLD | NEW |