Finish test cases for emptying recycle bin

This commit is contained in:
Vladimir Svyatski 2017-04-23 00:50:26 +03:00
parent 583f60a3f3
commit c613f44991

View File

@ -19,11 +19,15 @@
#include <QTest>
#include <QSignalSpy>
#include <QTemporaryFile>
#include "config-keepassx-tests.h"
#include "core/Database.h"
#include "crypto/Crypto.h"
#include "keys/PasswordKey.h"
#include "core/Metadata.h"
#include "core/Group.h"
#include "format/KeePass2Writer.h"
QTEST_GUILESS_MAIN(TestDatabase)
@ -85,5 +89,24 @@ void TestDatabase::testEmptyRecycleBinOnEmpty()
void TestDatabase::testEmptyRecycleBinWithHierarchicalData()
{
//TODO: implement
QString filename = QString(KEEPASSX_TEST_DATA_DIR).append("/RecycleBinWithData.kdbx");
CompositeKey key;
key.addKey(PasswordKey("123"));
Database* db = Database::openDatabaseFile(filename, key);
QVERIFY(db);
QFile originalFile(filename);
qint64 initialSize = originalFile.size();
db->emptyRecycleBin();
QVERIFY(db->metadata()->recycleBin());
QVERIFY(db->metadata()->recycleBin()->entries().empty());
QVERIFY(db->metadata()->recycleBin()->children().empty());
QTemporaryFile afterCleanup;
KeePass2Writer writer;
writer.writeDatabase(&afterCleanup, db);
QVERIFY(afterCleanup.size() < initialSize);
delete db;
}