diff --git a/Makefile b/Makefile index 632c0658..e2646864 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,10 @@ ifdef BUILD_API_DOCS SUBDIRS += doc endif +ifdef BUILD_TESTS +SUBDIRS += tests +endif + .PHONY: all all: @for dir in $(SUBDIRS); do \ diff --git a/bin/Makefile b/bin/Makefile index 3d578483..bd5e71d9 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -5,26 +5,4 @@ SUBDIRS += xbps-repo SUBDIRS += xbps-dgraph SUBDIRS += xbps-uhelper -.PHONY: all -all: - @for dir in $(SUBDIRS); do \ - $(MAKE) -C $$dir || exit 1; \ - done - -.PHONY: install -install: - @for dir in $(SUBDIRS); do \ - $(MAKE) -C $$dir install || exit 1; \ - done - -.PHONY: uninstall -uninstall: - @for dir in $(SUBDIRS); do \ - $(MAKE) -C $$dir uninstall || exit1; \ - done - -.PHONY: clean -clean: - @for dir in $(SUBDIRS); do \ - $(MAKE) -C $$dir clean || exit 1; \ - done +include ../mk/subdir.mk diff --git a/bin/xbps-bin/Makefile b/bin/xbps-bin/Makefile index 749ba00f..86117e36 100644 --- a/bin/xbps-bin/Makefile +++ b/bin/xbps-bin/Makefile @@ -11,4 +11,4 @@ OBJS += check_pkg_requiredby.o OBJS += show-orphans.o unpack_cb.o list.o MAN = $(BIN).8 -include $(TOPDIR)/bin/prog.mk +include $(TOPDIR)/mk/prog.mk diff --git a/bin/xbps-dgraph/Makefile b/bin/xbps-dgraph/Makefile index 6df03936..9934c97a 100644 --- a/bin/xbps-dgraph/Makefile +++ b/bin/xbps-dgraph/Makefile @@ -3,4 +3,4 @@ TOPDIR = ../.. BIN = xbps-dgraph -include $(TOPDIR)/bin/prog.mk +include $(TOPDIR)/mk/prog.mk diff --git a/bin/xbps-repo/Makefile b/bin/xbps-repo/Makefile index bbbe27ab..a6af0cc1 100644 --- a/bin/xbps-repo/Makefile +++ b/bin/xbps-repo/Makefile @@ -8,4 +8,4 @@ OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o OBJS += ../xbps-bin/state_cb.o ../xbps-bin/list.o MAN = $(BIN).8 -include $(TOPDIR)/bin/prog.mk +include $(TOPDIR)/mk/prog.mk diff --git a/bin/xbps-uhelper/Makefile b/bin/xbps-uhelper/Makefile index c90cfc6a..ba63e72d 100644 --- a/bin/xbps-uhelper/Makefile +++ b/bin/xbps-uhelper/Makefile @@ -4,4 +4,4 @@ TOPDIR = ../.. BIN = xbps-uhelper OBJS = main.o ../xbps-bin/fetch_cb.o -include $(TOPDIR)/bin/prog.mk +include $(TOPDIR)/mk/prog.mk diff --git a/configure b/configure index 6a5d9b6b..ac42fa72 100755 --- a/configure +++ b/configure @@ -12,6 +12,7 @@ BUILD= HOST= TARGET= DEBUG= +BUILD_TESTS= BUILD_API_DOCS= BUILD_PIE= SILENT=yes @@ -40,8 +41,9 @@ for instance \`--prefix=\$HOME'. --debug Build with debugging code and symbols --verbose Disable silent build to see compilation details --with-pie Build XBPS programs as PIE (default disabled) ---with-api-docs install XBPS API Library documentation (default disabled) - +--with-api-docs Install XBPS API Library documentation (default disabled) +--with-tests Build and install Kyua tests (default disabled) + Needs atf >= 0.15 (http://code.google.com/p/kyua) _EOF exit 1 } @@ -67,6 +69,7 @@ for x; do --verbose) unset SILENT;; --with-pie) BUILD_PIE=$var;; --pkgconfigdir) PKGCONFIGDIR=$var;; + --with-tests) BUILD_TESTS=yes;; --help) usage;; *) echo "$0: WARNING: unknown option $opt" >&2;; esac @@ -84,6 +87,7 @@ done : ${INCLUDEDIR:=${EPREFIX}/include} : ${ETCDIR:=${PREFIX}/etc} : ${PKGCONFIGDIR:=${LIBDIR}/pkgconfig} +: ${TESTSDIR:=${EPREFIX}/tests} : ${TOPDIR:=..} _which() @@ -144,6 +148,7 @@ echo "LIBDIR ?= $LIBDIR" >>$CONFIG_MK echo "MANDIR ?= $MANDIR" >>$CONFIG_MK echo "SHAREDIR ?= $SHAREDIR" >>$CONFIG_MK echo "PKGCONFIGDIR ?= $PKGCONFIGDIR" >>$CONFIG_MK +echo "TESTSDIR ?= $TESTSDIR" >>$CONFIG_MK ETCDIR="${ETCDIR}/xbps" echo "ETCDIR ?= $ETCDIR" >>$CONFIG_MK @@ -591,6 +596,24 @@ else >>$CONFIG_MK fi +# +# If --with-tests enabled, check for ATF >= 0.15 via pkg-config. +# +if [ "$BUILD_TESTS" = "yes" ]; then + printf "Checking for ATF via pkg-config ... " + if ! $PKGCONFIG_BIN --atleast-version=0.15 atf-c; then + echo "ATF >= 0.15 not found in PKG_CONFIG_LIBDIR, exiting." + exit 1 + fi + echo "found version $($PKGCONFIG_BIN --modversion atf-c)." + echo "TEST_CFLAGS += $($PKGCONFIG_BIN --cflags atf-c)" >>$CONFIG_MK + echo "TEST_LDFLAGS += $($PKGCONFIG_BIN --libs atf-c)" >>$CONFIG_MK + echo "BUILD_TESTS = yes" >>$CONFIG_MK + BUILD_TESTS_VALUE=yes +else + BUILD_TESTS_VALUE=no +fi + if [ -n "$SILENT" ]; then echo "SILENT = @" >>$CONFIG_MK else @@ -617,6 +640,7 @@ if [ -n "$LDFLAGS" ]; then fi echo echo " Build API documentation = $BUILD_API_DOCS_VALUE" +echo " Build Kyua test suite = $BUILD_TESTS_VALUE" echo " Build programs as PIE = $BUILD_PIE_VAL" echo " Build with debug = $DEBUG" echo " Use external proplib = $PROPLIB" diff --git a/bin/prog.mk b/mk/prog.mk similarity index 100% rename from bin/prog.mk rename to mk/prog.mk diff --git a/mk/subdir.mk b/mk/subdir.mk new file mode 100644 index 00000000..25620dc5 --- /dev/null +++ b/mk/subdir.mk @@ -0,0 +1,23 @@ +.PHONY: all +all: + @for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir || exit 1; \ + done + +.PHONY: install +install: + @for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir install || exit 1; \ + done + +.PHONY: uninstall +uninstall: + @for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir uninstall || exit1; \ + done + +.PHONY: clean +clean: + @for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir clean || exit 1; \ + done diff --git a/mk/test.mk b/mk/test.mk new file mode 100644 index 00000000..af234baa --- /dev/null +++ b/mk/test.mk @@ -0,0 +1,29 @@ +-include $(TOPDIR)/config.mk + +OBJS ?= main.o + +.PHONY: all +all: $(TEST) + +.PHONY: clean +clean: + -rm -f $(TEST) $(OBJS) + +.PHONY: install +install: all + install -d $(DESTDIR)$(TESTSDIR)/$(TESTSSUBDIR) + install -m755 $(TEST) $(DESTDIR)$(TESTSDIR)/$(TESTSSUBDIR) + +.PHONY: uninstall +uninstall: + -rm -f $(DESTDIR)$(TESTSDIR)/$(TESTSSUBDIR)/$(TEST) + +%.o: %.c + @printf " [CC]\t\t$@\n" + ${SILENT}$(CC) $(CPPFLAGS) $(CFLAGS) -c $< + +$(TEST): $(OBJS) + @printf " [CCLD]\t\t$@\n" + ${SILENT}$(CC) $^ $(CPPFLAGS) -L$(TOPDIR)/lib $(CFLAGS) \ + $(PROG_CFLAGS) -lprop -lxbps -latf-c -o $@ + diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 00000000..2220499a --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,5 @@ +-include ../config.mk + +SUBDIRS = libxbps + +include ../mk/subdir.mk diff --git a/tests/libxbps/Makefile b/tests/libxbps/Makefile new file mode 100644 index 00000000..cdd5bd27 --- /dev/null +++ b/tests/libxbps/Makefile @@ -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 diff --git a/tests/libxbps/Makefile.inc b/tests/libxbps/Makefile.inc new file mode 100644 index 00000000..f49f88cf --- /dev/null +++ b/tests/libxbps/Makefile.inc @@ -0,0 +1 @@ +TESTSSUBDIR = libxbps diff --git a/tests/libxbps/cmpver/Makefile b/tests/libxbps/cmpver/Makefile new file mode 100644 index 00000000..4537ffe4 --- /dev/null +++ b/tests/libxbps/cmpver/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TEST = cmpver_test + +include ../Makefile.inc +include $(TOPDIR)/mk/test.mk diff --git a/tests/libxbps/cmpver/main.c b/tests/libxbps/cmpver/main.c new file mode 100644 index 00000000..bfd0fbd4 --- /dev/null +++ b/tests/libxbps/cmpver/main.c @@ -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 +#include + +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(); +} diff --git a/tests/libxbps/common/Kyuafile b/tests/libxbps/common/Kyuafile new file mode 100644 index 00000000..a5fd030d --- /dev/null +++ b/tests/libxbps/common/Kyuafile @@ -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"} diff --git a/tests/libxbps/common/Makefile b/tests/libxbps/common/Makefile new file mode 100644 index 00000000..149e98bb --- /dev/null +++ b/tests/libxbps/common/Makefile @@ -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: diff --git a/tests/libxbps/pkgpattern_match/Makefile b/tests/libxbps/pkgpattern_match/Makefile new file mode 100644 index 00000000..fc24f199 --- /dev/null +++ b/tests/libxbps/pkgpattern_match/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TEST = pkgpattern_match_test + +include ../Makefile.inc +include $(TOPDIR)/mk/test.mk diff --git a/tests/libxbps/pkgpattern_match/main.c b/tests/libxbps/pkgpattern_match/main.c new file mode 100644 index 00000000..afa8e38e --- /dev/null +++ b/tests/libxbps/pkgpattern_match/main.c @@ -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 +#include + +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(); +} diff --git a/tests/libxbps/plist_array_replace/Makefile b/tests/libxbps/plist_array_replace/Makefile new file mode 100644 index 00000000..adbc9781 --- /dev/null +++ b/tests/libxbps/plist_array_replace/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TEST = plist_array_replace_test + +include ../Makefile.inc +include $(TOPDIR)/mk/test.mk diff --git a/tests/libxbps/plist_array_replace/main.c b/tests/libxbps/plist_array_replace/main.c new file mode 100644 index 00000000..90443cc4 --- /dev/null +++ b/tests/libxbps/plist_array_replace/main.c @@ -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 +#include + +static const char axml[] = +"\n" +"\n" +"\n" +"\n" +" \n" +" pkgname\n" +" afoo\n" +" version\n" +" 1.1\n" +" pkgver\n" +" afoo-1.1\n" +" \n" +" \n" +" pkgname\n" +" foo\n" +" version\n" +" 2.0\n" +" pkgver\n" +" foo-2.0\n" +" \n" +"\n" +"\n"; + +static const char axml2[] = +"\n" +"\n" +"\n" +"\n" +" \n" +" pkgname\n" +" bfoo\n" +" version\n" +" 1.2\n" +" pkgver\n" +" bfoo-1.2\n" +" \n" +" \n" +" pkgname\n" +" foo\n" +" version\n" +" 2.0\n" +" pkgver\n" +" foo-2.0\n" +" \n" +"\n" +"\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(); +} diff --git a/tests/libxbps/plist_find_array/Makefile b/tests/libxbps/plist_find_array/Makefile new file mode 100644 index 00000000..ab0c59f1 --- /dev/null +++ b/tests/libxbps/plist_find_array/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TEST = plist_find_array_test + +include ../Makefile.inc +include $(TOPDIR)/mk/test.mk diff --git a/tests/libxbps/plist_find_array/main.c b/tests/libxbps/plist_find_array/main.c new file mode 100644 index 00000000..7be0f6f2 --- /dev/null +++ b/tests/libxbps/plist_find_array/main.c @@ -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 +#include +#include + +static const char arrayxml[] = +"\n" +"\n" +"\n" +"\n" +" \n" +" pkgname\n" +" afoo\n" +" version\n" +" 1.1\n" +" pkgver\n" +" afoo-1.1\n" +" provides\n" +" \n" +" virtualpkg-9999\n" +" \n" +" \n" +" \n" +" pkgname\n" +" foo\n" +" version\n" +" 2.0\n" +" pkgver\n" +" foo-2.0\n" +" \n" +"\n" +"\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(); +} diff --git a/tests/libxbps/plist_find_dictionary/Makefile b/tests/libxbps/plist_find_dictionary/Makefile new file mode 100644 index 00000000..21948836 --- /dev/null +++ b/tests/libxbps/plist_find_dictionary/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TEST = plist_find_dictionary_test + +include ../Makefile.inc +include $(TOPDIR)/mk/test.mk diff --git a/tests/libxbps/plist_find_dictionary/main.c b/tests/libxbps/plist_find_dictionary/main.c new file mode 100644 index 00000000..250f4289 --- /dev/null +++ b/tests/libxbps/plist_find_dictionary/main.c @@ -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 +#include + +static const char dictxml[] = +"\n" +"\n" +"\n" +"\n" +" packages\n" +" \n" +" \n" +" pkgname\n" +" afoo\n" +" version\n" +" 1.1\n" +" pkgver\n" +" afoo-1.1\n" +" \n" +" \n" +" pkgname\n" +" foo\n" +" version\n" +" 2.0\n" +" pkgver\n" +" foo-2.0\n" +" \n" +" \n" +"\n" +"\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(); +} diff --git a/tests/libxbps/plist_match/Makefile b/tests/libxbps/plist_match/Makefile new file mode 100644 index 00000000..c7270f6d --- /dev/null +++ b/tests/libxbps/plist_match/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TEST = plist_match_test + +include ../Makefile.inc +include $(TOPDIR)/mk/test.mk diff --git a/tests/libxbps/plist_match/main.c b/tests/libxbps/plist_match/main.c new file mode 100644 index 00000000..3f9349e6 --- /dev/null +++ b/tests/libxbps/plist_match/main.c @@ -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 +#include + +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(); +} diff --git a/tests/libxbps/plist_match_virtual/Makefile b/tests/libxbps/plist_match_virtual/Makefile new file mode 100644 index 00000000..8b7f408d --- /dev/null +++ b/tests/libxbps/plist_match_virtual/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TEST = plist_match_virtual_test + +include ../Makefile.inc +include $(TOPDIR)/mk/test.mk diff --git a/tests/libxbps/plist_match_virtual/main.c b/tests/libxbps/plist_match_virtual/main.c new file mode 100644 index 00000000..ce7ceae5 --- /dev/null +++ b/tests/libxbps/plist_match_virtual/main.c @@ -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 +#include + +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(); +} diff --git a/tests/libxbps/plist_remove/Makefile b/tests/libxbps/plist_remove/Makefile new file mode 100644 index 00000000..6d4b63cc --- /dev/null +++ b/tests/libxbps/plist_remove/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TEST = plist_remove_test + +include ../Makefile.inc +include $(TOPDIR)/mk/test.mk diff --git a/tests/libxbps/plist_remove/main.c b/tests/libxbps/plist_remove/main.c new file mode 100644 index 00000000..86ef3ef4 --- /dev/null +++ b/tests/libxbps/plist_remove/main.c @@ -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 +#include + +static const char dictxml[] = +"\n" +"\n" +"\n" +"\n" +" packages\n" +" \n" +" \n" +" pkgname\n" +" afoo\n" +" version\n" +" 1.1\n" +" pkgver\n" +" afoo-1.1\n" +" \n" +" \n" +" pkgname\n" +" foo\n" +" version\n" +" 2.0\n" +" pkgver\n" +" foo-2.0\n" +" \n" +" \n" +"\n" +"\n"; + +static const char dictxml2[] = +"\n" +"\n" +"\n" +"\n" +" packages\n" +" \n" +" \n" +" pkgname\n" +" foo\n" +" version\n" +" 2.0\n" +" pkgver\n" +" foo-2.0\n" +" \n" +" \n" +"\n" +"\n"; + +static const char axml[] = +"\n" +"\n" +"\n" +"\n" +" foo-1.0\n" +" blah-2.0\n" +"\n" +"\n"; + +static const char axml2[] = +"\n" +"\n" +"\n" +"\n" +" blah-2.0\n" +"\n" +"\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(); +} diff --git a/tests/libxbps/util/Makefile b/tests/libxbps/util/Makefile new file mode 100644 index 00000000..1a67815f --- /dev/null +++ b/tests/libxbps/util/Makefile @@ -0,0 +1,7 @@ +TOPDIR = ../../.. +-include $(TOPDIR)/config.mk + +TEST = util_test + +include ../Makefile.inc +include $(TOPDIR)/mk/test.mk diff --git a/tests/libxbps/util/main.c b/tests/libxbps/util/main.c new file mode 100644 index 00000000..affdca82 --- /dev/null +++ b/tests/libxbps/util/main.c @@ -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 +#include +#include + +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(); +}