A macro for creating member-invoke traits
[folly.git] / folly / test / IndestructibleTest.cpp
index 4e144eec4b3160201a95a8bc37b79bcf2604dce1..ad57b1faf375d9f40e7c89546d7507bb7f9f17b7 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.
@@ -47,7 +47,7 @@ struct Magic {
 };
 
 class IndestructibleTest : public testing::Test {};
-}
+} // namespace
 
 TEST_F(IndestructibleTest, access) {
   static const Indestructible<map<string, int>> data{
@@ -75,6 +75,12 @@ TEST_F(IndestructibleTest, no_destruction) {
   EXPECT_EQ(1, state);
 }
 
+TEST_F(IndestructibleTest, empty) {
+  static const Indestructible<map<string, int>> data;
+  auto& m = *data;
+  EXPECT_EQ(0, m.size());
+}
+
 TEST_F(IndestructibleTest, move) {
   int state = 0;
   int value = 0;
@@ -102,3 +108,14 @@ TEST_F(IndestructibleTest, move) {
   EXPECT_EQ(1, state);
   EXPECT_EQ(2, moves);
 }
+
+TEST_F(IndestructibleTest, disabled_default_ctor) {
+  EXPECT_TRUE((std::is_constructible<Indestructible<int>>::value)) << "sanity";
+
+  struct Foo {
+    Foo(int) {}
+  };
+  EXPECT_FALSE((std::is_constructible<Indestructible<Foo>>::value));
+  EXPECT_FALSE((std::is_constructible<Indestructible<Foo>, Magic>::value));
+  EXPECT_TRUE((std::is_constructible<Indestructible<Foo>, int>::value));
+}