code wiki / _hdl_build / nx_stl_view_html_test.nx

nx_stl_view_html_test.nx source

↩ module page · 108 lines · 4736 B

1// nx_stl_view_html_test.nx -- ACCEPTANCE GATE for nx_stl_view_html. 2// Builds the same synthetic 1-triangle binary STL as the slice test (v0=0, v1=(10,0,10)mm, 3// v2=(0,10,10)mm), emits the viewer HTML, and asserts: well-formed doctype, a <canvas>, the 4// sovereign WebGL markers (getContext('webgl'), drawArrays), the embedded geometry array with 5// the EXACT expected vertex string, the correct triangle count in the HUD, and NO three.js 6// (sovereignty check -- nothing injected). All assertions are exact substring/structural facts. 7// license_tier: ORIGINAL 8import "nx_stl_view_html.nx" 9import "nx_fab_slice.nx" 10import "nx_syscalls.nx" 11 12func vt_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 13func vt_putn(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } let t: *u8 = sys_mmap(28); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { bb[i] = t[k-1-i]; i = i + 1 } sys_write(1, bb, k); return 0 } 14 15func vt_w32(b: *u8, off: i64, v: i64) -> i64 { 16 b[off] = (v % 256) as u8 17 b[off+1] = ((v / 256) % 256) as u8 18 b[off+2] = ((v / 65536) % 256) as u8 19 b[off+3] = ((v / 16777216) % 256) as u8 20 return 4 21} 22 23// strlen 24func vt_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 25 26// substring search: does hay (len hn) contain needle (NUL-terminated)? 1/0 27func vt_has(hay: *u8, hn: i64, needle: *u8) -> i64 { 28 let nl: i64 = vt_len(needle) 29 if nl == 0 { return 1 } 30 var i: i64 = 0 31 while i + nl <= hn { 32 var j: i64 = 0 33 var ok: i64 = 1 34 while j < nl { if hay[i+j] != needle[j] { ok = 0; j = nl } j = j + 1 } 35 if ok == 1 { return 1 } 36 i = i + 1 37 } 38 return 0 39} 40 41func main() -> i64 { 42 var pass: i64 = 0 43 var total: i64 = 0 44 45 // synthetic STL: 1 triangle, v0=(0,0,0), v1=(10,0,10), v2=(0,10,10) mm 46 let stl: *u8 = sys_mmap(256) 47 vt_w32(stl, 80, 1) 48 vt_w32(stl, 108, 1092616192) // v1.x = 10.0f 49 vt_w32(stl, 116, 1092616192) // v1.z = 10.0f 50 vt_w32(stl, 124, 1092616192) // v2.y = 10.0f 51 vt_w32(stl, 128, 1092616192) // v2.z = 10.0f 52 53 let html: *u8 = sys_mmap(65536) 54 let hn: i64 = nx_stl_view_emit(stl, html) 55 56 // T1: non-trivial length + NUL terminated at hn 57 total = total + 1 58 if hn > 1500 { if html[hn] == (0 as u8) { pass = pass + 1 } } 59 if hn <= 1500 { vt_puts("T1 FAIL len=" as *u8); vt_putn(hn); vt_puts("\n" as *u8) } 60 61 // T2: doctype + canvas 62 total = total + 1 63 var t2: i64 = 1 64 if vt_has(html, hn, "<!doctype html>" as *u8) == 0 { t2 = 0 } 65 if vt_has(html, hn, "<canvas id=c>" as *u8) == 0 { t2 = 0 } 66 if t2 == 1 { pass = pass + 1 } 67 if t2 == 0 { vt_puts("T2 FAIL structure\n" as *u8) } 68 69 // T3: sovereign WebGL renderer markers 70 total = total + 1 71 var t3: i64 = 1 72 if vt_has(html, hn, "getContext('webgl')" as *u8) == 0 { t3 = 0 } 73 if vt_has(html, hn, "drawArrays" as *u8) == 0 { t3 = 0 } 74 if vt_has(html, hn, "VERTEX_SHADER" as *u8) == 0 { t3 = 0 } 75 if t3 == 1 { pass = pass + 1 } 76 if t3 == 0 { vt_puts("T3 FAIL webgl markers\n" as *u8) } 77 78 // T4: SOVEREIGNTY -- no three.js injected 79 total = total + 1 80 var t4: i64 = 1 81 if vt_has(html, hn, "three.js" as *u8) == 1 { t4 = 0 } 82 if vt_has(html, hn, "THREE." as *u8) == 1 { t4 = 0 } 83 if vt_has(html, hn, "cdn" as *u8) == 1 { t4 = 0 } 84 if t4 == 1 { pass = pass + 1 } 85 if t4 == 0 { vt_puts("T4 FAIL not sovereign (external dep found)\n" as *u8) } 86 87 // T5: embedded geometry contains the exact triangle vertices (mm, 3-decimals), correctly ordered 88 // v0=0,0,0 v1=10,0,10 v2=0,10,10 -> the comma-joined run: 89 total = total + 1 90 let geom: *u8 = "V=[0.000,0.000,0.000,10.000,0.000,10.000,0.000,10.000,10.000];" as *u8 91 if vt_has(html, hn, geom) == 1 { pass = pass + 1 } 92 if vt_has(html, hn, geom) == 0 { vt_puts("T5 FAIL geometry array\n" as *u8) } 93 94 // T6: HUD shows the triangle count 95 total = total + 1 96 if vt_has(html, hn, "tris=1<" as *u8) == 1 { pass = pass + 1 } 97 if vt_has(html, hn, "tris=1<" as *u8) == 0 { vt_puts("T6 FAIL tri count in hud\n" as *u8) } 98 99 // T7: closes html 100 total = total + 1 101 if vt_has(html, hn, "</script></body></html>" as *u8) == 1 { pass = pass + 1 } 102 if vt_has(html, hn, "</script></body></html>" as *u8) == 0 { vt_puts("T7 FAIL close\n" as *u8) } 103 104 vt_puts("STL-VIEW " as *u8); vt_putn(pass); vt_puts("/" as *u8); vt_putn(total); vt_puts("\n" as *u8) 105 if pass == total { vt_puts("STL-VIEW ALL-PASS\n" as *u8); sys_exit(0) } 106 sys_exit(1) 107 return 1 108}