summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/generic/problemresolver/choice_set.h23
-rw-r--r--tests/test_choice_set.cc45
2 files changed, 68 insertions, 0 deletions
diff --git a/src/generic/problemresolver/choice_set.h b/src/generic/problemresolver/choice_set.h
index e8bbc03e..5441856b 100644
--- a/src/generic/problemresolver/choice_set.h
+++ b/src/generic/problemresolver/choice_set.h
@@ -315,6 +315,29 @@ public:
install_version_choices.for_each(for_each_choice_pair<F>(f));
not_install_version_choices.for_each(f);
}
+
+ /** \brief Retrieve the version, if any, that was chosen for the
+ * given package.
+ *
+ * \param p The package to examine.
+ * \param out A location in which to store the retrieved version.
+ *
+ * \return \b true if a version of the package p is installed
+ * by this choice set; \b false if not (in which case out is
+ * unchanged).
+ */
+ bool get_version_of(const package &p, version &out) const
+ {
+ typename imm::map<package, choice>::node found = install_version_choices.lookup(p);
+
+ if(found.isValid())
+ {
+ out = found.getVal().second.get_ver();
+ return true;
+ }
+ else
+ return false;
+ }
};
template<typename PackageUniverse>
diff --git a/tests/test_choice_set.cc b/tests/test_choice_set.cc
index 163405e5..cd8feaae 100644
--- a/tests/test_choice_set.cc
+++ b/tests/test_choice_set.cc
@@ -43,6 +43,7 @@ class Choice_Set_Test : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE(Choice_Set_Test);
CPPUNIT_TEST(testInsertNarrow);
+ CPPUNIT_TEST(testGetVersionOf);
CPPUNIT_TEST(testContainsChoice);
CPPUNIT_TEST(testContainsChoiceSet);
// No test for for_each(), because it's tested in testInsertNarrow
@@ -251,6 +252,50 @@ public:
CPPUNIT_ASSERT(!s.contains(make_break_soft_dep(av3d1)));
}
+ void testGetVersionOf()
+ {
+ dummy_universe_ref u(parseUniverse(dummy_universe_1));
+
+ package a(u.find_package("a"));
+ package b(u.find_package("b"));
+ package c(u.find_package("c"));
+
+ version av1(a.version_from_name("v1"));
+ version av2(a.version_from_name("v2"));
+ version av3(a.version_from_name("v3"));
+
+ version bv1(b.version_from_name("v1"));
+ version bv2(b.version_from_name("v2"));
+ version bv3(b.version_from_name("v3"));
+
+ version cv1(c.version_from_name("v1"));
+ version cv2(c.version_from_name("v2"));
+ version cv3(c.version_from_name("v3"));
+
+ dep av1d1(*av1.deps_begin());
+ dep bv2d1(*bv2.deps_begin());
+ dep av2d1(*av2.deps_begin());
+ dep av3d1(*av3.deps_begin());
+
+
+ choice_set s;
+ s.insert_or_narrow(choice::make_install_version(av1, -1));
+ s.insert_or_narrow(choice::make_install_version(bv3, -1));
+
+ version v;
+ CPPUNIT_ASSERT(s.get_version_of(a, v));
+ CPPUNIT_ASSERT_EQUAL(av1, v);
+
+ CPPUNIT_ASSERT(s.get_version_of(b, v));
+ CPPUNIT_ASSERT_EQUAL(bv3, v);
+
+ s.insert_or_narrow(choice::make_install_version_from_dep_source(bv3, bv2d1, -1));
+ CPPUNIT_ASSERT(s.get_version_of(b, v));
+ CPPUNIT_ASSERT_EQUAL(bv3, v);
+
+ CPPUNIT_ASSERT(!s.get_version_of(c, v));
+ }
+
void testContainsChoiceSet()
{
dummy_universe_ref u(parseUniverse(dummy_universe_1));