proxygen
FBStringTest.cpp File Reference
#include <folly/FBString.h>
#include <atomic>
#include <cstdlib>
#include <iomanip>
#include <list>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include <boost/random.hpp>
#include <folly/Conv.h>
#include <folly/Portability.h>
#include <folly/Random.h>
#include <folly/Utility.h>
#include <folly/container/Foreach.h>
#include <folly/portability/GTest.h>
#include <folly/test/TestUtils.h>

Go to the source code of this file.

Macros

#define TEST_CLAUSE(x)
 

Functions

template<class String >
void clause11_21_4_2_a (String &test)
 
template<class String >
void clause11_21_4_2_b (String &test)
 
template<class String >
void clause11_21_4_2_c (String &test)
 
template<class String >
void clause11_21_4_2_d (String &test)
 
template<class String >
void clause11_21_4_2_e (String &test)
 
template<class String >
void clause11_21_4_2_f (String &test)
 
template<class String >
void clause11_21_4_2_g (String &test)
 
template<class String >
void clause11_21_4_2_h (String &test)
 
template<class String >
void clause11_21_4_2_i (String &test)
 
template<class String >
void clause11_21_4_2_j (String &test)
 
template<class String >
void clause11_21_4_2_k (String &test)
 
template<class String >
void clause11_21_4_2_l (String &test)
 
template<class String >
void clause11_21_4_2_lprime (String &test)
 
template<class String >
void clause11_21_4_2_m (String &test)
 
template<class String >
void clause11_21_4_2_n (String &test)
 
template<class String >
void clause11_21_4_3 (String &test)
 
template<class String >
void clause11_21_4_4 (String &test)
 
template<class String >
void clause11_21_4_5 (String &test)
 
template<class String >
void clause11_21_4_6_1 (String &test)
 
template<class String >
void clause11_21_4_6_2 (String &test)
 
template<class String >
void clause11_21_4_6_3_a (String &test)
 
template<class String >
void clause11_21_4_6_3_b (String &test)
 
template<class String >
void clause11_21_4_6_3_c (String &test)
 
template<class String >
void clause11_21_4_6_3_d (String &test)
 
template<class String >
void clause11_21_4_6_3_e (String &test)
 
template<class String >
void clause11_21_4_6_3_f (String &test)
 
template<class String >
void clause11_21_4_6_3_g (String &test)
 
template<class String >
void clause11_21_4_6_3_h (String &test)
 
template<class String >
void clause11_21_4_6_3_i (String &test)
 
template<class String >
void clause11_21_4_6_3_j (String &test)
 
template<class String >
void clause11_21_4_6_3_k (String &test)
 
template<class String >
void clause11_21_4_6_4 (String &test)
 
template<class String >
void clause11_21_4_6_5 (String &test)
 
template<class String >
void clause11_21_4_6_6 (String &test)
 
template<class String >
void clause11_21_4_6_7 (String &test)
 
template<class String >
void clause11_21_4_6_8 (String &test)
 
template<class String >
void clause11_21_4_7_1 (String &test)
 
template<class String >
void clause11_21_4_7_2_a (String &test)
 
template<class String >
void clause11_21_4_7_2_a1 (String &test)
 
template<class String >
void clause11_21_4_7_2_a2 (String &test)
 
template<class String >
void clause11_21_4_7_2_b (String &test)
 
template<class String >
void clause11_21_4_7_2_b1 (String &test)
 
template<class String >
void clause11_21_4_7_2_b2 (String &test)
 
template<class String >
void clause11_21_4_7_2_c (String &test)
 
template<class String >
void clause11_21_4_7_2_c1 (String &test)
 
template<class String >
void clause11_21_4_7_2_c2 (String &test)
 
template<class String >
void clause11_21_4_7_2_d (String &test)
 
template<class String >
void clause11_21_4_7_3_a (String &test)
 
template<class String >
void clause11_21_4_7_3_b (String &test)
 
template<class String >
void clause11_21_4_7_3_c (String &test)
 
template<class String >
void clause11_21_4_7_3_d (String &test)
 
template<class String >
void clause11_21_4_7_4_a (String &test)
 
template<class String >
void clause11_21_4_7_4_b (String &test)
 
template<class String >
void clause11_21_4_7_4_c (String &test)
 
template<class String >
void clause11_21_4_7_4_d (String &test)
 
template<class String >
void clause11_21_4_7_5_a (String &test)
 
template<class String >
void clause11_21_4_7_5_b (String &test)
 
template<class String >
void clause11_21_4_7_5_c (String &test)
 
template<class String >
void clause11_21_4_7_5_d (String &test)
 
template<class String >
void clause11_21_4_7_6_a (String &test)
 
template<class String >
void clause11_21_4_7_6_b (String &test)
 
template<class String >
void clause11_21_4_7_6_c (String &test)
 
template<class String >
void clause11_21_4_7_6_d (String &test)
 
template<class String >
void clause11_21_4_7_7_a (String &test)
 
template<class String >
void clause11_21_4_7_7_b (String &test)
 
template<class String >
void clause11_21_4_7_7_c (String &test)
 
template<class String >
void clause11_21_4_7_7_d (String &test)
 
template<class String >
void clause11_21_4_7_8 (String &test)
 
template<class String >
void clause11_21_4_7_9_a (String &test)
 
template<class String >
void clause11_21_4_7_9_b (String &test)
 
template<class String >
void clause11_21_4_7_9_c (String &test)
 
template<class String >
void clause11_21_4_7_9_d (String &test)
 
template<class String >
void clause11_21_4_7_9_e (String &test)
 
template<class String >
void clause11_21_4_8_1_a (String &test)
 
template<class String >
void clause11_21_4_8_1_b (String &test)
 
template<class String >
void clause11_21_4_8_1_c (String &test)
 
template<class String >
void clause11_21_4_8_1_d (String &test)
 
template<class String >
void clause11_21_4_8_1_e (String &test)
 
template<class String >
void clause11_21_4_8_1_f (String &test)
 
template<class String >
void clause11_21_4_8_1_g (String &test)
 
template<class String >
void clause11_21_4_8_1_h (String &test)
 
template<class String >
void clause11_21_4_8_1_i (String &test)
 
template<class String >
void clause11_21_4_8_1_j (String &test)
 
template<class String >
void clause11_21_4_8_1_k (String &test)
 
template<class String >
void clause11_21_4_8_1_l (String &test)
 
template<class String >
void clause11_21_4_8_9_a (String &test)
 
 TEST (FBString, testAllClauses)
 
 TEST (FBString, testGetline)
 
 TEST (FBString, testMoveCtor)
 
 TEST (FBString, testMoveAssign)
 
 TEST (FBString, testMoveOperatorPlusLhs)
 
 TEST (FBString, testMoveOperatorPlusRhs)
 
 TEST (FBString, testConstructionFromLiteralZero)
 
 TEST (FBString, testFixedBugs_D479397)
 
 TEST (FBString, testFixedBugs_D481173)
 
 TEST (FBString, testFixedBugs_D580267_push_back)
 
 TEST (FBString, testFixedBugs_D580267_operator_add_assign)
 
 TEST (FBString, testFixedBugs_D661622)
 
 TEST (FBString, testFixedBugs_D785057)
 
 TEST (FBString, testFixedBugs_D1012196_allocator_malloc)
 
 TEST (FBString, testFixedBugs_D2813713)
 
 TEST (FBString, testFixedBugs_D3698862)
 
 TEST (FBString, testFixedBugs_D4355440)
 
 TEST (FBString, findWithNpos)
 
 TEST (FBString, testHash)
 
 TEST (FBString, testFrontBack)
 
 TEST (FBString, noexcept)
 
 TEST (FBString, iomanip)
 
 TEST (FBString, rvalueIterators)
 
 TEST (FBString, moveTerminator)
 
 TEST (FBStringCtorTest, DefaultInitStructDefaultAlloc)
 
 TEST (FBStringCtorTest, DefaultInitStructAlloc)
 
 TEST (FBStringCtorTest, NullZeroConstruction)
 
 TEST (FBString, compareToStdString)
 
 TEST (U16FBString, compareToStdU16String)
 
 TEST (U32FBString, compareToStdU32String)
 
 TEST (WFBString, compareToStdWString)
 
 TEST (FBString, compareToStdStringLong)
 
 TEST (U16FBString, compareToStdU16StringLong)
 

Macro Definition Documentation

