Make xbps_find_virtualpkg_in_dict_by_xxx part of the API and add kyua tests.

This commit is contained in:
Juan RP 2012-03-12 16:36:46 +01:00
parent d4c01be9f9
commit 715990a1e5
4 changed files with 87 additions and 11 deletions

View File

@ -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.

View File

@ -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

View File

@ -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)

View File

@ -23,6 +23,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*-
*/
#include <string.h>
#include <atf-c.h>
#include <xbps_api.h>
@ -40,6 +41,10 @@ static const char dictxml[] =
" <string>1.1</string>\n"
" <key>pkgver</key>\n"
" <string>afoo-1.1</string>\n"
" <key>provides</key>\n"
" <array>\n"
" <string>virtualpkg-9999</string>\n"
" </array>\n"
" </dict>\n"
" <dict>\n"
" <key>pkgname</key>\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();
}