]> Savannah Git Hosting - gnulib.git/commitdiff
list-c++: Add tests.
authorBruno Haible <bruno@clisp.org>
Sun, 2 Feb 2020 18:00:11 +0000 (19:00 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 2 Feb 2020 18:00:11 +0000 (19:00 +0100)
* tests/test-list-c++.cc: New file.
* modules/list-c++-tests: New file.

ChangeLog
modules/list-c++-tests [new file with mode: 0644]
tests/test-list-c++.cc [new file with mode: 0644]

index a9350ec961922331746f872bfd56779e2bc8621c..9d28f869fcd9c6b4a75241a334a8622a2e4fc0bb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2020-02-02  Bruno Haible  <bruno@clisp.org>
 
+       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 (file)
index 0000000..e1d74a6
--- /dev/null
@@ -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 (file)
index 0000000..d0be7ba
--- /dev/null
@@ -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 <bruno@clisp.org>, 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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include "gl_list.hh"
+#include "gl_array_list.h"
+
+#include <string.h>
+
+#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<const char *> list1;
+
+  list1 = gl_List<const char *> (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<const char *>::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<const char *> list2 = gl_List<const char *> (list1, 1, 3);
+
+  gl_List<const char *>::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;
+}