Files
entity/tests/model_test.zi
T
waozi 33e5446288 Read the node's profile picture for every app through one path
EntityPictureReader signs in to the account's node on connecting and every
ten minutes and returns its picture, so a host such as Breeze shows a
picture chosen in another app. EntityPictureAdopt is the shared rule: the
node's picture replaces the profile's unless a choice made here has not
reached the node yet. Entity's own store uses the same rule.
2026-10-30 00:44:18 -03:00

91 lines
4.8 KiB
Ziran

#import, file "../src/model.zi";
#import, file "../src/node_url.zi";
#import "std/c_string"
#import "std/text_buffer"
#program_export
main :: () -> s32 {
for icon: cast(s32)41..65 { if EntityPictureFromPublicIcon(icon) != icon - 41 { return 80 } }
for icon: cast(s32)124..126 { if EntityPictureFromPublicIcon(icon) != icon - 124 + 25 { return 81 } }
if EntityPictureFromPublicIcon(1) != 1 || EntityPictureFromPublicIcon(7) != 21 || EntityPictureFromPublicIcon(11) != 24 { return 82 }
if EntityPictureFromPublicIcon(0) != -1 || EntityPictureFromPublicIcon(99) != -1 { return 83 }
decoded: EntityState
legacy := "{\"version\":1,\"name\":\"\",\"intention\":\"\",\"picture\":0,\"theme\":0,\"accent\":0,\"material\":1,\"controls\":0,\"preferred\":0,\"nodes\":[\"https://example.com\"],\"extensions\":[]}"
if !EntityDecode(legacy, *decoded) || decoded.host_navigation { return 10 }
if !decoded.show_storage { return 84 }
state := EntityDefault()
for picture: cast(s32)0..27 {
state.picture = picture
if EntityPictureFromPublicIcon(EntityPublicIcon(state)) != picture { return 87 }
}
state.picture_kind = 1
for picture: cast(s32)0..2 {
state.abstract_picture = picture
if EntityAbstractFromPublicIcon(EntityPublicIcon(state)) != picture { return 88 }
}
if EntityAbstractFromPublicIcon(126) != -1 || EntityAbstractFromPublicIcon(130) != -1 { return 89 }
// Kryon pictures publish as their Kryon icon numbers, abstract as 127-129.
if EntityPictureIcon(0, 0, 2) != 41 || EntityPictureIcon(0, 24, 0) != 65 || EntityPictureIcon(0, 27, 0) != 126 { return 90 }
if EntityPictureIcon(1, 5, 0) != 127 || EntityPictureIcon(1, 0, 2) != 129 { return 91 }
// A picture from the node replaces the profile's in either kind.
shown := EntityWithPublicIcon(EntityDefault(), 128)
if shown.picture_kind != 1 || shown.abstract_picture != 1 || EntityPublicIcon(shown) != 128 { return 92 }
shown = EntityWithPublicIcon(shown, 125)
if shown.picture_kind != 0 || shown.picture != 26 || EntityPublicIcon(shown) != 125 { return 93 }
unchanged := EntityWithPublicIcon(shown, 130)
if EntityPublicIcon(unchanged) != 125 { return 94 }
for icon: cast(s32)0..140 {
current := icon >= 41 && icon <= 65 || icon >= 124 && icon <= 129
if EntityPublicIconChosen(icon) != current { return 92 }
}
// Friends show their own picture in current numbers, older numbers mapped.
if EntityFriendIcon(55, "a") != 55 || EntityFriendIcon(125, "a") != 125 || EntityFriendIcon(128, "a") != 128 { return 93 }
if EntityFriendIcon(1, "a") != 42 || EntityFriendIcon(11, "a") != 65 { return 94 }
// Without a picture, the same person always gets the same abstract one.
without := EntityFriendIcon(0, "0123abcd")
if without < 127 || without > 129 || EntityFriendIcon(99, "0123abcd") != without { return 95 }
if EntityFriendIcon(0, "0") == EntityFriendIcon(0, "1") && EntityFriendIcon(0, "1") == EntityFriendIcon(0, "2") { return 96 }
if !state.show_storage { return 85 }
state.show_storage = false
if state.host_navigation { return 8 }
state.host_navigation = true
unused CopyCString("Waozi \"quoted\" \\ UTF-8: 花", state.name[:])
unused CopyCString("Breathe slowly", state.intention[:])
// A profile saved with the removed Avatar loads with its Classic picture.
state.picture_kind = 2
state.abstract_picture = 1
state.picture = 27
state.theme = 2
state.node_count = 2
state.preferred = 1
unused CopyCString("http://127.0.0.1:8090", state.nodes[1][:])
EntityAddExtension(*state, "inbe", "Inner Breeze")
encoded := EntityEncode(state)
if !EntityDecode(encoded, *decoded) { return 1 }
if !decoded.host_navigation { return 9 }
if decoded.show_storage { return 86 }
if decoded.picture_kind != 0 || decoded.abstract_picture != 1 { return 11 }
if TextUntilNul(decoded.name[:]) != TextUntilNul(state.name[:]) ||
TextUntilNul(decoded.intention[:]) != "Breathe slowly" || decoded.picture != 27 ||
decoded.preferred != 1 || decoded.node_count != 2 ||
TextUntilNul(decoded.extensions[0].id[:]) != "inbe" { return 2 }
EntityFree(encoded)
state.preferred = 2
invalid := EntityEncode(state)
if EntityDecode(invalid, *decoded) { return 3 }
EntityFree(invalid)
state.preferred = 0
state.nodes[1] = state.nodes[0]
duplicate := EntityEncode(state)
if EntityDecode(duplicate, *decoded) { return 4 }
EntityFree(duplicate)
unused CopyCString("https://example.com/path", state.nodes[1][:])
path := EntityEncode(state)
if EntityDecode(path, *decoded) { return 5 }
EntityFree(path)
if EntityDecode("{\"version\":2}", *decoded) { return 6 }
if NodeOrigin("http://example.com") != "" || NodeOrigin("https://name:[email protected]") != "" { return 7 }
return 0
}