Simplify TestModified a bit.

This commit is contained in:
Felix Geyer 2012-04-18 17:26:32 +02:00
parent cfe5b48bfd
commit 433e8c4508

View File

@ -17,7 +17,6 @@
#include "TestModified.h" #include "TestModified.h"
#include <QtCore/QPointer>
#include <QtTest/QSignalSpy> #include <QtTest/QSignalSpy>
#include <QtTest/QTest> #include <QtTest/QTest>
@ -36,81 +35,70 @@ void TestModified::testSignals()
int spyCount = 0; int spyCount = 0;
int spyCount2 = 0; int spyCount2 = 0;
CompositeKey* compositeKey = new CompositeKey(); CompositeKey compositeKey;
Database* db = new Database(); Database* db = new Database();
QPointer<Group> root = db->rootGroup(); Group* root = db->rootGroup();
QSignalSpy spyModified(db, SIGNAL(modified())); QSignalSpy spyModified(db, SIGNAL(modified()));
db->setKey(*compositeKey); db->setKey(compositeKey);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
Group* g1 = new Group(); Group* g1 = new Group();
g1->setParent(root); g1->setParent(root);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
Group* g2 = new Group(); Group* g2 = new Group();
g2->setParent(root); g2->setParent(root);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
QPointer<Entry> entry1 = new Entry(); Entry* entry1 = new Entry();
entry1->setGroup(g1); entry1->setGroup(g1);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
Database* db2 = new Database(); Database* db2 = new Database();
QPointer<Group> root2 = db2->rootGroup(); Group* root2 = db2->rootGroup();
QSignalSpy spyModified2(db2, SIGNAL(modified())); QSignalSpy spyModified2(db2, SIGNAL(modified()));
g1->setParent(root2); g1->setParent(root2);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
spyCount2++; QCOMPARE(spyModified2.count(), ++spyCount2);
QCOMPARE(spyModified.count(), spyCount);
QCOMPARE(spyModified2.count(), spyCount2);
entry1->setTitle("test"); entry1->setTitle("test");
spyCount2++;
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
QCOMPARE(spyModified2.count(), spyCount2); QCOMPARE(spyModified2.count(), ++spyCount2);
QPointer<Entry> entry2 = new Entry(); Entry* entry2 = new Entry();
entry2->setGroup(g2); entry2->setGroup(g2);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
QCOMPARE(spyModified2.count(), spyCount2); QCOMPARE(spyModified2.count(), spyCount2);
entry2->setGroup(root2); entry2->setGroup(root2);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
spyCount2++; QCOMPARE(spyModified2.count(), ++spyCount2);
QCOMPARE(spyModified.count(), spyCount);
QCOMPARE(spyModified2.count(), spyCount2);
entry2->setTitle("test2"); entry2->setTitle("test2");
spyCount2++;
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
QCOMPARE(spyModified2.count(), spyCount2); QCOMPARE(spyModified2.count(), ++spyCount2);
Group* g3 = new Group(); Group* g3 = new Group();
g3->setParent(root); g3->setParent(root);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
Group* g4 = new Group(); Group* g4 = new Group();
g4->setParent(g3); g4->setParent(g3);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
QCOMPARE(spyModified2.count(), spyCount2); QCOMPARE(spyModified2.count(), spyCount2);
delete db;
} }
void TestModified::testGroupSets() void TestModified::testGroupSets()
{ {
int spyCount = 0; int spyCount = 0;
Database* db = new Database(); Database* db = new Database();
QPointer<Group> root = db->rootGroup(); Group* root = db->rootGroup();
Group* g = new Group(); Group* g = new Group();
g->setParent(root); g->setParent(root);
@ -118,199 +106,172 @@ void TestModified::testGroupSets()
QSignalSpy spyModified(db, SIGNAL(modified())); QSignalSpy spyModified(db, SIGNAL(modified()));
root->setUuid(Uuid::random()); root->setUuid(Uuid::random());
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
root->setUuid(root->uuid()); root->setUuid(root->uuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
root->setName("test"); root->setName("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
root->setName(root->name()); root->setName(root->name());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
root->setNotes("test"); root->setNotes("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
root->setNotes(root->notes()); root->setNotes(root->notes());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
root->setIcon(1); root->setIcon(1);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
root->setIcon(root->iconNumber()); root->setIcon(root->iconNumber());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
root->setIcon(Uuid::random()); root->setIcon(Uuid::random());
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
root->setIcon(root->iconUuid()); root->setIcon(root->iconUuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
g->setUuid(Uuid::random()); g->setUuid(Uuid::random());
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
g->setUuid(g->uuid()); g->setUuid(g->uuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
g->setName("test"); g->setName("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
g->setName(g->name()); g->setName(g->name());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
g->setNotes("test"); g->setNotes("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
g->setNotes(g->notes()); g->setNotes(g->notes());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
g->setIcon(1); g->setIcon(1);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
g->setIcon(g->iconNumber()); g->setIcon(g->iconNumber());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
g->setIcon(Uuid::random()); g->setIcon(Uuid::random());
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
g->setIcon(g->iconUuid()); g->setIcon(g->iconUuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
delete db;
} }
void TestModified::testEntrySets() void TestModified::testEntrySets()
{ {
int spyCount = 0; int spyCount = 0;
Database* db = new Database(); Database* db = new Database();
QPointer<Group> root = db->rootGroup(); Group* root = db->rootGroup();
Group* g = new Group(); Group* g = new Group();
g->setParent(root); g->setParent(root);
QPointer<Entry> entry = new Entry(); Entry* entry = new Entry();
entry->setGroup(g); entry->setGroup(g);
QSignalSpy spyModified(db, SIGNAL(modified())); QSignalSpy spyModified(db, SIGNAL(modified()));
entry->setUuid(Uuid::random()); entry->setUuid(Uuid::random());
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setUuid(entry->uuid()); entry->setUuid(entry->uuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setTitle("test"); entry->setTitle("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setTitle(entry->title()); entry->setTitle(entry->title());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setUrl("test"); entry->setUrl("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setUrl(entry->url()); entry->setUrl(entry->url());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setUsername("test"); entry->setUsername("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setUsername(entry->username()); entry->setUsername(entry->username());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setPassword("test"); entry->setPassword("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setPassword(entry->password()); entry->setPassword(entry->password());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setNotes("test"); entry->setNotes("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setNotes(entry->notes()); entry->setNotes(entry->notes());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setIcon(1); entry->setIcon(1);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setIcon(entry->iconNumber()); entry->setIcon(entry->iconNumber());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setIcon(Uuid::random()); entry->setIcon(Uuid::random());
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setIcon(entry->iconUuid()); entry->setIcon(entry->iconUuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setTags("test"); entry->setTags("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setTags(entry->tags()); entry->setTags(entry->tags());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setExpires(true); entry->setExpires(true);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setExpires(entry->timeInfo().expires()); entry->setExpires(entry->timeInfo().expires());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setExpiryTime(QDateTime::currentDateTimeUtc().addYears(1)); entry->setExpiryTime(QDateTime::currentDateTimeUtc().addYears(1));
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setExpiryTime(entry->timeInfo().expiryTime()); entry->setExpiryTime(entry->timeInfo().expiryTime());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setAutoTypeEnabled(false); entry->setAutoTypeEnabled(false);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setAutoTypeEnabled(entry->autoTypeEnabled()); entry->setAutoTypeEnabled(entry->autoTypeEnabled());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setAutoTypeObfuscation(1); entry->setAutoTypeObfuscation(1);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setAutoTypeObfuscation(entry->autoTypeObfuscation()); entry->setAutoTypeObfuscation(entry->autoTypeObfuscation());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setDefaultAutoTypeSequence("test"); entry->setDefaultAutoTypeSequence("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setDefaultAutoTypeSequence(entry->defaultAutoTypeSequence()); entry->setDefaultAutoTypeSequence(entry->defaultAutoTypeSequence());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setForegroundColor(Qt::red); entry->setForegroundColor(Qt::red);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setForegroundColor(entry->foregroundColor()); entry->setForegroundColor(entry->foregroundColor());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setBackgroundColor(Qt::red); entry->setBackgroundColor(Qt::red);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setBackgroundColor(entry->backgroundColor()); entry->setBackgroundColor(entry->backgroundColor());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setOverrideUrl("test"); entry->setOverrideUrl("test");
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->setOverrideUrl(entry->overrideUrl()); entry->setOverrideUrl(entry->overrideUrl());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->attributes()->set("test key", "test value", false); entry->attributes()->set("test key", "test value", false);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->attributes()->set("test key", entry->attributes()->value("test key"), false); entry->attributes()->set("test key", entry->attributes()->value("test key"), false);
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->attributes()->set("test key", entry->attributes()->value("test key"), true); entry->attributes()->set("test key", entry->attributes()->value("test key"), true);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->attributes()->set("test key", "new test value", true); entry->attributes()->set("test key", "new test value", true);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->attributes()->set("test key2", "test value2", true); entry->attributes()->set("test key2", "test value2", true);
spyCount++; QCOMPARE(spyModified.count(), ++spyCount);
QCOMPARE(spyModified.count(), spyCount);
entry->attributes()->set("test key2", entry->attributes()->value("test key2"), true); entry->attributes()->set("test key2", entry->attributes()->value("test key2"), true);
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
delete db;
} }
KEEPASSX_QTEST_CORE_MAIN(TestModified) KEEPASSX_QTEST_CORE_MAIN(TestModified)