#include <atomic>
#include <cstdlib>
-#include <list>
-#include <fstream>
#include <iomanip>
+#include <list>
+#include <sstream>
#include <boost/algorithm/string.hpp>
#include <boost/random.hpp>
#include <gtest/gtest.h>
-#include <gflags/gflags.h>
-
#include <folly/Foreach.h>
#include <folly/Portability.h>
#include <folly/Random.h>
#include <folly/Conv.h>
+#include <folly/experimental/TestUtil.h>
using namespace std;
using namespace folly;
// exercise get_allocator()
String s;
randomString(&s, maxString);
- assert(test.get_allocator() == s.get_allocator());
+ DCHECK(test.get_allocator() == s.get_allocator());
}
template <class String> void clause11_21_4_7_2_a(String & test) {
TEST(FBString, testAllClauses) {
EXPECT_TRUE(1) << "Starting with seed: " << seed;
std::string r;
- std::wstring wr;
folly::fbstring c;
+#ifndef __ANDROID__
+ // Disabled on Android: wchar support is not recommended and does not
+ // always behave as expected
+ std::wstring wr;
folly::basic_fbstring<wchar_t> wc;
+#endif
int count = 0;
auto l = [&](const char * const clause,
randomString(&r);
c = r;
EXPECT_EQ(c, r);
+#ifndef __ANDROID__
wr = std::wstring(r.begin(), r.end());
wc = folly::basic_fbstring<wchar_t>(wr.c_str());
+#endif
auto localSeed = seed + count;
rng = RandomT(localSeed);
f_string(r);
<< "Lengths: " << r.size() << " vs. " << c.size()
<< "\nReference: '" << r << "'"
<< "\nActual: '" << c.data()[0] << "'";
+#ifndef __ANDROID__
rng = RandomT(localSeed);
f_wfbstring(wc);
int wret = wcslen(wc.c_str());
std::string one(mb);
std::string two(mc);
EXPECT_EQ(one, two);
+#endif
} while (++count % 100 != 0);
};
}
TEST(FBString, testGetline) {
- fbstring s1 = "\
+ string s1 = "\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras accumsan \n\
elit ut urna consectetur in sagittis mi auctor. Nulla facilisi. In nec \n\
dolor leo, vitae imperdiet neque. Donec ut erat mauris, a faucibus \n\
laoreet. Phasellus lectus quam, ultricies ut tincidunt in, dignissim \n\
id eros. Mauris vulputate tortor nec neque pellentesque sagittis quis \n\
sed nisl. In diam lacus, lobortis ut posuere nec, ornare id quam.";
- char f[] = "/tmp/fbstring_testing.XXXXXX";
- int fd = mkstemp(f);
- EXPECT_TRUE(fd > 0);
- if (fd > 0) {
- close(fd); // Yeah
- std::ofstream out(f);
- if (!(out << s1)) {
- EXPECT_TRUE(0) << "Couldn't write to temp file.";
- return;
- }
- }
+
vector<fbstring> v;
boost::split(v, s1, boost::is_any_of("\n"));
{
- ifstream input(f);
+ istringstream input(s1);
fbstring line;
FOR_EACH (i, v) {
EXPECT_TRUE(!getline(input, line).fail());
EXPECT_EQ(line, *i);
}
}
- unlink(f);
}
TEST(FBString, testMoveCtor) {
EXPECT_TRUE(t2.stringMember.empty());
EXPECT_EQ(allocatorConstructedCount.load(), 1);
}
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- gflags::ParseCommandLineFlags(&argc, &argv, true);
- return RUN_ALL_TESTS();
-}