summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-03-08 00:43:21 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-31 12:06:13 +0200
commit8dc24d0256314265053a9e4b93d0542d14f8d8a7 (patch)
treea6ba94f76eb656676810bee89a2b906b7a3994db /Tests
parent49d29c8298dbf2a0a7265b7d58b09772e384be5b (diff)
downloadserenity-8dc24d0256314265053a9e4b93d0542d14f8d8a7.zip
Tests: Test non-trivial re-hashing in HashTable
This caused a system-wide crash because of a previous bug relating to non-trivial types in HashTable. Therefore, check that such types actually work under various workloads.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/AK/TestHashTable.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/Tests/AK/TestHashTable.cpp b/Tests/AK/TestHashTable.cpp
index 2e3ddc5582..4f5aa422b5 100644
--- a/Tests/AK/TestHashTable.cpp
+++ b/Tests/AK/TestHashTable.cpp
@@ -7,6 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/HashTable.h>
+#include <AK/NonnullOwnPtr.h>
#include <AK/String.h>
TEST_CASE(construct)
@@ -235,6 +236,26 @@ TEST_CASE(capacity_leak)
EXPECT(table.capacity() < 100u);
}
+TEST_CASE(non_trivial_type_table)
+{
+ HashTable<NonnullOwnPtr<int>> table;
+
+ table.set(make<int>(3));
+ table.set(make<int>(11));
+
+ for (int i = 0; i < 1'000; ++i) {
+ table.set(make<int>(-i));
+ }
+ for (int i = 0; i < 10'000; ++i) {
+ table.set(make<int>(i));
+ table.remove(make<int>(i));
+ }
+
+ EXPECT_EQ(table.remove_all_matching([&](auto&) { return true; }), true);
+ EXPECT(table.is_empty());
+ EXPECT_EQ(table.remove_all_matching([&](auto&) { return true; }), false);
+}
+
// Inserting and removing a bunch of elements will "thrash" the table, leading to a lot of "deleted" markers.
BENCHMARK_CASE(benchmark_thrashing)
{