aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-19 18:53:46 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-19 18:53:46 +0100
commita436158492bc800e1e588b96f3e00037bfe45f10 (patch)
treedded6665e1e8bdcfbfdab4c1de0a33c87c9b6ec2
parent62e333a285f16fa1404d974f6d62c580363eb029 (diff)
downloadpaludis-a436158492bc800e1e588b96f3e00037bfe45f10.tar.gz
paludis-a436158492bc800e1e588b96f3e00037bfe45f10.tar.xz
more tests
-rw-r--r--.gitignore1
-rw-r--r--paludis/resolver/Makefile.am17
-rw-r--r--paludis/resolver/resolver_TEST_serialisation.cc114
-rwxr-xr-xpaludis/resolver/resolver_TEST_serialisation_cleanup.sh9
-rwxr-xr-xpaludis/resolver/resolver_TEST_serialisation_setup.sh53
-rw-r--r--paludis/resolver/resolver_test.cc33
-rw-r--r--paludis/resolver/resolver_test.hh8
7 files changed, 235 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index fa4095f..2db0290 100644
--- a/.gitignore
+++ b/.gitignore
@@ -309,6 +309,7 @@ paludis-*.*.*.tar.bz2
/paludis/repositories/virtuals/virtuals_repository_TEST
/paludis/repository_name_cache_TEST
/paludis/resolver/resolver_TEST_blockers
+/paludis/resolver/resolver_TEST_serialisation
/paludis/resolver/resolver_TEST_suggestions
/paludis/resolver/resolver_TEST_virtuals
/paludis/selection_TEST
diff --git a/paludis/resolver/Makefile.am b/paludis/resolver/Makefile.am
index 335576d..225c027 100644
--- a/paludis/resolver/Makefile.am
+++ b/paludis/resolver/Makefile.am
@@ -82,6 +82,7 @@ noinst_LIBRARIES = libpaludisresolver.a
TESTS = \
resolver_TEST_blockers \
+ resolver_TEST_serialisation \
resolver_TEST_suggestions \
$(virtuals_tests)
endif
@@ -90,6 +91,7 @@ endif
check_PROGRAMS = $(TESTS)
check_SCRIPTS = \
resolver_TEST_blockers_setup.sh resolver_TEST_blockers_cleanup.sh \
+ resolver_TEST_serialisation_setup.sh resolver_TEST_serialisation_cleanup.sh \
resolver_TEST_suggestions_setup.sh resolver_TEST_suggestions_cleanup.sh \
resolver_TEST_virtuals_setup.sh resolver_TEST_virtuals_cleanup.sh
check_LIBRARIES = libpaludisresolvertest.a
@@ -143,6 +145,21 @@ resolver_TEST_suggestions_LDADD = \
resolver_TEST_suggestions_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
+resolver_TEST_serialisation_SOURCES = resolver_TEST_serialisation.cc
+
+resolver_TEST_serialisation_LDADD = \
+ libpaludisresolvertest.a \
+ $(top_builddir)/paludis/util/test_extras.o \
+ $(top_builddir)/test/libtest.a \
+ $(top_builddir)/paludis/environments/test/libpaludistestenvironment_@PALUDIS_PC_SLOT@.la \
+ $(top_builddir)/paludis/repositories/fake/libpaludisfakerepository_@PALUDIS_PC_SLOT@.la \
+ $(top_builddir)/paludis/libpaludis_@PALUDIS_PC_SLOT@.la \
+ $(top_builddir)/paludis/util/libpaludisutil_@PALUDIS_PC_SLOT@.la \
+ libpaludisresolver.a \
+ $(DYNAMIC_LD_LIBS)
+
+resolver_TEST_serialisation_CXXFLAGS = $(AM_CXXFLAGS) @PALUDIS_CXXFLAGS_NO_DEBUGGING@
+
built-sources : $(BUILT_SOURCES)
for s in `echo $(SUBDIRS) | tr -d .` ; do $(MAKE) -C $$s built-sources || exit 1 ; done
diff --git a/paludis/resolver/resolver_TEST_serialisation.cc b/paludis/resolver/resolver_TEST_serialisation.cc
new file mode 100644
index 0000000..8c0f4b5
--- /dev/null
+++ b/paludis/resolver/resolver_TEST_serialisation.cc
@@ -0,0 +1,114 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/resolver/resolver.hh>
+#include <paludis/resolver/resolver_functions.hh>
+#include <paludis/resolver/resolution.hh>
+#include <paludis/resolver/decision.hh>
+#include <paludis/resolver/resolutions.hh>
+#include <paludis/resolver/constraint.hh>
+#include <paludis/resolver/qpn_s.hh>
+#include <paludis/resolver/suggest_restart.hh>
+#include <paludis/resolver/serialise.hh>
+#include <paludis/environments/test/test_environment.hh>
+#include <paludis/util/make_named_values.hh>
+#include <paludis/util/options.hh>
+#include <paludis/util/wrapped_forward_iterator-impl.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/sequence.hh>
+#include <paludis/util/map.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/accept_visitor.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/repository_factory.hh>
+#include <paludis/package_database.hh>
+
+#include <paludis/resolver/resolver_test.hh>
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
+
+#include <list>
+#include <tr1/functional>
+#include <algorithm>
+#include <map>
+
+using namespace paludis;
+using namespace paludis::resolver;
+using namespace paludis::resolver::resolver_test;
+using namespace test;
+
+namespace
+{
+ struct ResolverSerialisationTestCase : ResolverTestCase
+ {
+ ResolverSerialisationTestCase(const std::string & s) :
+ ResolverTestCase("serialisation", s, "exheres-0", "exheres")
+ {
+ }
+ };
+}
+
+namespace test_cases
+{
+ struct TestSerialisation : ResolverSerialisationTestCase
+ {
+ TestSerialisation() : ResolverSerialisationTestCase("serialisation") { }
+
+ void run()
+ {
+ std::tr1::shared_ptr<const ResolutionLists> resolutions;
+ {
+ std::tr1::shared_ptr<const ResolutionLists> orig_resolutions(get_resolutions("serialisation/target"));
+ std::stringstream str;
+ Serialiser ser(str);
+ orig_resolutions->serialise(ser);
+
+ Deserialiser deser(&env, str.str());
+ Deserialisation desern("ResolutionLists", deser);
+ resolutions = make_shared_ptr(new ResolutionLists(ResolutionLists::deserialise(desern)));
+ }
+
+ {
+ TestMessageSuffix s("errors");
+ check_resolution_list(resolutions->errors(), ResolutionListChecks()
+ .kind(dk_unable_to_decide, QualifiedPackageName("serialisation/error"))
+ .finished()
+ );
+ }
+
+ {
+ TestMessageSuffix s("ordered");
+ check_resolution_list(resolutions->ordered(), ResolutionListChecks()
+ .qpn(QualifiedPackageName("serialisation/dep"))
+ .qpn(QualifiedPackageName("serialisation/target"))
+ .finished()
+ );
+ }
+
+ {
+ TestMessageSuffix s("untaken");
+ check_resolution_list(resolutions->untaken(), ResolutionListChecks()
+ .qpn(QualifiedPackageName("serialisation/suggestion"))
+ .finished()
+ );
+ }
+ }
+ } test_serialisation;
+}
+
diff --git a/paludis/resolver/resolver_TEST_serialisation_cleanup.sh b/paludis/resolver/resolver_TEST_serialisation_cleanup.sh
new file mode 100755
index 0000000..1abbdf8
--- /dev/null
+++ b/paludis/resolver/resolver_TEST_serialisation_cleanup.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d resolver_TEST_serialisation_dir ] ; then
+ rm -fr resolver_TEST_serialisation_dir
+else
+ true
+fi
+
diff --git a/paludis/resolver/resolver_TEST_serialisation_setup.sh b/paludis/resolver/resolver_TEST_serialisation_setup.sh
new file mode 100755
index 0000000..73ba965
--- /dev/null
+++ b/paludis/resolver/resolver_TEST_serialisation_setup.sh
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir resolver_TEST_serialisation_dir || exit 1
+cd resolver_TEST_serialisation_dir || exit 1
+
+mkdir -p build
+mkdir -p distdir
+mkdir -p installed
+
+mkdir -p repo/{profiles/profile,metadata}
+
+cd repo
+echo "repo" > profiles/repo_name
+: > metadata/categories.conf
+
+# serialisation
+echo 'serialisation' >> metadata/categories.conf
+
+mkdir -p 'packages/serialisation/target'
+cat <<END > packages/serialisation/target/target-1.exheres-0
+SUMMARY="target"
+PLATFORMS="test"
+SLOT="0"
+DEPENDENCIES="
+ ( build: serialisation/dep serialisation/error )
+ ( post,suggested: serialisation/suggestion )
+ "
+END
+
+mkdir -p 'packages/serialisation/dep'
+cat <<END > packages/serialisation/dep/dep-1.exheres-0
+SUMMARY="dep"
+PLATFORMS="test"
+SLOT="0"
+END
+
+mkdir -p 'packages/serialisation/suggestion'
+cat <<END > packages/serialisation/suggestion/suggestion-1.exheres-0
+SUMMARY="suggestion"
+PLATFORMS="test"
+SLOT="0"
+END
+
+mkdir -p 'packages/serialisation/error'
+cat <<END > packages/serialisation/error/error-1.exheres-0
+SUMMARY="error"
+SLOT="0"
+END
+
+cd ..
+
+
diff --git a/paludis/resolver/resolver_test.cc b/paludis/resolver/resolver_test.cc
index 1d7a676..58018c1 100644
--- a/paludis/resolver/resolver_test.cc
+++ b/paludis/resolver/resolver_test.cc
@@ -247,6 +247,29 @@ ResolverTestCase::ResolutionListChecks::check_qpn(const QualifiedPackageName & q
return r->decision()->if_package_id()->name() == q;
}
+bool
+ResolverTestCase::ResolutionListChecks::check_kind(const DecisionKind k,
+ const QualifiedPackageName & q, const std::tr1::shared_ptr<const Resolution> & r)
+{
+ if ((! r) || (! r->decision()))
+ return false;
+
+ return r->decision()->kind() == k && r->qpn_s().package() == q;
+}
+
+std::string
+ResolverTestCase::ResolutionListChecks::check_kind_msg(const DecisionKind k,
+ const QualifiedPackageName & q, const std::tr1::shared_ptr<const Resolution> & r)
+{
+ if (! r)
+ return "Expected " + stringify(k) + " " + stringify(q) + " but got finished";
+ else if (! r->decision())
+ return "Expected " + stringify(k) + " " + stringify(q) + " but got undecided for " + stringify(r->qpn_s());
+ else
+ return "Expected " + stringify(k) + " " + stringify(q) + " but got " + stringify(r->decision()->kind()) + " "
+ + stringify(r->qpn_s().package());
+}
+
std::string
ResolverTestCase::ResolutionListChecks::check_generic_msg(const std::string & q, const std::tr1::shared_ptr<const Resolution> & r)
{
@@ -291,6 +314,16 @@ ResolverTestCase::ResolutionListChecks::qpn(const QualifiedPackageName & q)
}
ResolverTestCase::ResolutionListChecks &
+ResolverTestCase::ResolutionListChecks::kind(const DecisionKind k, const QualifiedPackageName & q)
+{
+ checks.push_back(std::make_pair(
+ std::tr1::bind(&check_kind, k, q, std::tr1::placeholders::_1),
+ std::tr1::bind(&check_kind_msg, k, q, std::tr1::placeholders::_1)
+ ));
+ return *this;
+}
+
+ResolverTestCase::ResolutionListChecks &
ResolverTestCase::ResolutionListChecks::finished()
{
checks.push_back(std::make_pair(
diff --git a/paludis/resolver/resolver_test.hh b/paludis/resolver/resolver_test.hh
index cb0d60b..1e773df 100644
--- a/paludis/resolver/resolver_test.hh
+++ b/paludis/resolver/resolver_test.hh
@@ -27,6 +27,7 @@
#include <paludis/resolver/reason-fwd.hh>
#include <paludis/resolver/use_existing-fwd.hh>
#include <paludis/resolver/resolutions-fwd.hh>
+#include <paludis/resolver/decision-fwd.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/environments/test/test_environment.hh>
#include <paludis/util/map-fwd.hh>
@@ -99,8 +100,15 @@ namespace paludis
static std::string check_finished_msg(const std::tr1::shared_ptr<const Resolution> & r);
+ static bool check_kind(const DecisionKind, const QualifiedPackageName &, const std::tr1::shared_ptr<const Resolution> & r);
+
+ static std::string check_kind_msg(const DecisionKind, const QualifiedPackageName &,
+ const std::tr1::shared_ptr<const Resolution> & r);
+
ResolutionListChecks & qpn(const QualifiedPackageName & q);
+ ResolutionListChecks & kind(const DecisionKind, const QualifiedPackageName & q);
+
ResolutionListChecks & finished();
};