From 67cc7bf2357980c51bc345855d9a8d69ff9a7a9f Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 26 Aug 2026 15:34:41 +0200 Subject: feat: paint the avatar squircle from a hashed seed --- tests/test_avatar.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/test_avatar.cpp') 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" -- cgit v1.2.3