The following commit has been merged in the master branch:
commit b6b23a82594019d08dcdaf4f8b2a238dce78c945
Author: Guillem Jover <[email protected]>
Date: Sat Sep 17 05:09:56 2011 +0200
libdpkg: Add new mod-db, progname and subproc modules test cases
diff --git a/lib/dpkg/test/.gitignore b/lib/dpkg/test/.gitignore
index 93819ca..8857e47 100644
--- a/lib/dpkg/test/.gitignore
+++ b/lib/dpkg/test/.gitignore
@@ -2,11 +2,14 @@ t-ar
t-buffer
t-command
t-macros
+t-mod-db
t-path
t-pkginfo
t-pkg-list
t-pkg-queue
+t-progname
t-string
+t-subproc
t-test
t-varbuf
t-version
diff --git a/lib/dpkg/test/Makefile.am b/lib/dpkg/test/Makefile.am
index 0a81e82..0795a78 100644
--- a/lib/dpkg/test/Makefile.am
+++ b/lib/dpkg/test/Makefile.am
@@ -1,6 +1,7 @@
## Process this file with automake to produce Makefile.in
AM_CPPFLAGS = \
+ -DADMINDIR=\"$(admindir)\" \
-idirafter $(top_srcdir)/lib/compat \
-I$(top_builddir) \
-I$(top_srcdir)/lib
@@ -14,12 +15,15 @@ check_PROGRAMS = \
t-string \
t-buffer \
t-path \
+ t-progname \
+ t-subproc \
t-command \
t-varbuf \
t-ar \
t-version \
t-pkginfo \
t-pkg-list \
- t-pkg-queue
+ t-pkg-queue \
+ t-mod-db
TESTS = $(check_PROGRAMS)
diff --git a/lib/dpkg/test/t-pkginfo.c b/lib/dpkg/test/t-mod-db.c
similarity index 58%
copy from lib/dpkg/test/t-pkginfo.c
copy to lib/dpkg/test/t-mod-db.c
index b1df8f8..d3cd55d 100644
--- a/lib/dpkg/test/t-pkginfo.c
+++ b/lib/dpkg/test/t-mod-db.c
@@ -1,8 +1,8 @@
/*
* libdpkg - Debian packaging suite library routines
- * t-pkginfo.c - test pkginfo handling
+ * t-db.c - test database implementation
*
- * Copyright © 2009 Guillem Jover <[email protected]>
+ * Copyright © 2011 Guillem Jover <[email protected]>
*
* 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,31 +21,36 @@
#include <config.h>
#include <compat.h>
+#include <stdlib.h>
+
#include <dpkg/test.h>
#include <dpkg/dpkg-db.h>
static void
-test_pkginfo_informative(void)
+test_db_dir(void)
{
- struct pkginfo pkg;
+ char *dir;
+
+ test_str(dpkg_db_get_dir(), ==, ADMINDIR);
- pkg_blank(&pkg);
- test_fail(pkg_is_informative(&pkg, &pkg.installed));
+ dpkg_db_set_dir("testdir");
+ test_str(dpkg_db_get_dir(), ==, "testdir");
- pkg.want = want_purge;
- test_pass(pkg_is_informative(&pkg, &pkg.installed));
+ setenv("DPKG_ADMINDIR", "testenvdir", 1);
+ dpkg_db_set_dir(NULL);
+ test_str(dpkg_db_get_dir(), ==, "testenvdir");
- pkg_blank(&pkg);
- pkg.installed.description = "test description";
- test_pass(pkg_is_informative(&pkg, &pkg.installed));
+ unsetenv("DPKG_ADMINDIR");
+ dpkg_db_set_dir(NULL);
+ test_str(dpkg_db_get_dir(), ==, ADMINDIR);
- /* FIXME: Complete. */
+ dir = dpkg_db_get_path("testfile");
+ test_str(dir, ==, ADMINDIR "/testfile");
+ free(dir);
}
static void
test(void)
{
- test_pkginfo_informative();
-
- /* FIXME: Complete. */
+ test_db_dir();
}
diff --git a/lib/dpkg/test/t-pkginfo.c b/lib/dpkg/test/t-progname.c
similarity index 60%
copy from lib/dpkg/test/t-pkginfo.c
copy to lib/dpkg/test/t-progname.c
index b1df8f8..17ed5df 100644
--- a/lib/dpkg/test/t-pkginfo.c
+++ b/lib/dpkg/test/t-progname.c
@@ -1,8 +1,8 @@
/*
* libdpkg - Debian packaging suite library routines
- * t-pkginfo.c - test pkginfo handling
+ * t-progname.c - test program name handling
*
- * Copyright © 2009 Guillem Jover <[email protected]>
+ * Copyright © 2011 Guillem Jover <[email protected]>
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,30 +22,25 @@
#include <compat.h>
#include <dpkg/test.h>
-#include <dpkg/dpkg-db.h>
+#include <dpkg/progname.h>
static void
-test_pkginfo_informative(void)
+test_progname(void)
{
- struct pkginfo pkg;
+ /* Test initially empty progname. */
+ test_str(dpkg_get_progname(), ==, "t-progname");
- pkg_blank(&pkg);
- test_fail(pkg_is_informative(&pkg, &pkg.installed));
+ /* Test setting a new progname. */
+ dpkg_set_progname("newname");
+ test_str(dpkg_get_progname(), ==, "newname");
- pkg.want = want_purge;
- test_pass(pkg_is_informative(&pkg, &pkg.installed));
-
- pkg_blank(&pkg);
- pkg.installed.description = "test description";
- test_pass(pkg_is_informative(&pkg, &pkg.installed));
-
- /* FIXME: Complete. */
+ /* Test setting a new progname with path. */
+ dpkg_set_progname("path/newprogname");
+ test_str(dpkg_get_progname(), ==, "newprogname");
}
static void
test(void)
{
- test_pkginfo_informative();
-
- /* FIXME: Complete. */
+ test_progname();
}
diff --git a/lib/dpkg/test/t-subproc.c b/lib/dpkg/test/t-subproc.c
new file mode 100644
index 0000000..5cb5b13
--- /dev/null
+++ b/lib/dpkg/test/t-subproc.c
@@ -0,0 +1,91 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * t-subproc.c - test sub-process module
+ *
+ * Copyright © 2011 Guillem Jover <[email protected]>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <sys/types.h>
+
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <dpkg/test.h>
+#include <dpkg/subproc.h>
+
+static void
+test_subproc_fork(void)
+{
+ pid_t pid;
+ int ret;
+
+ /* Test exit(). */
+ pid = subproc_fork();
+ if (pid == 0)
+ exit(0);
+ ret = subproc_wait_check(pid, "subproc exit pass", PROCNOERR);
+ test_pass(ret == 0);
+
+ pid = subproc_fork();
+ if (pid == 0)
+ exit(128);
+ ret = subproc_wait_check(pid, "subproc exit fail", PROCNOERR);
+ test_pass(ret == 128);
+
+ /* Test signals. */
+ pid = subproc_fork();
+ if (pid == 0)
+ raise(SIGINT);
+ ret = subproc_wait_check(pid, "subproc signal", PROCWARN);
+ test_pass(ret == -1);
+
+ pid = subproc_fork();
+ if (pid == 0)
+ raise(SIGTERM);
+ ret = subproc_wait_check(pid, "subproc signal", PROCWARN);
+ test_pass(ret == -1);
+
+ pid = subproc_fork();
+ if (pid == 0)
+ raise(SIGPIPE);
+ ret = subproc_wait_check(pid, "subproc SIGPIPE", PROCWARN | PROCPIPE);
+ test_pass(ret == 0);
+
+ pid = subproc_fork();
+ if (pid == 0)
+ raise(SIGPIPE);
+ ret = subproc_wait_check(pid, "subproc SIGPIPE", PROCWARN);
+ test_pass(ret == -1);
+}
+
+static void
+test(void)
+{
+ int fd;
+
+ /* XXX: Shut up output, we just want the error code. */
+ fd = open("/dev/null", O_RDWR);
+ test_pass(fd >= 0);
+ dup2(fd, 1);
+ dup2(fd, 2);
+
+ test_subproc_fork();
+}
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]