LCOV - code coverage report
Current view: top level - gcc - typed-splay-tree.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 28 28 100.0 %
Date: 2020-04-04 11:58:09 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Selftests for typed-splay-tree.h.
       2                 :            :    Copyright (C) 2016-2020 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 "typed-splay-tree.h"
      24                 :            : #include "selftest.h"
      25                 :            : 
      26                 :            : #if CHECKING_P
      27                 :            : 
      28                 :            : namespace selftest {
      29                 :            : 
      30                 :            : /* Callback for use by test_str_to_int.  */
      31                 :            : 
      32                 :            : static int
      33                 :          6 : append_cb (const char *, int value, void *user_data)
      34                 :            : {
      35                 :          6 :   auto_vec <int> *vec = (auto_vec <int> *)user_data;
      36                 :          6 :   vec->safe_push (value);
      37                 :          6 :   return 0;
      38                 :            : }
      39                 :            : 
      40                 :            : /* Test of typed_splay_tree <const char *, int>.  */
      41                 :            : 
      42                 :            : static void
      43                 :          2 : test_str_to_int ()
      44                 :            : {
      45                 :          2 :   typed_splay_tree <const char *, int> t (strcmp, NULL, NULL);
      46                 :            : 
      47                 :          2 :   t.insert ("a", 1);
      48                 :          2 :   t.insert ("b", 2);
      49                 :          2 :   t.insert ("c", 3);
      50                 :          2 :   t.insert ("d", 4);
      51                 :            : 
      52                 :          2 :   t.remove ("d");
      53                 :            : 
      54                 :          4 :   ASSERT_EQ (1, t.lookup ("a"));
      55                 :          4 :   ASSERT_EQ (2, t.lookup ("b"));
      56                 :          4 :   ASSERT_EQ (3, t.lookup ("c"));
      57                 :            : 
      58                 :          4 :   ASSERT_EQ (2, t.predecessor ("c"));
      59                 :          4 :   ASSERT_EQ (3, t.successor ("b"));
      60                 :          4 :   ASSERT_EQ (1, t.min ());
      61                 :          4 :   ASSERT_EQ (3, t.max ());
      62                 :            : 
      63                 :            :   /* Test foreach by appending to a vec, and verifying the vec.  */
      64                 :          4 :   auto_vec <int> v;
      65                 :          2 :   t.foreach (append_cb, &v);
      66                 :          2 :   ASSERT_EQ (3, v.length ());
      67                 :          2 :   ASSERT_EQ (1, v[0]);
      68                 :          2 :   ASSERT_EQ (2, v[1]);
      69                 :          2 :   ASSERT_EQ (3, v[2]);
      70                 :          2 : }
      71                 :            : 
      72                 :            : /* Run all of the selftests within this file.  */
      73                 :            : 
      74                 :            : void
      75                 :          2 : typed_splay_tree_c_tests ()
      76                 :            : {
      77                 :          2 :   test_str_to_int ();
      78                 :          2 : }
      79                 :            : 
      80                 :            : } // namespace selftest
      81                 :            : 
      82                 :            : #endif /* #if CHECKING_P */

Generated by: LCOV version 1.0

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto --enable-host-shared. GCC test suite is run with the built compiler.