Commit Kyua/ATF test suite for libxbps.
This commit is contained in:
parent
35c2e2a75d
commit
d4f623e7e7
4
Makefile
4
Makefile
@ -6,6 +6,10 @@ ifdef BUILD_API_DOCS
|
|||||||
SUBDIRS += doc
|
SUBDIRS += doc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifdef BUILD_TESTS
|
||||||
|
SUBDIRS += tests
|
||||||
|
endif
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all:
|
all:
|
||||||
@for dir in $(SUBDIRS); do \
|
@for dir in $(SUBDIRS); do \
|
||||||
|
24
bin/Makefile
24
bin/Makefile
@ -5,26 +5,4 @@ SUBDIRS += xbps-repo
|
|||||||
SUBDIRS += xbps-dgraph
|
SUBDIRS += xbps-dgraph
|
||||||
SUBDIRS += xbps-uhelper
|
SUBDIRS += xbps-uhelper
|
||||||
|
|
||||||
.PHONY: all
|
include ../mk/subdir.mk
|
||||||
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
|
|
||||||
|
@ -11,4 +11,4 @@ OBJS += check_pkg_requiredby.o
|
|||||||
OBJS += show-orphans.o unpack_cb.o list.o
|
OBJS += show-orphans.o unpack_cb.o list.o
|
||||||
MAN = $(BIN).8
|
MAN = $(BIN).8
|
||||||
|
|
||||||
include $(TOPDIR)/bin/prog.mk
|
include $(TOPDIR)/mk/prog.mk
|
||||||
|
@ -3,4 +3,4 @@ TOPDIR = ../..
|
|||||||
|
|
||||||
BIN = xbps-dgraph
|
BIN = xbps-dgraph
|
||||||
|
|
||||||
include $(TOPDIR)/bin/prog.mk
|
include $(TOPDIR)/mk/prog.mk
|
||||||
|
@ -8,4 +8,4 @@ OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o
|
|||||||
OBJS += ../xbps-bin/state_cb.o ../xbps-bin/list.o
|
OBJS += ../xbps-bin/state_cb.o ../xbps-bin/list.o
|
||||||
MAN = $(BIN).8
|
MAN = $(BIN).8
|
||||||
|
|
||||||
include $(TOPDIR)/bin/prog.mk
|
include $(TOPDIR)/mk/prog.mk
|
||||||
|
@ -4,4 +4,4 @@ TOPDIR = ../..
|
|||||||
BIN = xbps-uhelper
|
BIN = xbps-uhelper
|
||||||
OBJS = main.o ../xbps-bin/fetch_cb.o
|
OBJS = main.o ../xbps-bin/fetch_cb.o
|
||||||
|
|
||||||
include $(TOPDIR)/bin/prog.mk
|
include $(TOPDIR)/mk/prog.mk
|
||||||
|
28
configure
vendored
28
configure
vendored
@ -12,6 +12,7 @@ BUILD=
|
|||||||
HOST=
|
HOST=
|
||||||
TARGET=
|
TARGET=
|
||||||
DEBUG=
|
DEBUG=
|
||||||
|
BUILD_TESTS=
|
||||||
BUILD_API_DOCS=
|
BUILD_API_DOCS=
|
||||||
BUILD_PIE=
|
BUILD_PIE=
|
||||||
SILENT=yes
|
SILENT=yes
|
||||||
@ -40,8 +41,9 @@ for instance \`--prefix=\$HOME'.
|
|||||||
--debug Build with debugging code and symbols
|
--debug Build with debugging code and symbols
|
||||||
--verbose Disable silent build to see compilation details
|
--verbose Disable silent build to see compilation details
|
||||||
--with-pie Build XBPS programs as PIE (default disabled)
|
--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
|
_EOF
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@ -67,6 +69,7 @@ for x; do
|
|||||||
--verbose) unset SILENT;;
|
--verbose) unset SILENT;;
|
||||||
--with-pie) BUILD_PIE=$var;;
|
--with-pie) BUILD_PIE=$var;;
|
||||||
--pkgconfigdir) PKGCONFIGDIR=$var;;
|
--pkgconfigdir) PKGCONFIGDIR=$var;;
|
||||||
|
--with-tests) BUILD_TESTS=yes;;
|
||||||
--help) usage;;
|
--help) usage;;
|
||||||
*) echo "$0: WARNING: unknown option $opt" >&2;;
|
*) echo "$0: WARNING: unknown option $opt" >&2;;
|
||||||
esac
|
esac
|
||||||
@ -84,6 +87,7 @@ done
|
|||||||
: ${INCLUDEDIR:=${EPREFIX}/include}
|
: ${INCLUDEDIR:=${EPREFIX}/include}
|
||||||
: ${ETCDIR:=${PREFIX}/etc}
|
: ${ETCDIR:=${PREFIX}/etc}
|
||||||
: ${PKGCONFIGDIR:=${LIBDIR}/pkgconfig}
|
: ${PKGCONFIGDIR:=${LIBDIR}/pkgconfig}
|
||||||
|
: ${TESTSDIR:=${EPREFIX}/tests}
|
||||||
: ${TOPDIR:=..}
|
: ${TOPDIR:=..}
|
||||||
|
|
||||||
_which()
|
_which()
|
||||||
@ -144,6 +148,7 @@ echo "LIBDIR ?= $LIBDIR" >>$CONFIG_MK
|
|||||||
echo "MANDIR ?= $MANDIR" >>$CONFIG_MK
|
echo "MANDIR ?= $MANDIR" >>$CONFIG_MK
|
||||||
echo "SHAREDIR ?= $SHAREDIR" >>$CONFIG_MK
|
echo "SHAREDIR ?= $SHAREDIR" >>$CONFIG_MK
|
||||||
echo "PKGCONFIGDIR ?= $PKGCONFIGDIR" >>$CONFIG_MK
|
echo "PKGCONFIGDIR ?= $PKGCONFIGDIR" >>$CONFIG_MK
|
||||||
|
echo "TESTSDIR ?= $TESTSDIR" >>$CONFIG_MK
|
||||||
|
|
||||||
ETCDIR="${ETCDIR}/xbps"
|
ETCDIR="${ETCDIR}/xbps"
|
||||||
echo "ETCDIR ?= $ETCDIR" >>$CONFIG_MK
|
echo "ETCDIR ?= $ETCDIR" >>$CONFIG_MK
|
||||||
@ -591,6 +596,24 @@ else
|
|||||||
>>$CONFIG_MK
|
>>$CONFIG_MK
|
||||||
fi
|
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
|
if [ -n "$SILENT" ]; then
|
||||||
echo "SILENT = @" >>$CONFIG_MK
|
echo "SILENT = @" >>$CONFIG_MK
|
||||||
else
|
else
|
||||||
@ -617,6 +640,7 @@ if [ -n "$LDFLAGS" ]; then
|
|||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
echo " Build API documentation = $BUILD_API_DOCS_VALUE"
|
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 programs as PIE = $BUILD_PIE_VAL"
|
||||||
echo " Build with debug = $DEBUG"
|
echo " Build with debug = $DEBUG"
|
||||||
echo " Use external proplib = $PROPLIB"
|
echo " Use external proplib = $PROPLIB"
|
||||||
|
23
mk/subdir.mk
Normal file
23
mk/subdir.mk
Normal file
@ -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
|
29
mk/test.mk
Normal file
29
mk/test.mk
Normal file
@ -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 $@
|
||||||
|
|
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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user