Mailinglist Archive: zypp-commit (149 mails)

< Previous Next >
[zypp-commit] r5374 - in /trunk/libzypp/tests/parser/yum: CMakeLists.txt PatchesFileReader_test.cc RepomdFileReader_test.cc data/patches-1.xml data/patches-1.xml.solution data/patches.xml data/patches.xml.solution
  • From: dmacvicar@xxxxxxxxxxxxxxxx
  • Date: Fri, 13 Apr 2007 12:10:53 -0000
  • Message-id: <20070413121053.6897B236ED@xxxxxxxxxxxxxxxx>
Author: dmacvicar
Date: Fri Apr 13 14:10:53 2007
New Revision: 5374

URL: http://svn.opensuse.org/viewcvs/zypp?rev=5374&view=rev
Log:
test for PatchesFileReader

Added:
    trunk/libzypp/tests/parser/yum/PatchesFileReader_test.cc
    trunk/libzypp/tests/parser/yum/data/patches-1.xml
      - copied unchanged from r5373, trunk/libzypp/tests/parser/yum/data/patches.xml
    trunk/libzypp/tests/parser/yum/data/patches-1.xml.solution
      - copied, changed from r5373, trunk/libzypp/tests/parser/yum/data/patches.xml.solution
Removed:
    trunk/libzypp/tests/parser/yum/data/patches.xml
    trunk/libzypp/tests/parser/yum/data/patches.xml.solution
Modified:
    trunk/libzypp/tests/parser/yum/CMakeLists.txt
    trunk/libzypp/tests/parser/yum/RepomdFileReader_test.cc

Modified: trunk/libzypp/tests/parser/yum/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/parser/yum/CMakeLists.txt?rev=5374&r1=5373&r2=5374&view=diff
==============================================================================
--- trunk/libzypp/tests/parser/yum/CMakeLists.txt (original)
+++ trunk/libzypp/tests/parser/yum/CMakeLists.txt Fri Apr 13 14:10:53 2007
@@ -1,4 +1,8 @@
 ADD_EXECUTABLE( RepomdFileReader RepomdFileReader_test.cc )
 TARGET_LINK_LIBRARIES( RepomdFileReader zypp boost_unit_test_framework )
 
-ADD_TEST(RepomdFileReader ${CMAKE_CURRENT_BINARY_DIR}/RepomdFileReader ${CMAKE_CURRENT_SOURCE_DIR}/data )
\ No newline at end of file
+ADD_EXECUTABLE( PatchesFileReader PatchesFileReader_test.cc )
+TARGET_LINK_LIBRARIES( PatchesFileReader zypp boost_unit_test_framework )
+
+ADD_TEST(RepomdFileReader ${CMAKE_CURRENT_BINARY_DIR}/RepomdFileReader ${CMAKE_CURRENT_SOURCE_DIR}/data )
+ADD_TEST(PatchesFileReader ${CMAKE_CURRENT_BINARY_DIR}/PatchesFileReader ${CMAKE_CURRENT_SOURCE_DIR}/data )
\ No newline at end of file

