This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=b051c0d58e99a76c3be616f374307d78503da5c5

commit b051c0d58e99a76c3be616f374307d78503da5c5
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Sat Aug 25 01:29:32 2018 +0200

    libdpkg: Add new unit tests for namevalue, fsys-hash and pkg-hash modules
---
 debian/changelog                          |   1 +
 lib/dpkg/t/.gitignore                     |   3 +
 lib/dpkg/t/Makefile.am                    |   3 +
 lib/dpkg/t/t-fsys-hash.c                  | 108 ++++++++++++++++++
 lib/dpkg/{namevalue.c => t/t-namevalue.c} |  32 ++++--
 lib/dpkg/t/t-pkg-hash.c                   | 178 ++++++++++++++++++++++++++++++
 6 files changed, 313 insertions(+), 12 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 6ebe703fc..3b883b060 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -275,6 +275,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
     - Add several TODO tests cases for dependency simplification.
     - Add new cppcheck author test.
     - Add support for new test_get_srcdir() test_get_builddir().
+    - Add new unit tests for namevalue, fsys-hash and pkg-hash libdpkg modules.
 
   [ Updated programs translations ]
   * Dutch (Frans Spiesschaert). Closes: #881401
diff --git a/lib/dpkg/t/.gitignore b/lib/dpkg/t/.gitignore
index ee1ab73ec..38bfe340f 100644
--- a/lib/dpkg/t/.gitignore
+++ b/lib/dpkg/t/.gitignore
@@ -10,11 +10,14 @@ t-deb-version
 t-ehandle
 t-error
 t-file
+t-fsys-hash
 t-macros
 t-mod-db
+t-namevalue
 t-pager
 t-path
 t-pkginfo
+t-pkg-hash
 t-pkg-list
 t-pkg-queue
 t-pkg-show
diff --git a/lib/dpkg/t/Makefile.am b/lib/dpkg/t/Makefile.am
index 6dff6267a..dcecc6155 100644
--- a/lib/dpkg/t/Makefile.am
+++ b/lib/dpkg/t/Makefile.am
@@ -23,6 +23,7 @@ test_programs = \
        t-test-skip \
        t-macros \
        t-c-ctype \
+       t-namevalue \
        t-ehandle \
        t-error \
        t-string \
@@ -42,7 +43,9 @@ test_programs = \
        t-pkginfo \
        t-pkg-list \
        t-pkg-queue \
+       t-pkg-hash \
        t-pkg-show \
+       t-fsys-hash \
        t-trigger \
        t-mod-db \
        $(nil)
