Commit Kyua/ATF test suite for libxbps.
This commit is contained in:
5
tests/Makefile
Normal file
5
tests/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
-include ../config.mk
|
||||
|
||||
SUBDIRS = libxbps
|
||||
|
||||
include ../mk/subdir.mk
|
15
tests/libxbps/Makefile
Normal file
15
tests/libxbps/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
-include ../../config.mk
|
||||
|
||||
SUBDIRS = common
|
||||
|
||||
SUBDIRS += cmpver
|
||||
SUBDIRS += pkgpattern_match
|
||||
SUBDIRS += plist_array_replace
|
||||
SUBDIRS += plist_find_array
|
||||
SUBDIRS += plist_find_dictionary
|
||||
SUBDIRS += plist_match
|
||||
SUBDIRS += plist_match_virtual
|
||||
SUBDIRS += plist_remove
|
||||
SUBDIRS += util
|
||||
|
||||
include ../../mk/subdir.mk
|
1
tests/libxbps/Makefile.inc
Normal file
1
tests/libxbps/Makefile.inc
Normal file
@ -0,0 +1 @@
|
||||
TESTSSUBDIR = libxbps
|
7
tests/libxbps/cmpver/Makefile
Normal file
7
tests/libxbps/cmpver/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TOPDIR = ../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
TEST = cmpver_test
|
||||
|
||||
include ../Makefile.inc
|
||||
include $(TOPDIR)/mk/test.mk
|
54
tests/libxbps/cmpver/main.c
Normal file
54
tests/libxbps/cmpver/main.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*-
|
||||
*/
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <xbps_api.h>
|
||||
|
||||
ATF_TC(cmpver_test);
|
||||
|
||||
ATF_TC_HEAD(cmpver_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_cmpver conditions");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(cmpver_test, tc)
|
||||
{
|
||||
ATF_REQUIRE_EQ(xbps_cmpver("foo-1.0", "foo-1.0"), 0);
|
||||
ATF_REQUIRE_EQ(xbps_cmpver("foo-1.0", "foo-1.0_1"), -1);
|
||||
ATF_REQUIRE_EQ(xbps_cmpver("foo-1.0_1", "foo-1.0"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_cmpver("foo-2.0rc2", "foo-2.0rc3"), -1);
|
||||
ATF_REQUIRE_EQ(xbps_cmpver("foo-2.0rc3", "foo-2.0rc2"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_cmpver("foo-129", "foo-129_1"), -1);
|
||||
ATF_REQUIRE_EQ(xbps_cmpver("foo-blah-100dpi-21", "foo-blah-100dpi-21_0"), 0);
|
||||
ATF_REQUIRE_EQ(xbps_cmpver("foo-blah-100dpi-21", "foo-blah-100dpi-2.1"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_cmpver("foo-1.0.1", "foo-1.0_1"), 1);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, cmpver_test);
|
||||
return atf_no_error();
|
||||
}
|
13
tests/libxbps/common/Kyuafile
Normal file
13
tests/libxbps/common/Kyuafile
Normal file
@ -0,0 +1,13 @@
|
||||
syntax("kyuafile", 1)
|
||||
|
||||
test_suite("libxbps")
|
||||
|
||||
atf_test_program{name="util_test"}
|
||||
atf_test_program{name="cmpver_test"}
|
||||
atf_test_program{name="pkgpattern_match_test"}
|
||||
atf_test_program{name="plist_find_dictionary_test"}
|
||||
atf_test_program{name="plist_find_array_test"}
|
||||
atf_test_program{name="plist_match_test"}
|
||||
atf_test_program{name="plist_match_virtual_test"}
|
||||
atf_test_program{name="plist_remove_test"}
|
||||
atf_test_program{name="plist_array_replace_test"}
|
15
tests/libxbps/common/Makefile
Normal file
15
tests/libxbps/common/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
TOPDIR = ../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
include ../Makefile.inc
|
||||
|
||||
all:
|
||||
|
||||
install:
|
||||
install -d $(DESTDIR)$(TESTSDIR)/$(TESTSSUBDIR)
|
||||
install -m644 Kyuafile $(DESTDIR)$(TESTSDIR)/$(TESTSSUBDIR)
|
||||
|
||||
uninstall:
|
||||
-rm -f $(DESTDIR)$(TESTSDIR)/$(TESTSSUBDIR)/Kyuafile
|
||||
|
||||
clean:
|
7
tests/libxbps/pkgpattern_match/Makefile
Normal file
7
tests/libxbps/pkgpattern_match/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TOPDIR = ../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
TEST = pkgpattern_match_test
|
||||
|
||||
include ../Makefile.inc
|
||||
include $(TOPDIR)/mk/test.mk
|
61
tests/libxbps/pkgpattern_match/main.c
Normal file
61
tests/libxbps/pkgpattern_match/main.c
Normal file
@ -0,0 +1,61 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*-
|
||||
*/
|
||||
#include <atf-c.h>
|
||||
#include <xbps_api.h>
|
||||
|
||||
ATF_TC(pkgpattern_match_test);
|
||||
|
||||
ATF_TC_HEAD(pkgpattern_match_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_pkgpattern_match");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(pkgpattern_match_test, tc)
|
||||
{
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.0", "foo>=0"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.0", "foo>=1.0"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.0", "foo>=1.0<1.0_1"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.0", "foo>1.0_1"), 0);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.0", "foo<1.0"), 0);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.0", "foo-1.0"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.0", "foo-[0-1].[0-9]*"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.0", "foo-[1-2].[1-9]*"), 0);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.01", "foo-1.[0-9]?"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.01", "foo-1.[1-9]?"), 0);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.01", "foo-1.[0-2][2-4]?"), 0);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.02", "foo>=1.[0-2][2-4]?"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.12", "foo>=1.[0-2][2-4]?"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.22", "foo>=1.[0-2][2-4]?"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.23", "foo>=1.[0-2][2-4]?"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.24", "foo>=1.[0-2][2-4]?"), 1);
|
||||
ATF_REQUIRE_EQ(xbps_pkgpattern_match("foo-1.11", "foo-1.[0-2][2-4]?"), 0);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, pkgpattern_match_test);
|
||||
return atf_no_error();
|
||||
}
|
7
tests/libxbps/plist_array_replace/Makefile
Normal file
7
tests/libxbps/plist_array_replace/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TOPDIR = ../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
TEST = plist_array_replace_test
|
||||
|
||||
include ../Makefile.inc
|
||||
include $(TOPDIR)/mk/test.mk
|
139
tests/libxbps/plist_array_replace/main.c
Normal file
139
tests/libxbps/plist_array_replace/main.c
Normal file
@ -0,0 +1,139 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*-
|
||||
*/
|
||||
#include <atf-c.h>
|
||||
#include <xbps_api.h>
|
||||
|
||||
static const char axml[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<array>\n"
|
||||
" <dict>\n"
|
||||
" <key>pkgname</key>\n"
|
||||
" <string>afoo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <string>1.1</string>\n"
|
||||
" <key>pkgver</key>\n"
|
||||
" <string>afoo-1.1</string>\n"
|
||||
" </dict>\n"
|
||||
" <dict>\n"
|
||||
" <key>pkgname</key>\n"
|
||||
" <string>foo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <string>2.0</string>\n"
|
||||
" <key>pkgver</key>\n"
|
||||
" <string>foo-2.0</string>\n"
|
||||
" </dict>\n"
|
||||
"</array>\n"
|
||||
"</plist>\n";
|
||||
|
||||
static const char axml2[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<array>\n"
|
||||
" <dict>\n"
|
||||
" <key>pkgname</key>\n"
|
||||
" <string>bfoo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <string>1.2</string>\n"
|
||||
" <key>pkgver</key>\n"
|
||||
" <string>bfoo-1.2</string>\n"
|
||||
" </dict>\n"
|
||||
" <dict>\n"
|
||||
" <key>pkgname</key>\n"
|
||||
" <string>foo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <string>2.0</string>\n"
|
||||
" <key>pkgver</key>\n"
|
||||
" <string>foo-2.0</string>\n"
|
||||
" </dict>\n"
|
||||
"</array>\n"
|
||||
"</plist>\n";
|
||||
|
||||
ATF_TC(array_replace_dict_by_name_test);
|
||||
|
||||
ATF_TC_HEAD(array_replace_dict_by_name_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_array_replace_dict_by_name");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(array_replace_dict_by_name_test, tc)
|
||||
{
|
||||
prop_array_t orig, new;
|
||||
prop_dictionary_t d;
|
||||
|
||||
orig = prop_array_internalize(axml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(orig), PROP_TYPE_ARRAY);
|
||||
|
||||
new = prop_array_internalize(axml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(new), PROP_TYPE_ARRAY);
|
||||
|
||||
d = prop_dictionary_create();
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_set_cstring_nocopy(d, "pkgname", "bfoo"), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_set_cstring_nocopy(d, "pkgver", "bfoo-1.2"), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_set_cstring_nocopy(d, "version", "1.2"), true);
|
||||
|
||||
ATF_REQUIRE_EQ(xbps_array_replace_dict_by_name(orig, d, "afoo"), 0);
|
||||
ATF_REQUIRE_EQ(prop_array_equals(orig, new), true);
|
||||
}
|
||||
|
||||
ATF_TC(array_replace_dict_by_pattern_test);
|
||||
|
||||
ATF_TC_HEAD(array_replace_dict_by_pattern_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_array_replace_dict_by_pattern");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(array_replace_dict_by_pattern_test, tc)
|
||||
{
|
||||
prop_array_t orig, new;
|
||||
prop_dictionary_t d;
|
||||
|
||||
orig = prop_array_internalize(axml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(orig), PROP_TYPE_ARRAY);
|
||||
|
||||
new = prop_array_internalize(axml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(new), PROP_TYPE_ARRAY);
|
||||
|
||||
d = prop_dictionary_create();
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_set_cstring_nocopy(d, "pkgname", "bfoo"), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_set_cstring_nocopy(d, "pkgver", "bfoo-1.2"), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_set_cstring_nocopy(d, "version", "1.2"), true);
|
||||
|
||||
ATF_REQUIRE_EQ(xbps_array_replace_dict_by_pattern(orig, d, "afoo>=1.0"), 0);
|
||||
ATF_REQUIRE_EQ(prop_array_equals(orig, new), true);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, array_replace_dict_by_name_test);
|
||||
ATF_TP_ADD_TC(tp, array_replace_dict_by_pattern_test);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
7
tests/libxbps/plist_find_array/Makefile
Normal file
7
tests/libxbps/plist_find_array/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TOPDIR = ../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
TEST = plist_find_array_test
|
||||
|
||||
include ../Makefile.inc
|
||||
include $(TOPDIR)/mk/test.mk
|
161
tests/libxbps/plist_find_array/main.c
Normal file
161
tests/libxbps/plist_find_array/main.c
Normal file
@ -0,0 +1,161 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*-
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <atf-c.h>
|
||||
#include <xbps_api.h>
|
||||
|
||||
static const char arrayxml[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<array>\n"
|
||||
" <dict>\n"
|
||||
" <key>pkgname</key>\n"
|
||||
" <string>afoo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <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"
|
||||
" <string>foo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <string>2.0</string>\n"
|
||||
" <key>pkgver</key>\n"
|
||||
" <string>foo-2.0</string>\n"
|
||||
" </dict>\n"
|
||||
"</array>\n"
|
||||
"</plist>\n";
|
||||
|
||||
ATF_TC(find_pkg_in_array_by_name_test);
|
||||
ATF_TC_HEAD(find_pkg_in_array_by_name_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_find_pkg_in_array_by_name");
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_array_by_name_test, tc)
|
||||
{
|
||||
prop_array_t a;
|
||||
prop_dictionary_t dr;
|
||||
|
||||
a = prop_array_internalize(arrayxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
/* match by pkgname */
|
||||
dr = xbps_find_pkg_in_array_by_name(a, "foo");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
ATF_TC(find_pkg_in_array_by_pattern_test);
|
||||
ATF_TC_HEAD(find_pkg_in_array_by_pattern_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_find_pkg_in_array_by_pattern");
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_array_by_pattern_test, tc)
|
||||
{
|
||||
prop_array_t a;
|
||||
prop_dictionary_t dr;
|
||||
|
||||
a = prop_array_internalize(arrayxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
/* match by pkgpattern */
|
||||
dr = xbps_find_pkg_in_array_by_pattern(a, "foo>=2.0");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
ATF_TC(find_pkg_in_array_by_pkgver_test);
|
||||
ATF_TC_HEAD(find_pkg_in_array_by_pkgver_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_find_pkg_in_array_by_pkgver");
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_array_by_pkgver_test, tc)
|
||||
{
|
||||
prop_array_t a;
|
||||
prop_dictionary_t dr;
|
||||
|
||||
a = prop_array_internalize(arrayxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
/* exact match by pkgver */
|
||||
dr = xbps_find_pkg_in_array_by_pkgver(a, "foo-2.0");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
ATF_TC(find_virtualpkg_in_array_by_name_test);
|
||||
ATF_TC_HEAD(find_virtualpkg_in_array_by_name_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_find_virtualpkg_in_array_by_name");
|
||||
}
|
||||
ATF_TC_BODY(find_virtualpkg_in_array_by_name_test, tc)
|
||||
{
|
||||
prop_array_t a;
|
||||
prop_dictionary_t dr;
|
||||
const char *pkgname;
|
||||
|
||||
a = prop_array_internalize(arrayxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
dr = xbps_find_virtualpkg_in_array_by_name(a, "virtualpkg");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
prop_dictionary_get_cstring_nocopy(dr, "pkgname", &pkgname);
|
||||
ATF_REQUIRE_STREQ(pkgname, "afoo");
|
||||
}
|
||||
|
||||
ATF_TC(find_virtualpkg_in_array_by_pattern_test);
|
||||
ATF_TC_HEAD(find_virtualpkg_in_array_by_pattern_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_find_virtualpkg_in_array_by_pattern");
|
||||
}
|
||||
ATF_TC_BODY(find_virtualpkg_in_array_by_pattern_test, tc)
|
||||
{
|
||||
prop_array_t a;
|
||||
prop_dictionary_t dr;
|
||||
const char *pkgname;
|
||||
|
||||
a = prop_array_internalize(arrayxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
dr = xbps_find_virtualpkg_in_array_by_pattern(a, "virtualpkg>=9999");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
prop_dictionary_get_cstring_nocopy(dr, "pkgname", &pkgname);
|
||||
ATF_REQUIRE_STREQ(pkgname, "afoo");
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, find_pkg_in_array_by_name_test);
|
||||
ATF_TP_ADD_TC(tp, find_pkg_in_array_by_pattern_test);
|
||||
ATF_TP_ADD_TC(tp, find_pkg_in_array_by_pkgver_test);
|
||||
ATF_TP_ADD_TC(tp, find_virtualpkg_in_array_by_name_test);
|
||||
ATF_TP_ADD_TC(tp, find_virtualpkg_in_array_by_pattern_test);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
7
tests/libxbps/plist_find_dictionary/Makefile
Normal file
7
tests/libxbps/plist_find_dictionary/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TOPDIR = ../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
TEST = plist_find_dictionary_test
|
||||
|
||||
include ../Makefile.inc
|
||||
include $(TOPDIR)/mk/test.mk
|
113
tests/libxbps/plist_find_dictionary/main.c
Normal file
113
tests/libxbps/plist_find_dictionary/main.c
Normal file
@ -0,0 +1,113 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*-
|
||||
*/
|
||||
#include <atf-c.h>
|
||||
#include <xbps_api.h>
|
||||
|
||||
static const char dictxml[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<dict>\n"
|
||||
" <key>packages</key>\n"
|
||||
" <array>\n"
|
||||
" <dict>\n"
|
||||
" <key>pkgname</key>\n"
|
||||
" <string>afoo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <string>1.1</string>\n"
|
||||
" <key>pkgver</key>\n"
|
||||
" <string>afoo-1.1</string>\n"
|
||||
" </dict>\n"
|
||||
" <dict>\n"
|
||||
" <key>pkgname</key>\n"
|
||||
" <string>foo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <string>2.0</string>\n"
|
||||
" <key>pkgver</key>\n"
|
||||
" <string>foo-2.0</string>\n"
|
||||
" </dict>\n"
|
||||
" </array>\n"
|
||||
"</dict>\n"
|
||||
"</plist>\n";
|
||||
|
||||
ATF_TC(find_pkg_in_dict_by_name_test);
|
||||
ATF_TC_HEAD(find_pkg_in_dict_by_name_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_find_pkg_in_dict_by_name");
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_dict_by_name_test, tc)
|
||||
{
|
||||
prop_dictionary_t d, dr;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
/* match by pkgname */
|
||||
dr = xbps_find_pkg_in_dict_by_name(d, "packages", "foo");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
ATF_TC(find_pkg_in_dict_by_pattern_test);
|
||||
ATF_TC_HEAD(find_pkg_in_dict_by_pattern_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_find_pkg_in_dict_by_pattern");
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_dict_by_pattern_test, tc)
|
||||
{
|
||||
prop_dictionary_t d, dr;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
/* match by pkgpattern */
|
||||
dr = xbps_find_pkg_in_dict_by_pattern(d, "packages", "foo>=2.0");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
ATF_TC(find_pkg_in_dict_by_pkgver_test);
|
||||
ATF_TC_HEAD(find_pkg_in_dict_by_pkgver_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_find_pkg_in_dict_by_pkgver");
|
||||
}
|
||||
ATF_TC_BODY(find_pkg_in_dict_by_pkgver_test, tc)
|
||||
{
|
||||
prop_dictionary_t d, dr;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
/* exact match by pkgver */
|
||||
dr = xbps_find_pkg_in_dict_by_pkgver(d, "packages", "foo-2.0");
|
||||
ATF_REQUIRE_EQ(prop_object_type(dr), PROP_TYPE_DICTIONARY);
|
||||
}
|
||||
|
||||
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);
|
||||
return atf_no_error();
|
||||
}
|
7
tests/libxbps/plist_match/Makefile
Normal file
7
tests/libxbps/plist_match/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TOPDIR = ../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
TEST = plist_match_test
|
||||
|
||||
include ../Makefile.inc
|
||||
include $(TOPDIR)/mk/test.mk
|
101
tests/libxbps/plist_match/main.c
Normal file
101
tests/libxbps/plist_match/main.c
Normal file
@ -0,0 +1,101 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*-
|
||||
*/
|
||||
#include <atf-c.h>
|
||||
#include <xbps_api.h>
|
||||
|
||||
static prop_array_t
|
||||
array_init(void)
|
||||
{
|
||||
prop_array_t a;
|
||||
|
||||
a = prop_array_create();
|
||||
ATF_REQUIRE(a != NULL);
|
||||
prop_array_add_cstring_nocopy(a, "foo-2.0");
|
||||
prop_array_add_cstring_nocopy(a, "blah-2.1");
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
ATF_TC(match_string_test);
|
||||
ATF_TC_HEAD(match_string_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_match_string_in_array");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(match_string_test, tc)
|
||||
{
|
||||
prop_array_t a = array_init();
|
||||
ATF_REQUIRE_EQ(xbps_match_string_in_array(a, "foo-2.0"), true);
|
||||
ATF_REQUIRE_EQ(xbps_match_string_in_array(a, "foo-2.1"), false);
|
||||
}
|
||||
|
||||
ATF_TC(match_pkgname_test);
|
||||
ATF_TC_HEAD(match_pkgname_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_match_pkgname_in_array");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(match_pkgname_test, tc)
|
||||
{
|
||||
prop_array_t a = array_init();
|
||||
ATF_REQUIRE_EQ(xbps_match_pkgname_in_array(a, "foo"), true);
|
||||
ATF_REQUIRE_EQ(xbps_match_pkgname_in_array(a, "baz"), false);
|
||||
}
|
||||
|
||||
ATF_TC(match_pkgpattern_test);
|
||||
ATF_TC_HEAD(match_pkgpattern_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_match_pkgpattern_in_array");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(match_pkgpattern_test, tc)
|
||||
{
|
||||
prop_array_t a = array_init();
|
||||
ATF_REQUIRE_EQ(xbps_match_pkgpattern_in_array(a, "foo>=1.0"), true);
|
||||
ATF_REQUIRE_EQ(xbps_match_pkgpattern_in_array(a, "blah<1.0"), false);
|
||||
}
|
||||
|
||||
ATF_TC(match_pkgdep_test);
|
||||
ATF_TC_HEAD(match_pkgdep_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_match_pkgdep_in_array");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(match_pkgdep_test, tc)
|
||||
{
|
||||
prop_array_t a = array_init();
|
||||
ATF_REQUIRE_EQ(xbps_match_pkgdep_in_array(a, "foo-2.0"), true);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, match_string_test);
|
||||
ATF_TP_ADD_TC(tp, match_pkgname_test);
|
||||
ATF_TP_ADD_TC(tp, match_pkgpattern_test);
|
||||
ATF_TP_ADD_TC(tp, match_pkgdep_test);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
7
tests/libxbps/plist_match_virtual/Makefile
Normal file
7
tests/libxbps/plist_match_virtual/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TOPDIR = ../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
TEST = plist_match_virtual_test
|
||||
|
||||
include ../Makefile.inc
|
||||
include $(TOPDIR)/mk/test.mk
|
114
tests/libxbps/plist_match_virtual/main.c
Normal file
114
tests/libxbps/plist_match_virtual/main.c
Normal file
@ -0,0 +1,114 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*-
|
||||
*/
|
||||
#include <atf-c.h>
|
||||
#include <xbps_api.h>
|
||||
|
||||
static prop_array_t
|
||||
rundeps_init(void)
|
||||
{
|
||||
prop_array_t a;
|
||||
|
||||
a = prop_array_create();
|
||||
ATF_REQUIRE(a != NULL);
|
||||
|
||||
prop_array_add_cstring_nocopy(a, "cron-daemon>=0");
|
||||
prop_array_add_cstring_nocopy(a, "xbps>=0.14");
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
static prop_array_t
|
||||
provides_init(void)
|
||||
{
|
||||
prop_array_t a;
|
||||
|
||||
a = prop_array_create();
|
||||
ATF_REQUIRE(a != NULL);
|
||||
|
||||
prop_array_add_cstring_nocopy(a, "cron-daemon-0");
|
||||
prop_array_add_cstring_nocopy(a, "xbps-9999");
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
static prop_dictionary_t
|
||||
pkgdict_init(void)
|
||||
{
|
||||
prop_array_t a;
|
||||
prop_dictionary_t d;
|
||||
|
||||
d = prop_dictionary_create();
|
||||
ATF_REQUIRE(d != NULL);
|
||||
|
||||
a = provides_init();
|
||||
ATF_REQUIRE_EQ(prop_dictionary_set(d, "provides", a), true);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
ATF_TC(match_virtual_pkg_dict_test);
|
||||
ATF_TC_HEAD(match_virtual_pkg_dict_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_match_virtual_pkg_in_dict");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(match_virtual_pkg_dict_test, tc)
|
||||
{
|
||||
prop_dictionary_t d;
|
||||
|
||||
d = pkgdict_init();
|
||||
ATF_REQUIRE_EQ(
|
||||
xbps_match_virtual_pkg_in_dict(d, "cron-daemon", false), true);
|
||||
ATF_REQUIRE_EQ(
|
||||
xbps_match_virtual_pkg_in_dict(d, "cron-daemon>=0", true), true);
|
||||
ATF_REQUIRE_EQ(
|
||||
xbps_match_virtual_pkg_in_dict(d, "cron-daemon>2", true), false);
|
||||
}
|
||||
|
||||
ATF_TC(match_any_virtualpkg_rundeps_test);
|
||||
ATF_TC_HEAD(match_any_virtualpkg_rundeps_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_match_any_virtualpkg_in_rundeps");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(match_any_virtualpkg_rundeps_test, tc)
|
||||
{
|
||||
prop_array_t provides, rundeps;
|
||||
|
||||
provides = provides_init();
|
||||
rundeps = rundeps_init();
|
||||
|
||||
ATF_REQUIRE_EQ(
|
||||
xbps_match_any_virtualpkg_in_rundeps(rundeps, provides), true);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, match_virtual_pkg_dict_test);
|
||||
ATF_TP_ADD_TC(tp, match_any_virtualpkg_rundeps_test);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
7
tests/libxbps/plist_remove/Makefile
Normal file
7
tests/libxbps/plist_remove/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TOPDIR = ../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
TEST = plist_remove_test
|
||||
|
||||
include ../Makefile.inc
|
||||
include $(TOPDIR)/mk/test.mk
|
236
tests/libxbps/plist_remove/main.c
Normal file
236
tests/libxbps/plist_remove/main.c
Normal file
@ -0,0 +1,236 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*-
|
||||
*/
|
||||
#include <atf-c.h>
|
||||
#include <xbps_api.h>
|
||||
|
||||
static const char dictxml[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<dict>\n"
|
||||
" <key>packages</key>\n"
|
||||
" <array>\n"
|
||||
" <dict>\n"
|
||||
" <key>pkgname</key>\n"
|
||||
" <string>afoo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <string>1.1</string>\n"
|
||||
" <key>pkgver</key>\n"
|
||||
" <string>afoo-1.1</string>\n"
|
||||
" </dict>\n"
|
||||
" <dict>\n"
|
||||
" <key>pkgname</key>\n"
|
||||
" <string>foo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <string>2.0</string>\n"
|
||||
" <key>pkgver</key>\n"
|
||||
" <string>foo-2.0</string>\n"
|
||||
" </dict>\n"
|
||||
" </array>\n"
|
||||
"</dict>\n"
|
||||
"</plist>\n";
|
||||
|
||||
static const char dictxml2[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<dict>\n"
|
||||
" <key>packages</key>\n"
|
||||
" <array>\n"
|
||||
" <dict>\n"
|
||||
" <key>pkgname</key>\n"
|
||||
" <string>foo</string>\n"
|
||||
" <key>version</key>\n"
|
||||
" <string>2.0</string>\n"
|
||||
" <key>pkgver</key>\n"
|
||||
" <string>foo-2.0</string>\n"
|
||||
" </dict>\n"
|
||||
" </array>\n"
|
||||
"</dict>\n"
|
||||
"</plist>\n";
|
||||
|
||||
static const char axml[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<array>\n"
|
||||
" <string>foo-1.0</string>\n"
|
||||
" <string>blah-2.0</string>\n"
|
||||
"</array>\n"
|
||||
"</plist>\n";
|
||||
|
||||
static const char axml2[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
|
||||
"<plist version=\"1.0\">\n"
|
||||
"<array>\n"
|
||||
" <string>blah-2.0</string>\n"
|
||||
"</array>\n"
|
||||
"</plist>\n";
|
||||
|
||||
ATF_TC(remove_pkg_from_array_by_name_test);
|
||||
|
||||
ATF_TC_HEAD(remove_pkg_from_array_by_name_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_remove_pkg_from_array_by_name");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(remove_pkg_from_array_by_name_test, tc)
|
||||
{
|
||||
prop_array_t a;
|
||||
prop_dictionary_t d, d2;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
d2 = prop_dictionary_internalize(dictxml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY);
|
||||
|
||||
a = prop_dictionary_get(d, "packages");
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_name(a, "afoo"), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true);
|
||||
}
|
||||
|
||||
ATF_TC(remove_pkg_from_array_by_pattern_test);
|
||||
|
||||
ATF_TC_HEAD(remove_pkg_from_array_by_pattern_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_remove_pkg_from_array_by_pattern");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(remove_pkg_from_array_by_pattern_test, tc)
|
||||
{
|
||||
prop_array_t a;
|
||||
prop_dictionary_t d, d2;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
d2 = prop_dictionary_internalize(dictxml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY);
|
||||
|
||||
a = prop_dictionary_get(d, "packages");
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_pattern(a, "afoo>=1.0"), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true);
|
||||
}
|
||||
|
||||
ATF_TC(remove_pkg_from_array_by_pkgver_test);
|
||||
|
||||
ATF_TC_HEAD(remove_pkg_from_array_by_pkgver_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_remove_pkg_from_array_by_pkgver");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(remove_pkg_from_array_by_pkgver_test, tc)
|
||||
{
|
||||
prop_array_t a;
|
||||
prop_dictionary_t d, d2;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
d2 = prop_dictionary_internalize(dictxml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY);
|
||||
|
||||
a = prop_dictionary_get(d, "packages");
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkg_from_array_by_pkgver(a, "afoo-1.1"), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true);
|
||||
}
|
||||
|
||||
ATF_TC(remove_string_from_array_test);
|
||||
|
||||
ATF_TC_HEAD(remove_string_from_array_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_remove_string_from_array");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(remove_string_from_array_test, tc)
|
||||
{
|
||||
prop_array_t a, a2;
|
||||
|
||||
a = prop_array_internalize(axml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
a2 = prop_array_internalize(axml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a2), PROP_TYPE_ARRAY);
|
||||
|
||||
ATF_REQUIRE_EQ(xbps_remove_string_from_array(a, "foo-1.0"), true);
|
||||
ATF_REQUIRE_EQ(prop_array_equals(a, a2), true);
|
||||
}
|
||||
|
||||
ATF_TC(remove_pkgname_from_array_test);
|
||||
|
||||
ATF_TC_HEAD(remove_pkgname_from_array_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_remove_pkgname_from_array");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(remove_pkgname_from_array_test, tc)
|
||||
{
|
||||
prop_array_t a, a2;
|
||||
|
||||
a = prop_array_internalize(axml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a), PROP_TYPE_ARRAY);
|
||||
|
||||
a2 = prop_array_internalize(axml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(a2), PROP_TYPE_ARRAY);
|
||||
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkgname_from_array(a, "foo"), true);
|
||||
ATF_REQUIRE_EQ(prop_array_equals(a, a2), true);
|
||||
}
|
||||
|
||||
ATF_TC(remove_pkg_from_dict_by_name_test);
|
||||
|
||||
ATF_TC_HEAD(remove_pkg_from_dict_by_name_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test xbps_remove_pkg_from_dict_by_name");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(remove_pkg_from_dict_by_name_test, tc)
|
||||
{
|
||||
prop_dictionary_t d, d2;
|
||||
|
||||
d = prop_dictionary_internalize(dictxml);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d), PROP_TYPE_DICTIONARY);
|
||||
|
||||
d2 = prop_dictionary_internalize(dictxml2);
|
||||
ATF_REQUIRE_EQ(prop_object_type(d2), PROP_TYPE_DICTIONARY);
|
||||
|
||||
ATF_REQUIRE_EQ(xbps_remove_pkg_from_dict_by_name(d, "packages", "afoo"), true);
|
||||
ATF_REQUIRE_EQ(prop_dictionary_equals(d, d2), true);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, remove_pkg_from_array_by_name_test);
|
||||
ATF_TP_ADD_TC(tp, remove_pkg_from_array_by_pattern_test);
|
||||
ATF_TP_ADD_TC(tp, remove_pkg_from_array_by_pkgver_test);
|
||||
ATF_TP_ADD_TC(tp, remove_string_from_array_test);
|
||||
ATF_TP_ADD_TC(tp, remove_pkgname_from_array_test);
|
||||
ATF_TP_ADD_TC(tp, remove_pkg_from_dict_by_name_test);
|
||||
|
||||
return atf_no_error();
|
||||
}
|
7
tests/libxbps/util/Makefile
Normal file
7
tests/libxbps/util/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
TOPDIR = ../../..
|
||||
-include $(TOPDIR)/config.mk
|
||||
|
||||
TEST = util_test
|
||||
|
||||
include ../Makefile.inc
|
||||
include $(TOPDIR)/mk/test.mk
|
55
tests/libxbps/util/main.c
Normal file
55
tests/libxbps/util/main.c
Normal file
@ -0,0 +1,55 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*-
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <atf-c.h>
|
||||
#include <xbps_api.h>
|
||||
|
||||
ATF_TC(util_test);
|
||||
|
||||
ATF_TC_HEAD(util_test, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test some utility functions");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(util_test, tc)
|
||||
{
|
||||
ATF_REQUIRE_STREQ(xbps_pkg_name("font-adobe-100dpi-7.8"), "font-adobe-100dpi");
|
||||
ATF_REQUIRE_STREQ(xbps_pkg_name("systemd-43_1"), "systemd");
|
||||
ATF_REQUIRE_STREQ(xbps_pkg_name("font-adobe-100dpi-1.8_blah"), "font-adobe-100dpi");
|
||||
ATF_REQUIRE_STREQ(xbps_pkg_version("font-adobe-100dpi-1.8_blah"), "1.8_blah");
|
||||
ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd-43_1_0"), "0");
|
||||
ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd_21-43_0"), "0");
|
||||
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>=43"), "systemd");
|
||||
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>=43"), "systemd");
|
||||
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd-[0-9]*"), "systemd");
|
||||
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>4[3-9]?"), "systemd");
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, util_test);
|
||||
return atf_no_error();
|
||||
}
|
Reference in New Issue
Block a user