socsvn commit: r256780 - soc2013/mattbw/backend

mattbw at FreeBSD.org mattbw at FreeBSD.org
Sat Aug 31 18:15:05 UTC 2013


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 <bsd.lib.mk>

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 <mattbw at FreeBSD.org>
+ *
+ * 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 <atf-c.h>
+#include <string.h>		/* ATF_CHECK_STREQ */
+#include <glib.h>		/* 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();
+}


More information about the svn-soc-all mailing list