code wiki / _hdl_build / nx_chat_unicode_store_gate_t60.nx
nx_chat_unicode_store_gate_t60.nx source
↩ module page · 29 lines · 1659 B
1import "../nx_chat_unicode_store_t60.nx"
2import "nx_gate_verdict.nx"
3func gate_contains(b:*u8,n:i64,s:*u8,m:i64)->i64{
4 var i:i64=0
5 while i+m<=n {var j:i64=0;while j<m {if b[i+j]!=s[j]{break};j=j+1};if j==m{return 1};i=i+1}
6 return 0
7}
8func main(argc:i64,argv:*i64)->i64{
9 let c:*i64=gv_ctr()
10 let raw:*u8=sys_mmap(CDA_OUTCAP)
11 let body:*u8="Beach こんにちは Привет 🌊\nnext\tline"
12 let room:*u8="demo_unicode_t60"
13 let prior:i64=csa_fetch(room,0,CDA_FETCH_MAX,raw,CDA_OUTCAP)
14 if prior<0 {let posted:i64=cda_post_v2("unicode_t60","gate",body);gv_check("v2 store append accepted",posted==0,c)}
15 let n:i64=csa_fetch(room,0,CDA_FETCH_MAX,raw,CDA_OUTCAP)
16 let hex:*u8=sys_mmap(CDA_TEXT_MAX*2)
17 let hn:i64=cda_hexe(body,cda_len(body),hex)
18 gv_check("real stored UTF8 body roundtrips exact bytes",n>0&&gate_contains(raw,n,hex,hn)==1,c)
19 let big:*u8=sys_mmap(CDA_TEXT_MAX+2);var i:i64=0;while i<CDA_TEXT_MAX+1{big[i]=97 as u8;i=i+1};big[i]=0 as u8
20 gv_check("v2 oversize refusal through post",cda_post_v2("unicode_t60","gate",big)==CDA_EXIT_REFUSED,c)
21 let after:i64=csa_fetch(room,0,CDA_FETCH_MAX,raw,CDA_OUTCAP)
22 gv_check("refused post adds no stored row",after==n,c)
23 let clean:*u8=sys_mmap(CDA_TEXT_MAX+1)
24 gv_check("legacy truncation contract retained",cda_text_legacy(big,clean,CDA_TEXT_MAX)==CDA_TEXT_MAX,c)
25 gv_check("v2 body still valid UTF8",utf8_validate(body,cda_len(body))==cda_len(body),c)
26 cda_w("JSON-ROUNDTRIP\n");let listed:i64=cda_list("unicode_t60","0")
27 gv_check("actual list emits successfully",listed==0,c)
28 return gv_verdict("CHAT-UNICODE-STORE",c,"isolated /tmp store and actual post/list functions; no HTTP/browser claim")
29}