Author: dmacvicar
Date: Thu Jul 12 16:56:24 2007
New Revision: 5995
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5995&view=rev
Log:
- add output iterator support for ResStore
- Cache store test improvements...
Modified:
branches/REFACTORING-10_3/libzypp/tests/cache/CacheStore_test.cc
branches/REFACTORING-10_3/libzypp/zypp/ResStore.h
Modified: branches/REFACTORING-10_3/libzypp/tests/cache/CacheStore_test.cc
URL: http://svn.opensuse.org/viewcvs/zypp/branches/REFACTORING-10_3/libzypp/tests/cache/CacheStore_test.cc?rev=5995&r1=5994&r2=5995&view=diff
==============================================================================
--- branches/REFACTORING-10_3/libzypp/tests/cache/CacheStore_test.cc (original)
+++ branches/REFACTORING-10_3/libzypp/tests/cache/CacheStore_test.cc Thu Jul 12 16:56:24 2007
@@ -17,6 +17,7 @@
#include "zypp/RepoInfo.h"
#include "zypp/repo/cached/RepoImpl.h"
#include "zypp/parser/yum/RepoParser.h"
+#include "zypp/parser/susetags/RepoParser.h"
#include "zypp/Url.h"
#include "zypp/NVRA.h"
#include "zypp/PathInfo.h"
@@ -24,8 +25,6 @@
#include "zypp/Package.h"
-#include "SimplePackagesParser.h"
-
using namespace std;
using namespace zypp;
using namespace zypp::parser;
@@ -34,53 +33,43 @@
using namespace boost::unit_test;
using namespace sqlite3x;
-void cache_write_test(const string &dir)
+/**
+ * \short Asserts a package against a fixed package
+ *
+ * kdelibs3 357-24 i586
+ */
+void check_kdelibs3_package( Package::Ptr p )
{
- Pathname repodir = Pathname(dir) + "/cache/data";
- data::RecordId repository_id;
- filesystem::TmpDir tmpdir;
- {
- Pathname nvra_list = Pathname(repodir) + "package-set.txt.gz";
- list<MiniResolvable> res_list;
-
- parse_mini_file( nvra_list, res_list );
-
- cache::CacheStore store(tmpdir.path());
-
- repository_id = store.lookupOrAppendRepository("novell.com");
-
- zypp::debug::Measure cap_parse_timer("store resolvables");
- for ( list<MiniResolvable>::iterator it = res_list.begin(); it != res_list.end(); it++)
- {
- data::RecordId id = store.appendResolvable( repository_id,
- ResTraits<Package>::kind,
- (*it).nvra,
- (*it).deps );
- }
- store.commit();
- }
- {
- MIL << "now read resolvables" << endl;
-
- cached::RepoImpl *repositoryImpl = new cached::RepoImpl( cached::RepoOptions( RepoInfo(), tmpdir.path(), repository_id ));
- //RepositoryFactory factory;
- //Repository_Ref repository = factory.createFrom(repositoryImpl);
- repositoryImpl->createResolvables();
- ResStore dbres = repositoryImpl->resolvables();
-
- MIL << dbres.size() << " resolvables" << endl;
- }
+ // check authors and timestamp?
+// =Tim: 1183399094
+// +Aut:
+// The KDE Team
+// -Aut:
+//
+ BOOST_CHECK_EQUAL( p->name(), "kdelibs3");
+ BOOST_CHECK_EQUAL( p->edition(), Edition("3.5.7", "24") );
+ BOOST_CHECK_EQUAL( p->arch(), Arch("i586") );
+ BOOST_CHECK_EQUAL( p->summary(), "KDE Base Libraries" );
+ BOOST_CHECK_EQUAL( p->description().substr(0, 16), "<!-- DT:Rich -->");
+ //BOOST_CHECK_EQUAL( p->packager(), "http://bugs.opensuse.org");
+ //BOOST_CHECK_EQUAL( p->url(), "http://glabels.sourceforge.net/");
+ BOOST_CHECK_EQUAL( p->group(), "System/GUI/KDE");
+ //BOOST_CHECK_EQUAL( p->buildhost(), "dale.suse.de");
+ //BOOST_CHECK_EQUAL( p->vendor(), "SUSE LINUX Products GmbH, Nuernberg, Germany");
+ BOOST_CHECK_EQUAL( p->license(), "BSD License and BSD-like, GNU General Public License (GPL)");
+ BOOST_CHECK_EQUAL( p->location().checksum(), CheckSum("sha1", "05f0647241433d01636785fd282cc824a6527269"));
+ BOOST_CHECK_EQUAL( p->location().filename(), Pathname("./suse/i586/kdelibs3-3.5.7-24.i586.rpm"));
+ BOOST_CHECK_EQUAL( p->size(), 38850584);
+ BOOST_CHECK_EQUAL( p->location().downloadSize(), 16356019);
}
+/**
+ * \short Asserts a package against a fixed package
+ *
+ * glabels 2.0.4-30.2-0 i586
+ */
void check_glabels_package( Package::Ptr p )
{
-//<checksum type="sha" pkgid="YES">34adf06a0c4873b9d53b4634beb8bee458b45767</checksum>
-// <time file="1165536261" build="1165501960"/>
-// <size package="983124" installed="2257356" archive="2271256"/>
-// <location href="rpm/i586/glabels-2.0.4-30.2.i586.rpm"/>
-
- MIL << "package group: " << p->group()<< endl;
-
BOOST_CHECK_EQUAL( p->name(), "glabels");
BOOST_CHECK_EQUAL( p->edition(), Edition("2.0.4", "30.2", "0") );
BOOST_CHECK_EQUAL( p->arch(), Arch("i586") );
@@ -88,104 +77,196 @@
BOOST_CHECK_EQUAL( p->description().substr(0, 20), "Labels is a powerful");
BOOST_CHECK_EQUAL( p->packager(), "http://bugs.opensuse.org");
BOOST_CHECK_EQUAL( p->url(), "http://glabels.sourceforge.net/");
-
+ BOOST_CHECK_EQUAL( p->group(), "Productivity/Office/Other");
+ BOOST_CHECK_EQUAL( p->buildhost(), "dale.suse.de");
+ BOOST_CHECK_EQUAL( p->vendor(), "SUSE LINUX Products GmbH, Nuernberg, Germany");
+ BOOST_CHECK_EQUAL( p->license(), "GNU General Public License (GPL)");
+ BOOST_CHECK_EQUAL( p->location().checksum(), CheckSum("sha1", "34adf06a0c4873b9d53b4634beb8bee458b45767"));
+ BOOST_CHECK_EQUAL( p->location().filename(), Pathname("rpm/i586/glabels-2.0.4-30.2.i586.rpm"));
BOOST_CHECK_EQUAL( p->size(), 2257356);
BOOST_CHECK_EQUAL( p->location().downloadSize(), 983124);
-
- BOOST_CHECK_MESSAGE( !p->group().empty(), "Package group not empty");
- MIL << "package location: " << p->location()<< endl;
- BOOST_CHECK_MESSAGE( !p->location().filename().empty(), "Package group not empty");
}
-void cache_write_test2(const string &dir)
+/**
+ * \short assert that tables are clean after removing a repo
+ *
+ * \note the only tables allowed to keep data are normalized
+ * tables like names, files. Those should be cleaned using
+ * a more smart vacuum
+ */
+void check_tables_clean( filesystem::TmpDir tmpdir )
{
- data::RecordId repository_id;
- Pathname repodir = Pathname(dir) + "/repo/yum/data/10.2-updates-subset";
- filesystem::TmpDir tmpdir;
+ cache::CacheStore store(tmpdir.path());
+ data::RecordId repository_id = store.lookupOrAppendRepository("novell.com");
+ store.cleanRepository(repository_id);
+ store.commit();
+
+ sqlite3_connection con((tmpdir.path() + "zypp.db").c_str());
+ int count;
+
+ sqlite3_command tables_cmd( con, "select name from sqlite_master where type='table';");
+ sqlite3_reader reader = tables_cmd.executereader();
+ list<string> tables;
+ while ( reader.read() )
{
- cache::CacheStore store(tmpdir.path());
- repository_id = store.lookupOrAppendRepository("novell.com");
-
- zypp::debug::Measure repo_write_timer("store resolvables");
+ string tablename = reader.getstring(0);
+ if (
+ (tablename == "sqlite_sequence" ) ||
+ (tablename == "db_info" ) ||
+ (tablename == "types" ) ||
+ (tablename == "names" ) ||
+ (tablename == "file_names" ) ||
+ (tablename == "dir_names" ) ||
+ (tablename == "files" )
+ )
+ continue;
- yum::RepoParser parser( repository_id, store);
- parser.parse(repodir);
- store.commit();
+ tables.push_back(tablename);
}
+ reader.close();
+
+ for ( list<string>::const_iterator it = tables.begin();
+ it != tables.end();
+ ++it )
{
- MIL << "now read resolvables" << endl;
+ MIL << "Checking table " << *it << endl;
+ string query = (string("select count(*) from ") + (*it) +";");
+ sqlite3_command cmd(con, query.c_str());
+ count = cmd.executeint();
+ string msg = (string("there should be no ") + (*it) +" after cleaning");
+ BOOST_CHECK_MESSAGE( count == 0, msg.c_str());
+ }
+}
+
+/**
+ * \short Write a YUM repo to the cache
+ */
+void write_yum_repo( const string &alias,
+ const Pathname &repodir,
+ filesystem::TmpDir tmpdir )
+{
+ data::RecordId repository_id;
+ cache::CacheStore store(tmpdir.path());
+ repository_id = store.lookupOrAppendRepository(alias);
- zypp::debug::Measure repo_read_timer("read resolvables");
- cached::RepoImpl *repositoryImpl = new cached::RepoImpl( cached::RepoOptions( RepoInfo(), tmpdir.path(), repository_id ));
- //RepositoryFactory factory;
- //Repository_Ref repository = factory.createFrom(repositoryImpl);
- repositoryImpl->createResolvables();
- ResStore dbres = repositoryImpl->resolvables();
-
- MIL << dbres.size() << " resolvables" << endl;
+ zypp::debug::Measure repo_write_timer("store resolvables");
+
+ yum::RepoParser parser( repository_id, store);
+ parser.parse(repodir);
+ store.commit();
+}
+
+/**
+ * \short Write a SUSETAGS repo to the cache
+ */
+void write_susetags_repo( const string &alias,
+ const Pathname &repodir,
+ filesystem::TmpDir tmpdir )
+{
+ data::RecordId repository_id;
+ cache::CacheStore store(tmpdir.path());
+ repository_id = store.lookupOrAppendRepository(alias);
- bool found_glabels_i586 = false;
- for ( ResStore::const_iterator it = dbres.begin();
- it != dbres.end();
- ++it )
- {
- if ( isKind<Package>(*it) )
- {
- Package::Ptr p = asKind<Package>(*it);
- if ( (p->name() == "glabels") && p->arch() == Arch("i586") )
- {
- found_glabels_i586 = true;
- check_glabels_package(p);
- }
- }
- }
- BOOST_CHECK_MESSAGE( found_glabels_i586, "Package glabels i586 should be in cache");
- }
+ zypp::debug::Measure repo_write_timer("store resolvables");
+
+ susetags::RepoParser parser( repository_id, store);
+ parser.parse(repodir);
+ store.commit();
+}
+
+/**
+ * \short get resolvables from the cache
+ */
+ResStore get_resolvables( const string &alias,
+ filesystem::TmpDir tmpdir )
+{
+ MIL << "now read resolvables" << endl;
- // now clean the repo and check everything is clean
+ data::RecordId repository_id;
{
cache::CacheStore store(tmpdir.path());
- repository_id = store.lookupOrAppendRepository("novell.com");
- store.cleanRepository(repository_id);
- store.commit();
+ repository_id = store.lookupOrAppendRepository(alias);
}
+ zypp::debug::Measure repo_read_timer("read resolvables");
+ cached::RepoImpl *repositoryImpl = new cached::RepoImpl( cached::RepoOptions( RepoInfo(),
+ tmpdir.path(),
+ repository_id ));
+ return repositoryImpl->resolvables();
+}
+
+/**
+ * \short Test that a yum repo is cached and restored
+ */
+void cache_write_yum_test(const string &dir)
+{
+ data::RecordId repository_id;
+ Pathname repodir = Pathname(dir) + "/repo/yum/data/10.2-updates-subset";
+ filesystem::TmpDir tmpdir;
+ string alias = "novell.com";
+ write_yum_repo( alias, repodir, tmpdir );
+
+ ResStore dbres = get_resolvables( alias, tmpdir);;;
+ //read_resolvables( alias, tmpdir, std::inserter(dbres, dbres.end()));
+ MIL << dbres.size() << " resolvables" << endl;
+ BOOST_CHECK_EQUAL( dbres.size(), 48);
+
+ bool found_glabels_i586 = false;
+ for ( ResStore::const_iterator it = dbres.begin();
+ it != dbres.end();
+ ++it )
{
- sqlite3_connection con((tmpdir.path() + "zypp.db").c_str());
- int count;
-
- sqlite3_command tables_cmd( con, "select name from sqlite_master where type='table';");
- sqlite3_reader reader = tables_cmd.executereader();
- list<string> tables;
- while ( reader.read() )
+ if ( isKind<Package>(*it) )
{
- string tablename = reader.getstring(0);
- if (
- (tablename == "sqlite_sequence" ) ||
- (tablename == "db_info" ) ||
- (tablename == "types" ) ||
- (tablename == "names" ) ||
- (tablename == "file_names" ) ||
- (tablename == "dir_names" ) ||
- (tablename == "files" )
- )
- continue;
-
- tables.push_back(tablename);
+ Package::Ptr p = asKind<Package>(*it);
+ if ( (p->name() == "glabels") && p->arch() == Arch("i586") )
+ {
+ found_glabels_i586 = true;
+ check_glabels_package(p);
+ }
}
- reader.close();
-
- for ( list<string>::const_iterator it = tables.begin();
- it != tables.end();
- ++it )
+ }
+ BOOST_CHECK_MESSAGE( found_glabels_i586, "Package glabels i586 should be in cache");
+
+ check_tables_clean(tmpdir);
+}
+
+/**
+ * \short Test that a susetags repo is cached and restored
+ */
+void cache_write_susetags_test(const string &dir)
+{
+ data::RecordId repository_id;
+ Pathname repodir = Pathname(dir) + "/repo/susetags/data/stable-x86-subset";
+ filesystem::TmpDir tmpdir;
+ string alias = "novell.com";
+ write_susetags_repo( alias, repodir, tmpdir );
+
+ ResStore dbres = get_resolvables( alias, tmpdir);;
+ //read_resolvables( alias, tmpdir, std::inserter(dbres, dbres.end()));
+ MIL << dbres.size() << " resolvables" << endl;
+
+ // packages and a patterns
+ BOOST_CHECK_EQUAL( dbres.size(), 7);
+ bool found_kdelibs3_i586 = false;
+ for ( ResStore::const_iterator it = dbres.begin();
+ it != dbres.end();
+ ++it )
+ {
+ MIL << *it << endl;
+ if ( isKind<Package>(*it) )
{
- MIL << "Checking table " << *it << endl;
- string query = (string("select count(*) from ") + (*it) +";");
- sqlite3_command cmd(con, query.c_str());
- count = cmd.executeint();
- string msg = (string("there should be no ") + (*it) +" after cleaning");
- BOOST_CHECK_MESSAGE( count == 0, msg.c_str());
+ Package::Ptr p = asKind<Package>(*it);
+ if ( (p->name() == "kdelibs3") && p->arch() == Arch("i586") )
+ {
+ BOOST_CHECK_MESSAGE( !found_kdelibs3_i586, "kdelibs3 i586 only once" );
+ found_kdelibs3_i586 = true;
+ check_kdelibs3_package(p);
+ }
}
}
+ BOOST_CHECK_MESSAGE( found_kdelibs3_i586, "Package kdelibs3 i586 should be in cache");
+
+ check_tables_clean(tmpdir);
}
test_suite*
@@ -208,7 +289,9 @@
test_suite* test= BOOST_TEST_SUITE("CacheStore");
std::string const params[] = { datadir };
- test->add(BOOST_PARAM_TEST_CASE(&cache_write_test2,
+ test->add(BOOST_PARAM_TEST_CASE(&cache_write_yum_test,
+ (std::string const*)params, params+1));
+ test->add(BOOST_PARAM_TEST_CASE(&cache_write_susetags_test,
(std::string const*)params, params+1));
//test->add(BOOST_PARAM_TEST_CASE(&cache_write_test2,
// (std::string const*)params, params+1));
Modified: branches/REFACTORING-10_3/libzypp/zypp/ResStore.h
URL: http://svn.opensuse.org/viewcvs/zypp/branches/REFACTORING-10_3/libzypp/zypp/ResStore.h?rev=5995&r1=5994&r2=5995&view=diff
==============================================================================
--- branches/REFACTORING-10_3/libzypp/zypp/ResStore.h (original)
+++ branches/REFACTORING-10_3/libzypp/zypp/ResStore.h Thu Jul 12 16:56:24 2007
@@ -39,12 +39,13 @@
/** Type of Resolvable provided by ResStore. */
typedef ResObject ResT;
-
+
private:
typedef std::setResT::Ptr StorageT;
-
+
public:
-
+ typedef StorageT::value_type value_type;
+ typedef StorageT::const_reference const_reference;
typedef StorageT::size_type size_type;
typedef StorageT::iterator iterator;
typedef StorageT::const_iterator const_iterator;
@@ -81,6 +82,11 @@
/** */
iterator insert( const ResT::Ptr & ptr_r )
{ return store().insert( ptr_r ).first; }
+
+ /** */
+ iterator insert( iterator position, const value_type &v )
+ { return store().insert( position, v ); }
+
/** */
template <class _InputIterator>
void insert( _InputIterator first_r, _InputIterator last_r )
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org