Use hazptr_local and hazptr_array
[folly.git] / folly / test / FileTest.cpp
index 290c53da55e62ad0ff3c7b21926dd42db62ae09f..1ee680c1c5b76ea19374f7857b2d9339b6c7d0e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,8 +18,7 @@
 
 #include <folly/String.h>
 #include <folly/portability/Fcntl.h>
-
-#include <gtest/gtest.h>
+#include <folly/portability/GTest.h>
 
 using namespace folly;
 
@@ -33,7 +32,7 @@ void expectOK(ssize_t r) {
   int savedErrno = errno;
   EXPECT_LE(0, r) << ": errno=" << errnoStr(savedErrno);
 }
-}  // namespace
+} // namespace
 
 TEST(File, Simple) {
   // Open a file, ensure it's indeed open for reading
@@ -119,20 +118,30 @@ TEST(File, Truthy) {
   if (temp) {
     ;
   } else {
-    EXPECT_FALSE(true);
+    ADD_FAILURE();
   }
 
   if (File file = File::temporary()) {
     ;
   } else {
-    EXPECT_FALSE(true);
+    ADD_FAILURE();
   }
 
   EXPECT_FALSE(bool(File()));
   if (File()) {
-    EXPECT_TRUE(false);
+    ADD_FAILURE();
   }
   if (File notOpened = File()) {
-    EXPECT_TRUE(false);
+    ADD_FAILURE();
   }
 }
+
+TEST(File, HelperCtor) {
+  File::makeFile(StringPiece("/etc/hosts")).then([](File&& f) {
+    char buf = 'x';
+    EXPECT_NE(-1, f.fd());
+    EXPECT_EQ(1, ::read(f.fd(), &buf, 1));
+    f.close();
+    EXPECT_EQ(-1, f.fd());
+  });
+}