Add wrapper for getting X509_digest from a cert
[folly.git] / folly / test / ExpectedTest.cpp
index a10c9e865ff12545ba4c79fcea9c6ab2fbf787c5..a3935e8c6c3924469a32b7b8a33d9b2ae9ede619 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.
@@ -230,10 +230,10 @@ TEST(Expected, Unique) {
 
   ex = makeUnexpected(-1);
   // empty->moved
-  ex = unique_ptr<int>(new int(6));
+  ex = std::make_unique<int>(6);
   EXPECT_EQ(6, **ex);
   // full->moved
-  ex = unique_ptr<int>(new int(7));
+  ex = std::make_unique<int>(7);
   EXPECT_EQ(7, **ex);
 
   // move it out by move construct
@@ -560,6 +560,36 @@ TEST(Expected, NoThrowMoveAssignable) {
       (std::is_nothrow_move_assignable<Expected<ThrowingBadness, E>>::value));
 }
 
+struct NoSelfAssign {
+  NoSelfAssign() = default;
+  NoSelfAssign(NoSelfAssign&&) = default;
+  NoSelfAssign(const NoSelfAssign&) = default;
+  NoSelfAssign& operator=(NoSelfAssign&& that) {
+    EXPECT_NE(this, &that);
+    return *this;
+  }
+  NoSelfAssign& operator=(const NoSelfAssign& that) {
+    EXPECT_NE(this, &that);
+    return *this;
+  }
+};
+
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpragmas"
+#pragma GCC diagnostic ignored "-Wself-move"
+#endif
+
+TEST(Expected, NoSelfAssign) {
+  folly::Expected<NoSelfAssign, int> e {NoSelfAssign{}};
+  e = e; // @nolint
+  e = std::move(e); // @nolint
+}
+
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
+
 struct NoDestructor {};
 
 struct WithDestructor {
@@ -646,7 +676,7 @@ TEST(Expected, Then) {
     // Error case:
     Expected<int, E> ex = Expected<std::unique_ptr<int>, E>{
         unexpected, E::E1}.then([](std::unique_ptr<int> p) -> int {
-      EXPECT_TRUE(false);
+      ADD_FAILURE();
       return *p;
     });
     EXPECT_FALSE(bool(ex));
@@ -714,4 +744,4 @@ TEST(Expected, ThenOrThrow) {
         Unexpected<E>::BadExpectedAccess);
   }
 }
-}
+} // namespace folly