aboutsummaryrefslogtreecommitdiff
path: root/absl/container/flat_hash_set_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/container/flat_hash_set_test.cc')
-rw-r--r--absl/container/flat_hash_set_test.cc71
1 files changed, 68 insertions, 3 deletions
diff --git a/absl/container/flat_hash_set_test.cc b/absl/container/flat_hash_set_test.cc
index b6a72a20..a60b4bf5 100644
--- a/absl/container/flat_hash_set_test.cc
+++ b/absl/container/flat_hash_set_test.cc
@@ -14,14 +14,21 @@
#include "absl/container/flat_hash_set.h"
+#include <cstdint>
+#include <memory>
+#include <utility>
#include <vector>
-#include "absl/base/internal/raw_logging.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include "absl/base/config.h"
+#include "absl/container/internal/container_memory.h"
#include "absl/container/internal/hash_generator_testing.h"
#include "absl/container/internal/unordered_set_constructor_test.h"
#include "absl/container/internal/unordered_set_lookup_test.h"
#include "absl/container/internal/unordered_set_members_test.h"
#include "absl/container/internal/unordered_set_modifiers_test.h"
+#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
@@ -42,8 +49,8 @@ struct BeforeMain {
BeforeMain() {
absl::flat_hash_set<int> x;
x.insert(1);
- ABSL_RAW_CHECK(!x.contains(0), "x should not contain 0");
- ABSL_RAW_CHECK(x.contains(1), "x should contain 1");
+ CHECK(!x.contains(0)) << "x should not contain 0";
+ CHECK(x.contains(1)) << "x should contain 1";
}
};
const BeforeMain before_main;
@@ -172,6 +179,64 @@ TEST(FlatHashSet, EraseIf) {
}
}
+class PoisonInline {
+ int64_t data_;
+
+ public:
+ explicit PoisonInline(int64_t d) : data_(d) {
+ SanitizerPoisonObject(&data_);
+ }
+ PoisonInline(const PoisonInline& that) : PoisonInline(*that) {}
+ ~PoisonInline() { SanitizerUnpoisonObject(&data_); }
+
+ int64_t operator*() const {
+ SanitizerUnpoisonObject(&data_);
+ const int64_t ret = data_;
+ SanitizerPoisonObject(&data_);
+ return ret;
+ }
+ template <typename H>
+ friend H AbslHashValue(H h, const PoisonInline& pi) {
+ return H::combine(std::move(h), *pi);
+ }
+ bool operator==(const PoisonInline& rhs) const { return **this == *rhs; }
+};
+
+// Tests that we don't touch the poison_ member of PoisonInline.
+TEST(FlatHashSet, PoisonInline) {
+ PoisonInline a(0), b(1);
+ { // basic usage
+ flat_hash_set<PoisonInline> set;
+ set.insert(a);
+ EXPECT_THAT(set, UnorderedElementsAre(a));
+ set.insert(b);
+ EXPECT_THAT(set, UnorderedElementsAre(a, b));
+ set.erase(a);
+ EXPECT_THAT(set, UnorderedElementsAre(b));
+ set.rehash(0); // shrink to inline
+ EXPECT_THAT(set, UnorderedElementsAre(b));
+ }
+ { // test move constructor from inline to inline
+ flat_hash_set<PoisonInline> set;
+ set.insert(a);
+ flat_hash_set<PoisonInline> set2(std::move(set));
+ EXPECT_THAT(set2, UnorderedElementsAre(a));
+ }
+ { // test move assignment from inline to inline
+ flat_hash_set<PoisonInline> set, set2;
+ set.insert(a);
+ set2 = std::move(set);
+ EXPECT_THAT(set2, UnorderedElementsAre(a));
+ }
+ { // test alloc move constructor from inline to inline
+ flat_hash_set<PoisonInline> set;
+ set.insert(a);
+ flat_hash_set<PoisonInline> set2(std::move(set),
+ std::allocator<PoisonInline>());
+ EXPECT_THAT(set2, UnorderedElementsAre(a));
+ }
+}
+
} // namespace
} // namespace container_internal
ABSL_NAMESPACE_END