socsvn commit: r256828 - soc2013/mattbw/backend
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Mon Sep 2 09:14:04 UTC 2013
Author: mattbw
Date: Mon Sep 2 09:14:03 2013
New Revision: 256828
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256828
Log:
Factor out gen_pkg in tests.
This now lies in a new file, "testutils.c", so it can be shared amongst all
unit tests.
Added:
soc2013/mattbw/backend/testutils.c
soc2013/mattbw/backend/testutils.h
Modified:
soc2013/mattbw/backend/Makefile
soc2013/mattbw/backend/namever.h
soc2013/mattbw/backend/namever_test.c
soc2013/mattbw/backend/pkgutils_test.c
Modified: soc2013/mattbw/backend/Makefile
==============================================================================
--- soc2013/mattbw/backend/Makefile Mon Sep 2 08:51:50 2013 (r256827)
+++ soc2013/mattbw/backend/Makefile Mon Sep 2 09:14:03 2013 (r256828)
@@ -101,28 +101,31 @@
tests: ${TESTPROGS}
# TODO: Find a more BSD way of doing this
-query/id_test: query/id_test.o query/id.o namever.o
+query/id_test: query/id_test.o query/id.o namever.o testutils.o
${CC} ${LDFLAGS} ${TESTLDFLAGS} -o ${.TARGET} ${.ALLSRC} ${LIBS} ${TESTLIBS}
query/id_test.o: query/id_test.c
${CC} ${CFLAGS} ${TESTCFLAGS} -o ${.TARGET} -c ${.ALLSRC}
-query/check_test: query/check_test.o query/check.o query/id.o query/packages.o query/find.o namever.o
+query/check_test: query/check_test.o query/check.o query/id.o query/packages.o query/find.o namever.o testutils.o
${CC} ${LDFLAGS} ${TESTLDFLAGS} -o ${.TARGET} ${.ALLSRC} ${LIBS} ${TESTLIBS}
query/check_test.o: query/check_test.c
${CC} ${CFLAGS} ${TESTCFLAGS} -o ${.TARGET} -c ${.ALLSRC}
-pkgutils_test: pkgutils_test.o pkgutils.o namever.o
+pkgutils_test: pkgutils_test.o pkgutils.o namever.o testutils.o
${CC} ${LDFLAGS} ${TESTLDFLAGS} -o ${.TARGET} ${.ALLSRC} ${LIBS} ${TESTLIBS}
pkgutils_test.o: pkgutils_test.c
${CC} ${CFLAGS} ${TESTCFLAGS} -o ${.TARGET} -c ${.ALLSRC}
-namever_test: namever_test.o namever.o
+namever_test: namever_test.o namever.o testutils.o
${CC} ${LDFLAGS} ${TESTLDFLAGS} -o ${.TARGET} ${.ALLSRC} ${LIBS} ${TESTLIBS}
namever_test.o: namever_test.c
${CC} ${CFLAGS} ${TESTCFLAGS} -o ${.TARGET} -c ${.ALLSRC}
+testutils.o: testutils.c
+ ${CC} ${CFLAGS} ${TESTCFLAGS} -o ${.TARGET} -c ${.ALLSRC}
+
.include <bsd.lib.mk>
Modified: soc2013/mattbw/backend/namever.h
==============================================================================
--- soc2013/mattbw/backend/namever.h Mon Sep 2 08:51:50 2013 (r256827)
+++ soc2013/mattbw/backend/namever.h Mon Sep 2 09:14:03 2013 (r256828)
@@ -29,4 +29,5 @@
char *namever_from_package_id(const gchar *package_id);
char **namever_array_from_package_ids(gchar **package_ids, guint count);
void namever_array_free(char ***namevers_p, guint count);
+
#endif /* !_PKGNG_BACKEND_NAMEVER_H_ */
Modified: soc2013/mattbw/backend/namever_test.c
==============================================================================
--- soc2013/mattbw/backend/namever_test.c Mon Sep 2 08:51:50 2013 (r256827)
+++ soc2013/mattbw/backend/namever_test.c Mon Sep 2 09:14:03 2013 (r256828)
@@ -22,31 +22,10 @@
#include <glib.h> /* gchar, g_free */
#include "namever.h" /* pkgutils_... */
+#include "testutils.h" /* gen_pkg */
/* 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)
{
Modified: soc2013/mattbw/backend/pkgutils_test.c
==============================================================================
--- soc2013/mattbw/backend/pkgutils_test.c Mon Sep 2 08:51:50 2013 (r256827)
+++ soc2013/mattbw/backend/pkgutils_test.c Mon Sep 2 09:14:03 2013 (r256828)
@@ -23,31 +23,10 @@
#include "pkg.h" /* pkg... */
#include "pkgutils.h" /* pkgutils_... */
+#include "testutils.h" /* gen_pkg */
/* 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)
{
Added: soc2013/mattbw/backend/testutils.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/testutils.c Mon Sep 2 09:14:03 2013 (r256828)
@@ -0,0 +1,50 @@
+/*-
+ * 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 "pkg.h" /* pkg... */
+
+#include "testutils.h" /* Prototypes */
+
+/*
+ * Utility functions for unit tests. These shouldn't be used for anything
+ * else.
+ */
+
+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;
+}
+
Added: soc2013/mattbw/backend/testutils.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/testutils.h Mon Sep 2 09:14:03 2013 (r256828)
@@ -0,0 +1,28 @@
+/*-
+ * 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.
+ */
+
+#ifndef _PKGNG_BACKEND_TESTUTILS_H_
+#define _PKGNG_BACKEND_TESTUTILS_H_
+
+#include "pkg.h" /* struct pkg */
+
+struct pkg *gen_pkg(pkg_t type);
+
+#endif /* !_PKGNG_BACKEND_TESTUTILS_H_ */
More information about the svn-soc-all
mailing list