[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
[llvm-project.git] / compiler-rt / lib / sanitizer_common / tests / sanitizer_addrhashmap_test.cpp
blob8c7574eb326af9b988ab3ce8122e298592c22fbc
1 //===-- sanitizer_addrhashmap_test.cpp ------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #include "sanitizer_common/sanitizer_addrhashmap.h"
10 #include <unordered_map>
12 #include "gtest/gtest.h"
14 namespace __sanitizer {
16 struct Value {
17 int payload;
18 inline bool operator==(const Value& rhs) const {
19 return payload == rhs.payload;
23 using MapTy = AddrHashMap<Value, 11>;
24 using HandleTy = MapTy::Handle;
25 using RefMapTy = std::unordered_map<uptr, Value>;
27 static void ExistsInReferenceMap(const uptr key, const Value& val, void* arg) {
28 RefMapTy* ref = reinterpret_cast<RefMapTy*>(arg);
29 const RefMapTy::iterator iter = ref->find(key);
30 ASSERT_NE(iter, ref->end());
31 EXPECT_EQ(iter->second, val);
32 ref->erase(iter);
35 TEST(AddrHashMap, Basic) {
36 // Use a reference implementation to compare with.
37 RefMapTy reference_map{
38 {0x1000, {1}},
39 {0x2000, {2}},
40 {0x3000, {3}},
43 MapTy m;
45 for (const auto& key_val : reference_map) {
46 const uptr key = key_val.first;
47 const Value val = key_val.second;
49 // Insert all the elements.
51 HandleTy h(&m, key);
52 ASSERT_TRUE(h.created());
53 h->payload = val.payload;
57 // Now check that all the elements are present.
58 m.ForEach(ExistsInReferenceMap, &reference_map);
59 EXPECT_TRUE(reference_map.empty());
62 } // namespace __sanitizer