Commit 97290bca authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Split the FBString.testFixedBugs test case

Summary: [Folly] Split the `FBString.testFixedBugs` test case into a test case per bug.

Reviewed By: Orvid

Differential Revision: D9727569

fbshipit-source-id: b319286031ded00451a1e960c0d450e7cfc4c362
parent 6caa1646
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <folly/Utility.h> #include <folly/Utility.h>
#include <folly/container/Foreach.h> #include <folly/container/Foreach.h>
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
#include <folly/test/TestUtils.h>
using namespace std; using namespace std;
using namespace folly; using namespace folly;
...@@ -1243,15 +1244,15 @@ TEST(FBString, testConstructionFromLiteralZero) { ...@@ -1243,15 +1244,15 @@ TEST(FBString, testConstructionFromLiteralZero) {
EXPECT_THROW(fbstring s(nullptr), std::logic_error); EXPECT_THROW(fbstring s(nullptr), std::logic_error);
} }
TEST(FBString, testFixedBugs) { TEST(FBString, testFixedBugs_D479397) {
{ // D479397
fbstring str(1337, 'f'); fbstring str(1337, 'f');
fbstring cp = str; fbstring cp = str;
cp.clear(); cp.clear();
cp.c_str(); cp.c_str();
EXPECT_EQ(str.front(), 'f'); EXPECT_EQ(str.front(), 'f');
} }
{ // D481173
TEST(FBString, testFixedBugs_D481173) {
fbstring str(1337, 'f'); fbstring str(1337, 'f');
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
fbstring cp = str; fbstring cp = str;
...@@ -1259,36 +1260,40 @@ TEST(FBString, testFixedBugs) { ...@@ -1259,36 +1260,40 @@ TEST(FBString, testFixedBugs) {
EXPECT_EQ(cp.c_str()[cp.size()], '\0'); EXPECT_EQ(cp.c_str()[cp.size()], '\0');
cp.push_back('?'); cp.push_back('?');
} }
} }
{ // D580267
{ TEST(FBString, testFixedBugs_D580267_push_back) {
fbstring str(1337, 'f'); fbstring str(1337, 'f');
fbstring cp = str; fbstring cp = str;
cp.push_back('f'); cp.push_back('f');
} }
{
TEST(FBString, testFixedBugs_D580267_operator_add_assign) {
fbstring str(1337, 'f'); fbstring str(1337, 'f');
fbstring cp = str; fbstring cp = str;
cp += "bb"; cp += "bb";
} }
}
{ // D661622 TEST(FBString, testFixedBugs_D661622) {
folly::basic_fbstring<wchar_t> s; folly::basic_fbstring<wchar_t> s;
EXPECT_EQ(0, s.size()); EXPECT_EQ(0, s.size());
} }
{ // D785057
TEST(FBString, testFixedBugs_D785057) {
fbstring str(1337, 'f'); fbstring str(1337, 'f');
std::swap(str, str); std::swap(str, str);
EXPECT_EQ(1337, str.size()); EXPECT_EQ(1337, str.size());
} }
{ // D1012196, --allocator=malloc
TEST(FBString, testFixedBugs_D1012196_allocator_malloc) {
fbstring str(128, 'f'); fbstring str(128, 'f');
str.clear(); // Empty medium string. str.clear(); // Empty medium string.
fbstring copy(str); // Medium string of 0 capacity. fbstring copy(str); // Medium string of 0 capacity.
copy.push_back('b'); copy.push_back('b');
EXPECT_GE(copy.capacity(), 1); EXPECT_GE(copy.capacity(), 1);
} }
{ // D2813713
TEST(FBString, testFixedBugs_D2813713) {
fbstring s1("a"); fbstring s1("a");
s1.reserve(8); // Trigger the optimized code path. s1.reserve(8); // Trigger the optimized code path.
auto test1 = '\0' + std::move(s1); auto test1 = '\0' + std::move(s1);
...@@ -1298,22 +1303,25 @@ TEST(FBString, testFixedBugs) { ...@@ -1298,22 +1303,25 @@ TEST(FBString, testFixedBugs) {
s2.reserve(8); s2.reserve(8);
auto test2 = "a" + std::move(s2); auto test2 = "a" + std::move(s2);
EXPECT_EQ(2, test2.size()); EXPECT_EQ(2, test2.size());
} }
{ // D3698862
TEST(FBString, testFixedBugs_D3698862) {
EXPECT_EQ(fbstring().find(fbstring(), 4), fbstring::npos); EXPECT_EQ(fbstring().find(fbstring(), 4), fbstring::npos);
} }
if (usingJEMalloc()) { // D4355440
TEST(FBString, testFixedBugs_D4355440) {
SKIP_IF(!usingJEMalloc());
fbstring str(1337, 'f'); fbstring str(1337, 'f');
str.reserve(3840); str.reserve(3840);
EXPECT_NE(str.capacity(), 3840); EXPECT_NE(str.capacity(), 3840);
struct { struct DummyRefCounted {
std::atomic<size_t> refCount_; std::atomic<size_t> refCount_;
} dummyRefCounted; };
EXPECT_EQ( EXPECT_EQ(
str.capacity(), str.capacity(),
goodMallocSize(3840) - sizeof(dummyRefCounted) - sizeof(char)); goodMallocSize(3840) - sizeof(DummyRefCounted) - sizeof(char));
}
} }
TEST(FBString, findWithNpos) { TEST(FBString, findWithNpos) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment