Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / communicate-dev / src / test / java / com / vayunmathur / communicate / whatsapp / W5Slice1DiagTest.kt

W5Slice1DiagTest.kt50 lines · 1.6 KiBRaw
1package com.vayunmathur.communicate.whatsapp
2
3import com.vayunmathur.communicate.data.whatsapp.WhatsAppDiag
4import kotlin.test.Test
5import kotlin.test.assertEquals
6import kotlin.test.assertTrue
7
8/**
9 * Slice 1 (w5): WhatsAppDiag log buffer + byte preview.
10 * `log()` also forwards to library Log (android.util.Log stub throws on JVM without
11 * Robolectric)... so these tests exercise [preview] and [clear] only, plus log-flow
12 * behavior is covered via preview. NOTE: log() calls Log.status which needs Android;
13 * keep this JVM-pure.
14 */
15class W5Slice1DiagTest {
16
17 @Test
18 fun preview_emptyBytes() {
19 assertEquals("0B[]", WhatsAppDiag.preview(ByteArray(0)))
20 }
21
22 @Test
23 fun preview_shortBytes_fullHex() {
24 assertEquals("3B[0102ff]", WhatsAppDiag.preview(byteArrayOf(1, 2, 0xFF.toByte())))
25 }
26
27 @Test
28 fun preview_longBytes_truncatedWithEllipsis() {
29 val data = ByteArray(30) { it.toByte() }
30 val out = WhatsAppDiag.preview(data, max = 24)
31 assertTrue(out.startsWith("30B["), out)
32 assertTrue(out.endsWith("…]"), out)
33 // 24 bytes -> 48 hex chars inside
34 assertEquals(48, out.removePrefix("30B[").removeSuffix("…]").length)
35 }
36
37 @Test
38 fun preview_exactMax_noEllipsis() {
39 val data = ByteArray(24) { 0xAB.toByte() }
40 val out = WhatsAppDiag.preview(data)
41 assertTrue(out.endsWith("]") && !out.contains("…"), out)
42 assertEquals("24B[" + "ab".repeat(24) + "]", out)
43 }
44
45 @Test
46 fun clear_emptiesLogFlow() {
47 WhatsAppDiag.clear()
48 assertEquals(emptyList(), WhatsAppDiag.log.value)
49 }
50}