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

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

Issue 2591143003: Add QuicStrCat. (Closed)
Patch Set: fix include 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 uint ui = 4;
Ryan Hamilton 2016/12/22 23:33:53 I think this is not a valid type on windows.
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 ssize_t ssize = -9;
27 const intptr_t intptr = -10;
28 const uintptr_t uintptr = 11;
29 string answer;
30 answer = QuicStrCat(s, us);
31 EXPECT_EQ(answer, "-12");
32 answer = QuicStrCat(i, ui);
33 EXPECT_EQ(answer, "-34");
34 answer = QuicStrCat(l, ul);
35 EXPECT_EQ(answer, "-56");
36 answer = QuicStrCat(ptrdiff, size);
37 EXPECT_EQ(answer, "-78");
38 answer = QuicStrCat(ssize, intptr);
39 EXPECT_EQ(answer, "-9-10");
40 answer = QuicStrCat(uintptr, 0);
41 EXPECT_EQ(answer, "110");
42 }
43
44 TEST(QuicStrCatTest, Basics) {
45 string result;
46
47 string strs[] = {"Hello", "Cruel", "World"};
48
49 StringPiece pieces[] = {"Hello", "Cruel", "World"};
50
51 const char* c_strs[] = {"Hello", "Cruel", "World"};
52
53 int32_t i32s[] = {'H', 'C', 'W'};
54 uint64_t ui64s[] = {12345678910LL, 10987654321LL};
55
56 result = QuicStrCat(false, true, 2, 3);
57 EXPECT_EQ(result, "0123");
58
59 result = QuicStrCat(-1);
60 EXPECT_EQ(result, "-1");
61
62 result = QuicStrCat(0.5);
63 EXPECT_EQ(result, "0.5");
64
65 result = QuicStrCat(strs[1], pieces[2]);
66 EXPECT_EQ(result, "CruelWorld");
67
68 result = QuicStrCat(strs[0], ", ", pieces[2]);
69 EXPECT_EQ(result, "Hello, World");
70
71 result = QuicStrCat(strs[0], ", ", strs[1], " ", strs[2], "!");
72 EXPECT_EQ(result, "Hello, Cruel World!");
73
74 result = QuicStrCat(pieces[0], ", ", pieces[1], " ", pieces[2]);
75 EXPECT_EQ(result, "Hello, Cruel World");
76
77 result = QuicStrCat(c_strs[0], ", ", c_strs[1], " ", c_strs[2]);
78 EXPECT_EQ(result, "Hello, Cruel World");
79
80 result = QuicStrCat("ASCII ", i32s[0], ", ", i32s[1], " ", i32s[2], "!");
81 EXPECT_EQ(result, "ASCII 72, 67 87!");
82
83 result = QuicStrCat(ui64s[0], ", ", ui64s[1], "!");
84 EXPECT_EQ(result, "12345678910, 10987654321!");
85
86 string one = "1";
87 result = QuicStrCat("And a ", one.size(), " and a ", &result[2] - &result[0],
88 " and a ", one, " 2 3 4", "!");
89 EXPECT_EQ(result, "And a 1 and a 2 and a 1 2 3 4!");
90
91 result =
92 QuicStrCat("To output a char by ASCII/numeric value, use +: ", '!' + 0);
93 EXPECT_EQ(result, "To output a char by ASCII/numeric value, use +: 33");
94
95 float f = 10000.5;
96 result = QuicStrCat("Ten K and a half is ", f);
97 EXPECT_EQ(result, "Ten K and a half is 10000.5");
98
99 double d = 99999.9;
100 result = QuicStrCat("This double number is ", d);
101 EXPECT_EQ(result, "This double number is 99999.9");
102
103 result =
104 QuicStrCat(1, 22, 333, 4444, 55555, 666666, 7777777, 88888888, 999999999);
105 EXPECT_EQ(result, "122333444455555666666777777788888888999999999");
106 }
107
108 TEST(QuicStrCatTest, MaxArgs) {
109 string result;
110 // Test 10 up to 26 arguments, the current maximum
111 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a");
112 EXPECT_EQ(result, "123456789a");
113 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b");
114 EXPECT_EQ(result, "123456789ab");
115 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c");
116 EXPECT_EQ(result, "123456789abc");
117 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d");
118 EXPECT_EQ(result, "123456789abcd");
119 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e");
120 EXPECT_EQ(result, "123456789abcde");
121 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f");
122 EXPECT_EQ(result, "123456789abcdef");
123 result =
124 QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f", "g");
125 EXPECT_EQ(result, "123456789abcdefg");
126 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
127 "g", "h");
128 EXPECT_EQ(result, "123456789abcdefgh");
129 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
130 "g", "h", "i");
131 EXPECT_EQ(result, "123456789abcdefghi");
132 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
133 "g", "h", "i", "j");
134 EXPECT_EQ(result, "123456789abcdefghij");
135 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
136 "g", "h", "i", "j", "k");
137 EXPECT_EQ(result, "123456789abcdefghijk");
138 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
139 "g", "h", "i", "j", "k", "l");
140 EXPECT_EQ(result, "123456789abcdefghijkl");
141 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
142 "g", "h", "i", "j", "k", "l", "m");
143 EXPECT_EQ(result, "123456789abcdefghijklm");
144 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
145 "g", "h", "i", "j", "k", "l", "m", "n");
146 EXPECT_EQ(result, "123456789abcdefghijklmn");
147 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
148 "g", "h", "i", "j", "k", "l", "m", "n", "o");
149 EXPECT_EQ(result, "123456789abcdefghijklmno");
150 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
151 "g", "h", "i", "j", "k", "l", "m", "n", "o", "p");
152 EXPECT_EQ(result, "123456789abcdefghijklmnop");
153 result = QuicStrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f",
154 "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q");
155 EXPECT_EQ(result, "123456789abcdefghijklmnopq");
156 // No limit thanks to C++11's variadic templates
157 result = QuicStrCat(
158 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "a", "b", "c", "d", "e", "f", "g", "h",
159 "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
160 "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
161 "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
162 EXPECT_EQ(result,
163 "12345678910abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
164 }
165
166 } // namespace
167 } // namespace test
168 } // 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