slice_test.cc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. // Because there are a small set of tests for Slice and there's a cost in having
  6. // extra test binaries for each component, this test file has evolved into a
  7. // "grab bag" of small tests for various reusable components, mostly in util/.
  8. #include "rocksdb/slice.h"
  9. #include <gtest/gtest.h>
  10. #include <semaphore>
  11. #include "port/port.h"
  12. #include "port/stack_trace.h"
  13. #include "rocksdb/data_structure.h"
  14. #include "rocksdb/types.h"
  15. #include "test_util/testharness.h"
  16. #include "test_util/testutil.h"
  17. #include "util/bit_fields.h"
  18. #include "util/cast_util.h"
  19. #include "util/semaphore.h"
  20. #include "util/string_util.h"
  21. namespace ROCKSDB_NAMESPACE {
  22. TEST(SliceTest, StringView) {
  23. std::string s = "foo";
  24. std::string_view sv = s;
  25. ASSERT_EQ(Slice(s), Slice(sv));
  26. ASSERT_EQ(Slice(s), Slice(std::move(sv)));
  27. }
  28. // Use this to keep track of the cleanups that were actually performed
  29. void Multiplier(void* arg1, void* arg2) {
  30. int* res = static_cast<int*>(arg1);
  31. int* num = static_cast<int*>(arg2);
  32. *res *= *num;
  33. }
  34. class PinnableSliceTest : public testing::Test {
  35. public:
  36. void AssertSameData(const std::string& expected, const PinnableSlice& slice) {
  37. std::string got;
  38. got.assign(slice.data(), slice.size());
  39. ASSERT_EQ(expected, got);
  40. }
  41. };
  42. // Test that the external buffer is moved instead of being copied.
  43. TEST_F(PinnableSliceTest, MoveExternalBuffer) {
  44. Slice s("123");
  45. std::string buf;
  46. PinnableSlice v1(&buf);
  47. v1.PinSelf(s);
  48. PinnableSlice v2(std::move(v1));
  49. ASSERT_EQ(buf.data(), v2.data());
  50. ASSERT_EQ(&buf, v2.GetSelf());
  51. PinnableSlice v3;
  52. v3 = std::move(v2);
  53. ASSERT_EQ(buf.data(), v3.data());
  54. ASSERT_EQ(&buf, v3.GetSelf());
  55. }
  56. TEST_F(PinnableSliceTest, Move) {
  57. int n2 = 2;
  58. int res = 1;
  59. const std::string const_str1 = "123";
  60. const std::string const_str2 = "ABC";
  61. Slice slice1(const_str1);
  62. Slice slice2(const_str2);
  63. {
  64. // Test move constructor on a pinned slice.
  65. res = 1;
  66. PinnableSlice v1;
  67. v1.PinSlice(slice1, Multiplier, &res, &n2);
  68. PinnableSlice v2(std::move(v1));
  69. // Since v1's Cleanable has been moved to v2,
  70. // no cleanup should happen in Reset.
  71. v1.Reset();
  72. ASSERT_EQ(1, res);
  73. AssertSameData(const_str1, v2);
  74. }
  75. // v2 is cleaned up.
  76. ASSERT_EQ(2, res);
  77. {
  78. // Test move constructor on an unpinned slice.
  79. PinnableSlice v1;
  80. v1.PinSelf(slice1);
  81. PinnableSlice v2(std::move(v1));
  82. AssertSameData(const_str1, v2);
  83. }
  84. {
  85. // Test move assignment from a pinned slice to
  86. // another pinned slice.
  87. res = 1;
  88. PinnableSlice v1;
  89. v1.PinSlice(slice1, Multiplier, &res, &n2);
  90. PinnableSlice v2;
  91. v2.PinSlice(slice2, Multiplier, &res, &n2);
  92. v2 = std::move(v1);
  93. // v2's Cleanable will be Reset before moving
  94. // anything from v1.
  95. ASSERT_EQ(2, res);
  96. // Since v1's Cleanable has been moved to v2,
  97. // no cleanup should happen in Reset.
  98. v1.Reset();
  99. ASSERT_EQ(2, res);
  100. AssertSameData(const_str1, v2);
  101. }
  102. // The Cleanable moved from v1 to v2 will be Reset.
  103. ASSERT_EQ(4, res);
  104. {
  105. // Test move assignment from a pinned slice to
  106. // an unpinned slice.
  107. res = 1;
  108. PinnableSlice v1;
  109. v1.PinSlice(slice1, Multiplier, &res, &n2);
  110. PinnableSlice v2;
  111. v2.PinSelf(slice2);
  112. v2 = std::move(v1);
  113. // Since v1's Cleanable has been moved to v2,
  114. // no cleanup should happen in Reset.
  115. v1.Reset();
  116. ASSERT_EQ(1, res);
  117. AssertSameData(const_str1, v2);
  118. }
  119. // The Cleanable moved from v1 to v2 will be Reset.
  120. ASSERT_EQ(2, res);
  121. {
  122. // Test move assignment from an upinned slice to
  123. // another unpinned slice.
  124. PinnableSlice v1;
  125. v1.PinSelf(slice1);
  126. PinnableSlice v2;
  127. v2.PinSelf(slice2);
  128. v2 = std::move(v1);
  129. AssertSameData(const_str1, v2);
  130. }
  131. {
  132. // Test move assignment from an upinned slice to
  133. // a pinned slice.
  134. res = 1;
  135. PinnableSlice v1;
  136. v1.PinSelf(slice1);
  137. PinnableSlice v2;
  138. v2.PinSlice(slice2, Multiplier, &res, &n2);
  139. v2 = std::move(v1);
  140. // v2's Cleanable will be Reset before moving
  141. // anything from v1.
  142. ASSERT_EQ(2, res);
  143. AssertSameData(const_str1, v2);
  144. }
  145. // No Cleanable is moved from v1 to v2, so no more cleanup.
  146. ASSERT_EQ(2, res);
  147. }
  148. // ***************************************************************** //
  149. // Unit test for SmallEnumSet
  150. class SmallEnumSetTest : public testing::Test {
  151. public:
  152. SmallEnumSetTest() = default;
  153. ~SmallEnumSetTest() = default;
  154. };
  155. TEST_F(SmallEnumSetTest, SmallEnumSetTest1) {
  156. FileTypeSet fs; // based on a legacy enum type
  157. ASSERT_TRUE(fs.empty());
  158. ASSERT_EQ(fs.count(), 0U);
  159. ASSERT_TRUE(fs.Add(FileType::kIdentityFile));
  160. ASSERT_FALSE(fs.empty());
  161. ASSERT_EQ(fs.count(), 1U);
  162. ASSERT_FALSE(fs.Add(FileType::kIdentityFile));
  163. ASSERT_TRUE(fs.Add(FileType::kInfoLogFile));
  164. ASSERT_TRUE(fs.Contains(FileType::kIdentityFile));
  165. ASSERT_FALSE(fs.Contains(FileType::kDBLockFile));
  166. ASSERT_FALSE(fs.empty());
  167. ASSERT_EQ(fs.count(), 2U);
  168. ASSERT_FALSE(fs.Remove(FileType::kDBLockFile));
  169. ASSERT_TRUE(fs.Remove(FileType::kIdentityFile));
  170. ASSERT_FALSE(fs.empty());
  171. ASSERT_EQ(fs.count(), 1U);
  172. ASSERT_TRUE(fs.Remove(FileType::kInfoLogFile));
  173. ASSERT_TRUE(fs.empty());
  174. ASSERT_EQ(fs.count(), 0U);
  175. }
  176. namespace {
  177. enum class MyEnumClass { A, B, C };
  178. } // namespace
  179. using MyEnumClassSet = SmallEnumSet<MyEnumClass, MyEnumClass::C>;
  180. TEST_F(SmallEnumSetTest, SmallEnumSetTest2) {
  181. MyEnumClassSet s; // based on an enum class type
  182. ASSERT_TRUE(s.Add(MyEnumClass::A));
  183. ASSERT_TRUE(s.Contains(MyEnumClass::A));
  184. ASSERT_FALSE(s.Contains(MyEnumClass::B));
  185. ASSERT_TRUE(s.With(MyEnumClass::B).Contains(MyEnumClass::B));
  186. ASSERT_TRUE(s.With(MyEnumClass::A).Contains(MyEnumClass::A));
  187. ASSERT_FALSE(s.Contains(MyEnumClass::B));
  188. ASSERT_FALSE(s.Without(MyEnumClass::A).Contains(MyEnumClass::A));
  189. ASSERT_FALSE(
  190. s.With(MyEnumClass::B).Without(MyEnumClass::B).Contains(MyEnumClass::B));
  191. ASSERT_TRUE(
  192. s.Without(MyEnumClass::B).With(MyEnumClass::B).Contains(MyEnumClass::B));
  193. ASSERT_TRUE(s.Contains(MyEnumClass::A));
  194. const MyEnumClassSet cs = s;
  195. ASSERT_TRUE(cs.Contains(MyEnumClass::A));
  196. ASSERT_EQ(cs, MyEnumClassSet{MyEnumClass::A});
  197. ASSERT_EQ(cs.Without(MyEnumClass::A), MyEnumClassSet{});
  198. ASSERT_EQ(cs, MyEnumClassSet::All().Without(MyEnumClass::B, MyEnumClass::C));
  199. ASSERT_EQ(cs.With(MyEnumClass::B, MyEnumClass::C), MyEnumClassSet::All());
  200. ASSERT_EQ(
  201. MyEnumClassSet::All(),
  202. MyEnumClassSet{}.With(MyEnumClass::A, MyEnumClass::B, MyEnumClass::C));
  203. ASSERT_NE(cs, MyEnumClassSet{MyEnumClass::B});
  204. ASSERT_NE(cs, MyEnumClassSet::All());
  205. ASSERT_EQ(MyEnumClassSet{}.count(), 0U);
  206. ASSERT_EQ(MyEnumClassSet::All().count(), 3U);
  207. int count = 0;
  208. for (MyEnumClass e : cs) {
  209. ASSERT_EQ(e, MyEnumClass::A);
  210. ++count;
  211. }
  212. ASSERT_EQ(count, 1);
  213. ASSERT_EQ(cs.count(), 1U);
  214. count = 0;
  215. for (MyEnumClass e : MyEnumClassSet::All().Without(MyEnumClass::B)) {
  216. ASSERT_NE(e, MyEnumClass::B);
  217. ++count;
  218. }
  219. ASSERT_EQ(count, 2);
  220. for (MyEnumClass e : MyEnumClassSet{}) {
  221. (void)e;
  222. assert(false);
  223. }
  224. }
  225. template <typename ENUM_TYPE, ENUM_TYPE MAX_ENUMERATOR>
  226. void TestBiggerEnumSet() {
  227. using MySet = SmallEnumSet<ENUM_TYPE, MAX_ENUMERATOR>;
  228. constexpr int kMaxValue = static_cast<int>(MAX_ENUMERATOR);
  229. SCOPED_TRACE("kMaxValue = " + std::to_string(kMaxValue));
  230. ASSERT_EQ(sizeof(MySet), (kMaxValue + 1 + 63) / 64 * 8);
  231. MySet s;
  232. ASSERT_TRUE(s.empty());
  233. ASSERT_EQ(s.count(), 0U);
  234. ASSERT_TRUE(s.Add(ENUM_TYPE(0)));
  235. ASSERT_FALSE(s.empty());
  236. ASSERT_EQ(s.count(), 1U);
  237. ASSERT_TRUE(s.Add(ENUM_TYPE(kMaxValue - 1)));
  238. ASSERT_FALSE(s.empty());
  239. ASSERT_EQ(s.count(), 2U);
  240. ASSERT_TRUE(s.Add(ENUM_TYPE(kMaxValue)));
  241. ASSERT_FALSE(s.empty());
  242. ASSERT_EQ(s.count(), 3U);
  243. int count = 0;
  244. for (ENUM_TYPE e : s) {
  245. ASSERT_TRUE(e == ENUM_TYPE(0) || e == ENUM_TYPE(kMaxValue - 1) ||
  246. e == ENUM_TYPE(kMaxValue));
  247. ++count;
  248. }
  249. ASSERT_EQ(count, 3);
  250. ASSERT_TRUE(s.Remove(ENUM_TYPE(0)));
  251. ASSERT_TRUE(s.Remove(ENUM_TYPE(kMaxValue)));
  252. ASSERT_FALSE(s.empty());
  253. ASSERT_EQ(s.count(), 1U);
  254. count = 0;
  255. for (ENUM_TYPE e : s) {
  256. ASSERT_EQ(e, ENUM_TYPE(kMaxValue - 1));
  257. ++count;
  258. }
  259. ASSERT_EQ(count, 1);
  260. }
  261. TEST_F(SmallEnumSetTest, BiggerEnumClasses) {
  262. enum class BiggerEnumClass63 { A, B, C = 63 };
  263. enum class BiggerEnumClass64 { A, B, C = 64 };
  264. enum class BiggerEnumClass65 { A, B, C = 65 };
  265. enum class BiggerEnumClass127 { A, B, C = 127 };
  266. enum class BiggerEnumClass128 { A, B, C = 128 };
  267. enum class BiggerEnumClass129 { A, B, C = 129 };
  268. enum class BiggerEnumClass150 { A, B, C = 150 };
  269. enum class BiggerEnumClass255 { A, B, C = 255 };
  270. TestBiggerEnumSet<BiggerEnumClass63, BiggerEnumClass63::C>();
  271. TestBiggerEnumSet<BiggerEnumClass64, BiggerEnumClass64::C>();
  272. TestBiggerEnumSet<BiggerEnumClass65, BiggerEnumClass65::C>();
  273. TestBiggerEnumSet<BiggerEnumClass127, BiggerEnumClass127::C>();
  274. TestBiggerEnumSet<BiggerEnumClass128, BiggerEnumClass128::C>();
  275. TestBiggerEnumSet<BiggerEnumClass129, BiggerEnumClass129::C>();
  276. TestBiggerEnumSet<BiggerEnumClass150, BiggerEnumClass150::C>();
  277. TestBiggerEnumSet<BiggerEnumClass255, BiggerEnumClass255::C>();
  278. }
  279. // ***************************************************************** //
  280. // Unit test for Status
  281. TEST(StatusTest, Update) {
  282. const Status ok = Status::OK();
  283. const Status inc = Status::Incomplete("blah");
  284. const Status notf = Status::NotFound("meow");
  285. Status s = ok;
  286. ASSERT_TRUE(s.UpdateIfOk(Status::Corruption("bad")).IsCorruption());
  287. ASSERT_TRUE(s.IsCorruption());
  288. s = ok;
  289. ASSERT_TRUE(s.UpdateIfOk(Status::OK()).ok());
  290. ASSERT_TRUE(s.UpdateIfOk(ok).ok());
  291. ASSERT_TRUE(s.ok());
  292. ASSERT_TRUE(s.UpdateIfOk(inc).IsIncomplete());
  293. ASSERT_TRUE(s.IsIncomplete());
  294. ASSERT_TRUE(s.UpdateIfOk(notf).IsIncomplete());
  295. ASSERT_TRUE(s.UpdateIfOk(ok).IsIncomplete());
  296. ASSERT_TRUE(s.IsIncomplete());
  297. // Keeps left-most non-OK status
  298. s = ok;
  299. ASSERT_TRUE(
  300. s.UpdateIfOk(Status()).UpdateIfOk(notf).UpdateIfOk(inc).IsNotFound());
  301. ASSERT_TRUE(s.IsNotFound());
  302. }
  303. // ***************************************************************** //
  304. // Unit test for UnownedPtr
  305. TEST(UnownedPtrTest, Tests) {
  306. {
  307. int x = 0;
  308. UnownedPtr<int> p(&x);
  309. ASSERT_EQ(p.get(), &x);
  310. ASSERT_EQ(*p, 0);
  311. x = 1;
  312. ASSERT_EQ(*p, 1);
  313. ASSERT_EQ(p.get(), &x);
  314. ASSERT_EQ(*p, 1);
  315. *p = 2;
  316. ASSERT_EQ(x, 2);
  317. ASSERT_EQ(*p, 2);
  318. ASSERT_EQ(p.get(), &x);
  319. ASSERT_EQ(*p, 2);
  320. }
  321. {
  322. std::unique_ptr<std::pair<int, int>> u =
  323. std::make_unique<std::pair<int, int>>();
  324. *u = {1, 2};
  325. UnownedPtr<std::pair<int, int>> p;
  326. ASSERT_FALSE(p);
  327. p = u.get();
  328. ASSERT_TRUE(p);
  329. ASSERT_EQ(p->first, 1);
  330. // These must not compile:
  331. /*
  332. u = p;
  333. u = std::move(p);
  334. std::unique_ptr<std::pair<int, int>> v{p};
  335. std::unique_ptr<std::pair<int, int>> v{std::move(p)};
  336. */
  337. // END must not compile
  338. UnownedPtr<std::pair<int, int>> q;
  339. q = std::move(p);
  340. ASSERT_EQ(q->first, 1);
  341. // Not committing to any moved-from semantics (on p here)
  342. }
  343. {
  344. std::shared_ptr<std::pair<int, int>> s =
  345. std::make_shared<std::pair<int, int>>();
  346. *s = {1, 2};
  347. UnownedPtr<std::pair<int, int>> p;
  348. ASSERT_FALSE(p);
  349. p = s.get();
  350. ASSERT_TRUE(p);
  351. ASSERT_EQ(p->first, 1);
  352. // These must not compile:
  353. /*
  354. s = p;
  355. s = std::move(p);
  356. std::unique_ptr<std::pair<int, int>> t{p};
  357. std::unique_ptr<std::pair<int, int>> t{std::move(p)};
  358. */
  359. // END must not compile
  360. UnownedPtr<std::pair<int, int>> q;
  361. q = std::move(p);
  362. ASSERT_EQ(q->first, 1);
  363. // Not committing to any moved-from semantics (on p here)
  364. }
  365. }
  366. TEST(ToBaseCharsStringTest, Tests) {
  367. using ROCKSDB_NAMESPACE::ToBaseCharsString;
  368. // Base 16
  369. ASSERT_EQ(ToBaseCharsString<16>(5, 0, true), "00000");
  370. ASSERT_EQ(ToBaseCharsString<16>(5, 42, true), "0002A");
  371. ASSERT_EQ(ToBaseCharsString<16>(5, 42, false), "0002a");
  372. ASSERT_EQ(ToBaseCharsString<16>(2, 255, false), "ff");
  373. // Base 32
  374. ASSERT_EQ(ToBaseCharsString<32>(2, 255, false), "7v");
  375. }
  376. TEST(SemaphoreTest, CountingSemaphore) {
  377. CountingSemaphore sem{0};
  378. int kCount = 5;
  379. std::vector<std::thread> threads;
  380. for (int i = 0; i < kCount; ++i) {
  381. threads.emplace_back([&sem] { sem.Release(); });
  382. }
  383. for (int i = 0; i < kCount; ++i) {
  384. threads.emplace_back([&sem] { sem.Acquire(); });
  385. }
  386. for (auto& t : threads) {
  387. t.join();
  388. }
  389. // Nothing left on the semaphore
  390. ASSERT_FALSE(sem.TryAcquire());
  391. // Keep testing
  392. sem.Release(2);
  393. ASSERT_TRUE(sem.TryAcquire());
  394. sem.Acquire();
  395. ASSERT_FALSE(sem.TryAcquire());
  396. }
  397. TEST(SemaphoreTest, BinarySemaphore) {
  398. BinarySemaphore sem{0};
  399. int kCount = 5;
  400. std::vector<std::thread> threads;
  401. for (int i = 0; i < kCount; ++i) {
  402. threads.emplace_back([&sem] {
  403. sem.Acquire();
  404. sem.Release();
  405. });
  406. }
  407. threads.emplace_back([&sem] { sem.Release(); });
  408. for (auto& t : threads) {
  409. t.join();
  410. }
  411. // Only able to acquire one excess release
  412. ASSERT_TRUE(sem.TryAcquire());
  413. ASSERT_FALSE(sem.TryAcquire());
  414. }
  415. TEST(BitFieldsTest, BitFields) {
  416. // Start by verifying example from BitFields comment
  417. struct MyState : public BitFields<uint32_t, MyState> {
  418. // Extra helper declarations and/or field type declarations
  419. };
  420. using Field1 = UnsignedBitField<MyState, 16, NoPrevBitField>;
  421. using Field2 = BoolBitField<MyState, Field1>;
  422. using Field3 = BoolBitField<MyState, Field2>;
  423. using Field4 = UnsignedBitField<MyState, 5, Field3>;
  424. // MyState{} is zero-initialized
  425. auto state = MyState{}.With<Field1>(42U).With<Field2>(true);
  426. state.Set<Field4>(3U);
  427. state.Ref<Field1>() += state.Get<Field4>();
  428. ASSERT_EQ(state.Get<Field1>(), 45U);
  429. ASSERT_EQ(state.Get<Field2>(), true);
  430. ASSERT_EQ(state.Get<Field3>(), false);
  431. ASSERT_EQ(state.Get<Field4>(), 3U);
  432. // Misc operators
  433. auto ref = state.Ref<Field3>();
  434. auto ref2 = std::move(ref);
  435. ref2 = true;
  436. ASSERT_EQ(state.Get<Field3>(), true);
  437. MyState state2;
  438. // Basic non-concurrent tests for atomic wrappers
  439. {
  440. RelaxedBitFieldsAtomic<MyState> relaxed{state};
  441. ASSERT_EQ(state, relaxed.LoadRelaxed());
  442. relaxed.StoreRelaxed(state2);
  443. ASSERT_EQ(state2, relaxed.LoadRelaxed());
  444. MyState state3 = relaxed.ExchangeRelaxed(state);
  445. ASSERT_EQ(state2, state3);
  446. ASSERT_TRUE(relaxed.CasStrongRelaxed(state, state2));
  447. while (!relaxed.CasWeakRelaxed(state2, state)) {
  448. }
  449. ASSERT_EQ(state2, state3);
  450. ASSERT_EQ(state, relaxed.LoadRelaxed());
  451. auto transform1 = Field2::ClearTransform() + Field3::ClearTransform();
  452. MyState before, after;
  453. relaxed.ApplyRelaxed(transform1, &before, &after);
  454. ASSERT_EQ(before, state);
  455. ASSERT_NE(after, state);
  456. ASSERT_EQ(after.Get<Field2>(), false);
  457. ASSERT_EQ(after.Get<Field3>(), false);
  458. auto transform2 = Field2::SetTransform() + Field3::SetTransform();
  459. relaxed.ApplyRelaxed(transform2, &before, &after);
  460. ASSERT_NE(before, state);
  461. ASSERT_EQ(before.Get<Field2>(), false);
  462. ASSERT_EQ(before.Get<Field3>(), false);
  463. ASSERT_EQ(after, state);
  464. }
  465. {
  466. AcqRelBitFieldsAtomic<MyState> acqrel{state};
  467. ASSERT_EQ(state, acqrel.Load());
  468. acqrel.Store(state2);
  469. ASSERT_EQ(state2, acqrel.Load());
  470. MyState state3 = acqrel.Exchange(state);
  471. ASSERT_EQ(state2, state3);
  472. ASSERT_TRUE(acqrel.CasStrong(state, state2));
  473. while (!acqrel.CasWeak(state2, state)) {
  474. }
  475. ASSERT_EQ(state2, state3);
  476. ASSERT_EQ(state, acqrel.Load());
  477. auto transform1 = Field2::ClearTransform() + Field3::ClearTransform();
  478. MyState before, after;
  479. acqrel.Apply(transform1, &before, &after);
  480. ASSERT_EQ(before, state);
  481. ASSERT_NE(after, state);
  482. ASSERT_EQ(after.Get<Field2>(), false);
  483. ASSERT_EQ(after.Get<Field3>(), false);
  484. auto transform2 = Field2::SetTransform() + Field3::SetTransform();
  485. acqrel.Apply(transform2, &before, &after);
  486. ASSERT_NE(before, state);
  487. ASSERT_EQ(before.Get<Field2>(), false);
  488. ASSERT_EQ(before.Get<Field3>(), false);
  489. ASSERT_EQ(after, state);
  490. }
  491. }
  492. } // namespace ROCKSDB_NAMESPACE
  493. int main(int argc, char** argv) {
  494. ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
  495. ::testing::InitGoogleTest(&argc, argv);
  496. return RUN_ALL_TESTS();
  497. }