diff options
author | Florian Jung <florian.jung@fau.de> | 2018-10-11 09:57:35 +0200 |
---|---|---|
committer | Florian Jung <florian.jung@fau.de> | 2018-10-11 09:57:35 +0200 |
commit | 15d3c96afdbb73505f128c5d3a6393ed24140c67 (patch) | |
tree | 7b178e18b2cf524654b13fd241ba926efa4f9dc8 /main | |
parent | 4c1a5d9cfe2da761bfe17d52126deabc1f1c1bd3 (diff) |
Add testcase whether OAHashMap loses keys
This demonstrates issue #22928.
Diffstat (limited to 'main')
-rw-r--r-- | main/tests/test_oa_hash_map.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/main/tests/test_oa_hash_map.cpp b/main/tests/test_oa_hash_map.cpp index 26e728d3aa..deaba285cf 100644 --- a/main/tests/test_oa_hash_map.cpp +++ b/main/tests/test_oa_hash_map.cpp @@ -92,6 +92,35 @@ MainLoop *test() { } } + // stress test / test for issue #22928 + { + OAHashMap<int, int> map; + int dummy; + const int N = 1000; + uint32_t *keys = new uint32_t[N]; + + Math::seed(0); + + // insert a couple of random keys (with a dummy value, which is ignored) + for (int i = 0; i < N; i++) { + keys[i] = Math::rand(); + map.set(keys[i], dummy); + + if (!map.lookup(keys[i], dummy)) + OS::get_singleton()->print("could not find 0x%X despite it was just inserted!\n", unsigned(keys[i])); + } + + // check whether the keys are still present + for (int i = 0; i < N; i++) { + if (!map.lookup(keys[i], dummy)) { + OS::get_singleton()->print("could not find 0x%X despite it has been inserted previously! (not checking the other keys, breaking...)\n", unsigned(keys[i])); + break; + } + } + + delete[] keys; + } + return NULL; } } // namespace TestOAHashMap |