| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/quic/platform/api/quic_str_cat.h" | 5 #include "net/quic/platform/api/quic_str_cat.h" |
| 6 | 6 |
| 7 #include "net/quic/platform/api/quic_string_piece.h" | 7 #include "net/quic/platform/api/quic_string_piece.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "net/quic/platform/api/quic_test.h" |
| 9 | 9 |
| 10 using std::string; | 10 using std::string; |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 namespace test { | 13 namespace test { |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 TEST(QuicStrCatTest, Ints) { | 16 class QuicStrCatTest : public QuicTest {}; |
| 17 |
| 18 TEST_F(QuicStrCatTest, Ints) { |
| 17 const int16_t s = -1; | 19 const int16_t s = -1; |
| 18 const uint16_t us = 2; | 20 const uint16_t us = 2; |
| 19 const int i = -3; | 21 const int i = -3; |
| 20 const uint32_t ui = 4; | 22 const uint32_t ui = 4; |
| 21 const int64_t l = -5; | 23 const int64_t l = -5; |
| 22 const uint64_t ul = 6; | 24 const uint64_t ul = 6; |
| 23 const ptrdiff_t ptrdiff = -7; | 25 const ptrdiff_t ptrdiff = -7; |
| 24 const size_t size = 8; | 26 const size_t size = 8; |
| 25 const intptr_t intptr = -9; | 27 const intptr_t intptr = -9; |
| 26 const uintptr_t uintptr = 10; | 28 const uintptr_t uintptr = 10; |
| 27 string answer; | 29 string answer; |
| 28 answer = QuicStrCat(s, us); | 30 answer = QuicStrCat(s, us); |
| 29 EXPECT_EQ(answer, "-12"); | 31 EXPECT_EQ(answer, "-12"); |
| 30 answer = QuicStrCat(i, ui); | 32 answer = QuicStrCat(i, ui); |
| 31 EXPECT_EQ(answer, "-34"); | 33 EXPECT_EQ(answer, "-34"); |
| 32 answer = QuicStrCat(l, ul); | 34 answer = QuicStrCat(l, ul); |
| 33 EXPECT_EQ(answer, "-56"); | 35 EXPECT_EQ(answer, "-56"); |
| 34 answer = QuicStrCat(ptrdiff, size); | 36 answer = QuicStrCat(ptrdiff, size); |
| 35 EXPECT_EQ(answer, "-78"); | 37 EXPECT_EQ(answer, "-78"); |
| 36 answer = QuicStrCat(size, intptr); | 38 answer = QuicStrCat(size, intptr); |
| 37 EXPECT_EQ(answer, "8-9"); | 39 EXPECT_EQ(answer, "8-9"); |
| 38 answer = QuicStrCat(uintptr, 0); | 40 answer = QuicStrCat(uintptr, 0); |
| 39 EXPECT_EQ(answer, "100"); | 41 EXPECT_EQ(answer, "100"); |
| 40 } | 42 } |
| 41 | 43 |
| 42 TEST(QuicStrCatTest, Basics) { | 44 TEST_F(QuicStrCatTest, Basics) { |
| 43 string result; | 45 string result; |
| 44 | 46 |
| 45 string strs[] = {"Hello", "Cruel", "World"}; | 47 string strs[] = {"Hello", "Cruel", "World"}; |
| 46 | 48 |
| 47 QuicStringPiece pieces[] = {"Hello", "Cruel", "World"}; | 49 QuicStringPiece pieces[] = {"Hello", "Cruel", "World"}; |
| 48 | 50 |
| 49 const char* c_strs[] = {"Hello", "Cruel", "World"}; | 51 const char* c_strs[] = {"Hello", "Cruel", "World"}; |
| 50 | 52 |
| 51 int32_t i32s[] = {'H', 'C', 'W'}; | 53 int32_t i32s[] = {'H', 'C', 'W'}; |
| 52 uint64_t ui64s[] = {12345678910LL, 10987654321LL}; | 54 uint64_t ui64s[] = {12345678910LL, 10987654321LL}; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 98 |
| 97 double d = 99999.9; | 99 double d = 99999.9; |
| 98 result = QuicStrCat("This double number is ", d); | 100 result = QuicStrCat("This double number is ", d); |
| 99 EXPECT_EQ(result, "This double number is 99999.9"); | 101 EXPECT_EQ(result, "This double number is 99999.9"); |
| 100 | 102 |
| 101 result = | 103 result = |
| 102 QuicStrCat(1, 22, 333, 4444, 55555, 666666, 7777777, 88888888, 999999999); | 104 QuicStrCat(1, 22, 333, 4444, 55555, 666666, 7777777, 88888888, 999999999); |
| 103 EXPECT_EQ(result, "122333444455555666666777777788888888999999999"); | 105 EXPECT_EQ(result, "122333444455555666666777777788888888999999999"); |
| 104 } | 106 } |
| 105 | 107 |
| 106 TEST(QuicStrCatTest, MaxArgs) { | 108 TEST_F(QuicStrCatTest, MaxArgs) { |
| 107 string result; | 109 string result; |
| 108 // Test 10 up to 26 arguments, the current maximum | 110 // Test 10 up to 26 arguments, the current maximum |
| 109 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a"); | 111 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a"); |
| 110 EXPECT_EQ(result, "123456789a"); | 112 EXPECT_EQ(result, "123456789a"); |
| 111 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b"); | 113 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b"); |
| 112 EXPECT_EQ(result, "123456789ab"); | 114 EXPECT_EQ(result, "123456789ab"); |
| 113 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c"); | 115 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c"); |
| 114 EXPECT_EQ(result, "123456789abc"); | 116 EXPECT_EQ(result, "123456789abc"); |
| 115 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d"); | 117 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d"); |
| 116 EXPECT_EQ(result, "123456789abcd"); | 118 EXPECT_EQ(result, "123456789abcd"); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", | 159 "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", |
| 158 "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", | 160 "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", |
| 159 "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); | 161 "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); |
| 160 EXPECT_EQ(result, | 162 EXPECT_EQ(result, |
| 161 "12345678910abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); | 163 "12345678910abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
| 162 } | 164 } |
| 163 | 165 |
| 164 } // namespace | 166 } // namespace |
| 165 } // namespace test | 167 } // namespace test |
| 166 } // namespace net | 168 } // namespace net |
| OLD | NEW |