From 715990a1e506eeba1eb39a74fba9a9f083f2d64f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 12 Mar 2012 16:36:46 +0100 Subject: [PATCH] Make xbps_find_virtualpkg_in_dict_by_xxx part of the API and add kyua tests. --- include/xbps_api.h | 38 ++++++++++++++++- include/xbps_api_impl.h | 8 ---- lib/plist_find.c | 4 +- tests/libxbps/plist_find_dictionary/main.c | 48 ++++++++++++++++++++++ 4 files changed, 87 insertions(+), 11 deletions(-) diff --git a/include/xbps_api.h b/include/xbps_api.h index 1e8806c8..4d92dd0b 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -56,7 +56,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.4" -#define XBPS_API_VERSION "20120307" +#define XBPS_API_VERSION "20120312" #define XBPS_VERSION "0.15" /** @@ -898,6 +898,42 @@ prop_dictionary_t xbps_find_pkg_in_dict_by_pkgver(prop_dictionary_t dict, const char *key, const char *pkgver); +/** + * Finds the proplib's dictionary associated with a package, by matching + * a pkgname in \a name on any of the virtual package in + * the "provides" array object. + * + * @param[in] d Proplib dictionary to look for the package dictionary. + * @param[in] key Key associated with the array storing the package's + * dictionary. + * @param[in] name The virtual package name to match. + * + * @return The package dictionary, otherwise NULL is returned and errno + * is set appropiately. + * Finds a virtual package dictionary in a proplib array by matching a + * package name. + */ +prop_dictionary_t xbps_find_virtualpkg_in_dict_by_name(prop_dictionary_t d, + const char *key, + const char *name); + +/** + * Finds the proplib's dictionary associated with a package, by matching + * a pkg pattern in \a pattern on any of the virtual package in + * the "provides" array object. + * + * @param[in] d Proplib dictionary to look for the package dictionary. + * @param[in] key Key associated with the array storing the package's + * dictionary. + * @param[in] pattern The virtual package pattern to match, i.e + * `foo>=0' or `foo<1'. + * + * @return The package dictionary, otherwise NULL is returned and errno + * is set appropiately. + */ +prop_dictionary_t xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t d, + const char *key, + const char *pattern); /** * Finds the package's proplib dictionary in a plist file by specifying * a package name. diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index b8bfdb02..30bb53c0 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -163,14 +163,6 @@ int HIDDEN xbps_transaction_package_replace(prop_dictionary_t); * @private * From lib/plist_find.c */ -prop_dictionary_t HIDDEN - xbps_find_virtualpkg_in_dict_by_name(prop_dictionary_t, - const char *, - const char *); -prop_dictionary_t HIDDEN - xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t, - const char *, - const char *); prop_dictionary_t HIDDEN xbps_find_virtualpkg_conf_in_array_by_name(prop_array_t, const char *); prop_dictionary_t HIDDEN diff --git a/lib/plist_find.c b/lib/plist_find.c index afc95923..e25ecff3 100644 --- a/lib/plist_find.c +++ b/lib/plist_find.c @@ -296,7 +296,7 @@ xbps_find_pkg_in_dict_by_pkgver(prop_dictionary_t d, return xbps_find_pkg_in_array_by_pkgver(array, pkgver); } -prop_dictionary_t HIDDEN +prop_dictionary_t xbps_find_virtualpkg_in_dict_by_name(prop_dictionary_t d, const char *key, const char *name) @@ -304,7 +304,7 @@ xbps_find_virtualpkg_in_dict_by_name(prop_dictionary_t d, return find_pkg_in_dict(d, key, name, false, true); } -prop_dictionary_t HIDDEN +prop_dictionary_t xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t d, const char *key, const char *pattern) diff --git a/tests/libxbps/plist_find_dictionary/main.c b/tests/libxbps/plist_find_dictionary/main.c index 95055ce3..934a1533 100644 --- a/tests/libxbps/plist_find_dictionary/main.c +++ b/tests/libxbps/plist_find_dictionary/main.c @@ -23,6 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *- */ +#include #include #include @@ -40,6 +41,10 @@ static const char dictxml[] = " 1.1\n" " pkgver\n" " afoo-1.1\n" +" provides\n" +" \n" +" virtualpkg-9999\n" +" \n" " \n" " \n" " pkgname\n" @@ -104,10 +109,53 @@ ATF_TC_BODY(find_pkg_in_dict_by_pkgver_test, tc) ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); } +ATF_TC(find_virtualpkg_in_dict_by_pattern_test); +ATF_TC_HEAD(find_virtualpkg_in_dict_by_pattern_test, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test xbps_find_virtualpkg_in_dict_by_pattern"); +} +ATF_TC_BODY(find_virtualpkg_in_dict_by_pattern_test, tc) +{ + prop_dictionary_t d, dr; + const char *pkgver; + + d = prop_dictionary_internalize(dictxml); + ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY); + + /* match virtualpkg by pattern */ + dr = xbps_find_virtualpkg_in_dict_by_pattern(d, "packages", "virtualpkg<=9999"); + ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); + prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver); + ATF_REQUIRE_STREQ(pkgver, "afoo-1.1"); +} + +ATF_TC(find_virtualpkg_in_dict_by_name_test); +ATF_TC_HEAD(find_virtualpkg_in_dict_by_name_test, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test xbps_find_virtualpkg_in_dict_by_name"); +} +ATF_TC_BODY(find_virtualpkg_in_dict_by_name_test, tc) +{ + prop_dictionary_t d, dr; + const char *pkgver; + + d = prop_dictionary_internalize(dictxml); + ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY); + + /* match virtualpkg by name */ + dr = xbps_find_virtualpkg_in_dict_by_name(d, "packages", "virtualpkg"); + ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY); + prop_dictionary_get_cstring_nocopy(dr, "pkgver", &pkgver); + ATF_REQUIRE_STREQ(pkgver, "afoo-1.1"); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, find_pkg_in_dict_by_name_test); ATF_TP_ADD_TC(tp, find_pkg_in_dict_by_pattern_test); ATF_TP_ADD_TC(tp, find_pkg_in_dict_by_pkgver_test); + ATF_TP_ADD_TC(tp, find_virtualpkg_in_dict_by_name_test); + ATF_TP_ADD_TC(tp, find_virtualpkg_in_dict_by_pattern_test); + return atf_no_error(); }