Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add test cases for pkg_add_dir_to_del
Baptiste Daroussin committed 11 years ago
commit 156540e1350aac731b08498378f5ba6a1860e221
parent 5f335dd
5 files changed +79 -2
modified libpkg/pkg_delete.c
@@ -107,7 +107,7 @@ pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags)
	return (pkgdb_unregister_pkg(db, id));
}

-
static void
+
void
pkg_add_dir_to_del(struct pkg *pkg, const char *file, const char *dir)
{
	char path[MAXPATHLEN];
modified libpkg/private/pkg.h
@@ -539,5 +539,6 @@ int pkg_add_upgrade(struct pkgdb *db, const char *path, unsigned flags,
void pkg_delete_dir(struct pkg *pkg, struct pkg_dir *dir);
void pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force);
int pkg_open_root_fd(struct pkg *pkg);
+
void pkg_add_dir_to_del(struct pkg *pkg, const char *file, const char *dir);

#endif
modified tests/Kyuafile
@@ -5,5 +5,6 @@ test_suite("pkg")
atf_test_program{name='pkg_validation'}
atf_test_program{name='pkg_printf'}
atf_test_program{name='plist'}
+
atf_test_program{name='pkg_add_dir_to_del'}

include('frontend/Kyuafile')
modified tests/Makefile.am
@@ -34,6 +34,10 @@ plist_SOURCES= lib/plist.c
plist_CFLAGS=		$(PRIVATE_INCS)
plist_LDADD=		$(GENERIC_LDADD)

+
pkg_add_dir_to_del_SOURCES=	lib/pkg_add_dir_to_del.c
+
pkg_add_dir_to_del_CFLAGS=	$(PRIVATE_INCS)
+
pkg_add_dir_to_del_LDADD=	$(GENERIC_LDADD)
+

EXTRA_DIST=	frontend/png.uclin \
		frontend/sqlite3.uclin \
		Kyuafile \
@@ -45,7 +49,10 @@ EXTRA_DIST= frontend/png.uclin \
		frontend/test_environment.shin

TESTS =
-
tests_programs=	pkg_printf pkg_validation plist
+
tests_programs=	pkg_printf \
+
		pkg_validation \
+
		plist \
+
		pkg_add_dir_to_del
EXTRA_PROGRAMS=	$(tests_programs)
check_PROGRAMS=	$(tests_programs)
check_SCRIPTS=	frontend/pkg.sh \
added tests/lib/pkg_add_dir_to_del.c
@@ -0,0 +1,68 @@
+
/*-
+
 * Copyright (c) 2013 Baptiste Daroussin <bapt@FreeBSD.org>
+
 * All rights reserved.
+
 *~
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions
+
 * are met:
+
 * 1. Redistributions of source code must retain the above copyright
+
 *    notice, this list of conditions and the following disclaimer
+
 *    in this position and unchanged.
+
 * 2. Redistributions in binary form must reproduce the above copyright
+
 *    notice, this list of conditions and the following disclaimer in the
+
 *    documentation and/or other materials provided with the distribution.
+
 *~
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
#include <atf-c.h>
+
#include <pkg.h>
+
#include <private/pkg.h>
+

+
ATF_TC(pkg_add_dir_to_del);
+

+
ATF_TC_HEAD(pkg_add_dir_to_del, tc)
+
{
+
	atf_tc_set_md_var(tc, "descr",
+
	    "pkg_add_dir_to_del()");
+
}
+

+
ATF_TC_BODY(pkg_add_dir_to_del, tc)
+
{
+
	struct pkg *p = NULL;
+

+
	ATF_REQUIRE_EQ(EPKG_OK, pkg_new(&p, PKG_FILE));
+
	pkg_set(p, PKG_PREFIX, "/usr/local");
+

+
	ATF_REQUIRE(p->dir_to_del == NULL);
+

+
	pkg_add_dir_to_del(p, "/usr/local/plop/bla", NULL);
+

+
	ATF_REQUIRE_STREQ(p->dir_to_del[0], "/usr/local/plop/");
+

+
	pkg_add_dir_to_del(p, NULL, "/usr/local/plop");
+

+
	ATF_REQUIRE(p->dir_to_del_len == 1);
+

+
	pkg_add_dir_to_del(p, NULL, "/var/run/yeah");
+

+
	ATF_REQUIRE_STREQ(p->dir_to_del[1], "/var/run/yeah/");
+

+
	pkg_free(p);
+
}
+

+
ATF_TP_ADD_TCS(tp)
+
{
+
	ATF_TP_ADD_TC(tp, pkg_add_dir_to_del); 
+

+
	return (atf_no_error());
+
}