try to make this testcase actually work
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 21 Aug 2006 16:19:44 +0000 (16:19 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 21 Aug 2006 16:19:44 +0000 (16:19 +0000)
testsuite/parser/Makefile.am
testsuite/parser/YUMParserTest.cc [new file with mode: 0644]

index 4df4ee5..dd59dc6 100644 (file)
@@ -7,9 +7,13 @@ PACKAGE = parser
 
 LDADD = $(top_srcdir)/zypp/lib@PACKAGE@.la
 
-noinst_PROGRAMS = YUMtest
+noinst_PROGRAMS = YUMtest YUMParserTest
 
 YUMtest_SOURCES = YUMtest.cc
+
+YUMParserTest_SOURCES = YUMParserTest.cc
+YUMParserTest_LDADD = $(LDADD) -lboost_unit_test_framework
+
 #YUMLeakTest_SOURCES = YUMLeakTest.cc
 
 EXTRA_DIST = lib/*.exp config/*.exp $(PACKAGE).test/*.exp
@@ -18,3 +22,7 @@ clean-local:
        rm -rf *.log
        rm -rf *.exp
        rm -rf tmp*
+
+.PHONY:        always
+
+$(noinst_PROGRAMS):    $(top_srcdir)/zypp/lib@PACKAGE@.la
\ No newline at end of file
diff --git a/testsuite/parser/YUMParserTest.cc b/testsuite/parser/YUMParserTest.cc
new file mode 100644 (file)
index 0000000..68fdfd0
--- /dev/null
@@ -0,0 +1,164 @@
+
+#include <boost/test/output_test_stream.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/test_tools.hpp>
+#include <boost/regex.hpp>
+
+#include "zypp/parser/yum/YUMParser.h"
+#include "zypp/base/Logger.h"
+#include "zypp/PathInfo.h"
+
+using namespace zypp;
+using namespace zypp::parser;
+using namespace zypp::parser::yum;
+using namespace std;
+using namespace boost;
+using namespace boost::unit_test;
+using namespace boost::test_tools;
+
+typedef std::list<Pathname> PathnameList;
+
+
+void parse( std::ostream &str, const std::string &type )
+{
+    if ( type == "repomd" )
+    {
+      YUMRepomdParser iter(cin,"");
+      for (;
+           !iter.atEnd();
+           ++iter) {
+             str << **iter;
+           }
+      if (iter.errorStatus())
+        throw *iter.errorStatus();
+    }
+    else if ( type == "primary")
+    {
+      YUMPrimaryParser iter(cin,"");
+      for (;
+           !iter.atEnd();
+           ++iter) {
+             str << **iter;
+           }
+      if (iter.errorStatus())
+        throw *iter.errorStatus();
+    }
+    else if ( type == "group")
+    {
+      YUMGroupParser iter(cin,"");
+      for (;
+           !iter.atEnd();
+           ++iter) {
+             str << **iter;
+           }
+      if (iter.errorStatus())
+        throw *iter.errorStatus();
+    }
+    else if ( type == "pattern" )
+    {
+      YUMPatternParser iter(cin,"");
+      for (;
+           !iter.atEnd();
+           ++iter) {
+             str << **iter;
+           }
+      if (iter.errorStatus())
+        throw *iter.errorStatus();
+    }
+    else if ( type == "filelist" )
+    {
+      YUMFileListParser iter(cin,"");
+      for (;
+           !iter.atEnd();
+           ++iter) {
+             str << **iter;
+           }
+      if (iter.errorStatus())
+        throw *iter.errorStatus();
+    }
+    else if ( type == "other" )
+    {
+      YUMOtherParser iter(cin,"");
+      for (;
+           !iter.atEnd();
+           ++iter) {
+             str << **iter;
+           }
+      if (iter.errorStatus())
+        throw *iter.errorStatus();
+    }
+    else if ( type == "patch" )
+    {
+      YUMPatchParser iter(cin,"");
+      for (;
+           !iter.atEnd();
+           ++iter) {
+             str << **iter;
+           }
+      if (iter.errorStatus())
+        throw *iter.errorStatus();
+    }
+    else if ( type == "patches" )
+    {
+      YUMPatchesParser iter(cin,"");
+      for (;
+           !iter.atEnd();
+           ++iter) {
+             str << **iter;
+           }
+      if (iter.errorStatus())
+        throw *iter.errorStatus();
+    }
+    else if ( type == "product" )
+    {
+      YUMProductParser iter(cin,"");
+      for (;
+           !iter.atEnd();
+           ++iter) {
+             str << **iter;
+           }
+      if (iter.errorStatus())
+        throw *iter.errorStatus();
+    }
+}
+
+void test_blah()
+{
+  PathnameList files;
+  readdir( files, "tests/" );
+  
+  boost::regex rxInput("^yum-(.+)-(.+)\\.xml$");
+  
+  for ( PathnameList::const_iterator it = files.begin(); it != files.end(); ++it )
+  { 
+    Pathname file = *it;
+    //std::cout << "processing: " << file << std::endl;
+    boost::smatch what;
+    if(boost::regex_match( file.basename(), what, rxInput, boost::match_extra))
+    {
+      //std::cout << what.size() << " matches" << std::endl;
+      std::cout << "processing input file: " << file << std::endl;
+      try
+      {
+        Pathname out_filename ( std::string("tests/yum-") + std::string(what[1]) + "-" + std::string(what[2]) + std::string(".out"));
+        std::cout << "output file: " << out_filename << std::endl;
+        output_test_stream output( out_filename.asString(), false);
+        parse( output, std::string(what[1]) );
+        
+        BOOST_CHECK( output.match_pattern() );
+      }
+      catch (XMLParserError& err) {
+        BOOST_FAIL( err.msg() << " " << err.position() );
+      }
+      
+    }
+  }
+}
+
+test_suite*
+init_unit_test_suite( int, char* [] )
+{
+  test_suite* test= BOOST_TEST_SUITE( "YUMParser" );
+  test->add( BOOST_TEST_CASE( &test_blah ), 0 /* expected zero error */ );
+  return test;
+}