summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJanusz Kozerski <j.kozerski@samsung.com>2015-07-20 14:09:12 (GMT)
committerJanusz Kozerski <j.kozerski@samsung.com>2015-08-03 14:14:30 (GMT)
commit4373c73514186ce90d71a0486447fa66dcf0a6c1 (patch)
tree7c5bd75cc6655094b865fdffc0db37ec59c574e0 /tests
parent9c839946822cbf84b8f6d4edebca8bc678941c85 (diff)
downloadcert-checker-4373c73514186ce90d71a0486447fa66dcf0a6c1.zip
cert-checker-4373c73514186ce90d71a0486447fa66dcf0a6c1.tar.gz
cert-checker-4373c73514186ce90d71a0486447fa66dcf0a6c1.tar.bz2
Restore test DB from copy instead of clearing itrefs/changes/14/44414/7
Change-Id: Ia82a764c764f28f78d5c6f6a6d511c67459804b7
Diffstat (limited to 'tests')
-rw-r--r--tests/dbfixture.cpp44
-rw-r--r--tests/dbfixture.h2
-rw-r--r--tests/test_db.cpp4
3 files changed, 18 insertions, 32 deletions
diff --git a/tests/dbfixture.cpp b/tests/dbfixture.cpp
index 2fb73b5..2e99009 100644
--- a/tests/dbfixture.cpp
+++ b/tests/dbfixture.cpp
@@ -19,43 +19,35 @@
* @version 1.0
* @brief Implementation of DB test class
*/
+#include <boost/test/unit_test.hpp>
#include <tzplatform_config.h>
+#include <fstream>
#include <dbfixture.h>
using namespace CCHECKER;
namespace {
-const char *TEST_DB_PATH = tzplatform_mkpath(TZ_SYS_DB, ".cert-checker-test.db");
-
-const char *DB_CMD_CLEAR_URL =
- "DELETE FROM ocsp_urls;";
-
-const char *DB_CMD_CLEAR_TO_CHECK =
- "DELETE FROM to_check;";
-
-const char *DB_CMD_CLEAR_CERTS_TO_CHECK =
- "DELETE FROM certs_to_check;";
+const char *TEST_DB_PATH = tzplatform_mkpath(TZ_SYS_DB, ".cert-checker-test.db");
+const char *TEST_DB_PATH_TEMP = tzplatform_mkpath(TZ_SYS_DB, ".cert-checker-test-temp.db");
} // anonymus namespace
DBFixture::DBFixture() :
- DB::SqlQuery(TEST_DB_PATH)
-{};
-
-DBFixture::~DBFixture()
-{};
-
-void DBFixture::clear_database ()
+ DB::SqlQuery()
{
- // TODO: Restore DB from copy instead of removing all data from it.
+ // Remove temporary databse
+ BOOST_CHECK(unlink(TEST_DB_PATH_TEMP) == 0 || errno == ENOENT);
- DB::SqlConnection::DataCommandAutoPtr getUrlCommand =
- m_connection->PrepareDataCommand(DB_CMD_CLEAR_URL);
- getUrlCommand->Step();
+ // Restore original database
+ std::ifstream f1(TEST_DB_PATH, std::fstream::binary);
+ std::ofstream f2(TEST_DB_PATH_TEMP, std::fstream::trunc|std::fstream::binary);
+ f2 << f1.rdbuf();
+ f2.close();
+ f1.close();
- getUrlCommand = m_connection->PrepareDataCommand(DB_CMD_CLEAR_CERTS_TO_CHECK);
- getUrlCommand->Step();
+ // Open temporary database
+ BOOST_REQUIRE(connect(TEST_DB_PATH_TEMP));
+};
- getUrlCommand = m_connection->PrepareDataCommand(DB_CMD_CLEAR_TO_CHECK);
- getUrlCommand->Step();
-}
+DBFixture::~DBFixture()
+{};
diff --git a/tests/dbfixture.h b/tests/dbfixture.h
index 2b64164..68c1450 100644
--- a/tests/dbfixture.h
+++ b/tests/dbfixture.h
@@ -31,8 +31,6 @@ class DBFixture : public DB::SqlQuery {
public:
DBFixture();
virtual ~DBFixture();
-
- void clear_database ();
};
#endif //CCHECKER_DBFIXTURE_H
diff --git a/tests/test_db.cpp b/tests/test_db.cpp
index e9685a8..066e895 100644
--- a/tests/test_db.cpp
+++ b/tests/test_db.cpp
@@ -39,8 +39,6 @@ BOOST_AUTO_TEST_CASE(DB_url) {
std::string url_org3 = "########";
std::string url_update3 = "@@@";
- clear_database();
-
// No url in database
BOOST_REQUIRE(get_url("Issuer_test1", url)==false);
BOOST_REQUIRE(get_url("Issuer_test2", url)==false);
@@ -97,7 +95,6 @@ BOOST_AUTO_TEST_CASE(DB_url) {
}
BOOST_AUTO_TEST_CASE(DB_app_positive) {
- clear_database();
std::list<app_t> buffer;
app_t app1("app_1", "pkg_1", 5001, {});
@@ -144,7 +141,6 @@ BOOST_AUTO_TEST_CASE(DB_app_positive) {
}
BOOST_AUTO_TEST_CASE(DB_app_negative) {
- clear_database();
std::list<app_t> buffer;
app_t app1("app_1", "pkg_1", 5001, {});