From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31303 invoked by alias); 19 Nov 2015 16:46:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 31174 invoked by uid 89); 19 Nov 2015 16:46:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 19 Nov 2015 16:46:31 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 23BEDCF93 for ; Thu, 19 Nov 2015 16:46:30 +0000 (UTC) Received: from c64.redhat.com (vpn-232-222.phx2.redhat.com [10.3.232.222]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAJGkLJ8007552; Thu, 19 Nov 2015 11:46:29 -0500 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: Bernd Schmidt , Jeff Law , David Malcolm Subject: [PATCH 09/15] Add hash-map-tests.c Date: Thu, 19 Nov 2015 16:46:00 -0000 Message-Id: <1447952699-40820-10-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1447952699-40820-1-git-send-email-dmalcolm@redhat.com> References: <564A1DAB.1030700@redhat.com> <1447952699-40820-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg02374.txt.bz2 Jeff approved an earlier version of this (as unittests/test-hash-map.c): https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03301.html > OK if/when prereqs are approved. Minor twiddling if we end up > moving it elsewhere or standardizing/reducing header files is > pre-approved. This version moves the tests to gcc/hash-map-tests.c. gcc/ChangeLog: * hash-map-tests.c: New file. --- gcc/hash-map-tests.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 gcc/hash-map-tests.c diff --git a/gcc/hash-map-tests.c b/gcc/hash-map-tests.c new file mode 100644 index 0000000..8fc989a --- /dev/null +++ b/gcc/hash-map-tests.c @@ -0,0 +1,81 @@ +/* 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 +. */ + +#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" +#include "selftest.h" + +#if CHECKING_P + +namespace { + +TEST (hash_map_test, map_of_strings_to_int) +{ + hash_map 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. */ + +#endif /* CHECKING_P */ -- 1.8.5.3