summaryrefslogtreecommitdiff
path: root/tests/DBFixture.cpp
diff options
context:
space:
mode:
authorMaciej J. Karpiuk <m.karpiuk2@samsung.com>2015-01-07 11:40:55 +0100
committerMaciej J. Karpiuk <m.karpiuk2@samsung.com>2015-02-17 12:09:37 +0100
commit0c7a5e8c233996070520d87674372f1b5da2b9fe (patch)
treeedaad00c16ad5925ec37cd5cc0f9dfa9210f84d3 /tests/DBFixture.cpp
parent72c1f77726929b1e3a8dfa224d66a126a143f118 (diff)
downloadkey-manager-0c7a5e8c233996070520d87674372f1b5da2b9fe.tar.gz
key-manager-0c7a5e8c233996070520d87674372f1b5da2b9fe.tar.bz2
key-manager-0c7a5e8c233996070520d87674372f1b5da2b9fe.zip
Add CKM database versioning with DB migration mechanism.
Change-Id: I3d773b1b9ff4949a4ae98e25c778e6c010bc8a62
Diffstat (limited to 'tests/DBFixture.cpp')
-rw-r--r--tests/DBFixture.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/tests/DBFixture.cpp b/tests/DBFixture.cpp
index d82c4341..20e1a430 100644
--- a/tests/DBFixture.cpp
+++ b/tests/DBFixture.cpp
@@ -2,6 +2,7 @@
#include <db-crypto.h>
#include <ckm/ckm-error.h>
#include <DBFixture.h>
+#include <fstream>
using namespace CKM;
using namespace std::chrono;
@@ -9,10 +10,28 @@ using namespace std::chrono;
DBFixture::DBFixture()
{
+ BOOST_CHECK(unlink(m_crypto_db_fname) == 0 || errno == ENOENT);
+ init();
+}
+DBFixture::DBFixture(const char *db_fname)
+{
+ BOOST_CHECK(unlink(m_crypto_db_fname) == 0 || errno == ENOENT);
+
+ // copy file
+ std::ifstream f1(db_fname, std::fstream::binary);
+ std::ofstream f2(m_crypto_db_fname, std::fstream::trunc|std::fstream::binary);
+ f2 << f1.rdbuf();
+ f2.close();
+ f1.close();
+
+ init();
+}
+
+void DBFixture::init()
+{
high_resolution_clock::time_point srand_feed = high_resolution_clock::now();
srand(srand_feed.time_since_epoch().count());
- BOOST_CHECK(unlink(m_crypto_db_fname) == 0 || errno == ENOENT);
BOOST_REQUIRE_NO_THROW(m_db = DBCrypto(m_crypto_db_fname, defaultPass));
}
@@ -51,7 +70,7 @@ void DBFixture::generate_label(unsigned int id, Label & output)
output = ss.str();
}
-void DBFixture::generate_perf_DB(unsigned int num_name, unsigned int num_label)
+void DBFixture::generate_perf_DB(unsigned int num_name, unsigned int num_elements)
{
// to speed up data creation - cache the row
DBRow rowPattern = create_default_row(DBDataType::BINARY_DATA);
@@ -62,7 +81,7 @@ void DBFixture::generate_perf_DB(unsigned int num_name, unsigned int num_label)
for(unsigned int i=0; i<num_name; i++)
{
generate_name(i, rowPattern.name);
- generate_label(i/num_label, rowPattern.ownerLabel);
+ generate_label(i/num_elements, rowPattern.ownerLabel);
BOOST_REQUIRE_NO_THROW(m_db.saveDBRow(rowPattern));
}