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 3 // found in the LICENSE file. 4 5 #include "base/strings/strcat.h" 6 #include "base/strings/utf_string_conversions.h" 7 #include "testing/gtest/include/gtest/gtest.h" 8 9 namespace base { 10 11 TEST(StrCat, 8Bit) { 12 EXPECT_EQ("", StrCat({""})); 13 EXPECT_EQ("1", StrCat({"1"})); 14 EXPECT_EQ("122", StrCat({"1", "22"})); 15 EXPECT_EQ("122333", StrCat({"1", "22", "333"})); 16 EXPECT_EQ("1223334444", StrCat({"1", "22", "333", "4444"})); 17 EXPECT_EQ("122333444455555", StrCat({"1", "22", "333", "4444", "55555"})); 18 } 19 20 TEST(StrCat, 16Bit) { 21 string16 arg1 = ASCIIToUTF16("1"); 22 string16 arg2 = ASCIIToUTF16("22"); 23 string16 arg3 = ASCIIToUTF16("333"); 24 25 EXPECT_EQ(ASCIIToUTF16(""), StrCat({string16()})); 26 EXPECT_EQ(ASCIIToUTF16("1"), StrCat({arg1})); 27 EXPECT_EQ(ASCIIToUTF16("122"), StrCat({arg1, arg2})); 28 EXPECT_EQ(ASCIIToUTF16("122333"), StrCat({arg1, arg2, arg3})); 29 } 30 31 TEST(StrAppend, 8Bit) { 32 std::string result; 33 34 result = "foo"; 35 StrAppend(&result, {std::string()}); 36 EXPECT_EQ("foo", result); 37 38 result = "foo"; 39 StrAppend(&result, {"1"}); 40 EXPECT_EQ("foo1", result); 41 42 result = "foo"; 43 StrAppend(&result, {"1", "22", "333"}); 44 EXPECT_EQ("foo122333", result); 45 } 46 47 TEST(StrAppend, 16Bit) { 48 string16 arg1 = ASCIIToUTF16("1"); 49 string16 arg2 = ASCIIToUTF16("22"); 50 string16 arg3 = ASCIIToUTF16("333"); 51 52 string16 result; 53 54 result = ASCIIToUTF16("foo"); 55 StrAppend(&result, {string16()}); 56 EXPECT_EQ(ASCIIToUTF16("foo"), result); 57 58 result = ASCIIToUTF16("foo"); 59 StrAppend(&result, {arg1}); 60 EXPECT_EQ(ASCIIToUTF16("foo1"), result); 61 62 result = ASCIIToUTF16("foo"); 63 StrAppend(&result, {arg1, arg2, arg3}); 64 EXPECT_EQ(ASCIIToUTF16("foo122333"), result); 65 } 66 67 } // namespace base 68