From aa0e90e7bff935856212b64236cd540acccc66a0 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 19 Dec 2019 15:01:49 +0000 Subject: [PATCH] hash-map-tests.c: add a selftest involving int_hash gcc/ChangeLog: * hash-map-tests.c (selftest::test_map_of_int_to_strings): New selftest. (selftest::hash_map_tests_c_tests): Call it. From-SVN: r279582 --- gcc/ChangeLog | 6 ++++++ gcc/hash-map-tests.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4892f038597..299f3368d08 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-12-19 David Malcolm + + * hash-map-tests.c (selftest::test_map_of_int_to_strings): New + selftest. + (selftest::hash_map_tests_c_tests): Call it. + 2019-12-19 David Malcolm * gimple-predict.h (gimple_predict_predictor): Make "gs" param diff --git a/gcc/hash-map-tests.c b/gcc/hash-map-tests.c index a42eac21ab3..9a13a80442c 100644 --- a/gcc/hash-map-tests.c +++ b/gcc/hash-map-tests.c @@ -103,6 +103,46 @@ test_map_of_strings_to_int () ASSERT_EQ (1, string_map.elements ()); } +/* Construct a hash_map using int_hash and verify that + various operations work correctly. */ + +static void +test_map_of_int_to_strings () +{ + const int EMPTY = -1; + const int DELETED = -2; + typedef int_hash int_hash_t; + hash_map m; + + const char *ostrich = "ostrich"; + const char *elephant = "elephant"; + const char *ant = "ant"; + const char *spider = "spider"; + const char *millipede = "Illacme plenipes"; + const char *eric = "half a bee"; + + /* A fresh hash_map should be empty. */ + ASSERT_EQ (0, m.elements ()); + ASSERT_EQ (NULL, m.get (2)); + + /* Populate the hash_map. */ + ASSERT_EQ (false, m.put (2, ostrich)); + ASSERT_EQ (false, m.put (4, elephant)); + ASSERT_EQ (false, m.put (6, ant)); + ASSERT_EQ (false, m.put (8, spider)); + ASSERT_EQ (false, m.put (750, millipede)); + ASSERT_EQ (false, m.put (3, eric)); + + /* Verify that we can recover the stored values. */ + ASSERT_EQ (6, m.elements ()); + ASSERT_EQ (*m.get (2), ostrich); + ASSERT_EQ (*m.get (4), elephant); + ASSERT_EQ (*m.get (6), ant); + ASSERT_EQ (*m.get (8), spider); + ASSERT_EQ (*m.get (750), millipede); + ASSERT_EQ (*m.get (3), eric); +} + typedef class hash_map_test_val_t { public: @@ -244,6 +284,7 @@ void hash_map_tests_c_tests () { test_map_of_strings_to_int (); + test_map_of_int_to_strings (); test_map_of_type_with_ctor_and_dtor (); } -- 2.30.2