[Aptitude-svn-commit] r3852 - in branches/aptitude-0.3/aptitude: .
tests
Daniel Burrows
dburrows at costa.debian.org
Mon Aug 15 22:45:20 UTC 2005
Author: dburrows
Date: Mon Aug 15 22:45:17 2005
New Revision: 3852
Added:
branches/aptitude-0.3/aptitude/tests/test_resolver.cc
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/tests/Makefile.am
Log:
Add a future resolver test.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Mon Aug 15 22:45:17 2005
@@ -1,5 +1,9 @@
2005-08-15 Daniel Burrows <dburrows at debian.org>
+ * tests/Makefile.am, tests/test_resolver.cc:
+
+ Add a first iteration of a real test case for the resolver.
+
* src/generic/problemresolver/dummy_universe.cc, src/generic/problemresolver/dummy_universe.h, src/generic/problemresolver/test.cc:
Move some of the universe parsing code to the dummy_universe
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 Mon Aug 15 22:45:17 2005
@@ -1,7 +1,7 @@
MAINTAINERCLEANFILES = Makefile.in
INCLUDES = -Wall @WERROR@ -I../.. -I$(srcdir)
-LDADD = ../src/generic/libgeneric.a -lcppunit
+LDADD = ../src/generic/libgeneric.a ../src/generic/problemresolver/dummy_universe.o -lcppunit
check_PROGRAMS = test
@@ -10,4 +10,5 @@
test_SOURCES = \
main.cc \
test_misc.cc \
+ test_resolver.cc \
test_tags.cc
\ No newline at end of file
Added: branches/aptitude-0.3/aptitude/tests/test_resolver.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/tests/test_resolver.cc Mon Aug 15 22:45:17 2005
@@ -0,0 +1,117 @@
+// test_resolver.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 generic resolver layer.
+
+#include <src/generic/problemresolver/dummy_universe.h>
+#include <src/generic/problemresolver/problemresolver.h>
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <sstream>
+
+using namespace std;
+
+typedef generic_solution<dummy_universe> dummy_solution;
+
+const char *dummy_universe_1 = "\
+UNIVERSE [ \
+ PACKAGE a < v1 v2 v3 > v1 \
+ PACKAGE b < v1 v2 v3 > v1 \
+ PACKAGE c < v1 v2 v3 > v1 \
+\
+ DEP a v1 -> < b v2 > \
+ DEP b v2 -> < c v2 > \
+\
+ DEP a v2 -> < > \
+ DEP a v3 -> < > \
+]";
+
+class ResolverTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(ResolverTest);
+
+ CPPUNIT_TEST(testActionCompare);
+
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ static dummy_universe_ref parseUniverse(const std::string &s)
+ {
+ std::istringstream in(s);
+
+ return parse_universe(in);
+ }
+
+ /** Assert that two actions are equal. */
+ static void assertActionsEqual(const dummy_solution::action &a1,
+ const dummy_solution::action &a2)
+ {
+ CPPUNIT_ASSERT(a1 == a2);
+ CPPUNIT_ASSERT(!(a1 != a2));
+ CPPUNIT_ASSERT(!(a1 < a2));
+ CPPUNIT_ASSERT(!(a2 < a1));
+ }
+
+ /** Assert that two actions are inequal. */
+ static void assertActionsInequal(const dummy_solution::action &a1,
+ const dummy_solution::action &a2)
+ {
+ CPPUNIT_ASSERT(a1 != a2);
+ CPPUNIT_ASSERT(!(a1 == a2));
+ CPPUNIT_ASSERT(a1 < a2 || a2 < a1);
+ CPPUNIT_ASSERT(!(a1 < a2 && a2 < a1));
+ }
+
+ /** Test that the comparison operators on actions work. */
+ void testActionCompare()
+ {
+ dummy_universe_ref u = parseUniverse(dummy_universe_1);
+
+ // Grab two arbitrary deps.
+ dummy_universe::dep_iterator di = u.deps_begin();
+ CPPUNIT_ASSERT(!di.end());
+ dummy_universe::dep d1 = *di;
+ ++di;
+ CPPUNIT_ASSERT(!di.end());
+ dummy_universe::dep d2 = *di;
+
+ dummy_solution::action a1(u.find_package("a").version_from_name("v1"),
+ d1, 49);
+ dummy_solution::action a2(u.find_package("a").version_from_name("v1"),
+ d2, 21);
+
+ assertActionsEqual(a1, a2);
+
+ dummy_solution::action a3(u.find_package("a").version_from_name("v2"),
+ d1, 49);
+
+ assertActionsInequal(a1, a3);
+ assertActionsInequal(a2, a3);
+
+ dummy_solution::action a4(u.find_package("c").version_from_name("v3"),
+ d2, 21);
+
+ assertActionsInequal(a1, a4);
+ assertActionsInequal(a2, a4);
+ assertActionsInequal(a3, a4);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ResolverTest);
More information about the Aptitude-svn-commit
mailing list