From owner-svn-soc-all@FreeBSD.ORG Sat Aug 31 18:15:05 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id F3E25528 for ; Sat, 31 Aug 2013 18:15:04 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D1CB52E13 for ; Sat, 31 Aug 2013 18:15:04 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7VIF4pO002626 for ; Sat, 31 Aug 2013 18:15:04 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r7VIF4Rc002614 for svn-soc-all@FreeBSD.org; Sat, 31 Aug 2013 18:15:04 GMT (envelope-from mattbw@FreeBSD.org) Date: Sat, 31 Aug 2013 18:15:04 GMT Message-Id: <201308311815.r7VIF4Rc002614@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256780 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Aug 2013 18:15:05 -0000 Author: mattbw Date: Sat Aug 31 18:15:04 2013 New Revision: 256780 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256780 Log: Add tests for pkg_to_id. These mainly just check to see if the PackageID reflects a valid package's state (file/installed/local) and that the package repo line is pushed through undisturbed for remote packages. Added: soc2013/mattbw/backend/Atffile soc2013/mattbw/backend/pkgutils_test.c Modified: soc2013/mattbw/backend/Makefile Added: soc2013/mattbw/backend/Atffile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/Atffile Sat Aug 31 18:15:04 2013 (r256780) @@ -0,0 +1,5 @@ +Content-Type: application/X-atf-atffile; version="1" + +prop: test-suite = "main" + +tp: pkgutils_test Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Sat Aug 31 17:38:49 2013 (r256779) +++ soc2013/mattbw/backend/Makefile Sat Aug 31 18:15:04 2013 (r256780) @@ -71,6 +71,7 @@ # ATF test flags TESTPROGS= \ + pkgutils_test \ query/id_test \ query/check_test \ @@ -111,5 +112,11 @@ query/check_test.o: query/check_test.c ${CC} ${CFLAGS} ${TESTCFLAGS} -o ${.TARGET} -c ${.ALLSRC} +pkgutils_test: pkgutils_test.o pkgutils.o namever.o + ${CC} ${LDFLAGS} ${TESTLDFLAGS} -o ${.TARGET} ${.ALLSRC} ${LIBS} ${TESTLIBS} + +pkgutils_test.o: pkgutils_test.c + ${CC} ${CFLAGS} ${TESTCFLAGS} -o ${.TARGET} -c ${.ALLSRC} + .include Added: soc2013/mattbw/backend/pkgutils_test.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/pkgutils_test.c Sat Aug 31 18:15:04 2013 (r256780) @@ -0,0 +1,128 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#include +#include /* ATF_CHECK_STREQ */ +#include /* gchar, g_free */ +#include "pkg.h" /* pkg... */ + +#include "pkgutils.h" /* pkgutils_... */ + +/* ATF/kyua tests for 'pkgutils.c'. */ + +static struct pkg *gen_pkg(pkg_t type); + +static struct pkg * +gen_pkg(pkg_t type) +{ + struct pkg *pkg; + int pkg_new_result; + + pkg = NULL; + pkg_new_result = pkg_new(&pkg, type); + + ATF_REQUIRE_EQ(pkg_new_result, EPKG_OK); + + pkg_set(pkg, + PKG_NAME, "pkg", + PKG_VERSION, "1.1.4", + PKG_ARCH, "freebsd:10:x86:32", + PKG_REPONAME, "packagesite"); + + return pkg; +} + +ATF_TC(pkg_to_id_valid_local); +ATF_TC_HEAD(pkg_to_id_valid_local, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Test 'pkgutils_pkg_to_id' on a local (file) package."); +} +ATF_TC_BODY(pkg_to_id_valid_local, tc) +{ + struct pkg *pkg; + gchar *package_id; + + pkg = gen_pkg(PKG_FILE); + ATF_REQUIRE(pkg != NULL); + + package_id = pkgutils_pkg_to_id(pkg); + ATF_CHECK_STREQ(package_id, "pkg;1.1.4;freebsd:10:x86:32;local"); + + pkg_free(pkg); + g_free(package_id); +} + +ATF_TC(pkg_to_id_valid_installed); +ATF_TC_HEAD(pkg_to_id_valid_installed, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Test 'pkgutils_pkg_to_id' on an installed package."); +} +ATF_TC_BODY(pkg_to_id_valid_installed, tc) +{ + struct pkg *pkg; + gchar *package_id; + + pkg = gen_pkg(PKG_INSTALLED); + ATF_REQUIRE(pkg != NULL); + + package_id = pkgutils_pkg_to_id(pkg); + ATF_CHECK_STREQ(package_id, "pkg;1.1.4;freebsd:10:x86:32;installed"); + + pkg_free(pkg); + g_free(package_id); +} + +ATF_TC(pkg_to_id_valid_remote); +ATF_TC_HEAD(pkg_to_id_valid_remote, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Test 'pkgutils_pkg_to_id' on a remote package."); +} +ATF_TC_BODY(pkg_to_id_valid_remote, tc) +{ + struct pkg *pkg; + gchar *package_id; + + pkg = gen_pkg(PKG_REMOTE); + ATF_REQUIRE(pkg != NULL); + + package_id = pkgutils_pkg_to_id(pkg); + ATF_CHECK_STREQ(package_id, "pkg;1.1.4;freebsd:10:x86:32;packagesite"); + + pkg_free(pkg); + g_free(package_id); +} + +/* + * TEST PACK + */ + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, pkg_to_id_valid_local); + ATF_TP_ADD_TC(tp, pkg_to_id_valid_installed); + ATF_TP_ADD_TC(tp, pkg_to_id_valid_remote); + + return atf_no_error(); +}