This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 08/17] Add test-hash-map.c to gcc/unittests
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Wed, 10 Jun 2015 11:24:49 -0400
- Subject: [PATCH 08/17] Add test-hash-map.c to gcc/unittests
- Authentication-results: sourceware.org; auth=none
- References: <1433949898-22033-1-git-send-email-dmalcolm at redhat dot com>
gcc/unittests/ChangeLog:
* test-hash-map.c: New file.
---
gcc/unittests/test-hash-map.c | 78 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
create mode 100644 gcc/unittests/test-hash-map.c
diff --git a/gcc/unittests/test-hash-map.c b/gcc/unittests/test-hash-map.c
new file mode 100644
index 0000000..938c22b
--- /dev/null
+++ b/gcc/unittests/test-hash-map.c
@@ -0,0 +1,78 @@
+/* Unit tests for hash-map.h.
+ Copyright (C) 2015 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#include <gtest/gtest.h>
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "opts.h"
+#include "signop.h"
+#include "hash-set.h"
+#include "fixed-value.h"
+#include "alias.h"
+#include "flags.h"
+#include "symtab.h"
+#include "tree-core.h"
+#include "stor-layout.h"
+#include "tree.h"
+#include "stringpool.h"
+
+namespace {
+
+TEST (hash_map_test, map_of_strings_to_int)
+{
+ hash_map <const char *, int> 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. */
+ EXPECT_EQ (0, m.elements ());
+ EXPECT_EQ (NULL, m.get (ostrich));
+
+ /* Populate the hash_map. */
+ EXPECT_EQ (false, m.put (ostrich, 2));
+ EXPECT_EQ (false, m.put (elephant, 4));
+ EXPECT_EQ (false, m.put (ant, 6));
+ EXPECT_EQ (false, m.put (spider, 8));
+ EXPECT_EQ (false, m.put (millipede, 750));
+ EXPECT_EQ (false, m.put (eric, 3));
+
+ /* Verify that we can recover the stored values. */
+ EXPECT_EQ (6, m.elements ());
+ EXPECT_EQ (2, *m.get (ostrich));
+ EXPECT_EQ (4, *m.get (elephant));
+ EXPECT_EQ (6, *m.get (ant));
+ EXPECT_EQ (8, *m.get (spider));
+ EXPECT_EQ (750, *m.get (millipede));
+ EXPECT_EQ (3, *m.get (eric));
+
+ /* Verify removing an item. */
+ m.remove (eric);
+ EXPECT_EQ (5, m.elements ());
+ EXPECT_EQ (NULL, m.get (eric));
+}
+
+} /* anon namespace. */
--
1.8.5.3