xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/hash-set-tests.c (revision e6c7e151de239c49d2e38720a061ed9d1fa99309)
1 /* Unit tests for hash-set.h.
2    Copyright (C) 2015-2017 Free Software Foundation, Inc.
3 
4 This file is part of GCC.
5 
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.
10 
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.
15 
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/>.  */
19 
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 "selftest.h"
28 
29 #if CHECKING_P
30 
31 namespace selftest {
32 
33 /* Construct a hash_set <const char *> and verify that various operations
34    work correctly.  */
35 
36 static void
37 test_set_of_strings ()
38 {
39   hash_set <const char *> s;
40   ASSERT_EQ (0, s.elements ());
41 
42   const char *red = "red";
43   const char *green = "green";
44   const char *blue = "blue";
45 
46   ASSERT_EQ (false, s.contains (red));
47 
48   /* Populate the hash_set.  */
49   ASSERT_EQ (false, s.add (red));
50   ASSERT_EQ (false, s.add (green));
51   ASSERT_EQ (false, s.add (blue));
52 
53   /* Verify that the values are now within the set.  */
54   ASSERT_EQ (true, s.contains (red));
55   ASSERT_EQ (true, s.contains (green));
56   ASSERT_EQ (true, s.contains (blue));
57 }
58 
59 /* Run all of the selftests within this file.  */
60 
61 void
62 hash_set_tests_c_tests ()
63 {
64   test_set_of_strings ();
65 }
66 
67 } // namespace selftest
68 
69 #endif /* #if CHECKING_P */
70