LWG 3035. std::allocator's constructors should be constexpr
[official-gcc.git] / gcc / hash-map-tests.c
blob98b5830497d2e26b697c001e7cb9ca7cad9ff9ba
1 /* Unit tests for hash-map.h.
2 Copyright (C) 2015-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "opts.h"
25 #include "hash-set.h"
26 #include "fixed-value.h"
27 #include "alias.h"
28 #include "flags.h"
29 #include "symtab.h"
30 #include "tree-core.h"
31 #include "stor-layout.h"
32 #include "tree.h"
33 #include "stringpool.h"
34 #include "selftest.h"
36 #if CHECKING_P
38 namespace selftest {
40 /* Construct a hash_map <const char *, int> and verify that
41 various operations work correctly. */
43 static void
44 test_map_of_strings_to_int ()
46 hash_map <const char *, int> m;
48 const char *ostrich = "ostrich";
49 const char *elephant = "elephant";
50 const char *ant = "ant";
51 const char *spider = "spider";
52 const char *millipede = "Illacme plenipes";
53 const char *eric = "half a bee";
55 /* A fresh hash_map should be empty. */
56 ASSERT_EQ (0, m.elements ());
57 ASSERT_EQ (NULL, m.get (ostrich));
59 /* Populate the hash_map. */
60 ASSERT_EQ (false, m.put (ostrich, 2));
61 ASSERT_EQ (false, m.put (elephant, 4));
62 ASSERT_EQ (false, m.put (ant, 6));
63 ASSERT_EQ (false, m.put (spider, 8));
64 ASSERT_EQ (false, m.put (millipede, 750));
65 ASSERT_EQ (false, m.put (eric, 3));
67 /* Verify that we can recover the stored values. */
68 ASSERT_EQ (6, m.elements ());
69 ASSERT_EQ (2, *m.get (ostrich));
70 ASSERT_EQ (4, *m.get (elephant));
71 ASSERT_EQ (6, *m.get (ant));
72 ASSERT_EQ (8, *m.get (spider));
73 ASSERT_EQ (750, *m.get (millipede));
74 ASSERT_EQ (3, *m.get (eric));
76 /* Verify removing an item. */
77 m.remove (eric);
78 ASSERT_EQ (5, m.elements ());
79 ASSERT_EQ (NULL, m.get (eric));
82 /* Run all of the selftests within this file. */
84 void
85 hash_map_tests_c_tests ()
87 test_map_of_strings_to_int ();
90 } // namespace selftest
92 #endif /* CHECKING_P */