diff options
Diffstat (limited to 'lib/dpkg/t')
-rw-r--r-- | lib/dpkg/t/.gitignore | 13 | ||||
-rw-r--r-- | lib/dpkg/t/Makefile.am | 17 | ||||
-rw-r--r-- | lib/dpkg/t/b-fsys-hash.c | 80 | ||||
-rw-r--r-- | lib/dpkg/t/b-pkg-hash.c | 65 | ||||
-rw-r--r-- | lib/dpkg/t/c-tarextract.c | 28 | ||||
-rw-r--r-- | lib/dpkg/t/t-ar.c | 6 | ||||
-rw-r--r-- | lib/dpkg/t/t-command.c | 38 | ||||
-rw-r--r-- | lib/dpkg/t/t-ehandle.c | 2 | ||||
-rw-r--r-- | lib/dpkg/t/t-error.c | 10 | ||||
-rw-r--r-- | lib/dpkg/t/t-file.c | 96 | ||||
-rw-r--r-- | lib/dpkg/t/t-fsys-dir.c | 65 | ||||
-rw-r--r-- | lib/dpkg/t/t-fsys-hash.c | 108 | ||||
-rw-r--r-- | lib/dpkg/t/t-headers-cpp.cc | 82 | ||||
-rw-r--r-- | lib/dpkg/t/t-mod-db.c | 2 | ||||
-rw-r--r-- | lib/dpkg/t/t-namevalue.c | 48 | ||||
-rw-r--r-- | lib/dpkg/t/t-pager.c | 75 | ||||
-rw-r--r-- | lib/dpkg/t/t-pkg-hash.c | 178 | ||||
-rw-r--r-- | lib/dpkg/t/t-pkg-show.c | 61 | ||||
-rw-r--r-- | lib/dpkg/t/t-string.c | 36 | ||||
-rw-r--r-- | lib/dpkg/t/t-tar.c | 8 | ||||
-rwxr-xr-x | lib/dpkg/t/t-tarextract.t | 2 | ||||
-rw-r--r-- | lib/dpkg/t/t-test.c | 7 | ||||
-rwxr-xr-x | lib/dpkg/t/t-treewalk.t | 2 | ||||
-rw-r--r-- | lib/dpkg/t/t-varbuf.c | 25 |
24 files changed, 990 insertions, 64 deletions
diff --git a/lib/dpkg/t/.gitignore b/lib/dpkg/t/.gitignore index e22bcc9e4..b711dbee7 100644 --- a/lib/dpkg/t/.gitignore +++ b/lib/dpkg/t/.gitignore @@ -1,6 +1,11 @@ +# Benchmarks +b-fsys-hash +b-pkg-hash +# Compiled helpers c-tarextract c-treewalk c-trigdeferred +# Testsuite t-ar t-arch t-buffer @@ -9,12 +14,20 @@ t-command t-deb-version t-ehandle t-error +t-file +t-fsys-dir +t-fsys-hash +t-headers-cpp 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 t-progname t-string t-subproc diff --git a/lib/dpkg/t/Makefile.am b/lib/dpkg/t/Makefile.am index 12dc4d86a..ab9ce3b4b 100644 --- a/lib/dpkg/t/Makefile.am +++ b/lib/dpkg/t/Makefile.am @@ -17,20 +17,26 @@ TEST_ENV_VARS = \ DPKG_PROGTAR=$(TAR) \ $(nil) +t_headers_cpp_SOURCES = t-headers-cpp.cc + # The tests are sorted in order of increasing complexity. test_programs = \ t-test \ t-test-skip \ t-macros \ + t-headers-cpp \ t-c-ctype \ + t-namevalue \ t-ehandle \ t-error \ t-string \ + t-file \ t-buffer \ t-path \ t-progname \ t-subproc \ t-command \ + t-pager \ t-varbuf \ t-ar \ t-tar \ @@ -40,6 +46,10 @@ test_programs = \ t-pkginfo \ t-pkg-list \ t-pkg-queue \ + t-pkg-hash \ + t-pkg-show \ + t-fsys-dir \ + t-fsys-hash \ t-trigger \ t-mod-db \ $(nil) @@ -50,8 +60,15 @@ test_scripts = \ t-trigdeferred.t \ $(nil) +BENCHMARK_LDADD_FLAGS = -lrt $(LDADD) + +b_fsys_hash_LDADD = $(BENCHMARK_LDADD_FLAGS) +b_pkg_hash_LDADD = $(BENCHMARK_LDADD_FLAGS) + check_PROGRAMS = \ $(test_programs) \ + b-fsys-hash \ + b-pkg-hash \ c-tarextract \ c-treewalk \ c-trigdeferred \ diff --git a/lib/dpkg/t/b-fsys-hash.c b/lib/dpkg/t/b-fsys-hash.c new file mode 100644 index 000000000..373cfc7c6 --- /dev/null +++ b/lib/dpkg/t/b-fsys-hash.c @@ -0,0 +1,80 @@ +/* + * dpkg - main program for package management + * b-fsys-hash.c - test fsys database load and hash performance + * + * Copyright © 2009-2019 Guillem Jover <guillem@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, + * 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 dpkg; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <config.h> +#include <compat.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <time.h> +#include <stdlib.h> +#include <stdio.h> + +#include <dpkg/i18n.h> +#include <dpkg/dpkg.h> +#include <dpkg/dpkg-db.h> + +#include <dpkg/perf.h> + +#include <dpkg/db-fsys.h> + +static const char *admindir; + +int +main(int argc, const char *const *argv) +{ + struct perf_slot ps; + + push_error_context(); + setvbuf(stdout, NULL, _IONBF, 0); + + admindir = dpkg_db_set_dir(admindir); + + perf_ts_mark_print("init"); + + perf_ts_slot_start(&ps); + fsys_hash_init(); + perf_ts_slot_stop(&ps); + + perf_ts_slot_print(&ps, "fsys_hash_init"); + + perf_ts_slot_start(&ps); + modstatdb_open(msdbrw_readonly | msdbrw_available_readonly); + perf_ts_slot_stop(&ps); + + perf_ts_slot_print(&ps, "modstatdb_init"); + + perf_ts_slot_start(&ps); + ensure_allinstfiles_available_quiet(); + perf_ts_slot_stop(&ps); + + perf_ts_slot_print(&ps, "load .list"); + + pkg_hash_report(stdout); + fsys_hash_report(stdout); + + modstatdb_shutdown(); + pop_error_context(ehflag_normaltidy); + + perf_ts_mark_print("shutdown"); + + return 0; +} diff --git a/lib/dpkg/t/b-pkg-hash.c b/lib/dpkg/t/b-pkg-hash.c new file mode 100644 index 000000000..74e26af7b --- /dev/null +++ b/lib/dpkg/t/b-pkg-hash.c @@ -0,0 +1,65 @@ +/* + * dpkg - main program for package management + * b-pkg-hash.c - test pkg database load and hash performance + * + * Copyright © 2009-2019 Guillem Jover <guillem@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, + * 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 dpkg; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <config.h> +#include <compat.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <time.h> +#include <stdlib.h> +#include <stdio.h> + +#include <dpkg/i18n.h> +#include <dpkg/dpkg.h> +#include <dpkg/dpkg-db.h> + +#include <dpkg/perf.h> + +static const char *admindir; + +int +main(int argc, const char *const *argv) +{ + struct perf_slot ps; + + push_error_context(); + setvbuf(stdout, NULL, _IONBF, 0); + + admindir = dpkg_db_set_dir(admindir); + + perf_ts_mark_print("init"); + + perf_ts_slot_start(&ps); + modstatdb_open(msdbrw_readonly | msdbrw_available_readonly); + perf_ts_slot_stop(&ps); + + perf_ts_slot_print(&ps, "modstatdb_init"); + + pkg_hash_report(stdout); + + modstatdb_shutdown(); + pop_error_context(ehflag_normaltidy); + + perf_ts_mark_print("shutdown"); + + return 0; +} diff --git a/lib/dpkg/t/c-tarextract.c b/lib/dpkg/t/c-tarextract.c index 4781c0237..34f3d08fa 100644 --- a/lib/dpkg/t/c-tarextract.c +++ b/lib/dpkg/t/c-tarextract.c @@ -42,16 +42,17 @@ struct tar_context { }; static int -tar_read(void *ctx, char *buffer, int size) +tar_read(struct tar_archive *tar, char *buffer, int size) { - struct tar_context *tc = ctx; + struct tar_context *tc = tar->ctx; return fd_read(tc->tar_fd, buffer, size); } static int -tar_object_skip(struct tar_context *tc, struct tar_entry *te) +tar_object_skip(struct tar_archive *tar, struct tar_entry *te) { + struct tar_context *tc = tar->ctx; off_t size; size = (te->size + TARBLKSZ - 1) / TARBLKSZ * TARBLKSZ; @@ -62,7 +63,7 @@ tar_object_skip(struct tar_context *tc, struct tar_entry *te) } static int -tar_object(void *ctx, struct tar_entry *te) +tar_object(struct tar_archive *tar, struct tar_entry *te) { printf("%s mode=%o time=%ld.%.9d uid=%d gid=%d", te->name, te->stat.mode, te->mtime, 0, te->stat.uid, te->stat.gid); @@ -74,7 +75,7 @@ tar_object(void *ctx, struct tar_entry *te) switch (te->type) { case TAR_FILETYPE_FILE0: case TAR_FILETYPE_FILE: - tar_object_skip(ctx, te); + tar_object_skip(tar, te); printf(" type=file size=%jd", (intmax_t)te->size); break; case TAR_FILETYPE_HARDLINK: @@ -116,7 +117,8 @@ struct tar_operations tar_ops = { int main(int argc, char **argv) { - struct tar_context ctx; + struct tar_archive tar; + struct tar_context tar_ctx; const char *tar_name = argv[1]; setvbuf(stdout, NULL, _IOLBF, 0); @@ -124,18 +126,22 @@ main(int argc, char **argv) push_error_context(); if (tar_name) { - ctx.tar_fd = open(tar_name, O_RDONLY); - if (ctx.tar_fd < 0) + tar_ctx.tar_fd = open(tar_name, O_RDONLY); + if (tar_ctx.tar_fd < 0) ohshite("cannot open file '%s'", tar_name); } else { - ctx.tar_fd = STDIN_FILENO; + tar_ctx.tar_fd = STDIN_FILENO; } - if (tar_extractor(&ctx, &tar_ops)) + tar.err = DPKG_ERROR_OBJECT; + tar.ctx = &tar_ctx; + tar.ops = &tar_ops; + + if (tar_extractor(&tar)) ohshite("extracting tar"); if (tar_name) - close(ctx.tar_fd); + close(tar_ctx.tar_fd); pop_error_context(ehflag_normaltidy); diff --git a/lib/dpkg/t/t-ar.c b/lib/dpkg/t/t-ar.c index 28b5e38f3..88e93872a 100644 --- a/lib/dpkg/t/t-ar.c +++ b/lib/dpkg/t/t-ar.c @@ -21,6 +21,8 @@ #include <config.h> #include <compat.h> +#include <string.h> + #include <dpkg/test.h> #include <dpkg/ar.h> @@ -29,11 +31,11 @@ test_ar_normalize_name(void) { struct dpkg_ar_hdr arh; - strncpy(arh.ar_name, "member-name/ ", sizeof(arh.ar_name)); + memccpy(arh.ar_name, "member-name/ ", '\0', sizeof(arh.ar_name)); dpkg_ar_normalize_name(&arh); test_str(arh.ar_name, ==, "member-name"); - strncpy(arh.ar_name, "member-name ", sizeof(arh.ar_name)); + memccpy(arh.ar_name, "member-name ", '\0', sizeof(arh.ar_name)); dpkg_ar_normalize_name(&arh); test_str(arh.ar_name, ==, "member-name"); } diff --git a/lib/dpkg/t/t-command.c b/lib/dpkg/t/t-command.c index b59abd4e4..099884560 100644 --- a/lib/dpkg/t/t-command.c +++ b/lib/dpkg/t/t-command.c @@ -208,44 +208,9 @@ test_command_shell(void) test_pass(ret == 0); } -static void -test_dup_file(int fd, const char *filename, int flags) -{ - int newfd; - - newfd = open(filename, flags); - dup2(newfd, fd); - close(newfd); -} - -static void -test_command_pager(void) -{ - const char *pager, *default_pager; - int origfd = dup(STDOUT_FILENO); - - /* Test stdout being a tty. */ - test_todo_block("environment might not expose controlling terminal") { - test_dup_file(STDOUT_FILENO, "/dev/tty", O_WRONLY); - setenv("PAGER", "test-pager", 1); - pager = command_get_pager(); - unsetenv("PAGER"); - default_pager = command_get_pager(); - dup2(origfd, STDOUT_FILENO); - test_str(pager, ==, "test-pager"); - test_str(default_pager, ==, DEFAULTPAGER); - } - - /* Test stdout not being a tty. */ - test_dup_file(STDOUT_FILENO, "/dev/null", O_WRONLY); - pager = command_get_pager(); - dup2(origfd, STDOUT_FILENO); - test_str(pager, ==, CAT); -} - TEST_ENTRY(test) { - test_plan(52); + test_plan(49); test_command_init(); test_command_grow_argv(); @@ -254,5 +219,4 @@ TEST_ENTRY(test) test_command_add_args(); test_command_exec(); test_command_shell(); - test_command_pager(); } diff --git a/lib/dpkg/t/t-ehandle.c b/lib/dpkg/t/t-ehandle.c index 5904bfae1..7a20887af 100644 --- a/lib/dpkg/t/t-ehandle.c +++ b/lib/dpkg/t/t-ehandle.c @@ -100,7 +100,7 @@ test_cleanup_error(void) pass = false; push_error_context_jump(&handler_jump, printer_empty, "test cleanup"); - push_cleanup(cleanup_error, ~ehflag_normaltidy, NULL, 0, 0); + push_cleanup(cleanup_error, ~ehflag_normaltidy, 0); pop_error_context(ehflag_bombout); /* We should have recovered from the cleanup handler failing, diff --git a/lib/dpkg/t/t-error.c b/lib/dpkg/t/t-error.c index 5e2f55fcd..e93459e7e 100644 --- a/lib/dpkg/t/t-error.c +++ b/lib/dpkg/t/t-error.c @@ -42,10 +42,12 @@ test_dpkg_error_put(void) test_pass(dpkg_put_errno(NULL, "void error") < 0); test_pass(dpkg_put_warn(&err, "test warning %d", 10) < 0); + test_pass(err.syserrno == 0); test_str(err.str, ==, "test warning 10"); test_warn(err); test_pass(dpkg_put_error(&err, "test error %d", 20) < 0); + test_pass(err.syserrno == 0); test_str(err.str, ==, "test error 20"); test_error(err); @@ -54,6 +56,7 @@ test_dpkg_error_put(void) test_bail("cannot allocate string"); test_pass(dpkg_put_errno(&err, "test errno %d", 30) < 0); test_str(err.str, ==, errstr_ref); + test_pass(err.syserrno == ENOENT); test_error(err); free(errstr_ref); errno = 0; @@ -64,17 +67,20 @@ test_dpkg_error_destroy(void) { struct dpkg_error err = DPKG_ERROR_INIT; - test_pass(dpkg_put_error(&err, "test destroy") < 0); + errno = ENOENT; + test_pass(dpkg_put_errno(&err, "test destroy") < 0); + test_pass(err.syserrno == ENOENT); test_pass(err.type == DPKG_MSG_ERROR); test_pass(err.str != NULL); dpkg_error_destroy(&err); test_pass(err.type == DPKG_MSG_NONE); + test_pass(err.syserrno == 0); test_pass(err.str == NULL); } TEST_ENTRY(test) { - test_plan(19); + test_plan(24); test_dpkg_error_put(); test_dpkg_error_destroy(); diff --git a/lib/dpkg/t/t-file.c b/lib/dpkg/t/t-file.c new file mode 100644 index 000000000..ca68eaefe --- /dev/null +++ b/lib/dpkg/t/t-file.c @@ -0,0 +1,96 @@ +/* + * libdpkg - Debian packaging suite library routines + * t-file.c - test file functions + * + * Copyright © 2018 Guillem Jover <guillem@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/file.h> + +#include <sys/types.h> + +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +static const char ref_data[] = + "this is a test string\n" + "within a test file\n" + "containing multiple lines\n" +; + +static void +test_file_slurp(void) +{ + struct varbuf vb = VARBUF_INIT; + struct dpkg_error err = DPKG_ERROR_INIT; + char *test_file; + char *test_dir; + int fd; + + test_pass(file_slurp("/nonexistent", &vb, &err) < 0); + test_pass(vb.used == 0); + test_pass(vb.buf == NULL); + test_pass(err.syserrno == ENOENT); + test_error(err); + varbuf_destroy(&vb); + + test_dir = test_alloc(strdup("test.XXXXXX")); + test_pass(mkdtemp(test_dir) != NULL); + test_pass(file_slurp(test_dir, &vb, &err) < 0); + test_pass(vb.used == 0); + test_pass(vb.buf == NULL); + test_pass(err.syserrno == 0); + test_error(err); + varbuf_destroy(&vb); + test_pass(rmdir(test_dir) == 0); + + test_file = test_alloc(strdup("test.XXXXXX")); + fd = mkstemp(test_file); + test_pass(fd >= 0); + + test_pass(file_slurp(test_file, &vb, &err) == 0); + test_pass(vb.used == 0); + test_pass(vb.buf == NULL); + test_pass(err.syserrno == 0); + test_pass(err.type == DPKG_MSG_NONE); + varbuf_destroy(&vb); + + test_pass(write(fd, ref_data, strlen(ref_data)) == (ssize_t)strlen(ref_data)); + test_pass(lseek(fd, 0, SEEK_SET) == 0); + + test_pass(file_slurp(test_file, &vb, &err) == 0); + test_pass(vb.used == strlen(ref_data)); + test_mem(vb.buf, ==, ref_data, min(vb.used, strlen(ref_data))); + test_pass(err.syserrno == 0); + test_pass(err.type == DPKG_MSG_NONE); + varbuf_destroy(&vb); + + test_pass(unlink(test_file) == 0); +} + +TEST_ENTRY(test) +{ + test_plan(26); + + test_file_slurp(); +} diff --git a/lib/dpkg/t/t-fsys-dir.c b/lib/dpkg/t/t-fsys-dir.c new file mode 100644 index 000000000..7dbe753d1 --- /dev/null +++ b/lib/dpkg/t/t-fsys-dir.c @@ -0,0 +1,65 @@ +/* + * libdpkg - Debian packaging suite library routines + * t-fsys.c - test filesystem handling + * + * Copyright © 2018 Guillem Jover <guillem@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 <stdlib.h> + +#include <dpkg/test.h> +#include <dpkg/fsys.h> + +static void +test_fsys_dir(void) +{ + char *dir; + + test_str(dpkg_fsys_get_dir(), ==, ""); + + dpkg_fsys_set_dir("/testdir"); + test_str(dpkg_fsys_get_dir(), ==, "/testdir"); + + dir = dpkg_fsys_get_path("testfile"); + test_str(dir, ==, "/testdir/testfile"); + free(dir); + + setenv("DPKG_ROOT", "/testenvdir", 1); + dpkg_fsys_set_dir(NULL); + test_str(dpkg_fsys_get_dir(), ==, "/testenvdir"); + + dir = dpkg_fsys_get_path("testfile"); + test_str(dir, ==, "/testenvdir/testfile"); + free(dir); + + unsetenv("DPKG_ROOT"); + dpkg_fsys_set_dir(NULL); + test_str(dpkg_fsys_get_dir(), ==, ""); + + dir = dpkg_fsys_get_path("testfile"); + test_str(dir, ==, "/testfile"); + free(dir); +} + +TEST_ENTRY(test) +{ + test_plan(7); + + test_fsys_dir(); +} diff --git a/lib/dpkg/t/t-fsys-hash.c b/lib/dpkg/t/t-fsys-hash.c new file mode 100644 index 000000000..d80dbe899 --- /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 <guillem@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 fsys_namenode *fnn; + struct fsys_hash_iter *iter; + const char *name; + + test_pass(fsys_hash_entries() == 0); + + fsys_hash_init(); + + fnn = fsys_hash_find_node("/nonexistent", FHFF_NONE); + test_pass(fnn == NULL); + test_pass(fsys_hash_entries() == 0); + + name = "/test/path/aa"; + fnn = fsys_hash_find_node(name, FHFF_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 = fsys_hash_find_node("//./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 = fsys_hash_find_node("/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 = fsys_hash_iter_new(); + while ((fnn = fsys_hash_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 fsys_namenode"); + } + fsys_hash_iter_free(iter); + + fsys_hash_init(); + test_pass(fsys_hash_entries() == 3); + fnn = fsys_hash_find_node("/test/path/aa", FHFF_NONE); + test_pass(fnn != NULL); + fnn = fsys_hash_find_node("/test/path/bb", FHFF_NONE); + test_pass(fnn != NULL); + fnn = fsys_hash_find_node("/test/path/cc", FHFF_NONE); + test_pass(fnn != NULL); + test_pass(fsys_hash_entries() == 3); + + fsys_hash_reset(); + test_pass(fsys_hash_entries() == 0); + fnn = fsys_hash_find_node("/test/path/aa", FHFF_NONE); + test_pass(fnn == NULL); + fnn = fsys_hash_find_node("/test/path/bb", FHFF_NONE); + test_pass(fnn == NULL); + fnn = fsys_hash_find_node("/test/path/cc", FHFF_NONE); + test_pass(fnn == NULL); + test_pass(fsys_hash_entries() == 0); +} + +TEST_ENTRY(test) +{ + test_plan(35); + + test_fsys_nodes(); +} diff --git a/lib/dpkg/t/t-headers-cpp.cc b/lib/dpkg/t/t-headers-cpp.cc new file mode 100644 index 000000000..b5becf9ae --- /dev/null +++ b/lib/dpkg/t/t-headers-cpp.cc @@ -0,0 +1,82 @@ +/* + * libdpkg - Debian packaging suite library routines + * t-headers-cpp.cc - test C++ inclusion of headers + * + * Copyright © 2018 Guillem Jover <guillem@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 <cstdbool> + +#include <dpkg/ar.h> +#include <dpkg/arch.h> +#include <dpkg/atomic-file.h> +#include <dpkg/buffer.h> +#include <dpkg/c-ctype.h> +#include <dpkg/color.h> +#include <dpkg/command.h> +#include <dpkg/compress.h> +#include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> +#include <dpkg/deb-version.h> +#include <dpkg/debug.h> +#include <dpkg/dir.h> +#include <dpkg/dlist.h> +#include <dpkg/dpkg-db.h> +#include <dpkg/dpkg.h> +#include <dpkg/ehandle.h> +#include <dpkg/error.h> +#include <dpkg/fdio.h> +#include <dpkg/file.h> +#include <dpkg/fsys.h> +#include <dpkg/glob.h> +#include <dpkg/i18n.h> +#include <dpkg/macros.h> +#include <dpkg/namevalue.h> +#include <dpkg/options.h> +#include <dpkg/pager.h> +#include <dpkg/parsedump.h> +#include <dpkg/path.h> +#include <dpkg/pkg-array.h> +#include <dpkg/pkg-files.h> +#include <dpkg/pkg-format.h> +#include <dpkg/pkg-list.h> +#include <dpkg/pkg-queue.h> +#include <dpkg/pkg-show.h> +#include <dpkg/pkg-spec.h> +#include <dpkg/pkg.h> +#include <dpkg/progname.h> +#include <dpkg/program.h> +#include <dpkg/progress.h> +#include <dpkg/report.h> +#include <dpkg/string.h> +#include <dpkg/subproc.h> +#include <dpkg/tarfn.h> +#include <dpkg/test.h> +#include <dpkg/treewalk.h> +#include <dpkg/trigdeferred.h> +#include <dpkg/triglib.h> +#include <dpkg/varbuf.h> +#include <dpkg/version.h> + +TEST_ENTRY(test) +{ + test_plan(1); + + test_pass(true); +} diff --git a/lib/dpkg/t/t-mod-db.c b/lib/dpkg/t/t-mod-db.c index 680dab5e5..c40d8e8ae 100644 --- a/lib/dpkg/t/t-mod-db.c +++ b/lib/dpkg/t/t-mod-db.c @@ -1,6 +1,6 @@ /* * libdpkg - Debian packaging suite library routines - * t-db.c - test database implementation + * t-mod-db.c - test database implementation * * Copyright © 2011 Guillem Jover <guillem@debian.org> * diff --git a/lib/dpkg/t/t-namevalue.c b/lib/dpkg/t/t-namevalue.c new file mode 100644 index 000000000..c8647662e --- /dev/null +++ b/lib/dpkg/t/t-namevalue.c @@ -0,0 +1,48 @@ +/* + * libdpkg - Debian packaging suite library routines + * t-namevalue.c - test name/value implementation + * + * Copyright © 2018 Guillem Jover <guillem@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/namevalue.h> +#include <dpkg/dpkg-db.h> + +static void +test_namevalue(void) +{ + const struct namevalue *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); + + test_namevalue(); +} diff --git a/lib/dpkg/t/t-pager.c b/lib/dpkg/t/t-pager.c new file mode 100644 index 000000000..2481e8065 --- /dev/null +++ b/lib/dpkg/t/t-pager.c @@ -0,0 +1,75 @@ +/* + * libdpkg - Debian packaging suite library routines + * t-pager.c - test pager implementation + * + * Copyright © 2010-2012 Guillem Jover <guillem@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 <sys/types.h> +#include <sys/stat.h> + +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> + +#include <dpkg/test.h> +#include <dpkg/pager.h> +#include <dpkg/dpkg.h> + +static void +test_dup_file(int fd, const char *filename, int flags) +{ + int newfd; + + newfd = open(filename, flags); + dup2(newfd, fd); + close(newfd); +} + +static void +test_pager_get_exec(void) +{ + const char *pager, *default_pager; + int origfd = dup(STDOUT_FILENO); + + /* Test stdout being a tty. */ + test_todo_block("environment might not expose controlling terminal") { + test_dup_file(STDOUT_FILENO, "/dev/tty", O_WRONLY); + setenv("PAGER", "test-pager", 1); + pager = pager_get_exec(); + unsetenv("PAGER"); + default_pager = pager_get_exec(); + dup2(origfd, STDOUT_FILENO); + test_str(pager, ==, "test-pager"); + test_str(default_pager, ==, DEFAULTPAGER); + } + + /* Test stdout not being a tty. */ + test_dup_file(STDOUT_FILENO, "/dev/null", O_WRONLY); + pager = pager_get_exec(); + dup2(origfd, STDOUT_FILENO); + test_str(pager, ==, CAT); +} + +TEST_ENTRY(test) +{ + test_plan(3); + + test_pager_get_exec(); +} diff --git a/lib/dpkg/t/t-pkg-hash.c b/lib/dpkg/t/t-pkg-hash.c new file mode 100644 index 000000000..72185a2f1 --- /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 <guillem@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 pkg_hash_iter *iter; + int pkginstance; + + test_pass(pkg_hash_count_set() == 0); + test_pass(pkg_hash_count_pkg() == 0); + + set = pkg_hash_find_set("pkg-aa"); + test_pass(set != NULL); + test_str(set->name, ==, "pkg-aa"); + test_pass(pkg_hash_count_set() == 1); + test_pass(pkg_hash_count_pkg() == 1); + + set = pkg_hash_find_set("pkg-aa"); + test_pass(set != NULL); + test_str(set->name, ==, "pkg-aa"); + test_pass(pkg_hash_count_set() == 1); + test_pass(pkg_hash_count_pkg() == 1); + + set = pkg_hash_find_set("Pkg-AA"); + test_pass(set != NULL); + test_str(set->name, ==, "pkg-aa"); + test_pass(pkg_hash_count_set() == 1); + test_pass(pkg_hash_count_pkg() == 1); + + set = pkg_hash_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_hash_count_set() == 2); + test_pass(pkg_hash_count_pkg() == 2); + + set = pkg_hash_find_set("pkg-cc"); + test_pass(set != NULL); + test_str(set->name, ==, "pkg-cc"); + test_pass(pkg_hash_count_set() == 3); + test_pass(pkg_hash_count_pkg() == 3); + + arch = dpkg_arch_find("arch-xx"); + pkg = pkg_hash_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_hash_count_set() == 3); + test_pass(pkg_hash_count_pkg() == 3); + + arch = dpkg_arch_find("arch-yy"); + pkg = pkg_hash_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_hash_count_set() == 3); + test_pass(pkg_hash_count_pkg() == 4); + + arch = dpkg_arch_find("arch-zz"); + pkg = pkg_hash_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_hash_count_set() == 3); + test_pass(pkg_hash_count_pkg() == 5); + + arch = dpkg_arch_find("arch-xx"); + pkg = pkg_hash_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_hash_count_set() == 3); + test_pass(pkg_hash_count_pkg() == 5); + + set = pkg_hash_find_set("pkg-aa"); + test_str(set->name, ==, "pkg-aa"); + pkg = pkg_hash_get_singleton(set); + test_pass(pkg == NULL); + test_pass(pkg_hash_count_set() == 3); + test_pass(pkg_hash_count_pkg() == 5); + + pkg = pkg_hash_find_singleton("pkg-bb"); + test_pass(pkg != NULL); + test_str(pkg->set->name, ==, "pkg-bb"); + test_pass(pkg_hash_count_set() == 3); + test_pass(pkg_hash_count_pkg() == 5); + + pkg = pkg_hash_find_singleton("pkg-cc"); + test_pass(pkg != NULL); + test_str(pkg->set->name, ==, "pkg-cc"); + test_pass(pkg_hash_count_set() == 3); + test_pass(pkg_hash_count_pkg() == 5); + + iter = pkg_hash_iter_new(); + while ((set = pkg_hash_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 fsys_namenode"); + } + pkg_hash_iter_free(iter); + + pkginstance = 0; + iter = pkg_hash_iter_new(); + while ((pkg = pkg_hash_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 fsys_namenode"); + } + } + pkg_hash_iter_free(iter); + + pkg_hash_reset(); + test_pass(pkg_hash_count_set() == 0); + test_pass(pkg_hash_count_pkg() == 0); +} + +TEST_ENTRY(test) +{ + test_plan(71); + + test_pkg_hash(); +} diff --git a/lib/dpkg/t/t-pkg-show.c b/lib/dpkg/t/t-pkg-show.c new file mode 100644 index 000000000..0f6ece061 --- /dev/null +++ b/lib/dpkg/t/t-pkg-show.c @@ -0,0 +1,61 @@ +/* + * libdpkg - Debian packaging suite library routines + * t-pkg-show.c - test pkg-show implementation + * + * Copyright © 2018 Guillem Jover <guillem@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-db.h> +#include <dpkg/arch.h> + +static void +test_pkg_show_name(void) +{ + struct dpkg_arch *arch; + struct pkginfo *pkg; + const char *pkgname; + + arch = dpkg_arch_find("arch"); + test_pass(arch); + + pkg = pkg_hash_find_pkg("test", arch); + test_pass(pkg); + test_str(pkg->set->name, ==, "test"); + test_pass(pkg->installed.arch->type == DPKG_ARCH_UNKNOWN); + + pkgname = pkg_name(pkg, pnaw_never); + test_pass(pkgname); + test_str(pkgname, ==, "test"); + + pkgname = pkg_name(pkg, pnaw_nonambig); + test_pass(pkgname); + test_str(pkgname, ==, "test:arch"); + + pkgname = pkg_name(pkg, pnaw_always); + test_pass(pkgname); + test_str(pkgname, ==, "test:arch"); +} + +TEST_ENTRY(test) +{ + test_plan(10); + + test_pkg_show_name(); +} diff --git a/lib/dpkg/t/t-string.c b/lib/dpkg/t/t-string.c index 038de84b0..fc2819b55 100644 --- a/lib/dpkg/t/t-string.c +++ b/lib/dpkg/t/t-string.c @@ -77,6 +77,37 @@ test_str_fnv_hash(void) } static void +test_str_concat(void) +{ + char buf[1024], *str; + + memset(buf, 0, sizeof(buf)); + str = str_concat(buf, NULL); + test_pass(str == buf); + test_str(buf, ==, ""); + + memset(buf, 0, sizeof(buf)); + str = str_concat(buf, "aaa", NULL); + test_str(buf, ==, "aaa"); + test_pass(str == buf + 3); + + memset(buf, 0, sizeof(buf)); + str = str_concat(buf, "zzzz", "yy", "xxxx", NULL); + test_str(buf, ==, "zzzzyyxxxx"); + test_pass(str == buf + 10); + + memset(buf, 0, sizeof(buf)); + str = str_concat(buf, "1234", "", "5678", NULL); + test_str(buf, ==, "12345678"); + test_pass(str == buf + 8); + + memset(buf, ' ', sizeof(buf)); + str = str_concat(buf, "eol", NULL, "bom", NULL); + test_str(buf, ==, "eol"); + test_pass(str == buf + 3); +} + +static void test_str_fmt(void) { char *str; @@ -119,6 +150,8 @@ test_str_escape_fmt(void) memset(buf, 'a', sizeof(buf)); q = str_escape_fmt(buf, NULL, 0); test_mem(buf, ==, "aaaa", 4); + test_pass(buf == q); + test_pass(strnlen(buf, sizeof(buf)) == sizeof(buf)); memset(buf, 'a', sizeof(buf)); q = str_escape_fmt(buf, "b", 1); @@ -197,11 +230,12 @@ test_str_strip_quotes(void) TEST_ENTRY(test) { - test_plan(50); + test_plan(62); test_str_is_set(); test_str_match_end(); test_str_fnv_hash(); + test_str_concat(); test_str_fmt(); test_str_escape_fmt(); test_str_quote_meta(); diff --git a/lib/dpkg/t/t-tar.c b/lib/dpkg/t/t-tar.c index 8417ed306..6fa217de5 100644 --- a/lib/dpkg/t/t-tar.c +++ b/lib/dpkg/t/t-tar.c @@ -72,22 +72,22 @@ test_tar_atol8(void) errno = 0; u = tar_atoul(" 11111aaa ", 12, UINTMAX_MAX); test_pass(u == 0); - test_pass(errno == EINVAL); + test_pass(errno == ERANGE); errno = 0; u = tar_atoul(" 8 ", 12, UINTMAX_MAX); test_pass(u == 0); - test_pass(errno == EINVAL); + test_pass(errno == ERANGE); errno = 0; u = tar_atoul(" 18 ", 12, UINTMAX_MAX); test_pass(u == 0); - test_pass(errno == EINVAL); + test_pass(errno == ERANGE); errno = 0; u = tar_atoul(" aa ", 12, UINTMAX_MAX); test_pass(u == 0); - test_pass(errno == EINVAL); + test_pass(errno == ERANGE); } static void diff --git a/lib/dpkg/t/t-tarextract.t b/lib/dpkg/t/t-tarextract.t index 25916bb8d..5fb9afa09 100755 --- a/lib/dpkg/t/t-tarextract.t +++ b/lib/dpkg/t/t-tarextract.t @@ -119,7 +119,7 @@ TAR make_path($tmpdir); - my $cwd = cwd(); + my $cwd = getcwd(); # Check generated tarballs. foreach my $type (qw(v7 ustar oldgnu gnu)) { diff --git a/lib/dpkg/t/t-test.c b/lib/dpkg/t/t-test.c index 62b35ce2f..48ce8726b 100644 --- a/lib/dpkg/t/t-test.c +++ b/lib/dpkg/t/t-test.c @@ -25,7 +25,7 @@ TEST_ENTRY(test) { - test_plan(20); + test_plan(22); test_pass(1); test_fail(0); @@ -58,4 +58,9 @@ TEST_ENTRY(test) test_mem("abcd", ==, "abcd", 5); test_mem("ababcd", ==, "ababff", 4); test_mem("ababcd", !=, "ababff", 6); + + setenv("srcdir", "aaa", 1); + setenv("builddir", "bbb", 1); + test_str(test_get_srcdir(), ==, "aaa"); + test_str(test_get_builddir(), ==, "bbb"); } diff --git a/lib/dpkg/t/t-treewalk.t b/lib/dpkg/t/t-treewalk.t index dcde7901e..6f379c81b 100755 --- a/lib/dpkg/t/t-treewalk.t +++ b/lib/dpkg/t/t-treewalk.t @@ -45,7 +45,7 @@ sub make_file { # Populate the tree hierarchy. sub make_tree { my ($dirtree) = @_; - my $cwd = cwd(); + my $cwd = getcwd(); make_path($dirtree); chdir $dirtree; diff --git a/lib/dpkg/t/t-varbuf.c b/lib/dpkg/t/t-varbuf.c index 3fb4444b2..8df733b9b 100644 --- a/lib/dpkg/t/t-varbuf.c +++ b/lib/dpkg/t/t-varbuf.c @@ -1,6 +1,6 @@ /* * libdpkg - Debian packaging suite library routines - * t-verbuf.c - test varbuf implementation + * t-varbuf.c - test varbuf implementation * * Copyright © 2009-2011, 2013-2015 Guillem Jover <guillem@debian.org> * @@ -60,6 +60,26 @@ test_varbuf_prealloc(void) } static void +test_varbuf_new(void) +{ + struct varbuf *vb; + + vb = varbuf_new(0); + test_pass(vb != NULL); + test_pass(vb->used == 0); + test_pass(vb->size == 0); + test_pass(vb->buf == NULL); + varbuf_free(vb); + + vb = varbuf_new(10); + test_pass(vb != NULL); + test_pass(vb->used == 0); + test_pass(vb->size >= 10); + test_pass(vb->buf != NULL); + varbuf_free(vb); +} + +static void test_varbuf_grow(void) { struct varbuf vb; @@ -350,10 +370,11 @@ test_varbuf_detach(void) TEST_ENTRY(test) { - test_plan(120); + test_plan(128); test_varbuf_init(); test_varbuf_prealloc(); + test_varbuf_new(); test_varbuf_grow(); test_varbuf_trunc(); test_varbuf_add_buf(); |