XBPS Library API 20250615
The X Binary Package System
plist_match/main.c
1/*-
2 * Copyright (c) 2012 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
30array_init(void)
31{
32 xbps_array_t a;
33
34 a = xbps_array_create();
35 ATF_REQUIRE(a != NULL);
36 xbps_array_add_cstring_nocopy(a, "foo-2.0_1");
37 xbps_array_add_cstring_nocopy(a, "blah-2.1_1");
38
39 return a;
40}
41
42ATF_TC(match_string_test);
43ATF_TC_HEAD(match_string_test, tc)
44{
45 atf_tc_set_md_var(tc, "descr", "Test xbps_match_string_in_array");
46}
47
48ATF_TC_BODY(match_string_test, tc)
49{
50 xbps_array_t a = array_init();
51 ATF_REQUIRE_EQ(xbps_match_string_in_array(a, "foo-2.0_1"), true);
52 ATF_REQUIRE_EQ(xbps_match_string_in_array(a, "foo-2.1_1"), false);
53}
54
55ATF_TC(match_pkgname_test);
56ATF_TC_HEAD(match_pkgname_test, tc)
57{
58 atf_tc_set_md_var(tc, "descr", "Test xbps_match_pkgname_in_array");
59}
60
61ATF_TC_BODY(match_pkgname_test, tc)
62{
63 xbps_array_t a = array_init();
64 ATF_REQUIRE_EQ(xbps_match_pkgname_in_array(a, "foo"), true);
65 ATF_REQUIRE_EQ(xbps_match_pkgname_in_array(a, "baz"), false);
66}
67
68ATF_TC(match_pkgpattern_test);
69ATF_TC_HEAD(match_pkgpattern_test, tc)
70{
71 atf_tc_set_md_var(tc, "descr", "Test xbps_match_pkgpattern_in_array");
72}
73
74ATF_TC_BODY(match_pkgpattern_test, tc)
75{
76 xbps_array_t a = array_init();
77 ATF_REQUIRE_EQ(xbps_match_pkgpattern_in_array(a, "foo>=1.0"), true);
78 ATF_REQUIRE_EQ(xbps_match_pkgpattern_in_array(a, "blah<1.0"), false);
79}
80
81ATF_TC(match_pkgdep_test);
82ATF_TC_HEAD(match_pkgdep_test, tc)
83{
84 atf_tc_set_md_var(tc, "descr", "Test xbps_match_pkgdep_in_array");
85}
86
87ATF_TC_BODY(match_pkgdep_test, tc)
88{
89 xbps_array_t a = array_init();
90 ATF_REQUIRE_EQ(xbps_match_pkgdep_in_array(a, "foo-2.0_1"), true);
91}
92
93ATF_TP_ADD_TCS(tp)
94{
95 ATF_TP_ADD_TC(tp, match_string_test);
96 ATF_TP_ADD_TC(tp, match_pkgname_test);
97 ATF_TP_ADD_TC(tp, match_pkgpattern_test);
98 ATF_TP_ADD_TC(tp, match_pkgdep_test);
99
100 return atf_no_error();
101}
bool xbps_match_pkgname_in_array(xbps_array_t array, const char *pkgname)
bool xbps_match_pkgdep_in_array(xbps_array_t array, const char *pkgver)
bool xbps_match_string_in_array(xbps_array_t array, const char *val)
bool xbps_match_pkgpattern_in_array(xbps_array_t array, const char *pattern)