OXYGENHUB
◆ v0.1.0 oxygenhub-android / app / src / test / java / io / oxygenhub / android / api / AvatarTest.kt
1.5 KiB · last changed Your avatar on the dashboard and the Account screen (closes #13) 10 days ago source blame history raw
1
package io.oxygenhub.android.api
2
3
import io.oxygenhub.android.Fixtures
4
import org.junit.Assert.assertEquals
5
import org.junit.Assert.assertNull
6
import org.junit.Assert.assertTrue
7
import org.junit.Test
8
9
class AvatarTest {
10
    @Test
11
    fun theHubsIdenticonIsReadIntoItsHueAndCells() {
12
        // As oxygenhub.io served /avatar/bob (2026-10-25).
13
        val a = Avatar.parse("image/svg+xml", Fixtures.text("identicon-bob.svg").toByteArray()) as Avatar.Identicon
14
        assertEquals(196, a.hue)
15
        assertEquals(16, a.cells.size)
16
        assertTrue((3 to 2) in a.cells && (1 to 5) in a.cells && (5 to 5) in a.cells)
17
        // Every cell has its mirror image, as the hub draws them.
18
        for ((x, y) in a.cells) assertTrue("($x,$y) has no mirror", (6 - x to y) in a.cells)
19
    }
20
21
    @Test
22
    fun anUploadedPictureIsKeptAsItCame() {
23
        val png = byteArrayOf(0x89.toByte(), 0x50, 0x4E, 0x47)
24
        val a = Avatar.parse("image/png", png) as Avatar.Picture
25
        assertTrue(a.bytes.contentEquals(png))
26
        assertTrue(Avatar.parse("image/jpeg; charset=binary", png) is Avatar.Picture)
27
    }
28
29
    @Test
30
    fun whatTheAppCannotDrawIsNoAvatar() {
31
        // A system account's own mark is SVG, but not the identicon.
32
        assertNull(Avatar.parse("image/svg+xml", "<svg><circle r=\"3\"/></svg>".toByteArray()))
33
        assertNull(Avatar.parse("text/html", "<html>".toByteArray()))
34
        assertNull(Avatar.parse(null, ByteArray(3)))
35
        assertNull(Avatar.parse("image/png", ByteArray(0)))
36
    }
37
}