Fixes RCU test cases error (loads should use Consume ordering)
[folly.git] / folly / test / ReplaceableTest.cpp
index 00eb01d9867ba38fa45de2d3bfeaf90ba853436d..af3c4bdcda4c3d861ce0a1acfd49897bead23d2a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-present Facebook, Inc.
+ * Copyright 2017-present Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ using namespace ::testing;
 using namespace ::folly;
 
 namespace {
+struct Basic {};
 struct alignas(128) BigAlign {};
 struct HasConst final {
   bool const b1;
@@ -69,7 +70,7 @@ struct OddA {
 struct Indestructible {
   ~Indestructible() = delete;
 };
-} // anonymous namespace
+} // namespace
 
 template <typename T>
 struct ReplaceableStaticAttributeTest : Test {};
@@ -81,6 +82,7 @@ using StaticAttributeTypes = ::testing::Types<
     float,
     double,
     char[11],
+    Basic,
     BigAlign,
     HasConst,
     HasRef,
@@ -168,6 +170,10 @@ TYPED_TEST(ReplaceableStaticAttributeTest, nothrow_copy_assignable) {
           std::is_nothrow_copy_constructible<TypeParam>::value,
       std::is_nothrow_copy_assignable<Replaceable<TypeParam>>::value);
 }
+TYPED_TEST(ReplaceableStaticAttributeTest, replaceable) {
+  EXPECT_FALSE(is_replaceable<TypeParam>::value);
+  EXPECT_TRUE(is_replaceable<Replaceable<TypeParam>>::value);
+}
 
 TYPED_TEST(ReplaceableStaticAttributePairTest, copy_construct) {
   using T = typename TypeParam::first_type;
@@ -250,6 +256,18 @@ TEST(ReplaceableTest, Basics) {
   EXPECT_TRUE(rHasConstB->b1);
 }
 
+TEST(ReplaceableTest, Constructors) {
+  Basic b{};
+  // From existing `T`
+  auto rBasicCopy1 = Replaceable<Basic>(b);
+  auto rBasicMove1 = Replaceable<Basic>(std::move(b));
+  // From existing `Replaceable<T>`
+  auto rBasicCopy2 = Replaceable<Basic>(rBasicCopy1);
+  auto rBasicMove2 = Replaceable<Basic>(std::move(rBasicMove1));
+  (void)rBasicCopy2;
+  (void)rBasicMove2;
+}
+
 TEST(ReplaceableTest, DestructsWhenExpected) {
   int i{0};
   {