From owner-svn-soc-all@FreeBSD.ORG Fri Sep 6 13:05:14 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 4341855A for ; Fri, 6 Sep 2013 13:05:14 +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 3071828B6 for ; Fri, 6 Sep 2013 13:05:14 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r86D5DDo021662 for ; Fri, 6 Sep 2013 13:05:13 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r86D5D33021652 for svn-soc-all@FreeBSD.org; Fri, 6 Sep 2013 13:05:13 GMT (envelope-from mattbw@FreeBSD.org) Date: Fri, 6 Sep 2013 13:05:13 GMT Message-Id: <201309061305.r86D5D33021652@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: r257013 - 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: Fri, 06 Sep 2013 13:05:14 -0000 Author: mattbw Date: Fri Sep 6 13:05:13 2013 New Revision: 257013 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257013 Log: Add test case for checking the type-of-repo functionality. This necessitated a separation of the package database-dependent code in repo.c. Modified: soc2013/mattbw/backend/repo.c soc2013/mattbw/backend/repo.h soc2013/mattbw/backend/repo_test.c Modified: soc2013/mattbw/backend/repo.c ============================================================================== --- soc2013/mattbw/backend/repo.c Fri Sep 6 12:59:48 2013 (r257012) +++ soc2013/mattbw/backend/repo.c Fri Sep 6 13:05:13 2013 (r257013) @@ -30,25 +30,45 @@ /* * Finds the type of the given PackageKit repository name. + * + * This function checks remote repositories to ensure they match actually + * configured repositories, and instead returns 'REPO_INVALID' when they don't. + * A separate function 'repo_type_no_remote_check' does not do this and can + * thus be unit tested. */ enum repo_type repo_type(const char *name) { - enum repo_type rtype; + enum repo_type type; + + /* 'name' may be NULL. This implies REPO_ANY. */ + + type = repo_type_no_remote_check(name); + + if (type == REPO_REMOTE && + (pkg_repo_find_ident(pkg_repo_ident_from_name(name)) != NULL)) { + type = REPO_INVALID; + } + + return type; +} + +/* As repo_type, but without the remote repository check. */ +enum repo_type +repo_type_no_remote_check(const char *name) +{ + enum repo_type type; /* Null or empty implies no specific repository */ if (name == NULL || name[0] == '\0') { - rtype = REPO_ANY; + type = REPO_ANY; } else if (strcmp(name, "installed") == 0) { - rtype = REPO_LOCAL; - } else if (pkg_repo_find_ident(pkg_repo_ident_from_name(name)) - != NULL) { - rtype = REPO_REMOTE; + type = REPO_LOCAL; } else { - rtype = REPO_INVALID; + type = REPO_REMOTE; } - return rtype; + return type; } /* Modified: soc2013/mattbw/backend/repo.h ============================================================================== --- soc2013/mattbw/backend/repo.h Fri Sep 6 12:59:48 2013 (r257012) +++ soc2013/mattbw/backend/repo.h Fri Sep 6 13:05:13 2013 (r257013) @@ -31,6 +31,7 @@ }; enum repo_type repo_type(const char *name); +enum repo_type repo_type_no_remote_check(const char *name); const char *repo_of_package(struct pkg *package); #endif /* !_PKGNG_BACKEND_REPO_H_ */ Modified: soc2013/mattbw/backend/repo_test.c ============================================================================== --- soc2013/mattbw/backend/repo_test.c Fri Sep 6 12:59:48 2013 (r257012) +++ soc2013/mattbw/backend/repo_test.c Fri Sep 6 13:05:13 2013 (r257013) @@ -84,12 +84,29 @@ pkg_free(pkg); } +ATF_TC(repo_type_test); +ATF_TC_HEAD(repo_type_test, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Test repo_type_no_remote_check."); +} +ATF_TC_BODY(repo_type_test, tc) +{ + + ATF_CHECK_EQ(repo_type_no_remote_check("installed"), REPO_LOCAL); + ATF_CHECK_EQ(repo_type_no_remote_check("derp"), REPO_REMOTE); + ATF_CHECK_EQ(repo_type_no_remote_check(""), REPO_ANY); + ATF_CHECK_EQ(repo_type_no_remote_check(NULL), REPO_ANY); +} + + /* * TEST PACK */ ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, repo_type_test); ATF_TP_ADD_TC(tp, repo_of_package_valid_local); ATF_TP_ADD_TC(tp, repo_of_package_valid_installed); ATF_TP_ADD_TC(tp, repo_of_package_valid_remote);