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:
parent
412964bcf4
commit
f124501c39
|
@ -16,13 +16,13 @@ Database<T> :: Database(std::string filepath)
|
||||||
template <class T>
|
template <class T>
|
||||||
Database<T> :: ~Database()
|
Database<T> :: ~Database()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void Database<T> :: save()
|
void Database<T> :: save()
|
||||||
{
|
{
|
||||||
file.open(OPEN_WRITE);
|
if (file.open(OPEN_WRITE) == false)
|
||||||
|
return;
|
||||||
|
|
||||||
file << db.size() << std::endl;
|
file << db.size() << std::endl;
|
||||||
for (unsigned int i = 0; i < db.size(); i++) {
|
for (unsigned int i = 0; i < db.size(); i++) {
|
||||||
|
@ -39,7 +39,8 @@ template <class T>
|
||||||
void Database<T> :: load()
|
void Database<T> :: load()
|
||||||
{
|
{
|
||||||
unsigned int db_size;
|
unsigned int db_size;
|
||||||
file.open(OPEN_READ);
|
if (file.open(OPEN_READ) == false)
|
||||||
|
return;
|
||||||
|
|
||||||
file >> db_size;
|
file >> db_size;
|
||||||
db.resize(db_size);
|
db.resize(db_size);
|
||||||
|
|
|
@ -68,6 +68,7 @@ void test_deletion(Database<DBTest> &db)
|
||||||
*/
|
*/
|
||||||
void test_0()
|
void test_0()
|
||||||
{
|
{
|
||||||
|
print("Test 0\n");
|
||||||
Database<DBTest> db("test.db");
|
Database<DBTest> db("test.db");
|
||||||
|
|
||||||
test_insertion(db);
|
test_insertion(db);
|
||||||
|
@ -82,15 +83,40 @@ void test_0()
|
||||||
*/
|
*/
|
||||||
void test_1()
|
void test_1()
|
||||||
{
|
{
|
||||||
|
print("Test 1\n");
|
||||||
Database<DBTest> db("test.db");
|
Database<DBTest> db("test.db");
|
||||||
db.load();
|
db.load();
|
||||||
print_db(db);
|
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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
test_0();
|
test_0();
|
||||||
test_1();
|
test_1();
|
||||||
|
test_2();
|
||||||
|
test_3();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
100011
tests/database/database.good
100011
tests/database/database.good
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue