make the cache initializer testeable
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 11 Jul 2006 15:54:34 +0000 (15:54 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 11 Jul 2006 15:54:34 +0000 (15:54 +0000)
configure.ac
testsuite/Makefile.am
testsuite/cache/Makefile.am [new file with mode: 0644]
testsuite/cache/SourceCacheInitializer.cc [new file with mode: 0644]
zypp/cache/SourceCacheInitializer.cpp

index 7e2afd9..fa4f472 100644 (file)
@@ -224,6 +224,7 @@ AC_OUTPUT(   po/Makefile.in\
   testsuite/src/Makefile \
        testsuite/src/utils/Makefile    \
        testsuite/zypp/Makefile         \
+  testsuite/cache/Makefile \
        testsuite/zypp/tests/Makefile   \
        testsuite/solver/Makefile       \
        testsuite/solver/src/Makefile   \
index d68f393..1718acf 100644 (file)
@@ -1,4 +1,4 @@
 #
 # Makefile.am for libzypp/testsuite
 #
-SUBDIRS = src zypp target solver source media parser
+SUBDIRS = src zypp cache target solver source media parser
diff --git a/testsuite/cache/Makefile.am b/testsuite/cache/Makefile.am
new file mode 100644 (file)
index 0000000..8912f63
--- /dev/null
@@ -0,0 +1,32 @@
+## Process this file with automake to produce Makefile.in
+## ##################################################
+
+# Do NOT list devel.* in subdirs. It's developers playgound and
+# must not prevent anything from building.
+SUBDIRS =
+
+## ##################################################
+
+TESTS = SourceCacheInitializer
+
+check_PROGRAMS = SourceCacheInitializer
+
+## ##################################################
+
+LDADD =        $(top_srcdir)/zypp/lib@PACKAGE@.la 
+
+## ##################################################
+
+SourceCacheInitializer_SOURCES = SourceCacheInitializer.cc
+SourceCacheInitializer_LDADD = $(LDADD) -lboost_unit_test_framework
+
+## ##################################################
+
+.PHONY:        always
+
+$(noinst_PROGRAMS):    $(top_srcdir)/zypp/lib@PACKAGE@.la
+
+#$(top_srcdir)/zypp/lib@PACKAGE@.la:     always
+#      $(MAKE) -C $(top_srcdir)/zypp
+
+## ##################################################
diff --git a/testsuite/cache/SourceCacheInitializer.cc b/testsuite/cache/SourceCacheInitializer.cc
new file mode 100644 (file)
index 0000000..1eb52b4
--- /dev/null
@@ -0,0 +1,50 @@
+
+#include <iostream>
+#include <list>
+#include <string>
+
+#include "zypp/base/Logger.h"
+#include "zypp/Arch.h"
+#include "zypp/TmpPath.h"
+#include "zypp/cache/SourceCacheInitializer.h"
+
+// Boost.Test
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/test/unit_test.hpp>
+
+#include "zypp/cache/sqlite3x/sqlite3x.hpp"
+
+using boost::unit_test::test_suite;
+using boost::unit_test::test_case;
+using boost::test_tools::close_at_tolerance;
+
+using namespace std;
+using namespace zypp;
+using namespace sqlite3x;
+
+/******************************************************************
+**
+**
+**      FUNCTION NAME : main
+**      FUNCTION TYPE : int
+**
+**      DESCRIPTION :
+*/
+void cacheinit_test()
+{
+  filesystem::TmpDir tmpdir;
+  cache::SourceCacheInitializer initializer(tmpdir.path(), "test.db");
+  sqlite3_connection con( (tmpdir.path() + "test.db").asString().c_str());
+  //con.executenonquery(SOURCES_TABLE_SCHEMA);
+  int count = con.executeint("select count(*) from sqlite_master where type='table';");
+  BOOST_CHECK( initializer.justInitialized() );
+  BOOST_CHECK_EQUAL( count, 3);
+}
+
+test_suite*
+init_unit_test_suite( int, char* [] )
+{
+    test_suite* test= BOOST_TEST_SUITE( "CacheInit" );
+    test->add( BOOST_TEST_CASE( &cacheinit_test ), 0 /* expected zero error */ );
+    return test;
+}
index 1a59624..f1e910f 100644 (file)
@@ -30,6 +30,23 @@ namespace cache
 
 static const char * SOURCES_TABLE_SCHEMA = "create table sources ( id integer primary key autoincrement, alias varchar unique, type varchar, description varchar,  url varchar, path varchar,  enabled integer, autorefresh integer, timestamp varchar, checksum varchar);";
 
+static const char * RESOLVABLES_TABLE_SCHEMA = "\
+ CREATE TABLE resolvables (   id INTEGER PRIMARY KEY AUTOINCREMENT,   name VARCHAR,   version VARCHAR,   release VARCHAR,   epoch INTEGER,   arch INTEGER,  installed_size INTEGER,  catalog VARCHAR,  installed INTEGER,  local INTEGER,  status INTEGER,  category VARCHAR,  license VARCHAR,  kind INTEGER); \
+ CREATE INDEX resolvable_sources ON resolvables (sources); \
+ CREATE INDEX resolvable_name ON resolvables (name); \
+ CREATE INDEX resolvable_spec ON resolvables (name, version, release, epoch, arch); \
+ CREATE TRIGGER remove_resolvables AFTER DELETE ON resolvables  BEGIN    DELETE FROM package_details WHERE resolvable_id = old.id; \
+ DELETE FROM patch_details WHERE resolvable_id = old.id; \
+ DELETE FROM pattern_details WHERE resolvable_id = old.id; \
+ DELETE FROM product_details WHERE resolvable_id = old.id; \
+ DELETE FROM message_details WHERE resolvable_id = old.id;   \
+ DELETE FROM script_details WHERE resolvable_id = old.id; \
+ DELETE FROM dependencies WHERE resolvable_id = old.id; \
+ DELETE FROM files WHERE resolvable_id = old.id;  END;";
+
+static const char * PACKAGES_DETAILS_TABLE_SCHEMA = "CREATE TABLE package_details (   resolvable_id INTEGER NOT NULL,   rpm_group VARCHAR,  summary VARCHAR,  description VARCHAR,  package_url VARCHAR,  package_filename VARCHAR,  signature_filename VARCHAR,  file_size INTEGER,  install_only INTEGER,  media_nr INTEGER); \
+CREATE INDEX package_details_resolvable_id ON package_details (resolvable_id);";
+
 // id 0, alias 1 , type 2, desc 3, url 4, path 5, enabled 6, autorefresh 7, timestamp 8, checksum 9
   
 SourceCacheInitializer::SourceCacheInitializer( const Pathname &root_r, const Pathname &db_file )
@@ -37,7 +54,7 @@ SourceCacheInitializer::SourceCacheInitializer( const Pathname &root_r, const Pa
 {
   try
   {
-    _con.reset( new sqlite3_connection(db_file.asString().c_str()) );
+    _con.reset( new sqlite3_connection( (_root + db_file).asString().c_str()) );
   }
   catch(exception &ex) {
     ERR << "Exception Occured: " << ex.what() << endl;
@@ -76,17 +93,16 @@ SourceCacheInitializer::~SourceCacheInitializer()
 
 bool SourceCacheInitializer::tablesCreated() const
 {
-       unsigned int count = _con->executeint("select count(*) from sqlite_master where type='table';");
-       return ( count == 1 );
+  unsigned int count = _con->executeint("select count(*) from sqlite_master where type='table';");
+  return ( count == 1 );
 }
 
 void SourceCacheInitializer::createTables()
 {
   sqlite3_transaction trans(*_con);
-
   {
-        _con->executenonquery(SOURCES_TABLE_SCHEMA);
-    
+    _con->executenonquery(SOURCES_TABLE_SCHEMA);
+    _con->executenonquery(RESOLVABLES_TABLE_SCHEMA);
   }
   
   trans.commit();