XBPS Library API 20250615
The X Binary Package System
plist_match_virtual/main.c
1/*-
2 * Copyright (c) 2012-2015 Juan Romero Pardines.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *-
25 */
26#include <atf-c.h>
27#include <xbps.h>
28
29static xbps_array_t
30rundeps_init(void)
31{
32 xbps_array_t a;
33
34 a = xbps_array_create();
35 ATF_REQUIRE(a != NULL);
36
37 xbps_array_add_cstring_nocopy(a, "cron-daemon>=0");
38 xbps_array_add_cstring_nocopy(a, "xbps>=0.14");
39
40 return a;
41}
42
43static xbps_array_t
44provides_init(void)
45{
46 xbps_array_t a;
47
48 a = xbps_array_create();
49 ATF_REQUIRE(a != NULL);
50
51 xbps_array_add_cstring_nocopy(a, "cron-daemon-0_1");
52 xbps_array_add_cstring_nocopy(a, "xbps-9999_1");
53
54 return a;
55}
56
57static xbps_dictionary_t
58pkgdict_init(void)
59{
60 xbps_array_t a;
61 xbps_dictionary_t d;
62
63 d = xbps_dictionary_create();
64 ATF_REQUIRE(d != NULL);
65
66 a = provides_init();
67 ATF_REQUIRE_EQ(xbps_dictionary_set(d, "provides", a), true);
68
69 return d;
70}
71
72ATF_TC(match_virtual_pkg_dict_test);
73ATF_TC_HEAD(match_virtual_pkg_dict_test, tc)
74{
75 atf_tc_set_md_var(tc, "descr", "Test xbps_match_virtual_pkg_in_dict");
76}
77
78ATF_TC_BODY(match_virtual_pkg_dict_test, tc)
79{
80 xbps_dictionary_t d;
81
82 d = pkgdict_init();
83 ATF_REQUIRE_EQ(xbps_match_virtual_pkg_in_dict(d, "cron-daemon"), true);
84 ATF_REQUIRE_EQ(xbps_match_virtual_pkg_in_dict(d, "cron-daemon>=0"), true);
85 ATF_REQUIRE_EQ(xbps_match_virtual_pkg_in_dict(d, "cron-daemon>2"), false);
86}
87
88ATF_TC(match_any_virtualpkg_rundeps_test);
89ATF_TC_HEAD(match_any_virtualpkg_rundeps_test, tc)
90{
91 atf_tc_set_md_var(tc, "descr", "Test xbps_match_any_virtualpkg_in_rundeps");
92}
93
94ATF_TC_BODY(match_any_virtualpkg_rundeps_test, tc)
95{
96 xbps_array_t provides, rundeps;
97
98 provides = provides_init();
99 rundeps = rundeps_init();
100
101 ATF_REQUIRE_EQ(
102 xbps_match_any_virtualpkg_in_rundeps(rundeps, provides), true);
103}
104
105ATF_TP_ADD_TCS(tp)
106{
107 ATF_TP_ADD_TC(tp, match_virtual_pkg_dict_test);
108 ATF_TP_ADD_TC(tp, match_any_virtualpkg_rundeps_test);
109
110 return atf_no_error();
111}
bool xbps_match_virtual_pkg_in_dict(xbps_dictionary_t pkgd, const char *str)
Definition plist_match.c:58
bool xbps_match_any_virtualpkg_in_rundeps(xbps_array_t rundeps, xbps_array_t provides)
Definition plist_match.c:71