TEST(GTestStringBuffer, TestClear) { String::CPtr s = String::create("abc"); StringBuffer::Ptr sb = StringBuffer::create(s); sb->ensureCapacity(1024); Size capacity = sb->capacity(); ASSERT_EQ(3, sb->length()); sb->clear(); ASSERT_EQ(0, sb->length()); ASSERT_EQ(capacity, sb->capacity()); }
TEST(GTestStringBuffer, TestCapacity) { StringBuffer::Ptr sb = StringBuffer::create(1024); ASSERT_LE(1024, sb->capacity()); sb->ensureCapacity(2048); ASSERT_LE(2048, sb->capacity()); ASSERT_EQ(0, sb->length()); }
TEST(GTestStringBuffer, TestToString2) { const char aiu8[] = { 0xe3, 0x81, 0x82, // a 0xe3, 0x81, 0x84, // i 0xe3, 0x81, 0x86, // u 0xe3, 0x81, 0x88, // e 0xe3, 0x81, 0x8a, // o 0 }; const char u8[] = { 0x31, 0x32, 0x33, // 1 2 3 0xe3, 0x81, 0x82, // a 0xe3, 0x81, 0x84, // i 0xe3, 0x81, 0x86, // u 0xe3, 0x81, 0x88, // e 0xe3, 0x81, 0x8a, // o 0x34, 0x35, 0x36, // 4 5 6 0 }; StringBuffer::Ptr sb = StringBuffer::create(); String::CPtr s1 = String::create("123"); String::CPtr s2 = String::create(aiu8, String::UTF8); String::CPtr s3 = String::create("456"); String::CPtr e0 = String::create(""); String::CPtr e1 = s1; String::CPtr e2 = String::create(u8, String::UTF8, NO_SIZE, 8); String::CPtr e3 = String::create(u8, String::UTF8); ASSERT_EQ(0, sb->length()); ASSERT_TRUE(sb->toString()->equals(e0)); sb->append(s1); ASSERT_EQ(3, sb->length()); ASSERT_TRUE(sb->toString()->equals(e1)); sb->append(s2); ASSERT_EQ(8, sb->length()); ASSERT_TRUE(sb->toString()->equals(e2)); sb->append(s3); ASSERT_EQ(11, sb->length()); ASSERT_TRUE(sb->toString()->equals(e3)); }