Added: trunk/libzypp/tests/parser/yum/PatchesFileReader_test.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/parser/yum/PatchesFileReader_test.cc?rev=5374&view=auto
==============================================================================
--- trunk/libzypp/tests/parser/yum/PatchesFileReader_test.cc (added)
+++ trunk/libzypp/tests/parser/yum/PatchesFileReader_test.cc Fri Apr 13 14:10:53 2007
@@ -0,0 +1,108 @@
+#include <stdio.h>
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <list>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/parameterized_test.hpp>
+#include <boost/test/unit_test_log.hpp>
+
+#include "zypp/parser/yum/PatchesFileReader.h"
+#include "zypp/Url.h"
+#include "zypp/PathInfo.h"
+
+using std::cout;
+using std::endl;
+using std::string;
+using namespace zypp;
+using namespace boost::unit_test;
+
+using namespace zypp::source::yum;
+
+class Collector
+{
+public:
+  Collector()
+  {}
+  
+  bool callback( const OnMediaLocation &loc, const string &id )
+  {
+    items.push_back( make_pair( id, loc ) );
+    //items.push_back(loc);
+    //cout << items.size() << endl;
+    return true;
+  }
+  
+  vector<pair<string, OnMediaLocation> > items;
+  //vector<OnMediaLocation> items;
+};
+
+void patches_read_test(const string &dir)
+{
+  list<Pathname> entries;
+  if ( filesystem::readdir( entries, Pathname(dir), false ) != 0 )
+    ZYPP_THROW(Exception("failed to read directory"));
+  
+  for ( list<Pathname>::const_iterator it = entries.begin(); it != entries.end(); ++it )
+  {
+    Pathname file = *it;
+    //cout << file.basename().substr(0, 7) << " " << file.extension() << endl;
+    if ( ( file.basename().substr(0, 7) == "patches" ) && (file.extension() == ".xml" ) )
+    {
+      //cout << *it << endl;
+      
+      Collector collect;
+      PatchesFileReader( file, bind( &Collector::callback, &collect, _1, _2 ));
+      
+      std::ifstream ifs( file.extend(".solution").asString().c_str() );
+      cout << "Comparing to " << file.extend(".solution") << endl;
+      int count = 0;
+      while ( ifs && ! ifs.eof() && count < collect.items.size() )
+      {
+        string id;
+        string checksum_type;
+        string checksum;
+        string loc;
+        
+        getline(ifs, id);
+        BOOST_CHECK_EQUAL( collect.items[count].first, id);
+        getline(ifs, checksum_type);
+        getline(ifs, checksum);
+        BOOST_CHECK_EQUAL( collect.items[count].second.checksum(), CheckSum(checksum_type, checksum) );
+        getline(ifs, loc);
+        BOOST_CHECK_EQUAL( collect.items[count].second.filename(), Pathname(loc) );
+        
+        count++;
+      }
+      BOOST_CHECK_EQUAL( collect.items.size(), count );
+    }
+  }
+}
+
+test_suite*
+init_unit_test_suite( int argc, char *argv[] )
+{
+  string datadir;
+  if (argc < 2)
+  {
+    datadir = TESTS_SRC_DIR;
+    datadir = (Pathname(datadir) + "/parser/yum/data").asString();
+    cout << "PatchesFileReader_test:"
+      " path to directory with test data required as parameter. Using " << datadir  << endl;
+    //return (test_suite *)0;
+    
+  }
+  else
+  {
+    datadir = argv[1];
+  }
+  
+  test_suite* test= BOOST_TEST_SUITE("PatchesFileReader");
+  
+  std::string const params[] = { datadir };
+  test->add(BOOST_PARAM_TEST_CASE(&patches_read_test,
+                                 (std::string const*)params, params+1));
+  return test;
+}
+
+// vim: set ts=2 sts=2 sw=2 ai et:

Modified: trunk/libzypp/tests/parser/yum/RepomdFileReader_test.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/parser/yum/RepomdFileReader_test.cc?rev=5374&r1=5373&r2=5374&view=diff
==============================================================================
--- trunk/libzypp/tests/parser/yum/RepomdFileReader_test.cc (original)
+++ trunk/libzypp/tests/parser/yum/RepomdFileReader_test.cc Fri Apr 13 14:10:53 2007
@@ -40,7 +40,9 @@
 void repomd_read_test(const string &dir)
 {
   list<Pathname> entries;
-  filesystem::readdir( entries, Pathname(dir), false );
+  if ( filesystem::readdir( entries, Pathname(dir), false ) != 0 )
+    ZYPP_THROW(Exception("failed to read directory"));
+    
   for ( list<Pathname>::const_iterator it = entries.begin(); it != entries.end(); ++it )
   {
     Pathname file = *it;

Copied: trunk/libzypp/tests/parser/yum/data/patches-1.xml.solution (from r5373, trunk/libzypp/tests/parser/yum/data/patches.xml.solution)
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/parser/yum/data/patches-1.xml.solution?p2=trunk/libzypp/tests/parser/yum/data/patches-1.xml.solution&p1=trunk/libzypp/tests/parser/yum/data/patches.xml.solution&r1=5373&r2=5374&rev=5374&view=diff
==============================================================================
--- trunk/libzypp/tests/parser/yum/data/patches.xml.solution (original)
+++ trunk/libzypp/tests/parser/yum/data/patches-1.xml.solution Fri Apr 13 14:10:53 2007
@@ -1,4 +1,4 @@
-<?xml version="1.0"?> fetchmsttfonts.sh-2333
+fetchmsttfonts.sh-2333
 sha
 6b72b4f3617d0d51af28399c0f5e0af401440245
 repodata/patch-fetchmsttfonts.sh-2333.xml

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages