>From 770219943d9e9d76daffbc427937b792acf25737 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 2 Feb 2020 19:00:11 +0100 Subject: [PATCH 02/11] list-c++: Add tests. * tests/test-list-c++.cc: New file. * modules/list-c++-tests: New file. --- ChangeLog | 4 +++ modules/list-c++-tests | 17 +++++++++++ tests/test-list-c++.cc | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 modules/list-c++-tests create mode 100644 tests/test-list-c++.cc diff --git a/ChangeLog b/ChangeLog index a9350ec..9d28f86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-02-02 Bruno Haible + list-c++: Add tests. + * tests/test-list-c++.cc: New file. + * modules/list-c++-tests: New file. + list-c++: New module. * lib/gl_list.hh: New file, based on lib/gl_list.h. * modules/list-c++: New file. diff --git a/modules/list-c++-tests b/modules/list-c++-tests new file mode 100644 index 0000000..e1d74a6 --- /dev/null +++ b/modules/list-c++-tests @@ -0,0 +1,17 @@ +Files: +tests/test-list-c++.cc +tests/macros.h + +Depends-on: +ansi-c++-opt +array-list + +configure.ac: + +Makefile.am: +if ANSICXX +TESTS += test-list-c++ +check_PROGRAMS += test-list-c++ +test_list_c___SOURCES = test-list-c++.cc +test_list_c___LDADD = $(LDADD) @LIBINTL@ +endif diff --git a/tests/test-list-c++.cc b/tests/test-list-c++.cc new file mode 100644 index 0000000..d0be7ba --- /dev/null +++ b/tests/test-list-c++.cc @@ -0,0 +1,79 @@ +/* Test of list data type implementation as a C++ class. + Copyright (C) 2020 Free Software Foundation, Inc. + Written by Bruno Haible , 2020. + + This program 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 of the License, or + (at your option) any later version. + + This program 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 this program. If not, see . */ + +#include + +#include "gl_list.hh" +#include "gl_array_list.h" + +#include + +#include "macros.h" + +static const char A[] = "A"; +static const char C[] = "C"; +static const char D[] = "D"; + +int +main (int argc, char *argv[]) +{ + gl_List list1; + + list1 = gl_List (GL_ARRAY_LIST, NULL, NULL, NULL, true); + list1.add_last (A); + list1.add_last (C); + list1.add_last (D); + list1.add_last (C); + ASSERT (list1.size () == 4); + + gl_List::iterator iter1 = list1.begin (); + { + const char *elt; + ASSERT (iter1.next (elt)); + ASSERT (strcmp (elt, "A") == 0); + ASSERT (iter1.next (elt)); + ASSERT (strcmp (elt, "C") == 0); + ASSERT (iter1.next (elt)); + ASSERT (strcmp (elt, "D") == 0); + ASSERT (iter1.next (elt)); + ASSERT (strcmp (elt, "C") == 0); + ASSERT (!iter1.next (elt)); + } + + gl_List list2 = gl_List (list1, 1, 3); + + gl_List::iterator iter2 = list2.begin (); + { + const char *elt; + ASSERT (iter2.next (elt)); + ASSERT (strcmp (elt, "C") == 0); + ASSERT (iter2.next (elt)); + ASSERT (strcmp (elt, "D") == 0); + ASSERT (!iter1.next (elt)); + } + + ASSERT (list2.indexof (A) == (size_t)(-1)); + ASSERT (list2.indexof (D) == 1); + + ASSERT (list2.sortedlist_indexof (strcmp, "A") == (size_t)(-1)); + ASSERT (list2.sortedlist_indexof (strcmp, "D") == 1); + + list2.free (); + list1.free (); + + return 0; +} -- 2.7.4