#define TEST_CLAUSE (   x)
Value:
l(#x, \
clause11_##x<std::string>, \
clause11_##x<folly::fbstring>, \
Definition: InvokeTest.cpp:58

Referenced by TEST().

Function Documentation

template<class String >
void clause11_21_4_2_a ( String &  test)

Definition at line 84 of file FBStringTest.cpp.

References test().

84  {
85  test.String::~String();
86  new (&test) String();
87 }
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
template<class String >
void clause11_21_4_2_b ( String &  test)

Definition at line 89 of file FBStringTest.cpp.

89  {
90  String test2(test);
91  assert(test2 == test);
92 }
template<class String >
void clause11_21_4_2_c ( String &  test)

Definition at line 94 of file FBStringTest.cpp.

References EXPECT_EQ, EXPECT_LE, and folly::gen::move.

94  {
95  // Test move constructor. There is a more specialized test, see
96  // TEST(FBString, testMoveCtor)
97  String donor(test);
98  String test2(std::move(donor));
99  EXPECT_EQ(test2, test);
100  // Technically not required, but all implementations that actually
101  // support move will move large strings. Make a guess for 128 as the
102  // maximum small string optimization that's reasonable.
103  EXPECT_LE(donor.size(), 128);
104 }
#define EXPECT_LE(val1, val2)
Definition: gtest.h:1928
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class String >
void clause11_21_4_2_d ( String &  test)

Definition at line 106 of file FBStringTest.cpp.

References random(), and s.

106  {
107  // Copy constructor with position and length
108  const size_t pos = random(0, test.size());
109  String s(
110  test,
111  pos,
112  random(0, 9) ? random(0, (size_t)(test.size() - pos))
113  : String::npos); // test for npos, too, in 10% of the cases
114  test = s;
115 }
Integral2 random(Integral1 low, Integral2 up)
static set< string > s
template<class String >
void clause11_21_4_2_e ( String &  test)

Definition at line 117 of file FBStringTest.cpp.

References EXPECT_EQ, random(), and s.

117  {
118  // Constructor from char*, size_t
119  const size_t pos = random(0, test.size()), n = random(0, test.size() - pos);
120  String before(test.data(), test.size());
121  String s(test.c_str() + pos, n);
122  String after(test.data(), test.size());
123  EXPECT_EQ(before, after);
124  test.swap(s);
125 }
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static set< string > s
template<class String >
void clause11_21_4_2_f ( String &  test)

Definition at line 127 of file FBStringTest.cpp.

References EXPECT_EQ, random(), and s.

127  {
128  // Constructor from char*
129  const size_t pos = random(0, test.size());
130  String before(test.data(), test.size());
131  String s(test.c_str() + pos);
132  String after(test.data(), test.size());
133  EXPECT_EQ(before, after);
134  test.swap(s);
135 }
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static set< string > s
template<class String >
void clause11_21_4_2_g ( String &  test)

Definition at line 137 of file FBStringTest.cpp.

References c, and random().

137  {
138  // Constructor from size_t, char
139  const size_t n = random(0, test.size());
140  const auto c = test.front();
141  test = String(n, c);
142 }
Integral2 random(Integral1 low, Integral2 up)
char c
template<class String >
void clause11_21_4_2_h ( String &  test)

Definition at line 144 of file FBStringTest.cpp.

References c, EXPECT_EQ, and folly::pushmi::detail::t.

144  {
145  // Constructors from various iterator pairs
146  // Constructor from char*, char*
147  String s1(test.begin(), test.end());
148  EXPECT_EQ(test, s1);
149  String s2(test.data(), test.data() + test.size());
150  EXPECT_EQ(test, s2);
151  // Constructor from other iterators
152  std::list<char> lst;
153  for (auto c : test) {
154  lst.push_back(c);
155  }
156  String s3(lst.begin(), lst.end());
157  EXPECT_EQ(test, s3);
158  // Constructor from wchar_t iterators
159  std::list<wchar_t> lst1;
160  for (auto c : test) {
161  lst1.push_back(c);
162  }
163  String s4(lst1.begin(), lst1.end());
164  EXPECT_EQ(test, s4);
165  // Constructor from wchar_t pointers
166  wchar_t t[20];
167  t[0] = 'a';
168  t[1] = 'b';
169  fbstring s5(t, t + 2);
170  EXPECT_EQ("ab", s5);
171 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
char c
template<class String >
void clause11_21_4_2_i ( String &  test)

Definition at line 173 of file FBStringTest.cpp.

References s.

173  {
174  // From initializer_list<char>
175  std::initializer_list<typename String::value_type> il = {
176  'h', 'e', 'l', 'l', 'o'};
177  String s(il);
178  test.swap(s);
179 }
static set< string > s
template<class String >
void clause11_21_4_2_j ( String &  test)

Definition at line 181 of file FBStringTest.cpp.

References EXPECT_EQ, FOR_EACH_RANGE, i, random(), s, and folly::size().

181  {
182  // Assignment from const String&
183  auto size = random(0, 2000);
184  String s(size, '\0');
185  EXPECT_EQ(s.size(), size);
186  FOR_EACH_RANGE (i, 0, s.size()) { s[i] = random('a', 'z'); }
187  test = s;
188 }
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
static set< string > s
template<class String >
void clause11_21_4_2_k ( String &  test)

Definition at line 190 of file FBStringTest.cpp.

References EXPECT_EQ, EXPECT_LE, FOR_EACH_RANGE, i, folly::gen::move, random(), s, and folly::size().

190  {
191  // Assignment from String&&
192  auto size = random(0, 2000);
193  String s(size, '\0');
194  EXPECT_EQ(s.size(), size);
195  FOR_EACH_RANGE (i, 0, s.size()) { s[i] = random('a', 'z'); }
196  test = std::move(s);
197  if (typeid(String) == typeid(fbstring)) {
198  EXPECT_LE(s.size(), 128);
199  }
200 }
#define EXPECT_LE(val1, val2)
Definition: gtest.h:1928
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
static set< string > s
template<class String >
void clause11_21_4_2_l ( String &  test)

Definition at line 202 of file FBStringTest.cpp.

References i, random(), and s.

202  {
203  // Assignment from char*
204  String s(random(0, 1000), '\0');
205  size_t i = 0;
206  for (; i != s.size(); ++i) {
207  s[i] = random('a', 'z');
208  }
209  test = s.c_str();
210 }
Integral2 random(Integral1 low, Integral2 up)
static set< string > s
template<class String >
void clause11_21_4_2_lprime ( String &  test)

Definition at line 212 of file FBStringTest.cpp.

References random().

212  {
213  // Aliased assign
214  const size_t pos = random(0, test.size());
215  if (avoidAliasing) {
216  test = String(test.c_str() + pos);
217  } else {
218  test = test.c_str() + pos;
219  }
220 }
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_2_m ( String &  test)

Definition at line 222 of file FBStringTest.cpp.

References random().

222  {
223  // Assignment from char
224  using value_type = typename String::value_type;
225  test = random(static_cast<value_type>('a'), static_cast<value_type>('z'));
226 }
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_2_n ( String &  test)

Definition at line 228 of file FBStringTest.cpp.

228  {
229  // Assignment from initializer_list<char>
230  initializer_list<typename String::value_type> il = {'h', 'e', 'l', 'l', 'o'};
231  test = il;
232 }
template<class String >
void clause11_21_4_3 ( String &  test)

Definition at line 235 of file FBStringTest.cpp.

References EXPECT_EQ, and s.

235  {
236  // Iterators. The code below should leave test unchanged
237  EXPECT_EQ(test.size(), test.end() - test.begin());
238  EXPECT_EQ(test.size(), test.rend() - test.rbegin());
239  EXPECT_EQ(test.size(), test.cend() - test.cbegin());
240  EXPECT_EQ(test.size(), test.crend() - test.crbegin());
241 
242  auto s = test.size();
243  test.resize(test.end() - test.begin());
244  EXPECT_EQ(s, test.size());
245  test.resize(test.rend() - test.rbegin());
246  EXPECT_EQ(s, test.size());
247 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static set< string > s
template<class String >
void clause11_21_4_4 ( String &  test)

Definition at line 250 of file FBStringTest.cpp.

References folly::copy(), folly::empty(), EXPECT_EQ, EXPECT_LE, and test().

250  {
251  // exercise capacity, size, max_size
252  EXPECT_EQ(test.size(), test.length());
253  EXPECT_LE(test.size(), test.max_size());
254  EXPECT_LE(test.capacity(), test.max_size());
255  EXPECT_LE(test.size(), test.capacity());
256 
257  // exercise shrink_to_fit. Nonbinding request so we can't really do
258  // much beyond calling it.
259  auto copy = test;
260  copy.reserve(copy.capacity() * 3);
261  copy.shrink_to_fit();
262  EXPECT_EQ(copy, test);
263 
264  // exercise empty
265  string empty("empty");
266  string notempty("not empty");
267  if (test.empty()) {
268  test = String(empty.begin(), empty.end());
269  } else {
270  test = String(notempty.begin(), notempty.end());
271  }
272 }
#define EXPECT_LE(val1, val2)
Definition: gtest.h:1928
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
constexpr auto empty(C const &c) -> decltype(c.empty())
Definition: Access.h:55
template<class String >
void clause11_21_4_5 ( String &  test)

Definition at line 275 of file FBStringTest.cpp.

References folly::pushmi::detail::as_const, EXPECT_EQ, EXPECT_THROW, i, and random().

275  {
276  // exercise element access
277  if (!test.empty()) {
278  EXPECT_EQ(test[0], test.front());
279  EXPECT_EQ(test[test.size() - 1], test.back());
280  auto const i = random(0, test.size() - 1);
281  EXPECT_EQ(test[i], test.at(i));
282  test = test[i];
283  }
284 
285  EXPECT_THROW(test.at(test.size()), std::out_of_range);
286  EXPECT_THROW(as_const(test).at(test.size()), std::out_of_range);
287 }
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::detail::as_const_fn as_const
template<class String >
void clause11_21_4_6_1 ( String &  test)

Definition at line 290 of file FBStringTest.cpp.

References folly::copy(), EXPECT_EQ, FOR_EACH_RANGE, random(), randomString(), and test().

290  {
291  // 21.3.5 modifiers (+=)
292  String test1;
293  randomString(&test1);
294  assert(
295  test1.size() ==
296  char_traits<typename String::value_type>::length(test1.c_str()));
297  auto len = test.size();
298  test += test1;
299  EXPECT_EQ(test.size(), test1.size() + len);
300  FOR_EACH_RANGE (i, 0, test1.size()) { EXPECT_EQ(test[len + i], test1[i]); }
301  // aliasing modifiers
302  String test2 = test;
303  auto dt = test2.data();
304  auto sz = test.c_str();
305  len = test.size();
306  EXPECT_EQ(memcmp(sz, dt, len), 0);
307  String copy(test.data(), test.size());
308  EXPECT_EQ(
309  char_traits<typename String::value_type>::length(test.c_str()), len);
310  test += test;
311  // test.append(test);
312  EXPECT_EQ(test.size(), 2 * len);
313  EXPECT_EQ(
314  char_traits<typename String::value_type>::length(test.c_str()), 2 * len);
315  FOR_EACH_RANGE (i, 0, len) {
316  EXPECT_EQ(test[i], copy[i]);
317  EXPECT_EQ(test[i], test[len + i]);
318  }
319  len = test.size();
320  EXPECT_EQ(
321  char_traits<typename String::value_type>::length(test.c_str()), len);
322  // more aliasing
323  auto const pos = random(0, test.size());
324  EXPECT_EQ(
325  char_traits<typename String::value_type>::length(test.c_str() + pos),
326  len - pos);
327  if (avoidAliasing) {
328  String addMe(test.c_str() + pos);
329  EXPECT_EQ(addMe.size(), len - pos);
330  test += addMe;
331  } else {
332  test += test.c_str() + pos;
333  }
334  EXPECT_EQ(test.size(), 2 * len - pos);
335  // single char
336  len = test.size();
337  test += random('a', 'z');
338  EXPECT_EQ(test.size(), len + 1);
339  // initializer_list
340  initializer_list<typename String::value_type> il{'a', 'b', 'c'};
341  test += il;
342 }
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_6_2 ( String &  test)

Definition at line 345 of file FBStringTest.cpp.

References c, EXPECT_EQ, random(), RandomList(), randomString(), and s.

345  {
346  // 21.3.5 modifiers (append, push_back)
347  String s;
348 
349  // Test with a small string first
350  char c = random('a', 'z');
351  s.push_back(c);
352  EXPECT_EQ(s[s.size() - 1], c);
353  EXPECT_EQ(s.size(), 1);
354  s.resize(s.size() - 1);
355 
356  randomString(&s, maxString);
357  test.append(s);
358  randomString(&s, maxString);
359  test.append(s, random(0, s.size()), random(0, maxString));
360  randomString(&s, maxString);
361  test.append(s.c_str(), random(0, s.size()));
362  randomString(&s, maxString);
363  test.append(s.c_str());
364  test.append(random(0, maxString), random('a', 'z'));
365  std::list<char> lst(RandomList(maxString));
366  test.append(lst.begin(), lst.end());
367  c = random('a', 'z');
368  test.push_back(c);
369  EXPECT_EQ(test[test.size() - 1], c);
370  // initializer_list
371  initializer_list<typename String::value_type> il{'a', 'b', 'c'};
372  test.append(il);
373 }
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::list< char > RandomList(unsigned int maxSize)
static set< string > s
char c
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_6_3_a ( String &  test)

Definition at line 376 of file FBStringTest.cpp.

References EXPECT_EQ, EXPECT_LE, folly::gen::move, randomString(), and s.

376  {
377  // assign
378  String s;
379  randomString(&s);
380  test.assign(s);
381  EXPECT_EQ(test, s);
382  // move assign
383  test.assign(std::move(s));
384  if (typeid(String) == typeid(fbstring)) {
385  EXPECT_LE(s.size(), 128);
386  }
387 }
#define EXPECT_LE(val1, val2)
Definition: gtest.h:1928
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_6_3_b ( String &  test)

Definition at line 390 of file FBStringTest.cpp.

References random(), randomString(), and s.

390  {
391  // assign
392  String s;
393  randomString(&s, maxString);
394  test.assign(s, random(0, s.size()), random(0, maxString));
395 }
Integral2 random(Integral1 low, Integral2 up)
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_6_3_c ( String &  test)

Definition at line 398 of file FBStringTest.cpp.

References random(), randomString(), and s.

398  {
399  // assign
400  String s;
401  randomString(&s, maxString);
402  test.assign(s.c_str(), random(0, s.size()));
403 }
Integral2 random(Integral1 low, Integral2 up)
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_6_3_d ( String &  test)

Definition at line 406 of file FBStringTest.cpp.

References randomString(), and s.

406  {
407  // assign
408  String s;
409  randomString(&s, maxString);
410  test.assign(s.c_str());
411 }
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_6_3_e ( String &  test)

Definition at line 414 of file FBStringTest.cpp.

References random(), randomString(), and s.

414  {
415  // assign
416  String s;
417  randomString(&s, maxString);
418  test.assign(random(0, maxString), random('a', 'z'));
419 }
Integral2 random(Integral1 low, Integral2 up)
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_6_3_f ( String &  test)

Definition at line 422 of file FBStringTest.cpp.

References RandomList().

422  {
423  // assign from bidirectional iterator
424  std::list<char> lst(RandomList(maxString));
425  test.assign(lst.begin(), lst.end());
426 }
std::list< char > RandomList(unsigned int maxSize)
template<class String >
void clause11_21_4_6_3_g ( String &  test)

Definition at line 429 of file FBStringTest.cpp.

429  {
430  // assign from aliased source
431  test.assign(test);
432 }
template<class String >
void clause11_21_4_6_3_h ( String &  test)

Definition at line 435 of file FBStringTest.cpp.

References random().

435  {
436  // assign from aliased source
437  test.assign(test, random(0, test.size()), random(0, maxString));
438 }
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_6_3_i ( String &  test)

Definition at line 441 of file FBStringTest.cpp.

References random().

441  {
442  // assign from aliased source
443  test.assign(test.c_str(), random(0, test.size()));
444 }
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_6_3_j ( String &  test)

Definition at line 447 of file FBStringTest.cpp.

447  {
448  // assign from aliased source
449  test.assign(test.c_str());
450 }
template<class String >
void clause11_21_4_6_3_k ( String &  test)

Definition at line 453 of file FBStringTest.cpp.

453  {
454  // assign from initializer_list
455  initializer_list<typename String::value_type> il{'a', 'b', 'c'};
456  test.assign(il);
457 }
template<class String >
void clause11_21_4_6_4 ( String &  test)

Definition at line 460 of file FBStringTest.cpp.

References EXPECT_EQ, i, random(), RandomList(), randomString(), and s.

460  {
461  // insert
462  String s;
463  randomString(&s, maxString);
464  test.insert(random(0, test.size()), s);
465  randomString(&s, maxString);
466  test.insert(
467  random(0, test.size()), s, random(0, s.size()), random(0, maxString));
468  randomString(&s, maxString);
469  test.insert(random(0, test.size()), s.c_str(), random(0, s.size()));
470  randomString(&s, maxString);
471  test.insert(random(0, test.size()), s.c_str());
472  test.insert(random(0, test.size()), random(0, maxString), random('a', 'z'));
473  typename String::size_type pos = random(0, test.size());
474  typename String::iterator res =
475  test.insert(test.begin() + pos, random('a', 'z'));
476  EXPECT_EQ(res - test.begin(), pos);
477  std::list<char> lst(RandomList(maxString));
478  pos = random(0, test.size());
479  // Uncomment below to see a bug in gcc
480  /*res = */ test.insert(test.begin() + pos, lst.begin(), lst.end());
481  // insert from initializer_list
482  initializer_list<typename String::value_type> il{'a', 'b', 'c'};
483  pos = random(0, test.size());
484  // Uncomment below to see a bug in gcc
485  /*res = */ test.insert(test.begin() + pos, il);
486 
487  // Test with actual input iterators
488  stringstream ss;
489  ss << "hello cruel world";
490  auto i = istream_iterator<char>(ss);
491  test.insert(test.begin(), i, istream_iterator<char>());
492 }
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::list< char > RandomList(unsigned int maxSize)
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_6_5 ( String &  test)

Definition at line 495 of file FBStringTest.cpp.

References i, and random().

495  {
496  // erase and pop_back
497  if (!test.empty()) {
498  test.erase(random(0, test.size()), random(0, maxString));
499  }
500  if (!test.empty()) {
501  // TODO: is erase(end()) allowed?
502  test.erase(test.begin() + random(0, test.size() - 1));
503  }
504  if (!test.empty()) {
505  auto const i = test.begin() + random(0, test.size());
506  if (i != test.end()) {
507  test.erase(i, i + random(0, size_t(test.end() - i)));
508  }
509  }
510  if (!test.empty()) {
511  // Can't test pop_back with std::string, doesn't support it yet.
512  // test.pop_back();
513  }
514 }
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_6_6 ( String &  test)

Definition at line 517 of file FBStringTest.cpp.

References b, random(), randomString(), and s.

517  {
518  auto pos = random(0, test.size());
519  if (avoidAliasing) {
520  test.replace(pos, random(0, test.size() - pos), String(test));
521  } else {
522  test.replace(pos, random(0, test.size() - pos), test);
523  }
524  pos = random(0, test.size());
525  String s;
526  randomString(&s, maxString);
527  test.replace(pos, pos + random(0, test.size() - pos), s);
528  auto pos1 = random(0, test.size());
529  auto pos2 = random(0, test.size());
530  if (avoidAliasing) {
531  test.replace(
532  pos1,
533  pos1 + random(0, test.size() - pos1),
534  String(test),
535  pos2,
536  pos2 + random(0, test.size() - pos2));
537  } else {
538  test.replace(
539  pos1,
540  pos1 + random(0, test.size() - pos1),
541  test,
542  pos2,
543  pos2 + random(0, test.size() - pos2));
544  }
545  pos1 = random(0, test.size());
546  String str;
547  randomString(&str, maxString);
548  pos2 = random(0, str.size());
549  test.replace(
550  pos1,
551  pos1 + random(0, test.size() - pos1),
552  str,
553  pos2,
554  pos2 + random(0, str.size() - pos2));
555  pos = random(0, test.size());
556  if (avoidAliasing) {
557  test.replace(
558  pos, random(0, test.size() - pos), String(test).c_str(), test.size());
559  } else {
560  test.replace(pos, random(0, test.size() - pos), test.c_str(), test.size());
561  }
562  pos = random(0, test.size());
563  randomString(&str, maxString);
564  test.replace(
565  pos, pos + random(0, test.size() - pos), str.c_str(), str.size());
566  pos = random(0, test.size());
567  randomString(&str, maxString);
568  test.replace(pos, pos + random(0, test.size() - pos), str.c_str());
569  pos = random(0, test.size());
570  test.replace(
571  pos,
572  random(0, test.size() - pos),
573  random(0, maxString),
574  random('a', 'z'));
575  pos = random(0, test.size());
576  if (avoidAliasing) {
577  auto newString = String(test);
578  test.replace(
579  test.begin() + pos,
580  test.begin() + pos + random(0, test.size() - pos),
581  newString);
582  } else {
583  test.replace(
584  test.begin() + pos,
585  test.begin() + pos + random(0, test.size() - pos),
586  test);
587  }
588  pos = random(0, test.size());
589  if (avoidAliasing) {
590  auto newString = String(test);
591  test.replace(
592  test.begin() + pos,
593  test.begin() + pos + random(0, test.size() - pos),
594  newString.c_str(),
595  test.size() - random(0, test.size()));
596  } else {
597  test.replace(
598  test.begin() + pos,
599  test.begin() + pos + random(0, test.size() - pos),
600  test.c_str(),
601  test.size() - random(0, test.size()));
602  }
603  pos = random(0, test.size());
604  auto const n = random(0, test.size() - pos);
605  typename String::iterator b = test.begin();
606  String str1;
607  randomString(&str1, maxString);
608  const String& str3 = str1;
609  const typename String::value_type* ss = str3.c_str();
610  test.replace(b + pos, b + pos + n, ss);
611  pos = random(0, test.size());
612  test.replace(
613  test.begin() + pos,
614  test.begin() + pos + random(0, test.size() - pos),
615  random(0, maxString),
616  random('a', 'z'));
617 }
Integral2 random(Integral1 low, Integral2 up)
char b
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_6_7 ( String &  test)

Definition at line 620 of file FBStringTest.cpp.

References random().

620  {
621  std::vector<typename String::value_type> vec(random(0, maxString));
622  if (vec.empty()) {
623  return;
624  }
625  test.copy(vec.data(), vec.size(), random(0, test.size()));
626 }
Integral2 random(Integral1 low, Integral2 up)
Definition: Traits.h:588
vector< string > vec
Definition: StringTest.cpp:35
template<class String >
void clause11_21_4_6_8 ( String &  test)

Definition at line 629 of file FBStringTest.cpp.

References randomString(), and s.

629  {
630  String s;
631  randomString(&s, maxString);
632  s.swap(test);
633 }
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_1 ( String &  test)

Definition at line 636 of file FBStringTest.cpp.

References randomString(), and s.

636  {
637  // 21.3.6 string operations
638  // exercise c_str() and data()
639  assert(test.c_str() == test.data());
640  // exercise get_allocator()
641  String s;
642  randomString(&s, maxString);
643  DCHECK(test.get_allocator() == s.get_allocator());
644 }
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_2_a ( String &  test)

Definition at line 647 of file FBStringTest.cpp.

References Num2String(), and random().

647  {
648  String str = test.substr(random(0, test.size()), random(0, test.size()));
649  Num2String(test, test.find(str, random(0, test.size())));
650 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_2_a1 ( String &  test)

Definition at line 653 of file FBStringTest.cpp.

References Num2String(), and random().

653  {
654  String str =
655  String(test).substr(random(0, test.size()), random(0, test.size()));
656  Num2String(test, test.find(str, random(0, test.size())));
657 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_2_a2 ( String &  test)

Definition at line 660 of file FBStringTest.cpp.

References Num2String(), random(), and test().

660  {
661  auto const& cTest = test;
662  String str = cTest.substr(random(0, test.size()), random(0, test.size()));
663  Num2String(test, test.find(str, random(0, test.size())));
664 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
template<class String >
void clause11_21_4_7_2_b ( String &  test)

Definition at line 667 of file FBStringTest.cpp.

References folly::pushmi::operators::from, Num2String(), and random().

667  {
668  auto from = random(0, test.size());
669  auto length = random(0, test.size() - from);
670  String str = test.substr(from, length);
671  Num2String(
672  test,
673  test.find(str.c_str(), random(0, test.size()), random(0, str.size())));
674 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
template<class String >
void clause11_21_4_7_2_b1 ( String &  test)

Definition at line 677 of file FBStringTest.cpp.

References folly::pushmi::operators::from, Num2String(), and random().

677  {
678  auto from = random(0, test.size());
679  auto length = random(0, test.size() - from);
680  String str = String(test).substr(from, length);
681  Num2String(
682  test,
683  test.find(str.c_str(), random(0, test.size()), random(0, str.size())));
684 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
template<class String >
void clause11_21_4_7_2_b2 ( String &  test)

Definition at line 687 of file FBStringTest.cpp.

References folly::pushmi::operators::from, Num2String(), random(), and test().

687  {
688  auto from = random(0, test.size());
689  auto length = random(0, test.size() - from);
690  const auto& cTest = test;
691  String str = cTest.substr(from, length);
692  Num2String(
693  test,
694  test.find(str.c_str(), random(0, test.size()), random(0, str.size())));
695 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
template<class String >
void clause11_21_4_7_2_c ( String &  test)

Definition at line 698 of file FBStringTest.cpp.

References Num2String(), and random().

698  {
699  String str = test.substr(random(0, test.size()), random(0, test.size()));
700  Num2String(test, test.find(str.c_str(), random(0, test.size())));
701 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_2_c1 ( String &  test)

Definition at line 704 of file FBStringTest.cpp.

References Num2String(), and random().

704  {
705  String str =
706  String(test).substr(random(0, test.size()), random(0, test.size()));
707  Num2String(test, test.find(str.c_str(), random(0, test.size())));
708 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_2_c2 ( String &  test)

Definition at line 711 of file FBStringTest.cpp.

References Num2String(), random(), and test().

711  {
712  const auto& cTest = test;
713  String str = cTest.substr(random(0, test.size()), random(0, test.size()));
714  Num2String(test, test.find(str.c_str(), random(0, test.size())));
715 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
template<class String >
void clause11_21_4_7_2_d ( String &  test)

Definition at line 718 of file FBStringTest.cpp.

References Num2String(), and random().

718  {
719  Num2String(test, test.find(random('a', 'z'), random(0, test.size())));
720 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_3_a ( String &  test)

Definition at line 723 of file FBStringTest.cpp.

References Num2String(), and random().

723  {
724  String str = test.substr(random(0, test.size()), random(0, test.size()));
725  Num2String(test, test.rfind(str, random(0, test.size())));
726 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_3_b ( String &  test)

Definition at line 729 of file FBStringTest.cpp.

References Num2String(), and random().

729  {
730  String str = test.substr(random(0, test.size()), random(0, test.size()));
731  Num2String(
732  test,
733  test.rfind(str.c_str(), random(0, test.size()), random(0, str.size())));
734 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_3_c ( String &  test)

Definition at line 737 of file FBStringTest.cpp.

References Num2String(), and random().

737  {
738  String str = test.substr(random(0, test.size()), random(0, test.size()));
739  Num2String(test, test.rfind(str.c_str(), random(0, test.size())));
740 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_3_d ( String &  test)

Definition at line 743 of file FBStringTest.cpp.

References Num2String(), and random().

743  {
744  Num2String(test, test.rfind(random('a', 'z'), random(0, test.size())));
745 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_4_a ( String &  test)

Definition at line 748 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

748  {
749  String str;
750  randomString(&str, maxString);
751  Num2String(test, test.find_first_of(str, random(0, test.size())));
752 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_4_b ( String &  test)

Definition at line 755 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

755  {
756  String str;
757  randomString(&str, maxString);
758  Num2String(
759  test,
760  test.find_first_of(
761  str.c_str(), random(0, test.size()), random(0, str.size())));
762 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_4_c ( String &  test)

Definition at line 765 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

765  {
766  String str;
767  randomString(&str, maxString);
768  Num2String(test, test.find_first_of(str.c_str(), random(0, test.size())));
769 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_4_d ( String &  test)

Definition at line 772 of file FBStringTest.cpp.

References Num2String(), and random().

772  {
773  Num2String(
774  test, test.find_first_of(random('a', 'z'), random(0, test.size())));
775 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_5_a ( String &  test)

Definition at line 778 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

778  {
779  String str;
780  randomString(&str, maxString);
781  Num2String(test, test.find_last_of(str, random(0, test.size())));
782 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_5_b ( String &  test)

Definition at line 785 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

785  {
786  String str;
787  randomString(&str, maxString);
788  Num2String(
789  test,
790  test.find_last_of(
791  str.c_str(), random(0, test.size()), random(0, str.size())));
792 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_5_c ( String &  test)

Definition at line 795 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

795  {
796  String str;
797  randomString(&str, maxString);
798  Num2String(test, test.find_last_of(str.c_str(), random(0, test.size())));
799 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_5_d ( String &  test)

Definition at line 802 of file FBStringTest.cpp.

References Num2String(), and random().

802  {
803  Num2String(test, test.find_last_of(random('a', 'z'), random(0, test.size())));
804 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_6_a ( String &  test)

Definition at line 807 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

807  {
808  String str;
809  randomString(&str, maxString);
810  Num2String(test, test.find_first_not_of(str, random(0, test.size())));
811 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_6_b ( String &  test)

Definition at line 814 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

814  {
815  String str;
816  randomString(&str, maxString);
817  Num2String(
818  test,
819  test.find_first_not_of(
820  str.c_str(), random(0, test.size()), random(0, str.size())));
821 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_6_c ( String &  test)

Definition at line 824 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

824  {
825  String str;
826  randomString(&str, maxString);
827  Num2String(test, test.find_first_not_of(str.c_str(), random(0, test.size())));
828 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_6_d ( String &  test)

Definition at line 831 of file FBStringTest.cpp.

References Num2String(), and random().

831  {
832  Num2String(
833  test, test.find_first_not_of(random('a', 'z'), random(0, test.size())));
834 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_7_a ( String &  test)

Definition at line 837 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

837  {
838  String str;
839  randomString(&str, maxString);
840  Num2String(test, test.find_last_not_of(str, random(0, test.size())));
841 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_7_b ( String &  test)

Definition at line 844 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

844  {
845  String str;
846  randomString(&str, maxString);
847  Num2String(
848  test,
849  test.find_last_not_of(
850  str.c_str(), random(0, test.size()), random(0, str.size())));
851 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_7_c ( String &  test)

Definition at line 854 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

854  {
855  String str;
856  randomString(&str, maxString);
857  Num2String(test, test.find_last_not_of(str.c_str(), random(0, test.size())));
858 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_7_d ( String &  test)

Definition at line 861 of file FBStringTest.cpp.

References Num2String(), and random().

861  {
862  Num2String(
863  test, test.find_last_not_of(random('a', 'z'), random(0, test.size())));
864 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_8 ( String &  test)

Definition at line 867 of file FBStringTest.cpp.

References random().

867  {
868  test = test.substr(random(0, test.size()), random(0, test.size()));
869 }
Integral2 random(Integral1 low, Integral2 up)
template<class String >
void clause11_21_4_7_9_a ( String &  test)

Definition at line 872 of file FBStringTest.cpp.

References Num2String(), randomString(), and s.

872  {
873  String s;
874  randomString(&s, maxString);
875  int tristate = test.compare(s);
876  if (tristate > 0) {
877  tristate = 1;
878  } else if (tristate < 0) {
879  tristate = 2;
880  }
881  Num2String(test, tristate);
882 }
void Num2String(String &str, Integral n)
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_9_b ( String &  test)

Definition at line 885 of file FBStringTest.cpp.

References Num2String(), random(), randomString(), and s.

885  {
886  String s;
887  randomString(&s, maxString);
888  int tristate =
889  test.compare(random(0, test.size()), random(0, test.size()), s);
890  if (tristate > 0) {
891  tristate = 1;
892  } else if (tristate < 0) {
893  tristate = 2;
894  }
895  Num2String(test, tristate);
896 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_9_c ( String &  test)

Definition at line 899 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

899  {
900  String str;
901  randomString(&str, maxString);
902  int tristate = test.compare(
903  random(0, test.size()),
904  random(0, test.size()),
905  str,
906  random(0, str.size()),
907  random(0, str.size()));
908  if (tristate > 0) {
909  tristate = 1;
910  } else if (tristate < 0) {
911  tristate = 2;
912  }
913  Num2String(test, tristate);
914 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_9_d ( String &  test)

Definition at line 917 of file FBStringTest.cpp.

References Num2String(), randomString(), and s.

917  {
918  String s;
919  randomString(&s, maxString);
920  int tristate = test.compare(s.c_str());
921  if (tristate > 0) {
922  tristate = 1;
923  } else if (tristate < 0) {
924  tristate = 2;
925  }
926  Num2String(test, tristate);
927 }
void Num2String(String &str, Integral n)
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_7_9_e ( String &  test)

Definition at line 930 of file FBStringTest.cpp.

References Num2String(), random(), and randomString().

930  {
931  String str;
932  randomString(&str, maxString);
933  int tristate = test.compare(
934  random(0, test.size()),
935  random(0, test.size()),
936  str.c_str(),
937  random(0, str.size()));
938  if (tristate > 0) {
939  tristate = 1;
940  } else if (tristate < 0) {
941  tristate = 2;
942  }
943  Num2String(test, tristate);
944 }
void Num2String(String &str, Integral n)
Integral2 random(Integral1 low, Integral2 up)
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_a ( String &  test)

Definition at line 947 of file FBStringTest.cpp.

References randomString().

947  {
948  String s1;
949  randomString(&s1, maxString);
950  String s2;
951  randomString(&s2, maxString);
952  test = s1 + s2;
953 }
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_b ( String &  test)

Definition at line 956 of file FBStringTest.cpp.

References folly::gen::move, and randomString().

956  {
957  String s1;
958  randomString(&s1, maxString);
959  String s2;
960  randomString(&s2, maxString);
961  test = move(s1) + s2;
962 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_c ( String &  test)

Definition at line 965 of file FBStringTest.cpp.

References folly::gen::move, and randomString().

965  {
966  String s1;
967  randomString(&s1, maxString);
968  String s2;
969  randomString(&s2, maxString);
970  test = s1 + move(s2);
971 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_d ( String &  test)

Definition at line 974 of file FBStringTest.cpp.

References folly::gen::move, and randomString().

974  {
975  String s1;
976  randomString(&s1, maxString);
977  String s2;
978  randomString(&s2, maxString);
979  test = move(s1) + move(s2);
980 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_e ( String &  test)

Definition at line 983 of file FBStringTest.cpp.

References randomString(), and s.

983  {
984  String s;
985  randomString(&s, maxString);
986  String s1;
987  randomString(&s1, maxString);
988  test = s.c_str() + s1;
989 }
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_f ( String &  test)

Definition at line 992 of file FBStringTest.cpp.

References folly::gen::move, randomString(), and s.

992  {
993  String s;
994  randomString(&s, maxString);
995  String s1;
996  randomString(&s1, maxString);
997  test = s.c_str() + move(s1);
998 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_g ( String &  test)

Definition at line 1001 of file FBStringTest.cpp.

References random(), randomString(), and s.

1001  {
1002  String s;
1003  randomString(&s, maxString);
1004  test = typename String::value_type(random('a', 'z')) + s;
1005 }
Integral2 random(Integral1 low, Integral2 up)
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_h ( String &  test)

Definition at line 1008 of file FBStringTest.cpp.

References folly::gen::move, random(), randomString(), and s.

1008  {
1009  String s;
1010  randomString(&s, maxString);
1011  test = typename String::value_type(random('a', 'z')) + move(s);
1012 }
Integral2 random(Integral1 low, Integral2 up)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_i ( String &  test)

Definition at line 1015 of file FBStringTest.cpp.

References randomString(), and s.

1015  {
1016  String s;
1017  randomString(&s, maxString);
1018  String s1;
1019  randomString(&s1, maxString);
1020  test = s + s1.c_str();
1021 }
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_j ( String &  test)

Definition at line 1024 of file FBStringTest.cpp.

References folly::gen::move, randomString(), and s.

1024  {
1025  String s;
1026  randomString(&s, maxString);
1027  String s1;
1028  randomString(&s1, maxString);
1029  test = move(s) + s1.c_str();
1030 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_k ( String &  test)

Definition at line 1033 of file FBStringTest.cpp.

References random(), randomString(), and s.

1033  {
1034  String s;
1035  randomString(&s, maxString);
1036  test = s + typename String::value_type(random('a', 'z'));
1037 }
Integral2 random(Integral1 low, Integral2 up)
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_1_l ( String &  test)

Definition at line 1040 of file FBStringTest.cpp.

References folly::gen::move, randomString(), and s.

1040  {
1041  String s;
1042  randomString(&s, maxString);
1043  String s1;
1044  randomString(&s1, maxString);
1045  test = move(s) + s1.c_str();
1046 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static set< string > s
void randomString(String *toFill, size_t size=1000)
template<class String >
void clause11_21_4_8_9_a ( String &  test)

Definition at line 1050 of file FBStringTest.cpp.

References test().

1050  {
1051  basic_stringstream<typename String::value_type> stst(test.c_str());
1052  String str;
1053  while (stst) {
1054  stst >> str;
1055  test += str + test;
1056  }
1057 }
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
TEST ( FBString  ,
testAllClauses   
)

Definition at line 1059 of file FBStringTest.cpp.

References c, folly::basic_fbstring< E, T, A, Storage >::c_str(), count, folly::basic_fbstring< E, T, A, Storage >::data(), EXPECT_EQ, EXPECT_TRUE, mb(), randomString(), rng, seed, folly::basic_fbstring< E, T, A, Storage >::size(), string, and TEST_CLAUSE.

Referenced by TEST().

1059  {
1060  EXPECT_TRUE(1) << "Starting with seed: " << seed;
1061  std::string r;
1063 #if FOLLY_HAVE_WCHAR_SUPPORT
1064  std::wstring wr;
1066 #endif
1067  int count = 0;
1068 
1069  auto l = [&](const char* const clause,
1070  void (*f_string)(std::string&),
1071  void (*f_fbstring)(folly::fbstring&),
1072  void (*f_wfbstring)(folly::basic_fbstring<wchar_t>&)) {
1073  do {
1074  if (true) {
1075  } else {
1076  EXPECT_TRUE(1) << "Testing clause " << clause;
1077  }
1078  randomString(&r);
1079  c = r;
1080  EXPECT_EQ(c, r);
1081 #if FOLLY_HAVE_WCHAR_SUPPORT
1082  wr = std::wstring(r.begin(), r.end());
1083  wc = folly::basic_fbstring<wchar_t>(wr.c_str());
1084 #endif
1085  auto localSeed = seed + count;
1086  rng = RandomT(localSeed);
1087  f_string(r);
1088  rng = RandomT(localSeed);
1089  f_fbstring(c);
1090  EXPECT_EQ(r, c) << "Lengths: " << r.size() << " vs. " << c.size()
1091  << "\nReference: '" << r << "'"
1092  << "\nActual: '" << c.data()[0] << "'";
1093 #if FOLLY_HAVE_WCHAR_SUPPORT
1094  rng = RandomT(localSeed);
1095  f_wfbstring(wc);
1096  int wret = wcslen(wc.c_str());
1097  auto mbv = std::vector<char>(wret + 1);
1098  auto mb = mbv.data();
1099  int ret = wcstombs(mb, wc.c_str(), wret + 1);
1100  if (ret == wret) {
1101  mb[wret] = '\0';
1102  }
1103  const char* mc = c.c_str();
1104  std::string one(mb);
1105  std::string two(mc);
1106  EXPECT_EQ(one, two);
1107 #endif
1108  } while (++count % 100 != 0);
1109  };
1110 
1111 #define TEST_CLAUSE(x) \
1112  l(#x, \
1113  clause11_##x<std::string>, \
1114  clause11_##x<folly::fbstring>, \
1115  clause11_##x<folly::basic_fbstring<wchar_t>>);
1116 
1117  TEST_CLAUSE(21_4_2_a);
1118  TEST_CLAUSE(21_4_2_b);
1119  TEST_CLAUSE(21_4_2_c);
1120  TEST_CLAUSE(21_4_2_d);
1121  TEST_CLAUSE(21_4_2_e);
1122  TEST_CLAUSE(21_4_2_f);
1123  TEST_CLAUSE(21_4_2_g);
1124  TEST_CLAUSE(21_4_2_h);
1125  TEST_CLAUSE(21_4_2_i);
1126  TEST_CLAUSE(21_4_2_j);
1127  TEST_CLAUSE(21_4_2_k);
1128  TEST_CLAUSE(21_4_2_l);
1129  TEST_CLAUSE(21_4_2_lprime);
1130  TEST_CLAUSE(21_4_2_m);
1131  TEST_CLAUSE(21_4_2_n);
1132  TEST_CLAUSE(21_4_3);
1133  TEST_CLAUSE(21_4_4);
1134  TEST_CLAUSE(21_4_5);
1135  TEST_CLAUSE(21_4_6_1);
1136  TEST_CLAUSE(21_4_6_2);
1137  TEST_CLAUSE(21_4_6_3_a);
1138  TEST_CLAUSE(21_4_6_3_b);
1139  TEST_CLAUSE(21_4_6_3_c);
1140  TEST_CLAUSE(21_4_6_3_d);
1141  TEST_CLAUSE(21_4_6_3_e);
1142  TEST_CLAUSE(21_4_6_3_f);
1143  TEST_CLAUSE(21_4_6_3_g);
1144  TEST_CLAUSE(21_4_6_3_h);
1145  TEST_CLAUSE(21_4_6_3_i);
1146  TEST_CLAUSE(21_4_6_3_j);
1147  TEST_CLAUSE(21_4_6_3_k);
1148  TEST_CLAUSE(21_4_6_4);
1149  TEST_CLAUSE(21_4_6_5);
1150  TEST_CLAUSE(21_4_6_6);
1151  TEST_CLAUSE(21_4_6_7);
1152  TEST_CLAUSE(21_4_6_8);
1153  TEST_CLAUSE(21_4_7_1);
1154 
1155  TEST_CLAUSE(21_4_7_2_a);
1156  TEST_CLAUSE(21_4_7_2_a1);
1157  TEST_CLAUSE(21_4_7_2_a2);
1158  TEST_CLAUSE(21_4_7_2_b);
1159  TEST_CLAUSE(21_4_7_2_b1);
1160  TEST_CLAUSE(21_4_7_2_b2);
1161  TEST_CLAUSE(21_4_7_2_c);
1162  TEST_CLAUSE(21_4_7_2_c1);
1163  TEST_CLAUSE(21_4_7_2_c2);
1164  TEST_CLAUSE(21_4_7_2_d);
1165  TEST_CLAUSE(21_4_7_3_a);
1166  TEST_CLAUSE(21_4_7_3_b);
1167  TEST_CLAUSE(21_4_7_3_c);
1168  TEST_CLAUSE(21_4_7_3_d);
1169  TEST_CLAUSE(21_4_7_4_a);
1170  TEST_CLAUSE(21_4_7_4_b);
1171  TEST_CLAUSE(21_4_7_4_c);
1172  TEST_CLAUSE(21_4_7_4_d);
1173  TEST_CLAUSE(21_4_7_5_a);
1174  TEST_CLAUSE(21_4_7_5_b);
1175  TEST_CLAUSE(21_4_7_5_c);
1176  TEST_CLAUSE(21_4_7_5_d);
1177  TEST_CLAUSE(21_4_7_6_a);
1178  TEST_CLAUSE(21_4_7_6_b);
1179  TEST_CLAUSE(21_4_7_6_c);
1180  TEST_CLAUSE(21_4_7_6_d);
1181  TEST_CLAUSE(21_4_7_7_a);
1182  TEST_CLAUSE(21_4_7_7_b);
1183  TEST_CLAUSE(21_4_7_7_c);
1184  TEST_CLAUSE(21_4_7_7_d);
1185  TEST_CLAUSE(21_4_7_8);
1186  TEST_CLAUSE(21_4_7_9_a);
1187  TEST_CLAUSE(21_4_7_9_b);
1188  TEST_CLAUSE(21_4_7_9_c);
1189  TEST_CLAUSE(21_4_7_9_d);
1190  TEST_CLAUSE(21_4_7_9_e);
1191  TEST_CLAUSE(21_4_8_1_a);
1192  TEST_CLAUSE(21_4_8_1_b);
1193  TEST_CLAUSE(21_4_8_1_c);
1194  TEST_CLAUSE(21_4_8_1_d);
1195  TEST_CLAUSE(21_4_8_1_e);
1196  TEST_CLAUSE(21_4_8_1_f);
1197  TEST_CLAUSE(21_4_8_1_g);
1198  TEST_CLAUSE(21_4_8_1_h);
1199  TEST_CLAUSE(21_4_8_1_i);
1200  TEST_CLAUSE(21_4_8_1_j);
1201  TEST_CLAUSE(21_4_8_1_k);
1202  TEST_CLAUSE(21_4_8_1_l);
1203  TEST_CLAUSE(21_4_8_9_a);
1204 }
const value_type * c_str() const
Definition: FBString.h:1712
size_type size() const
Definition: FBString.h:1337
#define TEST_CLAUSE(x)
static const int seed
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
boost::mt19937 RandomT
auto rng
Definition: CollectTest.cpp:31
const value_type * data() const
Definition: FBString.h:1716
::std::wstring wstring
Definition: gtest-port.h:1103
int * count
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static constexpr int mb(int megs)
const char * string
Definition: Conv.cpp:212
char c
void randomString(String *toFill, size_t size=1000)
TEST ( FBString  ,
testGetline   
)

Definition at line 1206 of file FBStringTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, fail(), FOR_EACH, getline(), folly::gen::split(), and v.

1206  {
1207  string s1 =
1208  "\
1209 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras accumsan \n\
1210 elit ut urna consectetur in sagittis mi auctor. Nulla facilisi. In nec \n\
1211 dolor leo, vitae imperdiet neque. Donec ut erat mauris, a faucibus \n\
1212 elit. Integer consectetur gravida augue, sit amet mattis mauris auctor \n\
1213 sed. Morbi congue libero eu nunc sodales adipiscing. In lectus nunc, \n\
1214 vulputate a fringilla at, venenatis quis justo. Proin eu velit \n\
1215 nibh. Maecenas vitae tellus eros. Pellentesque habitant morbi \n\
1216 tristique senectus et netus et malesuada fames ac turpis \n\
1217 egestas. Vivamus faucibus feugiat consequat. Donec fermentum neque sit \n\
1218 amet ligula suscipit porta. Phasellus facilisis felis in purus luctus \n\
1219 quis posuere leo tempor. Nam nunc purus, luctus a pharetra ut, \n\
1220 placerat at dui. Donec imperdiet, diam quis convallis pulvinar, dui \n\
1221 est commodo lorem, ut tincidunt diam nibh et nibh. Maecenas nec velit \n\
1222 massa, ut accumsan magna. Donec imperdiet tempor nisi et \n\
1223 laoreet. Phasellus lectus quam, ultricies ut tincidunt in, dignissim \n\
1224 id eros. Mauris vulputate tortor nec neque pellentesque sagittis quis \n\
1225 sed nisl. In diam lacus, lobortis ut posuere nec, ornare id quam.";
1226 
1227  vector<fbstring> v;
1228  boost::split(v, s1, boost::is_any_of("\n"));
1229  {
1230  istringstream input(s1);
1231  fbstring line;
1232  FOR_EACH (i, v) {
1233  EXPECT_TRUE(!getline(input, line).fail());
1234  EXPECT_EQ(line, *i);
1235  }
1236  }
1237 }
auto v
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void BENCHFUN() getline(size_t iters, size_t arg)
void fail()
S split(const StringPiece source, char delimiter)
Definition: String.h:61
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define FOR_EACH(i, c)
Definition: Foreach.h:143
TEST ( FBString  ,
testMoveCtor   
)

Definition at line 1239 of file FBStringTest.cpp.

References folly::basic_fbstring< E, T, A, Storage >::empty(), EXPECT_EQ, EXPECT_TRUE, folly::gen::move, random(), s, folly::size(), and folly::basic_fbstring< E, T, A, Storage >::size().

1239  {
1240  // Move constructor. Make sure we allocate a large string, so the
1241  // small string optimization doesn't kick in.
1242  auto size = random(100, 2000);
1243  fbstring s(size, 'a');
1244  fbstring test = std::move(s);
1245  EXPECT_TRUE(s.empty());
1246  EXPECT_EQ(size, test.size());
1247 }
size_type size() const
Definition: FBString.h:1337
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static set< string > s
TEST ( FBString  ,
testMoveAssign   
)

Definition at line 1249 of file FBStringTest.cpp.

References folly::basic_fbstring< E, T, A, Storage >::empty(), EXPECT_EQ, EXPECT_TRUE, folly::gen::move, random(), s, folly::size(), folly::basic_fbstring< E, T, A, Storage >::size(), and test().

1249  {
1250  // Move constructor. Make sure we allocate a large string, so the
1251  // small string optimization doesn't kick in.
1252  auto size = random(100, 2000);
1253  fbstring s(size, 'a');
1254  fbstring test;
1255  test = std::move(s);
1256  EXPECT_TRUE(s.empty());
1257  EXPECT_EQ(size, test.size());
1258 }
size_type size() const
Definition: FBString.h:1337
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static set< string > s
TEST ( FBString  ,
testMoveOperatorPlusLhs   
)

Definition at line 1260 of file FBStringTest.cpp.

References folly::basic_fbstring< E, T, A, Storage >::empty(), EXPECT_EQ, EXPECT_TRUE, folly::gen::move, random(), folly::basic_fbstring< E, T, A, Storage >::size(), and test().

1260  {
1261  // Make sure we allocate a large string, so the
1262  // small string optimization doesn't kick in.
1263  auto size1 = random(100, 2000);
1264  auto size2 = random(100, 2000);
1265  fbstring s1(size1, 'a');
1266  fbstring s2(size2, 'b');
1267  fbstring test;
1268  test = std::move(s1) + s2;
1269  EXPECT_TRUE(s1.empty());
1270  EXPECT_EQ(size1 + size2, test.size());
1271 }
size_type size() const
Definition: FBString.h:1337
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
TEST ( FBString  ,
testMoveOperatorPlusRhs   
)

Definition at line 1273 of file FBStringTest.cpp.

References EXPECT_EQ, folly::gen::move, random(), folly::basic_fbstring< E, T, A, Storage >::size(), and test().

1273  {
1274  // Make sure we allocate a large string, so the
1275  // small string optimization doesn't kick in.
1276  auto size1 = random(100, 2000);
1277  auto size2 = random(100, 2000);
1278  fbstring s1(size1, 'a');
1279  fbstring s2(size2, 'b');
1280  fbstring test;
1281  test = s1 + std::move(s2);
1282  EXPECT_EQ(size1 + size2, test.size());
1283 }
size_type size() const
Definition: FBString.h:1337
Integral2 random(Integral1 low, Integral2 up)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( FBString  ,
testConstructionFromLiteralZero   
)

Definition at line 1291 of file FBStringTest.cpp.

References EXPECT_THROW, and s.

1291  {
1292  EXPECT_THROW(fbstring s(nullptr), std::logic_error);
1293 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
static set< string > s
TEST ( FBString  ,
testFixedBugs_D479397   
)

Definition at line 1295 of file FBStringTest.cpp.

References folly::basic_fbstring< E, T, A, Storage >::c_str(), folly::basic_fbstring< E, T, A, Storage >::clear(), EXPECT_EQ, and folly::basic_fbstring< E, T, A, Storage >::front().

1295  {
1296  fbstring str(1337, 'f');
1297  fbstring cp = str;
1298  cp.clear();
1299  cp.c_str();
1300  EXPECT_EQ(str.front(), 'f');
1301 }
const value_type * c_str() const
Definition: FBString.h:1712
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( FBString  ,
testFixedBugs_D481173   
)

Definition at line 1303 of file FBStringTest.cpp.

References folly::basic_fbstring< E, T, A, Storage >::c_str(), EXPECT_EQ, i, folly::basic_fbstring< E, T, A, Storage >::push_back(), and folly::basic_fbstring< E, T, A, Storage >::size().

1303  {
1304  fbstring str(1337, 'f');
1305  for (int i = 0; i < 2; ++i) {
1306  fbstring cp = str;
1307  cp[1] = 'b';
1308  EXPECT_EQ(cp.c_str()[cp.size()], '\0');
1309  cp.push_back('?');
1310  }
1311 }
const value_type * c_str() const
Definition: FBString.h:1712
size_type size() const
Definition: FBString.h:1337
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void push_back(const value_type c)
Definition: FBString.h:1437
TEST ( FBString  ,
testFixedBugs_D580267_push_back   
)

Definition at line 1313 of file FBStringTest.cpp.

References folly::basic_fbstring< E, T, A, Storage >::push_back().

1313  {
1314  fbstring str(1337, 'f');
1315  fbstring cp = str;
1316  cp.push_back('f');
1317 }
void push_back(const value_type c)
Definition: FBString.h:1437
TEST ( FBString  ,
testFixedBugs_D580267_operator_add_assign   
)

Definition at line 1319 of file FBStringTest.cpp.

1319  {
1320  fbstring str(1337, 'f');
1321  fbstring cp = str;
1322  cp += "bb";
1323 }
TEST ( FBString  ,
testFixedBugs_D661622   
)

Definition at line 1325 of file FBStringTest.cpp.

References EXPECT_EQ, s, and folly::basic_fbstring< E, T, A, Storage >::size().

1325  {
1327  EXPECT_EQ(0, s.size());
1328 }
size_type size() const
Definition: FBString.h:1337
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static set< string > s
TEST ( FBString  ,
testFixedBugs_D785057   
)

Definition at line 1330 of file FBStringTest.cpp.

References EXPECT_EQ, folly::basic_fbstring< E, T, A, Storage >::size(), and folly::f14::swap().

1330  {
1331  fbstring str(1337, 'f');
1332  std::swap(str, str);
1333  EXPECT_EQ(1337, str.size());
1334 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414
TEST ( FBString  ,
testFixedBugs_D1012196_allocator_malloc   
)

Definition at line 1336 of file FBStringTest.cpp.

References folly::basic_fbstring< E, T, A, Storage >::capacity(), folly::basic_fbstring< E, T, A, Storage >::clear(), folly::copy(), EXPECT_GE, and folly::basic_fbstring< E, T, A, Storage >::push_back().

1336  {
1337  fbstring str(128, 'f');
1338  str.clear(); // Empty medium string.
1339  fbstring copy(str); // Medium string of 0 capacity.
1340  copy.push_back('b');
1341  EXPECT_GE(copy.capacity(), 1);
1342 }
#define EXPECT_GE(val1, val2)
Definition: gtest.h:1932
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
TEST ( FBString  ,
testFixedBugs_D2813713   
)

Definition at line 1344 of file FBStringTest.cpp.

References EXPECT_EQ, folly::gen::move, and folly::basic_fbstring< E, T, A, Storage >::reserve().

1344  {
1345  fbstring s1("a");
1346  s1.reserve(8); // Trigger the optimized code path.
1347  auto test1 = '\0' + std::move(s1);
1348  EXPECT_EQ(2, test1.size());
1349 
1350  fbstring s2(1, '\0');
1351  s2.reserve(8);
1352  auto test2 = "a" + std::move(s2);
1353  EXPECT_EQ(2, test2.size());
1354 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( FBString  ,
testFixedBugs_D3698862   
)

Definition at line 1356 of file FBStringTest.cpp.

References EXPECT_EQ.

1356  {
1357  EXPECT_EQ(fbstring().find(fbstring(), 4), fbstring::npos);
1358 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
basic_fbstring< char > fbstring
Definition: FBString.h:2904
TEST ( FBString  ,
testFixedBugs_D4355440   
)

Definition at line 1360 of file FBStringTest.cpp.

References folly::basic_fbstring< E, T, A, Storage >::capacity(), EXPECT_EQ, EXPECT_NE, folly::goodMallocSize(), folly::basic_fbstring< E, T, A, Storage >::reserve(), SKIP_IF, and folly::usingJEMalloc().

1360  {
1361  SKIP_IF(!usingJEMalloc());
1362 
1363  fbstring str(1337, 'f');
1364  str.reserve(3840);
1365  EXPECT_NE(str.capacity(), 3840);
1366 
1367  struct DummyRefCounted {
1368  std::atomic<size_t> refCount_;
1369  };
1370  EXPECT_EQ(
1371  str.capacity(),
1372  goodMallocSize(3840) - sizeof(DummyRefCounted) - sizeof(char));
1373 }
bool usingJEMalloc() noexcept
Definition: Malloc.h:147
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
#define SKIP_IF(expr)
Definition: TestUtils.h:59
size_t goodMallocSize(size_t minSize) noexcept
Definition: Malloc.h:201
TEST ( FBString  ,
findWithNpos   
)

Definition at line 1375 of file FBStringTest.cpp.

References EXPECT_EQ, and folly::basic_fbstring< E, T, A, Storage >::find().

1375  {
1376  fbstring fbstr("localhost:80");
1377  EXPECT_EQ(fbstring::npos, fbstr.find(":", fbstring::npos));
1378 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( FBString  ,
testHash   
)

Definition at line 1380 of file FBStringTest.cpp.

References a, b, EXPECT_NE, folly::basic_fbstring< E, T, A, Storage >::push_back(), and TEST().

1380  {
1381  fbstring a;
1382  fbstring b;
1383  a.push_back(0);
1384  a.push_back(1);
1385  b.push_back(0);
1386  b.push_back(2);
1387  std::hash<fbstring> hashfunc;
1388  EXPECT_NE(hashfunc(a), hashfunc(b));
1389 }
char b
char a
void push_back(const value_type c)
Definition: FBString.h:1437
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST ( FBString  ,
testFrontBack   
)

Definition at line 1405 of file FBStringTest.cpp.

References folly::basic_fbstring< E, T, A, Storage >::back(), EXPECT_EQ, and folly::basic_fbstring< E, T, A, Storage >::front().

1405  {
1406  fbstring str("hello");
1407  EXPECT_EQ(str.front(), 'h');
1408  EXPECT_EQ(str.back(), 'o');
1409  str.front() = 'H';
1410  EXPECT_EQ(str.front(), 'H');
1411  str.back() = 'O';
1412  EXPECT_EQ(str.back(), 'O');
1413  EXPECT_EQ(str, "HellO");
1414 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( FBString  ,
noexcept   
)

Definition at line 1416 of file FBStringTest.cpp.

References EXPECT_FALSE, EXPECT_TRUE, folly::gen::move, folly::pushmi::__adl::noexcept(), and x.

1416  {
1418  fbstring x;
1421  fbstring y;
1422  EXPECT_FALSE(noexcept(y = x));
1423  EXPECT_TRUE(noexcept(y = std::move(x)));
1424 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
requires E e noexcept(noexcept(s.error(std::move(e))))
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Definition: InvokeTest.cpp:65
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
basic_fbstring< char > fbstring
Definition: FBString.h:2904
TEST ( FBString  ,
iomanip   
)

Definition at line 1426 of file FBStringTest.cpp.

References EXPECT_EQ.

1426  {
1427  stringstream ss;
1428  fbstring fbstr("Hello");
1429 
1430  ss << setw(6) << fbstr;
1431  EXPECT_EQ(ss.str(), " Hello");
1432  ss.str("");
1433 
1434  ss << left << setw(6) << fbstr;
1435  EXPECT_EQ(ss.str(), "Hello ");
1436  ss.str("");
1437 
1438  ss << right << setw(6) << fbstr;
1439  EXPECT_EQ(ss.str(), " Hello");
1440  ss.str("");
1441 
1442  ss << setw(4) << fbstr;
1443  EXPECT_EQ(ss.str(), "Hello");
1444  ss.str("");
1445 
1446  ss << setfill('^') << setw(6) << fbstr;
1447  EXPECT_EQ(ss.str(), "^Hello");
1448  ss.str("");
1449 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( FBString  ,
rvalueIterators   
)

Definition at line 1451 of file FBStringTest.cpp.

References b, folly::basic_fbstring< E, T, A, Storage >::begin(), folly::basic_fbstring< E, T, A, Storage >::end(), EXPECT_EQ, folly::basic_fbstring< E, T, A, Storage >::replace(), and s.

1451  {
1452  // you cannot take &* of a move-iterator, so use that for testing
1453  fbstring s = "base";
1454  fbstring r = "hello";
1455  r.replace(
1456  r.begin(),
1457  r.end(),
1458  make_move_iterator(s.begin()),
1459  make_move_iterator(s.end()));
1460  EXPECT_EQ("base", r);
1461 
1462  // The following test is probably not required by the standard.
1463  // i.e. this could be in the realm of undefined behavior.
1464  fbstring b = "123abcXYZ";
1465  auto ait = b.begin() + 3;
1466  auto Xit = b.begin() + 6;
1467  b.replace(ait, b.end(), b.begin(), Xit);
1468  EXPECT_EQ("123123abc", b); // if things go wrong, you'd get "123123123"
1469 }
char b
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static set< string > s
basic_fbstring & replace(size_type pos1, size_type n1, const basic_fbstring &str)
Definition: FBString.h:1581
TEST ( FBString  ,
moveTerminator   
)

Definition at line 1471 of file FBStringTest.cpp.

References folly::basic_fbstring< E, T, A, Storage >::c_str(), EXPECT_EQ, k, folly::gen::move, s, and folly::basic_fbstring< E, T, A, Storage >::size().

1471  {
1472  // The source of a move must remain in a valid state
1473  fbstring s(100, 'x'); // too big to be in-situ
1474  fbstring k;
1475  k = std::move(s);
1476 
1477  EXPECT_EQ(0, s.size());
1478  EXPECT_EQ('\0', *s.c_str());
1479 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static set< string > s
KeyT k
TEST ( FBStringCtorTest  ,
DefaultInitStructDefaultAlloc   
)

Definition at line 1514 of file FBStringTest.cpp.

References EXPECT_TRUE.

1514  {
1515  TestStructDefaultAllocator t1{};
1516  EXPECT_TRUE(t1.stringMember.empty());
1517 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
TEST ( FBStringCtorTest  ,
DefaultInitStructAlloc   
)

Definition at line 1519 of file FBStringTest.cpp.

References EXPECT_EQ, and EXPECT_TRUE.

1519  {
1520  EXPECT_EQ(allocatorConstructedCount.load(), 0);
1521  TestStructWithAllocator<TestStructStringAllocator> t2;
1522  EXPECT_TRUE(t2.stringMember.empty());
1523  EXPECT_EQ(allocatorConstructedCount.load(), 1);
1524 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
TEST ( FBStringCtorTest  ,
NullZeroConstruction   
)

Definition at line 1526 of file FBStringTest.cpp.

References EXPECT_EQ, f, and folly::basic_fbstring< E, T, A, Storage >::size().

1526  {
1527  char* p = nullptr;
1528  int n = 0;
1529  folly::fbstring f(p, n);
1530  EXPECT_EQ(f.size(), 0);
1531 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( FBString  ,
compareToStdString   
)

Definition at line 1537 of file FBStringTest.cpp.

References EXPECT_TRUE, and s.

1537  {
1538  using folly::fbstring;
1539  using namespace std::string_literals;
1540  auto stdA = "a"s;
1541  auto stdB = "b"s;
1542  fbstring fbA("a");
1543  fbstring fbB("b");
1544  EXPECT_TRUE(stdA == fbA);
1545  EXPECT_TRUE(fbB == stdB);
1546  EXPECT_TRUE(stdA != fbB);
1547  EXPECT_TRUE(fbA != stdB);
1548  EXPECT_TRUE(stdA < fbB);
1549  EXPECT_TRUE(fbA < stdB);
1550  EXPECT_TRUE(stdB > fbA);
1551  EXPECT_TRUE(fbB > stdA);
1552  EXPECT_TRUE(stdA <= fbB);
1553  EXPECT_TRUE(fbA <= stdB);
1554  EXPECT_TRUE(stdA <= fbA);
1555  EXPECT_TRUE(fbA <= stdA);
1556  EXPECT_TRUE(stdB >= fbA);
1557  EXPECT_TRUE(fbB >= stdA);
1558  EXPECT_TRUE(stdB >= fbB);
1559  EXPECT_TRUE(fbB >= stdB);
1560 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static set< string > s
basic_fbstring< char > fbstring
Definition: FBString.h:2904
TEST ( U16FBString  ,
compareToStdU16String   
)

Definition at line 1562 of file FBStringTest.cpp.

References EXPECT_TRUE, and s.

1562  {
1563  using folly::basic_fbstring;
1564  using namespace std::string_literals;
1565  auto stdA = u"a"s;
1566  auto stdB = u"b"s;
1567  basic_fbstring<char16_t> fbA(u"a");
1568  basic_fbstring<char16_t> fbB(u"b");
1569  EXPECT_TRUE(stdA == fbA);
1570  EXPECT_TRUE(fbB == stdB);
1571  EXPECT_TRUE(stdA != fbB);
1572  EXPECT_TRUE(fbA != stdB);
1573  EXPECT_TRUE(stdA < fbB);
1574  EXPECT_TRUE(fbA < stdB);
1575  EXPECT_TRUE(stdB > fbA);
1576  EXPECT_TRUE(fbB > stdA);
1577  EXPECT_TRUE(stdA <= fbB);
1578  EXPECT_TRUE(fbA <= stdB);
1579  EXPECT_TRUE(stdA <= fbA);
1580  EXPECT_TRUE(fbA <= stdA);
1581  EXPECT_TRUE(stdB >= fbA);
1582  EXPECT_TRUE(fbB >= stdA);
1583  EXPECT_TRUE(stdB >= fbB);
1584  EXPECT_TRUE(fbB >= stdB);
1585 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static set< string > s
TEST ( U32FBString  ,
compareToStdU32String   
)

Definition at line 1587 of file FBStringTest.cpp.

References EXPECT_TRUE, and s.

1587  {
1588  using folly::basic_fbstring;
1589  using namespace std::string_literals;
1590  auto stdA = U"a"s;
1591  auto stdB = U"b"s;
1592  basic_fbstring<char32_t> fbA(U"a");
1593  basic_fbstring<char32_t> fbB(U"b");
1594  EXPECT_TRUE(stdA == fbA);
1595  EXPECT_TRUE(fbB == stdB);
1596  EXPECT_TRUE(stdA != fbB);
1597  EXPECT_TRUE(fbA != stdB);
1598  EXPECT_TRUE(stdA < fbB);
1599  EXPECT_TRUE(fbA < stdB);
1600  EXPECT_TRUE(stdB > fbA);
1601  EXPECT_TRUE(fbB > stdA);
1602  EXPECT_TRUE(stdA <= fbB);
1603  EXPECT_TRUE(fbA <= stdB);
1604  EXPECT_TRUE(stdA <= fbA);
1605  EXPECT_TRUE(fbA <= stdA);
1606  EXPECT_TRUE(stdB >= fbA);
1607  EXPECT_TRUE(fbB >= stdA);
1608  EXPECT_TRUE(stdB >= fbB);
1609  EXPECT_TRUE(fbB >= stdB);
1610 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static set< string > s
TEST ( WFBString  ,
compareToStdWString   
)

Definition at line 1612 of file FBStringTest.cpp.

References EXPECT_TRUE, and s.

1612  {
1613  using folly::basic_fbstring;
1614  using namespace std::string_literals;
1615  auto stdA = L"a"s;
1616  auto stdB = L"b"s;
1617  basic_fbstring<wchar_t> fbA(L"a");
1618  basic_fbstring<wchar_t> fbB(L"b");
1619  EXPECT_TRUE(stdA == fbA);
1620  EXPECT_TRUE(fbB == stdB);
1621  EXPECT_TRUE(stdA != fbB);
1622  EXPECT_TRUE(fbA != stdB);
1623  EXPECT_TRUE(stdA < fbB);
1624  EXPECT_TRUE(fbA < stdB);
1625  EXPECT_TRUE(stdB > fbA);
1626  EXPECT_TRUE(fbB > stdA);
1627  EXPECT_TRUE(stdA <= fbB);
1628  EXPECT_TRUE(fbA <= stdB);
1629  EXPECT_TRUE(stdA <= fbA);
1630  EXPECT_TRUE(fbA <= stdA);
1631  EXPECT_TRUE(stdB >= fbA);
1632  EXPECT_TRUE(fbB >= stdA);
1633  EXPECT_TRUE(stdB >= fbB);
1634  EXPECT_TRUE(fbB >= stdB);
1635 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static set< string > s
TEST ( FBString  ,
compareToStdStringLong   
)

Definition at line 1640 of file FBStringTest.cpp.

References EXPECT_TRUE, and s.

1640  {
1641  using folly::fbstring;
1642  using namespace std::string_literals;
1643  auto stdA = "1234567890a"s;
1644  auto stdB = "1234567890ab"s;
1645  fbstring fbA("1234567890a");
1646  fbstring fbB("1234567890ab");
1647  EXPECT_TRUE(stdA == fbA);
1648  EXPECT_TRUE(fbB == stdB);
1649  EXPECT_TRUE(stdA != fbB);
1650  EXPECT_TRUE(fbA != stdB);
1651  EXPECT_TRUE(stdA < fbB);
1652  EXPECT_TRUE(fbA < stdB);
1653  EXPECT_TRUE(stdB > fbA);
1654  EXPECT_TRUE(fbB > stdA);
1655  EXPECT_TRUE(stdA <= fbB);
1656  EXPECT_TRUE(fbA <= stdB);
1657  EXPECT_TRUE(stdA <= fbA);
1658  EXPECT_TRUE(fbA <= stdA);
1659  EXPECT_TRUE(stdB >= fbA);
1660  EXPECT_TRUE(fbB >= stdA);
1661  EXPECT_TRUE(stdB >= fbB);
1662  EXPECT_TRUE(fbB >= stdB);
1663 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static set< string > s
basic_fbstring< char > fbstring
Definition: FBString.h:2904
TEST ( U16FBString  ,
compareToStdU16StringLong   
)

Definition at line 1665 of file FBStringTest.cpp.

References EXPECT_TRUE, s, and TEST().

1665  {
1666  using folly::basic_fbstring;
1667  using namespace std::string_literals;
1668  auto stdA = u"1234567890a"s;
1669  auto stdB = u"1234567890ab"s;
1670  basic_fbstring<char16_t> fbA(u"1234567890a");
1671  basic_fbstring<char16_t> fbB(u"1234567890ab");
1672  EXPECT_TRUE(stdA == fbA);
1673  EXPECT_TRUE(fbB == stdB);
1674  EXPECT_TRUE(stdA != fbB);
1675  EXPECT_TRUE(fbA != stdB);
1676  EXPECT_TRUE(stdA < fbB);
1677  EXPECT_TRUE(fbA < stdB);
1678  EXPECT_TRUE(stdB > fbA);
1679  EXPECT_TRUE(fbB > stdA);
1680  EXPECT_TRUE(stdA <= fbB);
1681  EXPECT_TRUE(fbA <= stdB);
1682  EXPECT_TRUE(stdA <= fbA);
1683  EXPECT_TRUE(fbA <= stdA);
1684  EXPECT_TRUE(stdB >= fbA);
1685  EXPECT_TRUE(fbB >= stdA);
1686  EXPECT_TRUE(stdB >= fbB);
1687  EXPECT_TRUE(fbB >= stdB);
1688 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static set< string > s