aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_avatar.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-26 15:34:41 +0200
committerDanilo M. <danix@danix.xyz>2026-08-26 15:34:41 +0200
commit67cc7bf2357980c51bc345855d9a8d69ff9a7a9f (patch)
treeb8e12fde75395d504bc140a477c36ba9f5def74f /tests/test_avatar.cpp
parent39a0cce152dda3b3d828c6145f02c3db9bbd7449 (diff)
downloadqtmaildir-67cc7bf2357980c51bc345855d9a8d69ff9a7a9f.tar.gz
qtmaildir-67cc7bf2357980c51bc345855d9a8d69ff9a7a9f.zip
feat: paint the avatar squircle from a hashed seed
Diffstat (limited to 'tests/test_avatar.cpp')
-rw-r--r--tests/test_avatar.cpp30
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"