Files
entity/tests/model_test.zi
waozi 5b7ea8517f Share one profile picture record and unlock sets by installed app
The account's entity.profile-appearance.v1 record now carries an app-set
picture as picture_kind 3, so the one picture a person chooses reaches every
app through the node's ordinary sync. A saved set picture whose image is no
longer declared falls back to the owner's Classic icon, and every other saved
choice decodes exactly as before.

Apps unlock picture sets. src/picture_sets.zi declares each set's name, the app
that unlocks it and its images; the picker, native extraction, entity.asset and
EntityProfileAssetAt all read that list, so adding a set is a data change. The
README documents the image spec for generated sets.

entity.profile answers "picture" for game HUDs: the account icon in current
numbers, or a set picture's bundle-relative image path.
2026-11-23 10:00:38 -03:00

111 lines
6.2 KiB
Ziran

#import, file "../src/model.zi";
#import, file "../src/node_url.zi";
#import, file "../src/picture_sets.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 }
}
// An app-set picture has no node number and keeps every other choice.
set_shown := EntityWithSetPicture(EntityDefault(), 3)
if set_shown.picture_kind != 3 || set_shown.set_picture != 3 { return 97 }
if EntityPublicIcon(set_shown) != 0 || EntityPublicIconChosen(EntityPublicIcon(set_shown)) { return 98 }
if EntityWithSetPicture(set_shown, PFP_SET_IMAGE_COUNT).set_picture != 3 { return 99 }
set_round := EntityDefault()
if !EntityDecode(EntityEncode(set_shown), *set_round) { return 100 }
if set_round.picture_kind != 3 || set_round.set_picture != 3 { return 101 }
// A saved set picture stays valid exactly while its image is declared, so
// removing a set falls back instead of leaving a picture that draws nothing.
declared: EntityState
if !EntitySetPictureValid(declared) { return 102 }
declared.set_picture = PFP_SET_IMAGE_COUNT
if EntitySetPictureValid(declared) { return 103 }
declared.set_picture = -1
if EntitySetPictureValid(declared) { return 104 }
// An out-of-range set picture is refused whole, never clamped into another
// person's choice.
if EntityDecode("{\"version\":1,\"name\":\"\",\"intention\":\"\",\"picture\":4,\"picture_kind\":3,\"set_picture\":99,\"theme\":0,\"accent\":0,\"material\":1,\"controls\":0,\"preferred\":0,\"nodes\":[\"https://example.com\"],\"extensions\":[]}", *set_round) { return 105 }
// 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
}