From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22119 invoked by alias); 27 Oct 2015 19:31:49 -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 21992 invoked by uid 89); 27 Oct 2015 19:31:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 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; Tue, 27 Oct 2015 19:31:39 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 8A034C0AF7AC for ; Tue, 27 Oct 2015 19:31:38 +0000 (UTC) Received: from c64.redhat.com (vpn-230-173.phx2.redhat.com [10.3.230.173]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9RJVW5f018778; Tue, 27 Oct 2015 15:31:38 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 05/16] Add test-et-forest.c to unittests Date: Tue, 27 Oct 2015 19:31:00 -0000 Message-Id: <1445975355-37660-6-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1445975355-37660-1-git-send-email-dmalcolm@redhat.com> References: <5589B2FB.8010500@redhat.com> <1445975355-37660-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg02951.txt.bz2 gcc/testsuite/ChangeLog: * unittests/test-et-forest.c: New file. --- gcc/testsuite/unittests/test-et-forest.c | 121 +++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 gcc/testsuite/unittests/test-et-forest.c diff --git a/gcc/testsuite/unittests/test-et-forest.c b/gcc/testsuite/unittests/test-et-forest.c new file mode 100644 index 0000000..35ca084 --- /dev/null +++ b/gcc/testsuite/unittests/test-et-forest.c @@ -0,0 +1,121 @@ +/* Unit tests for et-forest.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 "gtest/gtest.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "opts.h" +#include "alloc-pool.h" +#include "et-forest.h" + +namespace { + +TEST (et_forest_test, single_node) +{ + void *test_data = (void *)0xcafebabe; + + et_node *n = et_new_tree (test_data); + EXPECT_EQ (n->data, test_data); + EXPECT_EQ (n, et_root (n)); + et_free_tree (n); +} + +/* Test of this tree: + a + / \ + / \ + b c + / \ | + d e f. */ + +TEST (et_forest_test, simple_tree) +{ + et_node *a = et_new_tree (NULL); + et_node *b = et_new_tree (NULL); + et_node *c = et_new_tree (NULL); + et_node *d = et_new_tree (NULL); + et_node *e = et_new_tree (NULL); + et_node *f = et_new_tree (NULL); + + et_set_father (b, a); + et_set_father (c, a); + et_set_father (d, b); + et_set_father (e, b); + et_set_father (f, c); + + EXPECT_TRUE (et_below (a, a)); + EXPECT_TRUE (et_below (b, a)); + EXPECT_TRUE (et_below (c, a)); + EXPECT_TRUE (et_below (d, a)); + EXPECT_TRUE (et_below (e, a)); + EXPECT_TRUE (et_below (f, a)); + + EXPECT_FALSE (et_below (a, b)); + EXPECT_TRUE (et_below (b, b)); + EXPECT_FALSE (et_below (c, b)); + EXPECT_TRUE (et_below (d, b)); + EXPECT_TRUE (et_below (e, b)); + EXPECT_FALSE (et_below (f, b)); + + EXPECT_FALSE (et_below (a, c)); + EXPECT_FALSE (et_below (b, c)); + EXPECT_TRUE (et_below (c, c)); + EXPECT_FALSE (et_below (d, c)); + EXPECT_FALSE (et_below (e, c)); + EXPECT_TRUE (et_below (f, c)); + + EXPECT_FALSE (et_below (a, d)); + EXPECT_FALSE (et_below (b, d)); + EXPECT_FALSE (et_below (c, d)); + EXPECT_TRUE (et_below (d, d)); + EXPECT_FALSE (et_below (e, d)); + EXPECT_FALSE (et_below (f, d)); + + EXPECT_FALSE (et_below (a, e)); + EXPECT_FALSE (et_below (b, e)); + EXPECT_FALSE (et_below (c, e)); + EXPECT_FALSE (et_below (d, e)); + EXPECT_TRUE (et_below (e, e)); + EXPECT_FALSE (et_below (f, e)); + + EXPECT_FALSE (et_below (a, f)); + EXPECT_FALSE (et_below (b, f)); + EXPECT_FALSE (et_below (c, f)); + EXPECT_FALSE (et_below (d, f)); + EXPECT_FALSE (et_below (e, f)); + EXPECT_TRUE (et_below (f, f)); + + et_free_tree_force (a); +} + +TEST (et_forest_test, disconnected_nodes) +{ + et_node *a = et_new_tree (NULL); + et_node *b = et_new_tree (NULL); + + EXPECT_FALSE (et_below (a, b)); + EXPECT_FALSE (et_below (b, a)); + + et_free_tree (a); + et_free_tree (b); +} + +} // anon namespace -- 1.8.5.3