From owner-svn-soc-all@FreeBSD.ORG Sun Sep 1 22:45:55 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7842CBBB for ; Sun, 1 Sep 2013 22:45:55 +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 63F402A08 for ; Sun, 1 Sep 2013 22:45:55 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r81MjtIq010025 for ; Sun, 1 Sep 2013 22:45:55 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r81MjtgC010021 for svn-soc-all@FreeBSD.org; Sun, 1 Sep 2013 22:45:55 GMT (envelope-from mattbw@FreeBSD.org) Date: Sun, 1 Sep 2013 22:45:55 GMT Message-Id: <201309012245.r81MjtgC010021@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: r256813 - 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: Sun, 01 Sep 2013 22:45:55 -0000 Author: mattbw Date: Sun Sep 1 22:45:54 2013 New Revision: 256813 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256813 Log: Actually commit namevers tests. In addition, the C standard has dropped back to C99, mainly so that this can be built with FreeBSD gcc again. Debug flags are currently switched on; this will probably change. Added: soc2013/mattbw/backend/namever_test.c Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/namever.c Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Sun Sep 1 21:44:43 2013 (r256812) +++ soc2013/mattbw/backend/Makefile Sun Sep 1 22:45:54 2013 (r256813) @@ -91,9 +91,9 @@ #.endif CFLAGS+= `pkg-config --cflags ${PKGS}` -CFLAGS+= -DPK_COMPILATION -LDFLAGS+= `pkg-config --libs ${PKGS}` -CSTD?= c11 +CFLAGS+= -DPK_COMPILATION -g +LDFLAGS+= `pkg-config --libs ${PKGS}` -g +CSTD?= c99 group_map.c: groups group_map.awk sort groups | awk -f group_map.awk > group_map.c Modified: soc2013/mattbw/backend/namever.c ============================================================================== --- soc2013/mattbw/backend/namever.c Sun Sep 1 21:44:43 2013 (r256812) +++ soc2013/mattbw/backend/namever.c Sun Sep 1 22:45:54 2013 (r256813) @@ -123,7 +123,7 @@ if (*namevers_p != NULL) { for (i = 0; i < count; i++) { - free(*namevers_p[i]); + free((*namevers_p)[i]); } free(*namevers_p); *namevers_p = NULL; Added: soc2013/mattbw/backend/namever_test.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/namever_test.c Sun Sep 1 22:45:54 2013 (r256813) @@ -0,0 +1,162 @@ +/*- + * 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 "namever.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(test_namever_from_name_and_version); +ATF_TC_HEAD(test_namever_from_name_and_version, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Test 'namever_from_name_and_version' on a valid pair."); +} +ATF_TC_BODY(test_namever_from_name_and_version, tc) +{ + char *namever; + + namever = namever_from_name_and_version("foo", "1.2.3"); + ATF_CHECK_STREQ(namever, "foo-1.2.3"); + free(namever); +} + +ATF_TC(test_namever_from_package_id); +ATF_TC_HEAD(test_namever_from_package_id, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Test 'namever_from_package_id' on a valid PackageID."); +} +ATF_TC_BODY(test_namever_from_package_id, tc) +{ + char *namever; + + namever = namever_from_package_id("foo;1.2.3;freebsd:10:x86:32;lohac"); + ATF_CHECK_STREQ(namever, "foo-1.2.3"); + free(namever); +} + +ATF_TC(test_namever_array_from_package_ids); +ATF_TC_HEAD(test_namever_array_from_package_ids, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test 'namever_array_from_package_ids' on valid PackageIDs."); +} +ATF_TC_BODY(test_namever_array_from_package_ids, tc) +{ + char *package_ids[9]; + char **namevers; + unsigned int i; + + /* Full PackageIDs */ + package_ids[0] = strdup("dave;1.2.3;freebsd:10:x86:32;lohac"); + package_ids[1] = strdup("rose;4.5.6;freebsd:10:x86:64;lolar"); + package_ids[2] = strdup("john;7.8;freebsd:9:x86:32;lowas"); + package_ids[3] = strdup("jade;9.0a;freebsd:9:x86:64;lofaf"); + + /* Non-canonical/non-remote PackageIDs should still work */ + package_ids[4] = strdup("dirk;1;freebsd:10:x86:32;installed"); + package_ids[5] = strdup("roxy;wizardy-herbert;;"); + package_ids[6] = strdup("jane;rolling;freebsd:8:x86:32;"); + package_ids[7] = strdup("jake;999;;lomax"); + + /* And one for luck */ + package_ids[8] = strdup("nepeta;3.3;dragonflybsd:3.4:x86:32;lolcat"); + + namevers = namever_array_from_package_ids(package_ids, 9); + + ATF_REQUIRE(namevers != NULL); + + ATF_CHECK_STREQ(namevers[0], "dave-1.2.3"); + ATF_CHECK_STREQ(namevers[1], "rose-4.5.6"); + ATF_CHECK_STREQ(namevers[2], "john-7.8"); + ATF_CHECK_STREQ(namevers[3], "jade-9.0a"); + ATF_CHECK_STREQ(namevers[4], "dirk-1"); + ATF_CHECK_STREQ(namevers[5], "roxy-wizardy-herbert"); + ATF_CHECK_STREQ(namevers[6], "jane-rolling"); + ATF_CHECK_STREQ(namevers[7], "jake-999"); + ATF_CHECK_STREQ(namevers[8], "nepeta-3.3"); + + namever_array_free(&namevers, 9); + ATF_CHECK_EQ(namevers, NULL); + + for (i = 0; i < 4; i++) { + free(package_ids[i]); + } +} + +ATF_TC(test_namever_from_package); +ATF_TC_HEAD(test_namever_from_package, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Test 'namever_from_package_id' on a valid package."); +} +ATF_TC_BODY(test_namever_from_package, tc) +{ + char *namever; + struct pkg *package; + + package = gen_pkg(PKG_FILE); + namever = namever_from_package(package); + ATF_CHECK_STREQ(namever, "pkg-1.1.4"); + pkg_free(package); + free(namever); +} + +/* + * TEST PACK + */ + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, test_namever_from_name_and_version); + ATF_TP_ADD_TC(tp, test_namever_from_package_id); + ATF_TP_ADD_TC(tp, test_namever_array_from_package_ids); + ATF_TP_ADD_TC(tp, test_namever_from_package); + + return atf_no_error(); +}