[Aptitude-svn-commit] r3945 - in branches/aptitude-0.3/aptitude: .
tests
Daniel Burrows
dburrows at costa.debian.org
Thu Aug 25 00:25:00 UTC 2005
Author: dburrows
Date: Thu Aug 25 00:24:57 2005
New Revision: 3945
Added:
branches/aptitude-0.3/aptitude/tests/test_apt_universe.cc
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/tests/Makefile.am
Log:
Add a test of the apt universe conversion layer to tests/.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Thu Aug 25 00:24:57 2005
@@ -1,5 +1,10 @@
2005-08-24 Daniel Burrows <dburrows at debian.org>
+ * tests/Makefile.am, tests/test_apt_universe.cc:
+
+ Add tests for the graph-structure of the apt universe
+ translation layer.
+
* src/generic/problemresolver/solution.h, tests/test_resolver.h:
Avoid crashing in test code by making the tester a friend of the
Modified: branches/aptitude-0.3/aptitude/tests/Makefile.am
==============================================================================
--- branches/aptitude-0.3/aptitude/tests/Makefile.am (original)
+++ branches/aptitude-0.3/aptitude/tests/Makefile.am Thu Aug 25 00:24:57 2005
@@ -9,6 +9,7 @@
test_SOURCES = \
main.cc \
+ test_apt_universe.cc \
test_misc.cc \
test_resolver.cc \
test_tags.cc
\ No newline at end of file
Added: branches/aptitude-0.3/aptitude/tests/test_apt_universe.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/tests/test_apt_universe.cc Thu Aug 25 00:24:57 2005
@@ -0,0 +1,157 @@
+// test_apt_universe.cc -*-c++-*-
+//
+// Copyright (C) 2005 Daniel Burrows
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program 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; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+//
+// A test of the aptitude universe wrapper.
+
+#include <src/generic/aptitude_resolver.h>
+#include <src/generic/aptitude_resolver_universe.h>
+#include <src/generic/problemresolver/problemresolver.h>
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <apt-pkg/error.h>
+
+#include <sstream>
+
+class AptUniverseTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(AptUniverseTest);
+
+ CPPUNIT_TEST(testSolves);
+ CPPUNIT_TEST(testReverseConnectivity);
+
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp()
+ {
+ // TODO: load information from a custom location
+ apt_preinit();
+
+ _error->DumpErrors();
+
+ OpProgress p;
+ apt_init(&p, false);
+
+ _error->DumpErrors();
+ }
+
+ void tearDown()
+ {
+ // TODO: close the global cache file.
+ }
+
+ /** Test that solved_by() is a precise representation of the
+ * dependency solver graph, and incidentally (just to be anal) test
+ * that solvers appear exactly once in the global versions list and
+ * that each solver appears there.
+ */
+ void testSolves()
+ {
+ CPPUNIT_ASSERT(apt_cache_file != NULL);
+
+ aptitude_universe u(*apt_cache_file);
+
+ for(aptitude_universe::dep_iterator di = u.deps_begin();
+ !di.end(); ++di)
+ {
+ aptitude_universe::dep d = *di;
+ std::set<aptitude_universe::version> solvers;
+
+ for(aptitude_universe::dep::solver_iterator si
+ = d.solvers_begin(); !si.end(); ++si)
+ {
+ CPPUNIT_ASSERT(d.solved_by(*si));
+ solvers.insert(*si);
+ }
+
+ for(aptitude_universe::package_iterator pi
+ = u.packages_begin(); !pi.end(); ++pi)
+ for(aptitude_universe::package::version_iterator vi
+ = (*pi).versions_begin(); !vi.end(); ++vi)
+ {
+ if(solvers.find(*vi) == solvers.end())
+ CPPUNIT_ASSERT(!d.solved_by(*vi));
+ else
+ solvers.erase(*vi);
+ }
+
+ CPPUNIT_ASSERT(solvers.empty());
+ }
+ }
+
+ void testReverseConnectivity()
+ {
+ CPPUNIT_ASSERT(apt_cache_file != NULL);
+
+ aptitude_universe u(*apt_cache_file);
+
+ // For each dep, look at each of its solvers. For every /other/
+ // version of the solver that is not itself a solver, the
+ // dependency should appear in one of their revdep lists.
+
+ for(aptitude_universe::dep_iterator di = u.deps_begin();
+ !di.end(); ++di)
+ for(aptitude_universe::dep::solver_iterator si
+ = (*di).solvers_begin(); !si.end(); ++si)
+ {
+ bool found = false;
+
+ for(aptitude_universe::version::revdep_iterator rdi
+ = (*si).revdeps_begin(); !found && !rdi.end(); ++rdi)
+ if(*rdi == *di)
+ found = true;
+
+ if(found)
+ continue;
+
+ // If the above fails, then one of the other versions of the
+ // package must have this dep as a revdep.
+
+ for(aptitude_universe::package::version_iterator vi
+ = (*si).get_package().versions_begin(); !vi.end(); ++vi)
+ {
+ bool vi_found = false;
+ // NB: relies on the properties of solved_by tested above.
+ if(*vi != *si && !(*di).solved_by(*vi))
+ {
+ for(aptitude_universe::version::revdep_iterator rdi
+ = (*si).revdeps_begin();
+ !vi_found && !rdi.end(); ++rdi)
+ if(*rdi == *di)
+ vi_found = true;
+ }
+
+ if(!vi_found)
+ {
+ std::ostringstream out;
+ out << "The dependency " << *di
+ << " does not occur in the revdep list of either "
+ << (*si).get_package().get_name() << " "
+ << (*si).get_name() << " or "
+ << (*vi).get_package().get_name() << " "
+ << (*vi).get_name() << std::endl;
+ CPPUNIT_FAIL(out.str());
+ }
+ }
+ }
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(AptUniverseTest);
More information about the Aptitude-svn-commit
mailing list