| 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(SpdyStringUtilsTest, SpdyStrCat) { | 16 TEST(SpdyStringUtilsTest, 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 SpdyString 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)); |
| 27 | 27 |
| 28 // Two string-like arguments. | 28 // Two string-like arguments. |
| 29 const char kBar[] = "bar"; | 29 const char kBar[] = "bar"; |
| 30 const SpdyStringPiece stringpiece_bar(kBar); | 30 const SpdyStringPiece stringpiece_bar(kBar); |
| 31 const std::string string_bar(kBar); | 31 const SpdyString string_bar(kBar); |
| 32 EXPECT_EQ("foobar", SpdyStrCat(kFoo, kBar)); | 32 EXPECT_EQ("foobar", SpdyStrCat(kFoo, kBar)); |
| 33 EXPECT_EQ("foobar", SpdyStrCat(kFoo, string_bar)); | 33 EXPECT_EQ("foobar", SpdyStrCat(kFoo, string_bar)); |
| 34 EXPECT_EQ("foobar", SpdyStrCat(kFoo, stringpiece_bar)); | 34 EXPECT_EQ("foobar", SpdyStrCat(kFoo, stringpiece_bar)); |
| 35 EXPECT_EQ("foobar", SpdyStrCat(string_foo, kBar)); | 35 EXPECT_EQ("foobar", SpdyStrCat(string_foo, kBar)); |
| 36 EXPECT_EQ("foobar", SpdyStrCat(string_foo, string_bar)); | 36 EXPECT_EQ("foobar", SpdyStrCat(string_foo, string_bar)); |
| 37 EXPECT_EQ("foobar", SpdyStrCat(string_foo, stringpiece_bar)); | 37 EXPECT_EQ("foobar", SpdyStrCat(string_foo, stringpiece_bar)); |
| 38 EXPECT_EQ("foobar", SpdyStrCat(stringpiece_foo, kBar)); | 38 EXPECT_EQ("foobar", SpdyStrCat(stringpiece_foo, kBar)); |
| 39 EXPECT_EQ("foobar", SpdyStrCat(stringpiece_foo, string_bar)); | 39 EXPECT_EQ("foobar", SpdyStrCat(stringpiece_foo, string_bar)); |
| 40 EXPECT_EQ("foobar", SpdyStrCat(stringpiece_foo, stringpiece_bar)); | 40 EXPECT_EQ("foobar", SpdyStrCat(stringpiece_foo, stringpiece_bar)); |
| 41 | 41 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 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(SpdyStringUtilsTest, SpdyStrAppend) { | 73 TEST(SpdyStringUtilsTest, SpdyStrAppend) { |
| 74 // No arguments on empty string. | 74 // No arguments on empty string. |
| 75 std::string output; | 75 SpdyString 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 SpdyString 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); |
| 84 EXPECT_EQ("foo", output); | 84 EXPECT_EQ("foo", output); |
| 85 SpdyStrAppend(&output, string_foo); | 85 SpdyStrAppend(&output, string_foo); |
| 86 EXPECT_EQ("foofoo", output); | 86 EXPECT_EQ("foofoo", output); |
| 87 SpdyStrAppend(&output, stringpiece_foo); | 87 SpdyStrAppend(&output, stringpiece_foo); |
| 88 EXPECT_EQ("foofoofoo", output); | 88 EXPECT_EQ("foofoofoo", output); |
| 89 | 89 |
| 90 // No arguments on non-empty string. | 90 // No arguments on non-empty string. |
| 91 SpdyStrAppend(&output); | 91 SpdyStrAppend(&output); |
| 92 EXPECT_EQ("foofoofoo", output); | 92 EXPECT_EQ("foofoofoo", output); |
| 93 | 93 |
| 94 output.clear(); | 94 output.clear(); |
| 95 | 95 |
| 96 // Two string-like arguments. | 96 // Two string-like arguments. |
| 97 const char kBar[] = "bar"; | 97 const char kBar[] = "bar"; |
| 98 const SpdyStringPiece stringpiece_bar(kBar); | 98 const SpdyStringPiece stringpiece_bar(kBar); |
| 99 const std::string string_bar(kBar); | 99 const SpdyString string_bar(kBar); |
| 100 SpdyStrAppend(&output, kFoo, kBar); | 100 SpdyStrAppend(&output, kFoo, kBar); |
| 101 EXPECT_EQ("foobar", output); | 101 EXPECT_EQ("foobar", output); |
| 102 SpdyStrAppend(&output, kFoo, string_bar); | 102 SpdyStrAppend(&output, kFoo, string_bar); |
| 103 EXPECT_EQ("foobarfoobar", output); | 103 EXPECT_EQ("foobarfoobar", output); |
| 104 SpdyStrAppend(&output, kFoo, stringpiece_bar); | 104 SpdyStrAppend(&output, kFoo, stringpiece_bar); |
| 105 EXPECT_EQ("foobarfoobarfoobar", output); | 105 EXPECT_EQ("foobarfoobarfoobar", output); |
| 106 SpdyStrAppend(&output, string_foo, kBar); | 106 SpdyStrAppend(&output, string_foo, kBar); |
| 107 EXPECT_EQ("foobarfoobarfoobarfoobar", output); | 107 EXPECT_EQ("foobarfoobarfoobarfoobar", output); |
| 108 | 108 |
| 109 output.clear(); | 109 output.clear(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 166 } |
| 167 | 167 |
| 168 TEST(SpdyStringUtilsTest, SpdyStringPrintf) { | 168 TEST(SpdyStringUtilsTest, 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(SpdyStringUtilsTest, SpdyStringAppendF) { | 175 TEST(SpdyStringUtilsTest, SpdyStringAppendF) { |
| 176 std::string output; | 176 SpdyString output; |
| 177 | 177 |
| 178 SpdyStringAppendF(&output, "%s", ""); | 178 SpdyStringAppendF(&output, "%s", ""); |
| 179 EXPECT_TRUE(output.empty()); | 179 EXPECT_TRUE(output.empty()); |
| 180 | 180 |
| 181 SpdyStringAppendF(&output, "%sbar", "foo"); | 181 SpdyStringAppendF(&output, "%sbar", "foo"); |
| 182 EXPECT_EQ("foobar", output); | 182 EXPECT_EQ("foobar", output); |
| 183 | 183 |
| 184 SpdyStringAppendF(&output, "%s%s", "foo", "bar"); | 184 SpdyStringAppendF(&output, "%s%s", "foo", "bar"); |
| 185 EXPECT_EQ("foobarfoobar", output); | 185 EXPECT_EQ("foobarfoobar", output); |
| 186 | 186 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 211 EXPECT_EQ(11, SpdyHexDigitToInt('B')); | 211 EXPECT_EQ(11, SpdyHexDigitToInt('B')); |
| 212 EXPECT_EQ(12, SpdyHexDigitToInt('C')); | 212 EXPECT_EQ(12, SpdyHexDigitToInt('C')); |
| 213 EXPECT_EQ(13, SpdyHexDigitToInt('D')); | 213 EXPECT_EQ(13, SpdyHexDigitToInt('D')); |
| 214 EXPECT_EQ(14, SpdyHexDigitToInt('E')); | 214 EXPECT_EQ(14, SpdyHexDigitToInt('E')); |
| 215 EXPECT_EQ(15, SpdyHexDigitToInt('F')); | 215 EXPECT_EQ(15, SpdyHexDigitToInt('F')); |
| 216 } | 216 } |
| 217 | 217 |
| 218 } // namespace | 218 } // namespace |
| 219 } // namespace test | 219 } // namespace test |
| 220 } // namespace net | 220 } // namespace net |
| OLD | NEW |