Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: net/quic/platform/api/quic_str_cat_test.cc

Issue 2591143003: Add QuicStrCat. (Closed)
Patch Set: sync Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/platform/api/quic_str_cat.h ('k') | net/quic/platform/impl/quic_str_cat_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/quic/platform/api/quic_str_cat.h"
6
7 #include "base/strings/string_piece.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 using base::StringPiece;
11 using std::string;
12
13 namespace net {
14 namespace test {
15 namespace {
16
17 TEST(QuicStrCatTest, Ints) {
18 const int16_t s = -1;
19 const uint16_t us = 2;
20 const int i = -3;
21 const uint32_t ui = 4;
22 const int64_t l = -5;
23 const uint64_t ul = 6;
24 const ptrdiff_t ptrdiff = -7;
25 const size_t size = 8;
26 const intptr_t intptr = -9;
27 const uintptr_t uintptr = 10;
28 string answer;
29 answer = QuicStrCat(s, us);
30 EXPECT_EQ(answer, "-12");
31 answer = QuicStrCat(i, ui);
32 EXPECT_EQ(answer, "-34");
33 answer = QuicStrCat(l, ul);
34 EXPECT_EQ(answer, "-56");
35 answer = QuicStrCat(ptrdiff, size);
36 EXPECT_EQ(answer, "-78");
37 answer = QuicStrCat(size, intptr);
38 EXPECT_EQ(answer, "8-9");
39 answer = QuicStrCat(uintptr, 0);
40 EXPECT_EQ(answer, "100");
41 }
42
43 TEST(QuicStrCatTest, Basics) {
44 string result;
45
46 string strs[] = {"Hello", "Cruel", "World"};
47
48 StringPiece pieces[] = {"Hello", "Cruel", "World"};
49
50 const char* c_strs[] = {"Hello", "Cruel", "World"};
51
52 int32_t i32s[] = {'H', 'C', 'W'};
53 uint64_t ui64s[] = {12345678910LL, 10987654321LL};
54
55 result = QuicStrCat(false, true, 2, 3);
56 EXPECT_EQ(result, "0123");
57
58 result = QuicStrCat(-1);
59 EXPECT_EQ(result, "-1");
60
61 result = QuicStrCat(0.5);
62 EXPECT_EQ(result, "0.5");
63
64 result = QuicStrCat(strs[1], pieces[2]);
65 EXPECT_EQ(result, "CruelWorld");
66
67 result = QuicStrCat(strs[0], ", ", pieces[2]);
68 EXPECT_EQ(result, "Hello, World");
69
70 result = QuicStrCat(strs[0], ", ", strs[1], " ", strs[2], "!");
71 EXPECT_EQ(result, "Hello, Cruel World!");
72
73 result = QuicStrCat(pieces[0], ", ", pieces[1], " ", pieces[2]);
74 EXPECT_EQ(result, "Hello, Cruel World");
75
76 result = QuicStrCat(c_strs[0], ", ", c_strs[1], " ", c_strs[2]);
77 EXPECT_EQ(result, "Hello, Cruel World");
78
79 result = QuicStrCat("ASCII ", i32s[0], ", ", i32s[1], " ", i32s[2], "!");
80 EXPECT_EQ(result, "ASCII 72, 67 87!");
81
82 result = QuicStrCat(ui64s[0], ", ", ui64s[1], "!");
83 EXPECT_EQ(result, "12345678910, 10987654321!");
84
85 string one = "1";
86 result = QuicStrCat("And a ", one.size(), " and a ", &result[2] - &result[0],
87 " and a ", one, " 2 3 4", "!");
88 EXPECT_EQ(result, "And a 1 and a 2 and a 1 2 3 4!");
89
90 result =
91 QuicStrCat("To output a char by ASCII/numeric value, use +: ", '!' + 0);
92 EXPECT_EQ(result, "To output a char by ASCII/numeric value, use +: 33");
93
94 float f = 10000.5;
95 result = QuicStrCat("Ten K and a half is ", f);
96 EXPECT_EQ(result, "Ten K and a half is 10000.5");
97
98 double d = 99999.9;
99 result = QuicStrCat("This double number is ", d);
100 EXPECT_EQ(result, "This double number is 99999.9");
101
102 result =
103 QuicStrCat(1, 22, 333, 4444, 55555, 666666, 7777777, 88888888, 999999999);
104 EXPECT_EQ(result, "122333444455555666666777777788888888999999999");
105 }
106
107 TEST(QuicStrCatTest, MaxArgs) {
108 string result;
109 // Test 10 up to 26 arguments, the current maximum
110 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a");
111 EXPECT_EQ(result, "123456789a");
112 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b");
113 EXPECT_EQ(result, "123456789ab");
114 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c");
115 EXPECT_EQ(result, "123456789abc");
116 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d");
117 EXPECT_EQ(result, "123456789abcd");
118 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e");
119 EXPECT_EQ(result, "123456789abcde");
120 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f");
121 EXPECT_EQ(result, "123456789abcdef");
122 result =
123 QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f", "g");
124 EXPECT_EQ(result, "123456789abcdefg");
125 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
126 "g", "h");
127 EXPECT_EQ(result, "123456789abcdefgh");
128 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
129 "g", "h", "i");
130 EXPECT_EQ(result, "123456789abcdefghi");
131 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
132 "g", "h", "i", "j");
133 EXPECT_EQ(result, "123456789abcdefghij");
134 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
135 "g", "h", "i", "j", "k");
136 EXPECT_EQ(result, "123456789abcdefghijk");
137 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
138 "g", "h", "i", "j", "k", "l");
139 EXPECT_EQ(result, "123456789abcdefghijkl");
140 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
141 "g", "h", "i", "j", "k", "l", "m");
142 EXPECT_EQ(result, "123456789abcdefghijklm");
143 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
144 "g", "h", "i", "j", "k", "l", "m", "n");
145 EXPECT_EQ(result, "123456789abcdefghijklmn");
146 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
147 "g", "h", "i", "j", "k", "l", "m", "n", "o");
148 EXPECT_EQ(result, "123456789abcdefghijklmno");
149 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
150 "g", "h", "i", "j", "k", "l", "m", "n", "o", "p");
151 EXPECT_EQ(result, "123456789abcdefghijklmnop");
152 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
153 "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q");
154 EXPECT_EQ(result, "123456789abcdefghijklmnopq");
155 // No limit thanks to C++11's variadic templates
156 result = QuicStrCat(
157 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "a", "b", "c", "d", "e", "f", "g", "h",
158 "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
159 "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
160 "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
161 EXPECT_EQ(result,
162 "12345678910abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
163 }
164
165 } // namespace
166 } // namespace test
167 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/platform/api/quic_str_cat.h ('k') | net/quic/platform/impl/quic_str_cat_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698