Implement P0607R0 "Inline Variables for Standard Library" for C++17
[official-gcc.git] / gcc / hash-map-tests.c
blob1fd796e8cb0c369b8c5405b2e961b968f7964daa
1 /* Unit tests for hash-map.h.
2 Copyright (C) 2015-2017 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 "signop.h"
26 #include "hash-set.h"
27 #include "fixed-value.h"
28 #include "alias.h"
29 #include "flags.h"
30 #include "symtab.h"
31 #include "tree-core.h"
32 #include "stor-layout.h"
33 #include "tree.h"
34 #include "stringpool.h"
35 #include "selftest.h"
37 #if CHECKING_P
39 namespace selftest {
41 /* Construct a hash_map <const char *, int> and verify that
42 various operations work correctly. */
44 static void
45 test_map_of_strings_to_int ()
47 hash_map <const char *, int> m;
49 const char *ostrich = "ostrich";
50 const char *elephant = "elephant";
51 const char *ant = "ant";
52 const char *spider = "spider";
53 const char *millipede = "Illacme plenipes";
54 const char *eric = "half a bee";
56 /* A fresh hash_map should be empty. */
57 ASSERT_EQ (0, m.elements ());
58 ASSERT_EQ (NULL, m.get (ostrich));
60 /* Populate the hash_map. */
61 ASSERT_EQ (false, m.put (ostrich, 2));
62 ASSERT_EQ (false, m.put (elephant, 4));
63 ASSERT_EQ (false, m.put (ant, 6));
64 ASSERT_EQ (false, m.put (spider, 8));
65 ASSERT_EQ (false, m.put (millipede, 750));
66 ASSERT_EQ (false, m.put (eric, 3));
68 /* Verify that we can recover the stored values. */
69 ASSERT_EQ (6, m.elements ());
70 ASSERT_EQ (2, *m.get (ostrich));
71 ASSERT_EQ (4, *m.get (elephant));
72 ASSERT_EQ (6, *m.get (ant));
73 ASSERT_EQ (8, *m.get (spider));
74 ASSERT_EQ (750, *m.get (millipede));
75 ASSERT_EQ (3, *m.get (eric));
77 /* Verify removing an item. */
78 m.remove (eric);
79 ASSERT_EQ (5, m.elements ());
80 ASSERT_EQ (NULL, m.get (eric));
83 /* Run all of the selftests within this file. */
85 void
86 hash_map_tests_c_tests ()
88 test_map_of_strings_to_int ();
91 } // namespace selftest
93 #endif /* CHECKING_P */