Turn off a FBStringTest for Android.
[folly.git] / folly / test / FBStringTest.cpp
index 94bbac992d91665e151accc88c52e9f70560d285..c32591424062dfe63a854b29809ae63e2d905cdc 100644 (file)
 #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;
@@ -592,7 +591,7 @@ template <class String> void clause11_21_4_7_1(String & test) {
   // 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) {
@@ -982,9 +981,13 @@ template <class String> void clause11_21_4_8_9_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,
@@ -996,8 +999,10 @@ TEST(FBString, testAllClauses) {
       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);
@@ -1007,6 +1012,7 @@ TEST(FBString, testAllClauses) {
         << "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());
@@ -1017,6 +1023,7 @@ TEST(FBString, testAllClauses) {
       std::string one(mb);
       std::string two(mc);
       EXPECT_EQ(one, two);
+#endif
     } while (++count % 100 != 0);
   };
 
@@ -1116,7 +1123,7 @@ TEST(FBString, testAllClauses) {
 }
 
 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\
@@ -1134,28 +1141,17 @@ massa, ut accumsan magna. Donec imperdiet tempor nisi et \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) {
@@ -1405,9 +1401,3 @@ TEST(FBStringCtorTest, DefaultInitStructAlloc) {
   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();
-}