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
+<http://www.gnu.org/licenses/>.  */
+
+#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

Reply via email to