diff --git a/lib/dpkg/t/t-fsys-hash.c b/lib/dpkg/t/t-fsys-hash.c
new file mode 100644
index 000000000..8d34d4807
--- /dev/null
+++ b/lib/dpkg/t/t-fsys-hash.c
@@ -0,0 +1,108 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * t-fsys-hash.c - test fsys-hash implementation
+ *
+ * Copyright © 2018 Guillem Jover <guil...@debian.org>
+ *
+ * This 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This 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 <compat.h>
+
+#include <dpkg/test.h>
+#include <dpkg/dpkg.h>
+#include <dpkg/fsys.h>
+
+static void
+test_fsys_nodes(void)
+{
+       struct filenamenode *fnn;
+       struct fileiterator *iter;
+       const char *name;
+
+       test_pass(fsys_hash_entries() == 0);
+
+       filesdbinit();
+
+       fnn = findnamenode("/nonexistent", fnn_nonew);
+       test_pass(fnn == NULL);
+       test_pass(fsys_hash_entries() == 0);
+
+       name = "/test/path/aa";
+       fnn = findnamenode(name, fnn_nocopy);
+       test_pass(fnn != NULL);
+       test_pass(fsys_hash_entries() == 1);
+       test_pass(fnn->name == name);
+       test_str(fnn->name, ==, "/test/path/aa");
+       test_pass(fnn->flags == 0);
+       test_pass(fnn->oldhash == NULL);
+       test_str(fnn->newhash, ==, EMPTYHASHFLAG);
+
+       fnn = findnamenode("//./test/path/bb", 0);
+       test_pass(fnn != NULL);
+       test_pass(fsys_hash_entries() == 2);
+       test_str(fnn->name, ==, "/test/path/bb");
+       test_pass(fnn->flags == 0);
+       test_pass(fnn->oldhash == NULL);
+       test_str(fnn->newhash, ==, EMPTYHASHFLAG);
+
+       fnn = findnamenode("/test/path/cc", 0);
+       test_pass(fnn != NULL);
+       test_pass(fsys_hash_entries() == 3);
+       test_str(fnn->name, ==, "/test/path/cc");
+       test_pass(fnn->flags == 0);
+       test_pass(fnn->oldhash == NULL);
+       test_str(fnn->newhash, ==, EMPTYHASHFLAG);
+
+       iter = files_db_iter_new();
+       while ((fnn = files_db_iter_next(iter))) {
+               if (strcmp(fnn->name, "/test/path/aa") == 0)
+                       test_str(fnn->name, ==, "/test/path/aa");
+               else if (strcmp(fnn->name, "/test/path/bb") == 0)
+                       test_str(fnn->name, ==, "/test/path/bb");
+               else if (strcmp(fnn->name, "/test/path/cc") == 0)
+                       test_str(fnn->name, ==, "/test/path/cc");
+               else
+                       test_fail("unknown filenamenode");
+       }
+       files_db_iter_free(iter);
+
+       filesdbinit();
+       test_pass(fsys_hash_entries() == 3);
+       fnn = findnamenode("/test/path/aa", fnn_nonew);
+       test_pass(fnn != NULL);
+       fnn = findnamenode("/test/path/bb", fnn_nonew);
+       test_pass(fnn != NULL);
+       fnn = findnamenode("/test/path/cc", fnn_nonew);
+       test_pass(fnn != NULL);
+       test_pass(fsys_hash_entries() == 3);
+
+       files_db_reset();
+       test_pass(fsys_hash_entries() == 0);
+       fnn = findnamenode("/test/path/aa", fnn_nonew);
+       test_pass(fnn == NULL);
+       fnn = findnamenode("/test/path/bb", fnn_nonew);
+       test_pass(fnn == NULL);
+       fnn = findnamenode("/test/path/cc", fnn_nonew);
+       test_pass(fnn == NULL);
+       test_pass(fsys_hash_entries() == 0);
+}
+
+TEST_ENTRY(test)
+{
+       test_plan(35);
+
+       test_fsys_nodes();
+}
diff --git a/lib/dpkg/namevalue.c b/lib/dpkg/t/t-namevalue.c
similarity index 61%
copy from lib/dpkg/namevalue.c
copy to lib/dpkg/t/t-namevalue.c
index d138f8706..c8647662e 100644
--- a/lib/dpkg/namevalue.c
+++ b/lib/dpkg/t/t-namevalue.c
@@ -1,8 +1,8 @@
 /*
  * libdpkg - Debian packaging suite library routines
- * namevalue.c - name value structure handling
+ * t-namevalue.c - test name/value implementation
  *
- * Copyright © 2010-2011, 2014-2015 Guillem Jover <guil...@debian.org>
+ * Copyright © 2018 Guillem Jover <guil...@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,20 +21,28 @@
 #include <config.h>
 #include <compat.h>
 
-#include <stddef.h>
-#include <string.h>
-
+#include <dpkg/test.h>
 #include <dpkg/namevalue.h>
+#include <dpkg/dpkg-db.h>
 
-const struct namevalue *
-namevalue_find_by_name(const struct namevalue *head, const char *str)
+static void
+test_namevalue(void)
 {
        const struct namevalue *nv;
 
-       for (nv = head; nv->name; nv++) {
-               if (strncasecmp(str, nv->name, nv->length) == 0)
-                       return nv;
-       }
+       nv = namevalue_find_by_name(booleaninfos, "");
+       test_pass(nv == NULL);
+
+       nv = namevalue_find_by_name(booleaninfos, "no");
+       test_pass(nv != NULL);
+       test_pass(nv->value == false);
+       test_pass(nv->length == strlen("no"));
+       test_str(nv->name, ==, "no");
+}
+
+TEST_ENTRY(test)
+{
+       test_plan(5);
 
-       return NULL;
+       test_namevalue();
 }
diff --git a/lib/dpkg/t/t-pkg-hash.c b/lib/dpkg/t/t-pkg-hash.c
new file mode 100644
index 000000000..f45594f15
--- /dev/null
+++ b/lib/dpkg/t/t-pkg-hash.c
@@ -0,0 +1,178 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * t-pkg-hash.c - test pkg-hash implementation
+ *
+ * Copyright © 2018 Guillem Jover <guil...@debian.org>
+ *
+ * This 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This 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 <compat.h>
+
+#include <dpkg/test.h>
+#include <dpkg/dpkg.h>
+#include <dpkg/dpkg-db.h>
+#include <dpkg/pkg.h>
+
+static void
+test_pkg_hash(void)
+{
+       struct dpkg_arch *arch;
+       struct pkgset *set;
+       struct pkginfo *pkg;
+       struct pkgiterator *iter;
+       int pkginstance;
+
+       test_pass(pkg_db_count_set() == 0);
+       test_pass(pkg_db_count_pkg() == 0);
+
+       set = pkg_db_find_set("pkg-aa");
+       test_pass(set != NULL);
+       test_str(set->name, ==, "pkg-aa");
+       test_pass(pkg_db_count_set() == 1);
+       test_pass(pkg_db_count_pkg() == 1);
+
+       set = pkg_db_find_set("pkg-aa");
+       test_pass(set != NULL);
+       test_str(set->name, ==, "pkg-aa");
+       test_pass(pkg_db_count_set() == 1);
+       test_pass(pkg_db_count_pkg() == 1);
+
+       set = pkg_db_find_set("Pkg-AA");
+       test_pass(set != NULL);
+       test_str(set->name, ==, "pkg-aa");
+       test_pass(pkg_db_count_set() == 1);
+       test_pass(pkg_db_count_pkg() == 1);
+
+       set = pkg_db_find_set("pkg-bb");
+       pkg_set_status(&set->pkg, PKG_STAT_INSTALLED);
+       test_pass(set != NULL);
+       test_str(set->name, ==, "pkg-bb");
+       test_pass(pkg_db_count_set() == 2);
+       test_pass(pkg_db_count_pkg() == 2);
+
+       set = pkg_db_find_set("pkg-cc");
+       test_pass(set != NULL);
+       test_str(set->name, ==, "pkg-cc");
+       test_pass(pkg_db_count_set() == 3);
+       test_pass(pkg_db_count_pkg() == 3);
+
+       arch = dpkg_arch_find("arch-xx");
+       pkg = pkg_db_find_pkg("pkg-aa", arch);
+       pkg_set_status(pkg, PKG_STAT_INSTALLED);
+       test_pass(pkg != NULL);
+       test_str(pkg->set->name, ==, "pkg-aa");
+       test_str(pkg->installed.arch->name, ==, "arch-xx");
+       test_str(pkg->available.arch->name, ==, "arch-xx");
+       test_pass(pkg_db_count_set() == 3);
+       test_pass(pkg_db_count_pkg() == 3);
+
+       arch = dpkg_arch_find("arch-yy");
+       pkg = pkg_db_find_pkg("pkg-aa", arch);
+       test_pass(pkg != NULL);
+       test_str(pkg->set->name, ==, "pkg-aa");
+       test_str(pkg->installed.arch->name, ==, "arch-yy");
+       test_str(pkg->available.arch->name, ==, "arch-yy");
+       test_pass(pkg_db_count_set() == 3);
+       test_pass(pkg_db_count_pkg() == 4);
+
+       arch = dpkg_arch_find("arch-zz");
+       pkg = pkg_db_find_pkg("pkg-aa", arch);
+       pkg_set_status(pkg, PKG_STAT_UNPACKED);
+       test_pass(pkg != NULL);
+       test_str(pkg->set->name, ==, "pkg-aa");
+       test_str(pkg->installed.arch->name, ==, "arch-zz");
+       test_str(pkg->available.arch->name, ==, "arch-zz");
+       test_pass(pkg_db_count_set() == 3);
+       test_pass(pkg_db_count_pkg() == 5);
+
+       arch = dpkg_arch_find("arch-xx");
+       pkg = pkg_db_find_pkg("pkg-aa", arch);
+       test_pass(pkg != NULL);
+       test_str(pkg->set->name, ==, "pkg-aa");
+       test_str(pkg->installed.arch->name, ==, "arch-xx");
+       test_str(pkg->available.arch->name, ==, "arch-xx");
+       test_pass(pkg_db_count_set() == 3);
+       test_pass(pkg_db_count_pkg() == 5);
+
+       set = pkg_db_find_set("pkg-aa");
+       test_str(set->name, ==, "pkg-aa");
+       pkg = pkg_db_get_singleton(set);
+       test_pass(pkg == NULL);
+       test_pass(pkg_db_count_set() == 3);
+       test_pass(pkg_db_count_pkg() == 5);
+
+       pkg = pkg_db_find_singleton("pkg-bb");
+       test_pass(pkg != NULL);
+       test_str(pkg->set->name, ==, "pkg-bb");
+       test_pass(pkg_db_count_set() == 3);
+       test_pass(pkg_db_count_pkg() == 5);
+
+       pkg = pkg_db_find_singleton("pkg-cc");
+       test_pass(pkg != NULL);
+       test_str(pkg->set->name, ==, "pkg-cc");
+       test_pass(pkg_db_count_set() == 3);
+       test_pass(pkg_db_count_pkg() == 5);
+
+       iter = pkg_db_iter_new();
+       while ((set = pkg_db_iter_next_set(iter))) {
+               if (strcmp(set->name, "pkg-aa") == 0)
+                       test_str(set->name, ==, "pkg-aa");
+               else if (strcmp(set->name, "pkg-bb") == 0)
+                       test_str(set->name, ==, "pkg-bb");
+               else if (strcmp(set->name, "pkg-cc") == 0)
+                       test_str(set->name, ==, "pkg-cc");
+               else
+                       test_fail("unknown filenamenode");
+       }
+       pkg_db_iter_free(iter);
+
+       pkginstance = 0;
+       iter = pkg_db_iter_new();
+       while ((pkg = pkg_db_iter_next_pkg(iter))) {
+               pkginstance++;
+               if (strcmp(pkg->set->name, "pkg-aa") == 0) {
+                       struct pkgbin *pkgbin = &pkg->installed;
+
+                       test_str(pkg->set->name, ==, "pkg-aa");
+                       if (strcmp(pkgbin->arch->name, "arch-xx") == 0)
+                               test_str(pkgbin->arch->name, ==, "arch-xx");
+                       else if (strcmp(pkgbin->arch->name, "arch-yy") == 0)
+                               test_str(pkgbin->arch->name, ==, "arch-yy");
+                       else if (strcmp(pkgbin->arch->name, "arch-zz") == 0)
+                               test_str(pkgbin->arch->name, ==, "arch-zz");
+                       else
+                               test_fail("unknown pkginfo instance");
+               } else if (strcmp(pkg->set->name, "pkg-bb") == 0) {
+                       test_str(pkg->set->name, ==, "pkg-bb");
+               } else if (strcmp(pkg->set->name, "pkg-cc") == 0) {
+                       test_str(pkg->set->name, ==, "pkg-cc");
+               } else {
+                       test_fail("unknown filenamenode");
+               }
+       }
+       pkg_db_iter_free(iter);
+
+       pkg_db_reset();
+       test_pass(pkg_db_count_set() == 0);
+       test_pass(pkg_db_count_pkg() == 0);
+}
+
+TEST_ENTRY(test)
+{
+       test_plan(71);
+
+       test_pkg_hash();
+}

-- 
Dpkg.Org's dpkg

Reply via email to