annotate gcc/hash-map-tests.c @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Unit tests for hash-map.h.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2015-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include "config.h"
kono
parents:
diff changeset
21 #include "system.h"
kono
parents:
diff changeset
22 #include "coretypes.h"
kono
parents:
diff changeset
23 #include "tm.h"
kono
parents:
diff changeset
24 #include "opts.h"
kono
parents:
diff changeset
25 #include "hash-set.h"
kono
parents:
diff changeset
26 #include "fixed-value.h"
kono
parents:
diff changeset
27 #include "alias.h"
kono
parents:
diff changeset
28 #include "flags.h"
kono
parents:
diff changeset
29 #include "symtab.h"
kono
parents:
diff changeset
30 #include "tree-core.h"
kono
parents:
diff changeset
31 #include "stor-layout.h"
kono
parents:
diff changeset
32 #include "tree.h"
kono
parents:
diff changeset
33 #include "stringpool.h"
kono
parents:
diff changeset
34 #include "selftest.h"
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 #if CHECKING_P
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 namespace selftest {
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 /* Construct a hash_map <const char *, int> and verify that
kono
parents:
diff changeset
41 various operations work correctly. */
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 static void
kono
parents:
diff changeset
44 test_map_of_strings_to_int ()
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 hash_map <const char *, int> m;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 const char *ostrich = "ostrich";
kono
parents:
diff changeset
49 const char *elephant = "elephant";
kono
parents:
diff changeset
50 const char *ant = "ant";
kono
parents:
diff changeset
51 const char *spider = "spider";
kono
parents:
diff changeset
52 const char *millipede = "Illacme plenipes";
kono
parents:
diff changeset
53 const char *eric = "half a bee";
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 /* A fresh hash_map should be empty. */
kono
parents:
diff changeset
56 ASSERT_EQ (0, m.elements ());
kono
parents:
diff changeset
57 ASSERT_EQ (NULL, m.get (ostrich));
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 /* Populate the hash_map. */
kono
parents:
diff changeset
60 ASSERT_EQ (false, m.put (ostrich, 2));
kono
parents:
diff changeset
61 ASSERT_EQ (false, m.put (elephant, 4));
kono
parents:
diff changeset
62 ASSERT_EQ (false, m.put (ant, 6));
kono
parents:
diff changeset
63 ASSERT_EQ (false, m.put (spider, 8));
kono
parents:
diff changeset
64 ASSERT_EQ (false, m.put (millipede, 750));
kono
parents:
diff changeset
65 ASSERT_EQ (false, m.put (eric, 3));
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 /* Verify that we can recover the stored values. */
kono
parents:
diff changeset
68 ASSERT_EQ (6, m.elements ());
kono
parents:
diff changeset
69 ASSERT_EQ (2, *m.get (ostrich));
kono
parents:
diff changeset
70 ASSERT_EQ (4, *m.get (elephant));
kono
parents:
diff changeset
71 ASSERT_EQ (6, *m.get (ant));
kono
parents:
diff changeset
72 ASSERT_EQ (8, *m.get (spider));
kono
parents:
diff changeset
73 ASSERT_EQ (750, *m.get (millipede));
kono
parents:
diff changeset
74 ASSERT_EQ (3, *m.get (eric));
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 /* Verify removing an item. */
kono
parents:
diff changeset
77 m.remove (eric);
kono
parents:
diff changeset
78 ASSERT_EQ (5, m.elements ());
kono
parents:
diff changeset
79 ASSERT_EQ (NULL, m.get (eric));
kono
parents:
diff changeset
80 }
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 /* Run all of the selftests within this file. */
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 void
kono
parents:
diff changeset
85 hash_map_tests_c_tests ()
kono
parents:
diff changeset
86 {
kono
parents:
diff changeset
87 test_map_of_strings_to_int ();
kono
parents:
diff changeset
88 }
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 } // namespace selftest
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 #endif /* CHECKING_P */