[Aptitude-svn-commit] r3660 - in branches/aptitude-0.3/aptitude: . src/generic src/generic/tests

Daniel Burrows dburrows at costa.debian.org
Fri Jul 22 05:41:29 UTC 2005


Author: dburrows
Date: Fri Jul 22 05:41:24 2005
New Revision: 3660

Added:
   branches/aptitude-0.3/aptitude/src/generic/tests/   (props changed)
   branches/aptitude-0.3/aptitude/src/generic/tests/Makefile.am
   branches/aptitude-0.3/aptitude/src/generic/tests/main.cc
   branches/aptitude-0.3/aptitude/src/generic/tests/test_tags.cc
Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/configure.ac
   branches/aptitude-0.3/aptitude/src/generic/Makefile.am
Log:
First steps towards unit tests.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Jul 22 05:41:24 2005
@@ -1,5 +1,9 @@
 2005-07-21  Daniel Burrows  <dburrows at debian.org>
 
+	* configure.ac, src/generic/Makefile.am, src/generic/tests/Makefile.am, src/generic/tests/main.cc, src/generic/tests/test_tags.cc:
+
+	  Add some basic magic to generate a unit tester with cppunit.
+
 	* src/generic/Makefile.am, src/generic/apt.cc, src/generic/tags.cc, src/generic/tags.h:
 
 	  Add backend support for parsing the new tag database.

Modified: branches/aptitude-0.3/aptitude/configure.ac
==============================================================================
--- branches/aptitude-0.3/aptitude/configure.ac	(original)
+++ branches/aptitude-0.3/aptitude/configure.ac	Fri Jul 22 05:41:24 2005
@@ -230,6 +230,7 @@
 	src/cmdline/Makefile
 	src/generic/Makefile
 	src/generic/problemresolver/Makefile
+	src/generic/tests/Makefile
 	src/mine/Makefile
 	src/vscreen/Makefile
 	src/vscreen/config/Makefile

Modified: branches/aptitude-0.3/aptitude/src/generic/Makefile.am
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/Makefile.am	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/Makefile.am	Fri Jul 22 05:41:24 2005
@@ -1,6 +1,6 @@
 MAINTAINERCLEANFILES=Makefile.in
 
-SUBDIRS=problemresolver
+SUBDIRS=problemresolver tests
 
 localedir = $(datadir)/locale
 INCLUDES = -Wall @WERROR@ -I../../ -I$(srcdir) -I$(top_srcdir)/lib -I../../intl

Added: branches/aptitude-0.3/aptitude/src/generic/tests/Makefile.am
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/tests/Makefile.am	Fri Jul 22 05:41:24 2005
@@ -0,0 +1,10 @@
+MAINTAINERCLEANFILES = Makefile.in
+
+INCLUDES = -Wall @WERROR@ -I../.. -I$(srcdir)
+LDADD = ../libgeneric.a -lcppunit
+
+noinst_PROGRAMS = test
+
+test_SOURCES = \
+	main.cc \
+	test_tags.cc
\ No newline at end of file

Added: branches/aptitude-0.3/aptitude/src/generic/tests/main.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/tests/main.cc	Fri Jul 22 05:41:24 2005
@@ -0,0 +1,34 @@
+// Main test program for the generic aptitude code.
+//
+//   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.
+
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+int main(int argc, char **argv[])
+{
+  CppUnit::TextUi::TestRunner runner;
+  CppUnit::TestFactoryRegistry &registry =
+    CppUnit::TestFactoryRegistry::getRegistry();
+
+  runner.addTest(registry.makeTest());
+
+  bool wasSuccessful = runner.run("", false);
+
+  return wasSuccessful;
+}

Added: branches/aptitude-0.3/aptitude/src/generic/tests/test_tags.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/generic/tests/test_tags.cc	Fri Jul 22 05:41:24 2005
@@ -0,0 +1,134 @@
+// Tester for the tag parser.
+//
+//   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.
+
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "../tags.h"
+
+#include <string.h>
+
+class TagTest : public CppUnit::TestFixture {
+  CPPUNIT_TEST_SUITE(TagTest);
+
+  CPPUNIT_TEST(testTagTraverse);
+  //CPPUNIT_TEST(testTagEqual);
+  //CPPUNIT_TEST(testTagOrder);
+  //CPPUNIT_TEST(testTagListTraverse);
+
+  CPPUNIT_TEST_SUITE_END();
+private:
+  static tag parseTag(const char *s)
+  {
+    return tag(s, s+strlen(s));
+  }
+
+  // These should all parse to (tag1, tag2, tag3):
+  static const char *basicTagEntries[];
+  // Erroneous entries.  Should parse as having no tags at all.
+  static const char *badEntry1;
+  static const char *badEntry2;
+  static const char *badEntry3;
+  static const char *badEntry4;
+
+  // Tag order checks.  The tag ordering function should say that
+  // forall n . tagorder[n]<tagorder[n+1]
+  static const char *tagorder[];
+  // Tag list checks.
+  static const char *tagLists[];
+  // One more test.
+  static const char *tagListLast;
+
+  // Checks that the given tag is "tag1::tag2::tag3".
+  void testTag123(const tag &t)
+  {
+    tag::const_iterator ti = t.begin();
+
+    CPPUNIT_ASSERT(ti != t.end());
+    CPPUNIT_ASSERT(*ti == "tag1");
+
+    ++ti;
+
+
+    CPPUNIT_ASSERT(ti != t.end());
+    CPPUNIT_ASSERT(*ti == "tag2");
+
+    ++ti;
+
+
+    CPPUNIT_ASSERT(ti != t.end());
+    CPPUNIT_ASSERT(*ti == "tag3");
+
+    ++ti;
+
+    CPPUNIT_ASSERT(ti == t.end());
+  }
+
+  void testTagTraverse()
+  {
+    const char **s=basicTagEntries;
+    while(*s)
+      {
+	tag parsed = parseTag(*s);
+	testTag123(parsed);
+	++s;
+      }
+  }
+};
+
+const char *TagTest::basicTagEntries[]={
+  "tag1::tag2::tag3",
+  "tag1 ::tag2::tag3",
+  "tag1:: tag2::tag3",
+  "  tag1::tag2::tag3",
+  "tag1::tag2::tag3  ",
+  "  tag1 :: tag2 :: tag3",
+  0
+};
+
+// Erroneous entries.  Should parse as having no tags at all.
+const char *TagTest::badEntry1="";
+const char *TagTest::badEntry2=0;
+const char *TagTest::badEntry3="   ";
+const char *TagTest::badEntry4="   ::    ";
+
+// Tag order checks.  The tag ordering function should say that
+// forall n . tagorder[n]<tagorder[n+1]
+const char *TagTest::tagorder[]={
+  "tag1 :: tag2::tag3",
+  "  tag1::tag3::tag3",
+  "tag2::tag1:: tag1",
+  "tag3::tag2::tag2",
+  "tag3::tag2::tag3",
+  0
+};
+
+// Tag list checks.
+const char *TagTest::tagLists[] = {
+  "a::b,c::d,e::f",
+  "a::b, c::d, e::f",
+  "  a::b,c::d,    e::f",
+  "a::b   ,   c::d   ,   e::f",
+  0
+};
+
+// One more test.
+const char *TagTest::tagListLast="  a  :: b";
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TagTest);



More information about the Aptitude-svn-commit mailing list