database: Add tests for databases without a filepath

These databases should not be saved to disk, since the user hasn't given
a valid filepath.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2013-08-14 21:50:08 -04:00 committed by Anna Schumaker
parent 412964bcf4
commit f124501c39
3 changed files with 100041 additions and 3 deletions

View File

@ -16,13 +16,13 @@ Database<T> :: Database(std::string filepath)
template <class T>
Database<T> :: ~Database()
{
}
template <class T>
void Database<T> :: save()
{
file.open(OPEN_WRITE);
if (file.open(OPEN_WRITE) == false)
return;
file << db.size() << std::endl;
for (unsigned int i = 0; i < db.size(); i++) {
@ -39,7 +39,8 @@ template <class T>
void Database<T> :: load()
{
unsigned int db_size;
file.open(OPEN_READ);
if (file.open(OPEN_READ) == false)
return;
file >> db_size;
db.resize(db_size);

View File

@ -68,6 +68,7 @@ void test_deletion(Database<DBTest> &db)
*/
void test_0()
{
print("Test 0\n");
Database<DBTest> db("test.db");
test_insertion(db);
@ -82,15 +83,40 @@ void test_0()
*/
void test_1()
{
print("Test 1\n");
Database<DBTest> db("test.db");
db.load();
print_db(db);
}
/*
* Attempt to save a db with an empty filepath.
*/
void test_2()
{
print("Test 2\n");
Database<DBTest> db("");
test_insertion(db);
db.save();
}
/*
* Attempt to load a db with an empty filepath
*/
void test_3()
{
print("Test 3\n");
Database<DBTest> db("");
db.load();
}
int main(int argc, char **argv)
{
test_0();
test_1();
test_2();
test_3();
return 0;
}

File diff suppressed because it is too large Load Diff