diff options
Diffstat (limited to 'tests/test_avatar.cpp')
| -rw-r--r-- | tests/test_avatar.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test_avatar.cpp b/tests/test_avatar.cpp index b53dfc1..72e5941 100644 --- a/tests/test_avatar.cpp +++ b/tests/test_avatar.cpp @@ -33,6 +33,7 @@ private slots: void aDisplayNameMeansAPerson(); void theListOverridesADisplayName(); void aColourIsStablePerAddress(); + void aPixmapIsStableAndDiffersPerSeed(); }; void TestAvatar::twoWordNameTakesOneLetterFromEach() @@ -119,5 +120,34 @@ void TestAvatar::aColourIsStablePerAddress() QVERIFY(Avatar::colourFor(QStringLiteral("b@example.org")) != first); } +void TestAvatar::aPixmapIsStableAndDiffersPerSeed() +{ + const QFont font; + const QPixmap first = Avatar::pixmapFor(QStringLiteral("a@example.org"), + QStringLiteral("AE"), + Avatar::Fill::Identicon, 44, font); + QCOMPARE(first.size(), QSize(44, 44)); + QVERIFY(!first.isNull()); + + const QPixmap again = Avatar::pixmapFor(QStringLiteral("a@example.org"), + QStringLiteral("AE"), + Avatar::Fill::Identicon, 44, font); + // Same seed, same image, byte for byte: the identity must not drift + // between repaints. + QCOMPARE(first.toImage(), again.toImage()); + + const QPixmap other = Avatar::pixmapFor(QStringLiteral("b@example.org"), + QStringLiteral("AE"), + Avatar::Fill::Identicon, 44, font); + // Different sender, different image, even with identical initials. + QVERIFY(first.toImage() != other.toImage()); + + const QPixmap twoTone = Avatar::pixmapFor(QStringLiteral("a@example.org"), + QStringLiteral("AE"), + Avatar::Fill::TwoTone, 44, font); + // The two fills are actually different renderings, not one with a flag. + QVERIFY(first.toImage() != twoTone.toImage()); +} + QTEST_MAIN(TestAvatar) #include "test_avatar.moc" |
