nx_gltf_inventory_gate_t180.nx source
↩ module page · 45 lines · 3526 B
1import "nx_gltf_load.nx"
2import "nx_itoa_lib.nx"
3func gi_test_json(s:*u8,stats:*i64)->i64 {
4 let n:i64=gll_slen(s);let padded:i64=gll_align4(n);let total:i64=20+padded
5 let b:*u8=sys_mmap(total)
6 glp_u32(b,0,0x46546c67);glp_u32(b,4,2);glp_u32(b,8,total);glp_u32(b,12,padded);glp_u32(b,16,0x4e4f534a)
7 var i:i64=0;while i<padded {b[20+i]=32 as u8;if i<n {b[20+i]=s[i]};i=i+1}
8 let rc:i64=gltf_inventory_glb(b,total,stats);sys_munmap(b,total);return rc
9}
10func gi_check(ok:i64,name:*u8)->i64 {if ok==1{return 0};sys_write(1,"FAIL ",5);sys_write(1,name,gll_slen(name));sys_write(1,"\n",1);return 1}
11func main()->i64 {
12 let s:*i64=sys_mmap(GLI_STATS_WORDS*8) as *i64
13 var f:i64=0
14 let result:i64=gi_test_json("{\"asset\":{\"version\":\"2.0\"},\"scenes\":[{\"nodes\":[0]}],\"nodes\":[{\"translation\":[0,0,0],\"rotation\":[0,0,0,1],\"scale\":[1,1,1],\"weights\":[0]}],\"meshes\":[{\"weights\":[0],\"primitives\":[{\"targets\":[{\"POSITION\":0},{\"POSITION\":1}]}]}],\"skins\":[{\"joints\":[0,1]}],\"animations\":[{\"channels\":[{\"sampler\":0,\"target\":{\"node\":0,\"path\":\"translation\"}},{\"sampler\":0,\"target\":{\"node\":0,\"path\":\"rotation\"}},{\"sampler\":0,\"target\":{\"node\":0,\"path\":\"scale\"}},{\"sampler\":0,\"target\":{\"node\":0,\"path\":\"weights\"}},{\"sampler\":0,\"target\":{\"node\":0,\"path\":\"custom\"}}],\"samplers\":[]},{\"channels\":[{\"sampler\":0,\"target\":{\"node\":0,\"path\":\"rotation\"}}],\"samplers\":[]}],\"materials\":[{},{}]}",s)
15 f=f+gi_check(result==0,"valid_fixture")
16 f=f+gi_check(s[4]==1 && s[5]==1 && s[6]==1 && s[7]==2 && s[8]==1 && s[9]==2,"top_level_counts")
17 f=f+gi_check(s[17]==1 && s[18]==2 && s[19]==1 && s[20]==2,"morph_and_skin_counts")
18 f=f+gi_check(s[21]==6 && s[22]==1 && s[23]==2 && s[24]==1 && s[25]==1 && s[26]==1,"complete_channel_counts")
19 f=f+gi_check(s[28]==1 && s[29]==1 && s[30]==1 && s[31]==1 && s[32]==1,"transform_presence")
20 f=f+gi_check(gi_test_json("{\"asset\":{\"version\":\"2.0\"}}",s)==0 && s[9]==0,"absent_animation_zero")
21 f=f+gi_check(gi_test_json("{\"nodes\":{},\"asset\":{\"version\":\"2.0\"}}",s)==-6,"wrong_array_type")
22 f=f+gi_check(gi_test_json("{\"nodes\":[],\"nodes\":[]}",s)==-6,"duplicate_inventory_key")
23 f=f+gi_check(gi_test_json("{\"nodes\":[}",s)==-5,"malformed_json")
24 f=f+gi_check(gi_test_json("{\"animations\":[{\"channels\":[{\"target\":{}}]}]}",s)==-6,"missing_channel_path")
25 let count:i64=5000
26 let cap:i64=count*3+64;let many:*u8=sys_mmap(cap)
27 let prefix:*u8="{\"asset\":{\"version\":\"2.0\"},\"nodes\":["
28 let pn:i64=gll_slen(prefix);var i:i64=0;while i<pn{many[i]=prefix[i];i=i+1}
29 var pos:i64=pn;var k:i64=0
30 while k<count {if k>0{many[pos]=44 as u8;pos=pos+1};many[pos]=123 as u8;many[pos+1]=125 as u8;pos=pos+2;k=k+1}
31 many[pos]=93 as u8;many[pos+1]=125 as u8;many[pos+2]=0 as u8
32 f=f+gi_check(gi_test_json(many,s)==0 && s[5]==5000,"no_4096_item_ceiling")
33 sys_munmap(many,cap)
34 let tiny:*u8=sys_mmap(32)
35 glp_u32(tiny,0,0x46546c67);glp_u32(tiny,4,2);glp_u32(tiny,8,24);glp_u32(tiny,12,4);glp_u32(tiny,16,0x4e4f534a)
36 tiny[20]=123 as u8;tiny[21]=125 as u8;tiny[22]=32 as u8;tiny[23]=32 as u8
37 f=f+gi_check(gltf_inventory_glb(tiny,23,s)==-2,"truncated_container")
38 glp_u32(tiny,12,100)
39 f=f+gi_check(gltf_inventory_glb(tiny,24,s)==-3,"chunk_overrun")
40 glp_u32(tiny,12,4);glp_u32(tiny,16,0x004e4942)
41 f=f+gi_check(gltf_inventory_glb(tiny,24,s)==-4,"bin_before_json")
42 sys_munmap(tiny,32);sys_munmap(s as *u8,GLI_STATS_WORDS*8)
43 sys_write(1,"GLTF-INVENTORY cases=14 failed=",31);nxi_out(f);sys_write(1,"\n",1)
44 return f
45}