17 #include "absl/strings/str_cat.h"
23 #include "gtest/gtest.h"
24 #include "absl/strings/substitute.h"
29 #define ABSL_EXPECT_DEBUG_DEATH(statement, regex) \
30 EXPECT_DEBUG_DEATH(statement, ".*")
32 #define ABSL_EXPECT_DEBUG_DEATH(statement, regex) \
33 EXPECT_DEBUG_DEATH(statement, regex)
43 const unsigned int ui = 4;
45 const unsigned long ul = 6;
46 const long long ll = -7;
47 const unsigned long long ull = 8;
48 const ptrdiff_t ptrdiff = -9;
49 const size_t size = 10;
70 enum SmallNumbers { One = 1, Ten = 10 } e = Ten;
74 enum class Option { Boxers = 1, Briefs = -1 };
88 TwoToTheSixteenth = 1 << 16,
97 TwoToTheSixteenth = 1 << 16,
98 TwoToTheThirtyFirst = 1U << 31
120 const char* c_strs[] = {
126 int32_t i32s[] = {
'H',
'C',
'W'};
169 &
result[2] - &
result[0],
" and a ", one,
" 2 3 4",
"!");
175 absl::StrCat(
"To output a char by ASCII/numeric value, use +: ",
'!' + 0);
176 EXPECT_EQ(
result,
"To output a char by ASCII/numeric value, use +: 33");
214 const char*
null =
nullptr;
219 template <
typename T>
222 typedef size_t size_type;
223 typedef ptrdiff_t difference_type;
226 typedef T& reference;
229 size_type max_size()
const {
232 template <
typename U>
234 typedef Mallocator<U> other;
236 Mallocator() =
default;
238 Mallocator(
const Mallocator<U>&) {}
240 T* allocate(
size_t n) {
return static_cast<T*
>(std::malloc(
n *
sizeof(
T))); }
241 void deallocate(
T*
p,
size_t) { std::free(
p); }
243 template <
typename T,
typename U>
244 bool operator==(
const Mallocator<T>&,
const Mallocator<U>&) {
247 template <
typename T,
typename U>
248 bool operator!=(
const Mallocator<T>&,
const Mallocator<U>&) {
254 std::basic_string<char, std::char_traits<char>, Mallocator<char>>;
255 const mstring str1(
"PARACHUTE OFF A BLIMP INTO MOSCONE!!");
257 const mstring str2(
"Read this book about coffee tables");
261 "PARACHUTE OFF A BLIMP INTO MOSCONE!!"
262 "Read this book about coffee tables");
270 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b");
272 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c");
274 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d");
276 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e");
279 absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f");
281 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
284 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
287 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
290 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
293 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
294 "g",
"h",
"i",
"j",
"k");
296 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
297 "g",
"h",
"i",
"j",
"k",
"l");
299 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
300 "g",
"h",
"i",
"j",
"k",
"l",
"m");
302 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
303 "g",
"h",
"i",
"j",
"k",
"l",
"m",
"n");
305 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
306 "g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o");
308 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
309 "g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p");
311 result =
absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9,
"a",
"b",
"c",
"d",
"e",
"f",
312 "g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q");
316 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
317 "i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
318 "x",
"y",
"z",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
319 "M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z");
321 "12345678910abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
337 const char* c_strs[] = {
343 int32_t i32s[] = {
'H',
'C',
'W'};
388 &
result[2] - &
result[0],
" and a ", one,
" 2 3 4",
"!");
395 "To output a char by ASCII/numeric value, use +: ",
'!' + 0);
397 "To output a char by ASCII/numeric value, use +: 33");
408 &
result, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
409 "a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
410 "n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
411 "A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
412 "N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
413 "No limit thanks to C++11's variadic templates");
415 "12345678910abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
416 "No limit thanks to C++11's variadic templates");
423 std::vector<bool>
const&
cv =
v;
445 #ifdef GTEST_HAS_DEATH_TEST
454 #endif // GTEST_HAS_DEATH_TEST
486 template <
typename IntType>
487 void CheckHex(IntType
v,
const char* nopad_format,
const char* zeropad_format,
488 const char* spacepad_format) {
492 snprintf(expected,
sizeof(expected), nopad_format,
v);
493 EXPECT_EQ(expected, actual) <<
" decimal value " <<
v;
498 snprintf(expected,
sizeof(expected), zeropad_format,
500 EXPECT_EQ(expected, actual) <<
" decimal value " <<
v;
506 snprintf(expected,
sizeof(expected), spacepad_format,
508 EXPECT_EQ(expected, actual) <<
" decimal value " <<
v;
512 template <
typename IntType>
513 void CheckDec(IntType
v,
const char* nopad_format,
const char* zeropad_format,
514 const char* spacepad_format) {
518 snprintf(expected,
sizeof(expected), nopad_format,
v);
519 EXPECT_EQ(expected, actual) <<
" decimal value " <<
v;
524 snprintf(expected,
sizeof(expected), zeropad_format,
527 <<
" decimal value " <<
v <<
" format '" << zeropad_format
534 snprintf(expected,
sizeof(expected), spacepad_format,
537 <<
" decimal value " <<
v <<
" format '" << spacepad_format
543 unsigned long long ullv =
v;
545 CheckHex(ullv,
"%llx",
"%0*llx",
"%*llx");
546 CheckDec(ullv,
"%llu",
"%0*llu",
"%*llu");
548 long long llv =
static_cast<long long>(ullv);
549 CheckDec(llv,
"%lld",
"%0*lld",
"%*lld");
551 if (
sizeof(
v) ==
sizeof(&
v)) {
553 void*
ptr =
reinterpret_cast<void*
>(uintptr);
554 CheckHex(
ptr,
"%llx",
"%0*llx",
"%*llx");
559 CheckHex(uv,
"%x",
"%0*x",
"%*x");
560 CheckDec(uv,
"%u",
"%0*u",
"%*u");
562 CheckDec(
v,
"%d",
"%0*d",
"%*d");
564 if (
sizeof(
v) ==
sizeof(&
v)) {
566 void*
ptr =
reinterpret_cast<void*
>(uintptr);
567 CheckHex(
ptr,
"%x",
"%0*x",
"%*x");
576 void TestFastPrints() {
578 for (
int i = 0;
i < 10000;
i++) {
591 CheckAll(1000000000);
592 CheckAll(9999999999);
593 CheckAll(10000000000);
594 CheckAll(999999999999999999);
595 CheckAll(9999999999999999999
u);
596 CheckAll(1000000000000000000);
597 CheckAll(10000000000000000000
u);
599 CheckAll(999999999876543210);
600 CheckAll(9999999999876543210
u);
601 CheckAll(0x123456789abcdef0);
602 CheckAll(0x12345678);
604 int8_t minus_one_8bit = -1;
611 TEST(Numbers, TestFunctionsMovedOverFromNumbersMain) {