Add a bunch of new Parser testcases.

This commit is contained in:
Felix Geyer 2010-08-25 21:14:41 +02:00
parent 542ecd41d1
commit cd26e9d474
4 changed files with 531 additions and 78 deletions

View File

@ -70,6 +70,12 @@ bool Uuid::operator!=(const Uuid& other) const
return !operator==(other);
}
Uuid Uuid::fromBase64(const QString& str)
{
QByteArray data = QByteArray::fromBase64(str.toAscii());
return Uuid(data);
}
uint qHash(const Uuid& key)
{
return qHash(key.toByteArray());

View File

@ -33,6 +33,7 @@ public:
bool operator==(const Uuid& other) const;
bool operator!=(const Uuid& other) const;
static const int length;
static Uuid fromBase64(const QString& str);
private:
QByteArray m_data;

View File

@ -15,20 +15,26 @@
<ProtectPassword>False</ProtectPassword>
<ProtectURL>True</ProtectURL>
<ProtectNotes>False</ProtectNotes>
<AutoEnableVisualHiding>True</AutoEnableVisualHiding>
<AutoEnableVisualHiding>False</AutoEnableVisualHiding>
</MemoryProtection>
<CustomIcons>
<Icon>
<UUID>++vyI+daLk6omox4a6kQGA==</UUID>
<Data>iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAACZJREFUOE9jbGBo+M9ACQAZQAlmoEQz2PWjBoyGwWg6AGdCivMCAKxN4SAQ+6S+AAAAAElFTkSuQmCC</Data>
</Icon>
</CustomIcons>
<RecycleBinEnabled>True</RecycleBinEnabled>
<RecycleBinUUID>7PAwxNhPaE2klutz45i2xg==</RecycleBinUUID>
<RecycleBinChanged>2010-08-08T17:24:17Z</RecycleBinChanged>
<RecycleBinUUID>6w7wZdhAp0qVlXjkemuCYw==</RecycleBinUUID>
<RecycleBinChanged>2010-08-25T16:12:57Z</RecycleBinChanged>
<EntryTemplatesGroup>AAAAAAAAAAAAAAAAAAAAAA==</EntryTemplatesGroup>
<EntryTemplatesGroupChanged>2010-08-08T17:24:19Z</EntryTemplatesGroupChanged>
<LastSelectedGroup>zKuE27EWr0mlU75b2SRkTQ==</LastSelectedGroup>
<LastTopVisibleGroup>zKuE27EWr0mlU75b2SRkTQ==</LastTopVisibleGroup>
<LastSelectedGroup>lmU+9n0aeESKZvcEze+bRg==</LastSelectedGroup>
<LastTopVisibleGroup>lmU+9n0aeESKZvcEze+bRg==</LastTopVisibleGroup>
<CustomData />
</Meta>
<Root>
<Group>
<UUID>zKuE27EWr0mlU75b2SRkTQ==</UUID>
<UUID>lmU+9n0aeESKZvcEze+bRg==</UUID>
<Name>NewDatabase</Name>
<Notes />
<IconID>49</IconID>
@ -38,33 +44,29 @@
<LastAccessTime>2010-08-09T09:09:44Z</LastAccessTime>
<ExpiryTime>2010-08-08T17:24:17Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>2</UsageCount>
<UsageCount>52</UsageCount>
<LocationChanged>2010-08-08T17:24:27Z</LocationChanged>
</Times>
<IsExpanded>True</IsExpanded>
<DefaultAutoTypeSequence />
<EnableAutoType>null</EnableAutoType>
<EnableSearching>null</EnableSearching>
<LastTopVisibleEntry>QW4G0r/z90qql4iKZ0RwlA==</LastTopVisibleEntry>
<LastTopVisibleEntry>+wSUOv6qf0OzW8/ZHAs2sA==</LastTopVisibleEntry>
<Entry>
<UUID>QW4G0r/z90qql4iKZ0RwlA==</UUID>
<UUID>+wSUOv6qf0OzW8/ZHAs2sA==</UUID>
<IconID>0</IconID>
<ForegroundColor>#0000FF</ForegroundColor>
<BackgroundColor>#000000</BackgroundColor>
<OverrideURL>OMGAURL</OverrideURL>
<ForegroundColor />
<BackgroundColor />
<OverrideURL />
<Times>
<LastModificationTime>2010-08-09T09:09:31Z</LastModificationTime>
<CreationTime>2010-08-08T17:24:53Z</CreationTime>
<LastAccessTime>2010-08-09T09:09:31Z</LastAccessTime>
<ExpiryTime>2011-08-08T17:25:58Z</ExpiryTime>
<Expires>True</Expires>
<UsageCount>6</UsageCount>
<LocationChanged>2010-08-08T17:24:53Z</LocationChanged>
<LastModificationTime>2010-08-25T16:19:25Z</LastModificationTime>
<CreationTime>2010-08-25T16:13:54Z</CreationTime>
<LastAccessTime>2010-08-25T16:19:25Z</LastAccessTime>
<ExpiryTime>2010-08-25T16:12:57Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>8</UsageCount>
<LocationChanged>2010-08-25T16:13:54Z</LocationChanged>
</Times>
<String>
<Key>customfield</Key>
<Value>customfield value</Value>
</String>
<String>
<Key>Notes</Key>
<Value>Notes</Value>
@ -75,84 +77,292 @@
</String>
<String>
<Key>Title</Key>
<Value>Sample Entry</Value>
<Value>Sample Entry 1</Value>
</String>
<String>
<Key>URL</Key>
<Value>bleh</Value>
<Value />
</String>
<String>
<Key>UserName</Key>
<Value>User Name</Value>
</String>
<AutoType>
<Enabled>False</Enabled>
<DataTransferObfuscation>0</DataTransferObfuscation>
<Association>
<Window>Target Window</Window>
<KeystrokeSequence />
</Association>
</AutoType>
<History>
<Entry>
<UUID>+wSUOv6qf0OzW8/ZHAs2sA==</UUID>
<IconID>0</IconID>
<ForegroundColor />
<BackgroundColor />
<OverrideURL />
<Times>
<LastModificationTime>2010-08-25T16:13:54Z</LastModificationTime>
<CreationTime>2010-08-25T16:13:54Z</CreationTime>
<LastAccessTime>2010-08-25T16:15:37Z</LastAccessTime>
<ExpiryTime>2010-08-25T16:12:57Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>3</UsageCount>
<LocationChanged>2010-08-25T16:13:54Z</LocationChanged>
</Times>
<String>
<Key>Notes</Key>
<Value>Notes</Value>
</String>
<String>
<Key>Password</Key>
<Value>Password</Value>
</String>
<String>
<Key>Title</Key>
<Value>Sample Entry</Value>
</String>
<String>
<Key>URL</Key>
<Value>http://www.somesite.com/</Value>
</String>
<String>
<Key>UserName</Key>
<Value>User Name</Value>
</String>
<AutoType>
<Enabled>True</Enabled>
<DataTransferObfuscation>0</DataTransferObfuscation>
<Association>
<Window>Target Window</Window>
<KeystrokeSequence>{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}</KeystrokeSequence>
</Association>
</AutoType>
</Entry>
<Entry>
<UUID>+wSUOv6qf0OzW8/ZHAs2sA==</UUID>
<IconID>0</IconID>
<ForegroundColor />
<BackgroundColor />
<OverrideURL />
<Times>
<LastModificationTime>2010-08-25T16:15:43Z</LastModificationTime>
<CreationTime>2010-08-25T16:13:54Z</CreationTime>
<LastAccessTime>2010-08-25T16:18:40Z</LastAccessTime>
<ExpiryTime>2010-08-25T16:12:57Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>7</UsageCount>
<LocationChanged>2010-08-25T16:13:54Z</LocationChanged>
</Times>
<String>
<Key>Notes</Key>
<Value>Notes</Value>
</String>
<String>
<Key>Password</Key>
<Value>Password</Value>
</String>
<String>
<Key>Title</Key>
<Value>Sample Entry 1</Value>
</String>
<String>
<Key>URL</Key>
<Value>http://www.somesite.com/</Value>
</String>
<String>
<Key>UserName</Key>
<Value>User Name</Value>
</String>
<AutoType>
<Enabled>True</Enabled>
<DataTransferObfuscation>0</DataTransferObfuscation>
<Association>
<Window>Target Window</Window>
<KeystrokeSequence>{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}</KeystrokeSequence>
</Association>
</AutoType>
</Entry>
</History>
</Entry>
<Entry>
<UUID>4jbADG37hkiLh2O0qUdaOQ==</UUID>
<IconID>0</IconID>
<CustomIconUUID>++vyI+daLk6omox4a6kQGA==</CustomIconUUID>
<ForegroundColor>#FF0000</ForegroundColor>
<BackgroundColor>#FFFF00</BackgroundColor>
<OverrideURL>http://override.net/</OverrideURL>
<Times>
<LastModificationTime>2010-08-25T16:20:24Z</LastModificationTime>
<CreationTime>2010-08-25T16:15:45Z</CreationTime>
<LastAccessTime>2010-08-25T16:20:24Z</LastAccessTime>
<ExpiryTime>2010-09-01T16:16:20Z</ExpiryTime>
<Expires>True</Expires>
<UsageCount>7</UsageCount>
<LocationChanged>2010-08-25T16:15:45Z</LocationChanged>
</Times>
<String>
<Key>CustomString</Key>
<Value>isavalue</Value>
</String>
<String>
<Key>Notes</Key>
<Value />
</String>
<String>
<Key>Password</Key>
<Value>Jer60Hz8o9XHvxBGcRqT</Value>
</String>
<String>
<Key>Protected String</Key>
<Value>y</Value>
</String>
<String>
<Key>Title</Key>
<Value>Sample Entry 2</Value>
</String>
<String>
<Key>URL</Key>
<Value>http://www.keepassx.org/</Value>
</String>
<String>
<Key>UserName</Key>
<Value>notDEFUSERNAME</Value>
</String>
<Binary>
<Key>testattach.txt</Key>
<Value>NDI=</Value>
</Binary>
<AutoType>
<Enabled>True</Enabled>
<DataTransferObfuscation>1</DataTransferObfuscation>
<DefaultSequence>{USERNAME}{TAB}{PASSWORD}{ENTER}</DefaultSequence>
<Association>
<Window>Target Window</Window>
<KeystrokeSequence>{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}</KeystrokeSequence>
<KeystrokeSequence>{Title}{UserName}</KeystrokeSequence>
</Association>
<Association>
<Window>Edit Entry</Window>
<KeystrokeSequence>{Title}{UserName}{UserName}</KeystrokeSequence>
<Window>Target Window 2</Window>
<KeystrokeSequence>{Title}{UserName} test</KeystrokeSequence>
</Association>
</AutoType>
<History />
</Entry>
<Group>
<UUID>abLbFtNUfEi5TmbaxiW6yg==</UUID>
<UUID>AaUYVdXsI02h4T1RiAlgtg==</UUID>
<Name>General</Name>
<Notes />
<Notes>Group Notez</Notes>
<IconID>48</IconID>
<Times>
<LastModificationTime>2010-08-08T17:24:53Z</LastModificationTime>
<CreationTime>2010-08-08T17:24:53Z</CreationTime>
<LastAccessTime>2010-08-08T17:24:53Z</LastAccessTime>
<ExpiryTime>2010-08-08T17:24:17Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>0</UsageCount>
<LocationChanged>2010-08-08T17:24:53Z</LocationChanged>
<LastModificationTime>2010-08-25T16:22:20Z</LastModificationTime>
<CreationTime>2010-08-25T16:13:54Z</CreationTime>
<LastAccessTime>2010-08-25T16:22:29Z</LastAccessTime>
<ExpiryTime>2010-08-20T16:21:51Z</ExpiryTime>
<Expires>True</Expires>
<UsageCount>12</UsageCount>
<LocationChanged>2010-08-25T16:13:54Z</LocationChanged>
</Times>
<IsExpanded>True</IsExpanded>
<DefaultAutoTypeSequence />
<EnableAutoType>null</EnableAutoType>
<EnableSearching>null</EnableSearching>
<DefaultAutoTypeSequence>{Password}{ENTER}</DefaultAutoTypeSequence>
<EnableAutoType>true</EnableAutoType>
<EnableSearching>false</EnableSearching>
<LastTopVisibleEntry>AAAAAAAAAAAAAAAAAAAAAA==</LastTopVisibleEntry>
</Group>
<Group>
<UUID>u1lTRAICOkWv5QSl2xyU8w==</UUID>
<UUID>1h4NtL5DK0yVyvaEnN//4A==</UUID>
<Name>Windows</Name>
<Notes />
<IconID>38</IconID>
<Times>
<LastModificationTime>2010-08-08T17:24:53Z</LastModificationTime>
<CreationTime>2010-08-08T17:24:53Z</CreationTime>
<LastAccessTime>2010-08-08T17:24:53Z</LastAccessTime>
<ExpiryTime>2010-08-08T17:24:17Z</ExpiryTime>
<LastModificationTime>2010-08-25T16:13:54Z</LastModificationTime>
<CreationTime>2010-08-25T16:13:54Z</CreationTime>
<LastAccessTime>2010-08-25T16:22:24Z</LastAccessTime>
<ExpiryTime>2010-08-25T16:12:57Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>0</UsageCount>
<LocationChanged>2010-08-08T17:24:53Z</LocationChanged>
<UsageCount>15</UsageCount>
<LocationChanged>2010-08-25T16:13:54Z</LocationChanged>
</Times>
<IsExpanded>True</IsExpanded>
<IsExpanded>False</IsExpanded>
<DefaultAutoTypeSequence />
<EnableAutoType>null</EnableAutoType>
<EnableSearching>null</EnableSearching>
<LastTopVisibleEntry>AAAAAAAAAAAAAAAAAAAAAA==</LastTopVisibleEntry>
<Group>
<UUID>HoYE/BjLfUSW257pCHJ/eA==</UUID>
<Name>Subsub</Name>
<Notes />
<IconID>68</IconID>
<Times>
<LastModificationTime>2010-08-25T16:21:33Z</LastModificationTime>
<CreationTime>2010-08-25T16:14:31Z</CreationTime>
<LastAccessTime>2010-08-25T16:21:41Z</LastAccessTime>
<ExpiryTime>2010-08-25T16:21:21Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>8</UsageCount>
<LocationChanged>2010-08-25T16:14:31Z</LocationChanged>
</Times>
<IsExpanded>True</IsExpanded>
<DefaultAutoTypeSequence />
<EnableAutoType>null</EnableAutoType>
<EnableSearching>null</EnableSearching>
<LastTopVisibleEntry>AAAAAAAAAAAAAAAAAAAAAA==</LastTopVisibleEntry>
<Entry>
<UUID>GZpdQvGXOU2kaKRL/IVAGg==</UUID>
<IconID>0</IconID>
<ForegroundColor />
<BackgroundColor />
<OverrideURL />
<Times>
<LastModificationTime>2010-08-25T16:21:15Z</LastModificationTime>
<CreationTime>2010-08-25T16:20:45Z</CreationTime>
<LastAccessTime>2010-08-25T16:21:41Z</LastAccessTime>
<ExpiryTime>2010-08-25T16:12:57Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>3</UsageCount>
<LocationChanged>2010-08-25T16:20:45Z</LocationChanged>
</Times>
<String>
<Key>Notes</Key>
<Value />
</String>
<String>
<Key>Password</Key>
<Value />
</String>
<String>
<Key>Title</Key>
<Value>Subsub Entry</Value>
</String>
<String>
<Key>URL</Key>
<Value />
</String>
<String>
<Key>UserName</Key>
<Value />
</String>
<AutoType>
<Enabled>True</Enabled>
<DataTransferObfuscation>0</DataTransferObfuscation>
</AutoType>
<History />
</Entry>
</Group>
</Group>
<Group>
<UUID>7PAwxNhPaE2klutz45i2xg==</UUID>
<UUID>6w7wZdhAp0qVlXjkemuCYw==</UUID>
<Name>Recycle Bin</Name>
<Notes />
<IconID>43</IconID>
<Times>
<LastModificationTime>2010-08-09T09:09:44Z</LastModificationTime>
<CreationTime>2010-08-09T09:09:44Z</CreationTime>
<LastAccessTime>2010-08-09T09:09:44Z</LastAccessTime>
<ExpiryTime>2010-08-09T09:07:16Z</ExpiryTime>
<LastModificationTime>2010-08-25T16:13:57Z</LastModificationTime>
<CreationTime>2010-08-25T16:13:57Z</CreationTime>
<LastAccessTime>2010-08-25T16:20:55Z</LastAccessTime>
<ExpiryTime>2010-08-25T16:12:57Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>1</UsageCount>
<LocationChanged>2010-08-09T09:09:44Z</LocationChanged>
<UsageCount>10</UsageCount>
<LocationChanged>2010-08-25T16:13:57Z</LocationChanged>
</Times>
<IsExpanded>True</IsExpanded>
<DefaultAutoTypeSequence />
@ -160,19 +370,19 @@
<EnableSearching>false</EnableSearching>
<LastTopVisibleEntry>AAAAAAAAAAAAAAAAAAAAAA==</LastTopVisibleEntry>
<Entry>
<UUID>KIeQe6yDN0SbjIJ83NB++Q==</UUID>
<UUID>Wh3kfvnEqE2VqK+5KIiPXg==</UUID>
<IconID>0</IconID>
<ForegroundColor />
<BackgroundColor />
<OverrideURL />
<Times>
<LastModificationTime>2010-08-09T09:09:40Z</LastModificationTime>
<CreationTime>2010-08-09T09:09:37Z</CreationTime>
<LastAccessTime>2010-08-09T09:09:44Z</LastAccessTime>
<ExpiryTime>2010-08-09T09:07:16Z</ExpiryTime>
<LastModificationTime>2010-08-25T16:20:32Z</LastModificationTime>
<CreationTime>2010-08-25T16:20:27Z</CreationTime>
<LastAccessTime>2010-08-25T16:20:37Z</LastAccessTime>
<ExpiryTime>2010-08-25T16:12:57Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>2</UsageCount>
<LocationChanged>2010-08-09T09:09:44Z</LocationChanged>
<LocationChanged>2010-08-25T16:20:37Z</LocationChanged>
</Times>
<String>
<Key>Notes</Key>
@ -180,11 +390,11 @@
</String>
<String>
<Key>Password</Key>
<Value>5Ciyy3kcVSPFUFqTuK1o</Value>
<Value>gJBbkrCsiLBftfocQbNM</Value>
</String>
<String>
<Key>Title</Key>
<Value>test</Value>
<Value>delentry</Value>
</String>
<String>
<Key>URL</Key>
@ -200,8 +410,37 @@
</AutoType>
<History />
</Entry>
<Group>
<UUID>KtRKIna41ky8WkqrAUXPig==</UUID>
<Name>Network</Name>
<Notes />
<IconID>3</IconID>
<Times>
<LastModificationTime>2010-08-25T16:13:54Z</LastModificationTime>
<CreationTime>2010-08-25T16:13:54Z</CreationTime>
<LastAccessTime>2010-08-25T16:20:55Z</LastAccessTime>
<ExpiryTime>2010-08-25T16:12:57Z</ExpiryTime>
<Expires>False</Expires>
<UsageCount>3</UsageCount>
<LocationChanged>2010-08-25T16:14:09Z</LocationChanged>
</Times>
<IsExpanded>True</IsExpanded>
<DefaultAutoTypeSequence />
<EnableAutoType>null</EnableAutoType>
<EnableSearching>null</EnableSearching>
<LastTopVisibleEntry>AAAAAAAAAAAAAAAAAAAAAA==</LastTopVisibleEntry>
</Group>
</Group>
</Group>
<DeletedObjects />
<DeletedObjects>
<DeletedObject>
<UUID>5K/bzWCSmkCv5OZxYl4N/w==</UUID>
<DeletionTime>2010-08-25T16:14:12Z</DeletionTime>
</DeletedObject>
<DeletedObject>
<UUID>80h8uSNWgkKhKCp1TgXF7g==</UUID>
<DeletionTime>2010-08-25T16:14:14Z</DeletionTime>
</DeletedObject>
</DeletedObjects>
</Root>
</KeePassFile>

View File

@ -22,6 +22,17 @@
#include "core/Parser.h"
#include "config-keepassx-tests.h"
namespace QTest {
template<>
char *toString(const Uuid &uuid)
{
QByteArray ba = "Uuid(";
ba += uuid.toBase64();
ba += ")";
return qstrdup(ba.data());
}
}
class TestParser : public QObject
{
Q_OBJECT
@ -29,7 +40,14 @@ class TestParser : public QObject
private Q_SLOTS:
void initTestCase();
void testMetadata();
void testGroups();
void testCustomIcon();
void testGroupRoot();
void testGroup1();
void testGroup2();
void testEntry1();
void testEntry2();
void testEntryHistory();
void testDeletedObjects();
private:
QDateTime genDT(int year, int month, int day, int hour, int min, int second);
@ -67,11 +85,11 @@ void TestParser::testMetadata()
QCOMPARE(m_db->metadata()->protectPassword(), false);
QCOMPARE(m_db->metadata()->protectUrl(), true);
QCOMPARE(m_db->metadata()->protectNotes(), false);
QCOMPARE(m_db->metadata()->autoEnableVisualHiding(), true);
QCOMPARE(m_db->metadata()->autoEnableVisualHiding(), false);
QCOMPARE(m_db->metadata()->recycleBinEnabled(), true);
QVERIFY(m_db->metadata()->recycleBin() != 0);
QCOMPARE(m_db->metadata()->recycleBin()->name(), QString("Recycle Bin"));
QCOMPARE(m_db->metadata()->recycleBinChanged(), genDT(2010, 8, 8, 17, 24, 17));
QCOMPARE(m_db->metadata()->recycleBinChanged(), genDT(2010, 8, 25, 16, 12, 57));
QVERIFY(m_db->metadata()->entryTemplatesGroup() == 0);
QCOMPARE(m_db->metadata()->entryTemplatesGroupChanged(), genDT(2010, 8, 8, 17, 24, 19));
QVERIFY(m_db->metadata()->lastSelectedGroup() != 0);
@ -79,26 +97,215 @@ void TestParser::testMetadata()
QVERIFY(m_db->metadata()->lastTopVisibleGroup() == m_db->metadata()->lastSelectedGroup());
}
void TestParser::testGroups()
void TestParser::testCustomIcon()
{
QVERIFY(m_db->rootGroup() != 0);
QCOMPARE(m_db->rootGroup()->name(), QString("NewDatabase"));
QCOMPARE(m_db->rootGroup()->uuid().toBase64(), QString("zKuE27EWr0mlU75b2SRkTQ=="));
QVERIFY(m_db->rootGroup()->isExpanded());
TimeInfo ti = m_db->rootGroup()->timeInfo();
QCOMPARE(m_db->metadata()->customIcons().size(), 1);
Uuid uuid = Uuid::fromBase64("++vyI+daLk6omox4a6kQGA==");
QVERIFY(m_db->metadata()->customIcons().contains(uuid));
const QImage& img = m_db->metadata()->customIcons()[uuid];
QCOMPARE(img.width(), 16);
QCOMPARE(img.height(), 16);
for (int x=0; x<16; x++) {
for (int y=0; y<16; y++) {
QRgb rgb = img.pixel(x, y);
QCOMPARE(qRed(rgb), 128);
QCOMPARE(qGreen(rgb), 0);
QCOMPARE(qBlue(rgb), 128);
}
}
}
void TestParser::testGroupRoot()
{
const Group* group = m_db->rootGroup();
QVERIFY(group);
QCOMPARE(group->uuid().toBase64(), QString("lmU+9n0aeESKZvcEze+bRg=="));
QCOMPARE(group->name(), QString("NewDatabase"));
QCOMPARE(group->notes(), QString(""));
QCOMPARE(group->iconNumber(), 49);
QCOMPARE(group->iconUuid(), Uuid());
QVERIFY(group->isExpanded());
TimeInfo ti = group->timeInfo();
QCOMPARE(ti.lastModificationTime(), genDT(2010, 8, 8, 17, 24, 27));
QCOMPARE(ti.creationTime(), genDT(2010, 8, 7, 17, 24, 27));
QCOMPARE(ti.lastAccessTime(), genDT(2010, 8, 9, 9, 9, 44));
QCOMPARE(ti.expiryTime(), genDT(2010, 8, 8, 17, 24, 17));
QVERIFY(!ti.expires());
QCOMPARE(ti.usageCount(), 2);
QCOMPARE(ti.usageCount(), 52);
QCOMPARE(ti.locationChanged(), genDT(2010, 8, 8, 17, 24, 27));
QCOMPARE(group->defaultAutoTypeSequence(), QString(""));
QCOMPARE(group->autoTypeEnabled(), -1);
QCOMPARE(group->searchingEnabed(), -1);
QCOMPARE(group->lastTopVisibleEntry()->uuid().toBase64(), QString("+wSUOv6qf0OzW8/ZHAs2sA=="));
QCOMPARE(m_db->rootGroup()->children().size(), 3);
QCOMPARE(m_db->rootGroup()->children().at(0)->uuid().toBase64(), QString("abLbFtNUfEi5TmbaxiW6yg=="));
QCOMPARE(m_db->rootGroup()->children().at(1)->uuid().toBase64(), QString("u1lTRAICOkWv5QSl2xyU8w=="));
QCOMPARE(m_db->rootGroup()->children().at(2)->uuid().toBase64(), QString("7PAwxNhPaE2klutz45i2xg=="));
QCOMPARE(group->children().size(), 3);
QVERIFY(m_db->metadata()->recycleBin() == m_db->rootGroup()->children().at(2));
QCOMPARE(group->entries().size(), 2);
}
void TestParser::testGroup1()
{
const Group* group = m_db->rootGroup()->children().at(0);
QCOMPARE(group->uuid().toBase64(), QString("AaUYVdXsI02h4T1RiAlgtg=="));
QCOMPARE(group->name(), QString("General"));
QCOMPARE(group->notes(), QString("Group Notez"));
QCOMPARE(group->iconNumber(), 48);
QCOMPARE(group->iconUuid(), Uuid());
QCOMPARE(group->isExpanded(), true);
QCOMPARE(group->defaultAutoTypeSequence(), QString("{Password}{ENTER}"));
QCOMPARE(group->autoTypeEnabled(), 1);
QCOMPARE(group->searchingEnabed(), 0);
QVERIFY(!group->lastTopVisibleEntry());
}
void TestParser::testGroup2()
{
const Group* group = m_db->rootGroup()->children().at(1);
QCOMPARE(group->uuid().toBase64(), QString("1h4NtL5DK0yVyvaEnN//4A=="));
QCOMPARE(group->name(), QString("Windows"));
QCOMPARE(group->isExpanded(), false);
QCOMPARE(group->children().size(), 1);
const Group* child = group->children().first();
QCOMPARE(child->uuid().toBase64(), QString("HoYE/BjLfUSW257pCHJ/eA=="));
QCOMPARE(child->name(), QString("Subsub"));
QCOMPARE(child->entries().size(), 1);
const Entry* entry = child->entries().first();
QCOMPARE(entry->uuid().toBase64(), QString("GZpdQvGXOU2kaKRL/IVAGg=="));
QCOMPARE(entry->title(), QString("Subsub Entry"));
}
void TestParser::testEntry1()
{
const Entry* entry = m_db->rootGroup()->entries().at(0);
QCOMPARE(entry->uuid().toBase64(), QString("+wSUOv6qf0OzW8/ZHAs2sA=="));
QCOMPARE(entry->iconNumber(), 0);
QCOMPARE(entry->iconUuid(), Uuid());
QVERIFY(!entry->foregroundColor().isValid());
QVERIFY(!entry->backgroundColor().isValid());
QCOMPARE(entry->overrideUrl(), QString(""));
const TimeInfo ti = entry->timeInfo();
QCOMPARE(ti.lastModificationTime(), genDT(2010, 8, 25, 16, 19, 25));
QCOMPARE(ti.creationTime(), genDT(2010, 8, 25, 16, 13, 54));
QCOMPARE(ti.lastAccessTime(), genDT(2010, 8, 25, 16, 19, 25));
QCOMPARE(ti.expiryTime(), genDT(2010, 8, 25, 16, 12, 57));
QVERIFY(!ti.expires());
QCOMPARE(ti.usageCount(), 8);
QCOMPARE(ti.locationChanged(), genDT(2010, 8, 25, 16, 13, 54));
QHash<QString,QString> attrs = entry->attributes();
QCOMPARE(attrs.take("Notes"), QString("Notes"));
QCOMPARE(attrs.take("Password"), QString("Password"));
QCOMPARE(attrs.take("Title"), QString("Sample Entry 1"));
QCOMPARE(attrs.take("URL"), QString(""));
QCOMPARE(attrs.take("UserName"), QString("User Name"));
QVERIFY(attrs.isEmpty());
QCOMPARE(entry->title(), entry->attributes().value("Title"));
QCOMPARE(entry->url(), entry->attributes().value("URL"));
QCOMPARE(entry->username(), entry->attributes().value("UserName"));
QCOMPARE(entry->password(), entry->attributes().value("Password"));
QCOMPARE(entry->notes(), entry->attributes().value("Notes"));
QCOMPARE(entry->attachments().size(), 0);
QCOMPARE(entry->autoTypeEnabled(), false);
QCOMPARE(entry->autoTypeObfuscation(), 0);
QCOMPARE(entry->defaultAutoTypeSequence(), QString(""));
QCOMPARE(entry->autoTypeAssociations().size(), 1);
const AutoTypeAssociation assoc1 = entry->autoTypeAssociations().at(0);
QCOMPARE(assoc1.window, QString("Target Window"));
QCOMPARE(assoc1.sequence, QString(""));
}
void TestParser::testEntry2()
{
const Entry* entry = m_db->rootGroup()->entries().at(1);
QCOMPARE(entry->uuid().toBase64(), QString("4jbADG37hkiLh2O0qUdaOQ=="));
QCOMPARE(entry->iconNumber(), 0);
QCOMPARE(entry->iconUuid().toBase64(), QString("++vyI+daLk6omox4a6kQGA=="));
// TODO test entry->icon()
QCOMPARE(entry->foregroundColor(), QColor(255, 0, 0));
QCOMPARE(entry->backgroundColor(), QColor(255, 255, 0));
QCOMPARE(entry->overrideUrl(), QString("http://override.net/"));
const TimeInfo ti = entry->timeInfo();
QCOMPARE(ti.usageCount(), 7);
QHash<QString,QString> attrs = entry->attributes();
QCOMPARE(attrs.take("CustomString"), QString("isavalue"));
QCOMPARE(attrs.take("Notes"), QString(""));
QCOMPARE(attrs.take("Password"), QString("Jer60Hz8o9XHvxBGcRqT"));
QCOMPARE(attrs.take("Protected String"), QString("y")); // TODO should have a protection attribute
QCOMPARE(attrs.take("Title"), QString("Sample Entry 2"));
QCOMPARE(attrs.take("URL"), QString("http://www.keepassx.org/"));
QCOMPARE(attrs.take("UserName"), QString("notDEFUSERNAME"));
QVERIFY(attrs.isEmpty());
QCOMPARE(entry->attachments().size(), 1);
QCOMPARE(QString(entry->attachments().value("testattach.txt")), QString("42"));
QCOMPARE(entry->autoTypeEnabled(), true);
QCOMPARE(entry->autoTypeObfuscation(), 1);
QCOMPARE(entry->defaultAutoTypeSequence(), QString("{USERNAME}{TAB}{PASSWORD}{ENTER}"));
QCOMPARE(entry->autoTypeAssociations().size(), 2);
const AutoTypeAssociation assoc1 = entry->autoTypeAssociations().at(0);
QCOMPARE(assoc1.window, QString("Target Window"));
QCOMPARE(assoc1.sequence, QString("{Title}{UserName}"));
const AutoTypeAssociation assoc2 = entry->autoTypeAssociations().at(1);
QCOMPARE(assoc2.window, QString("Target Window 2"));
QCOMPARE(assoc2.sequence, QString("{Title}{UserName} test"));
}
void TestParser::testEntryHistory()
{
const Entry* entryMain = m_db->rootGroup()->entries().first();
QCOMPARE(entryMain->historyItems().size(), 2);
{
const Entry* entry = entryMain->historyItems().at(0);
QCOMPARE(entry->uuid(), entryMain->uuid());
QVERIFY(!entry->parent());
QCOMPARE(entry->children().size(), 0);
QCOMPARE(entry->timeInfo().lastModificationTime(), genDT(2010, 8, 25, 16, 13, 54));
QCOMPARE(entry->timeInfo().usageCount(), 3);
QCOMPARE(entry->title(), QString("Sample Entry"));
QCOMPARE(entry->url(), QString("http://www.somesite.com/"));
}
{
const Entry* entry = entryMain->historyItems().at(1);
QCOMPARE(entry->uuid(), entryMain->uuid());
QVERIFY(!entry->parent());
QCOMPARE(entry->children().size(), 0);
QCOMPARE(entry->timeInfo().lastModificationTime(), genDT(2010, 8, 25, 16, 15, 43));
QCOMPARE(entry->timeInfo().usageCount(), 7);
QCOMPARE(entry->title(), QString("Sample Entry 1"));
QCOMPARE(entry->url(), QString("http://www.somesite.com/"));
}
}
void TestParser::testDeletedObjects()
{
QList<DeletedObject> objList = m_db->deletedObjects();
DeletedObject delObj;
delObj = objList.takeFirst();
QCOMPARE(delObj.uuid.toBase64(), QString("5K/bzWCSmkCv5OZxYl4N/w=="));
QCOMPARE(delObj.deletionTime, genDT(2010, 8, 25, 16, 14, 12));
delObj = objList.takeFirst();
QCOMPARE(delObj.uuid.toBase64(), QString("80h8uSNWgkKhKCp1TgXF7g=="));
QCOMPARE(delObj.deletionTime, genDT(2010, 8, 25, 16, 14, 14));
QVERIFY(objList.isEmpty());
}
QTEST_MAIN(TestParser);