code wiki / (root) / nx_escl_test.nx

nx_escl_test.nx source

↩ module page · 63 lines · 4003 B

1// nx_escl_test.nx -- offline gate for the eSCL scan protocol layer (nx_escl). Unique exit codes per invariant: 2// 1-5 ScanSettings emit carries the requested resolution / region / color mode / format / source 3// 10-14 ScannerCapabilities parse extracts MaxWidth/MaxHeight + sees the advertised color modes & formats 4// 15-16 negative controls: a format NOT advertised -> 0 ; an absent tag -> -1 (no fabricated value) 5// expect_exit: 0 ; license_tier: ORIGINAL ; genealogy_id: project-printer-management-ipp-sclass-2026-06-20 6 7import "nx_syscalls.nx" 8import "nx_escl.nx" 9 10func t_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 11 12// A representative eSCL ScannerCapabilities response (Brother-class MFP: platen, gray/color, jpeg+pdf). 13func build_caps(buf: *u8) -> i64 { 14 var o: i64 = 0 15 o = ex_puts(buf, o, "<?xml version='1.0' encoding='UTF-8'?>" as *u8) 16 o = ex_puts(buf, o, "<scan:ScannerCapabilities xmlns:scan='http://schemas.hp.com/imaging/escl/2011/05/03' xmlns:pwg='http://www.pwg.org/schemas/2010/12/sm'>" as *u8) 17 o = ex_puts(buf, o, "<pwg:Version>2.6</pwg:Version>" as *u8) 18 o = ex_puts(buf, o, "<pwg:MakeAndModel>Brother DCP-L2540DW</pwg:MakeAndModel>" as *u8) 19 o = ex_puts(buf, o, "<scan:Platen><scan:PlatenInputCaps>" as *u8) 20 o = ex_puts(buf, o, "<scan:MaxWidth>2550</scan:MaxWidth>" as *u8) 21 o = ex_puts(buf, o, "<scan:MaxHeight>3508</scan:MaxHeight>" as *u8) 22 o = ex_puts(buf, o, "<scan:SettingProfiles><scan:SettingProfile>" as *u8) 23 o = ex_puts(buf, o, "<scan:ColorModes>" as *u8) 24 o = ex_puts(buf, o, "<scan:ColorMode>BlackAndWhite1</scan:ColorMode>" as *u8) 25 o = ex_puts(buf, o, "<scan:ColorMode>Grayscale8</scan:ColorMode>" as *u8) 26 o = ex_puts(buf, o, "<scan:ColorMode>RGB24</scan:ColorMode>" as *u8) 27 o = ex_puts(buf, o, "</scan:ColorModes>" as *u8) 28 o = ex_puts(buf, o, "<scan:DocumentFormats>" as *u8) 29 o = ex_puts(buf, o, "<pwg:DocumentFormat>image/jpeg</pwg:DocumentFormat>" as *u8) 30 o = ex_puts(buf, o, "<pwg:DocumentFormat>application/pdf</pwg:DocumentFormat>" as *u8) 31 o = ex_puts(buf, o, "</scan:DocumentFormats>" as *u8) 32 o = ex_puts(buf, o, "</scan:SettingProfile></scan:SettingProfiles>" as *u8) 33 o = ex_puts(buf, o, "</scan:PlatenInputCaps></scan:Platen>" as *u8) 34 o = ex_puts(buf, o, "</scan:ScannerCapabilities>" as *u8) 35 return o 36} 37 38func main() -> i64 { 39 // ===== ScanSettings emit ===== 40 let sbuf: *u8 = sys_mmap(4096) 41 let sn: i64 = nx_escl_scan_settings(sbuf, 300, 2550, 3300, "Grayscale8" as *u8, "image/jpeg" as *u8, "Platen" as *u8) 42 if nx_escl_find(sbuf, sn, "<scan:XResolution>300<" as *u8, 22) < 0 { return 1 } 43 if nx_escl_find(sbuf, sn, "<pwg:Width>2550<" as *u8, 16) < 0 { return 2 } 44 if nx_escl_find(sbuf, sn, "Grayscale8" as *u8, 10) < 0 { return 3 } 45 if nx_escl_find(sbuf, sn, "image/jpeg" as *u8, 10) < 0 { return 4 } 46 if nx_escl_find(sbuf, sn, "Platen" as *u8, 6) < 0 { return 5 } 47 48 // ===== ScannerCapabilities parse ===== 49 let cbuf: *u8 = sys_mmap(4096) 50 let cn: i64 = build_caps(cbuf) 51 if nx_escl_caps_int(cbuf, cn, "<scan:MaxWidth>" as *u8, 15) != 2550 { return 10 } 52 if nx_escl_caps_int(cbuf, cn, "<scan:MaxHeight>" as *u8, 16) != 3508 { return 11 } 53 if nx_escl_has(cbuf, cn, ">Grayscale8<" as *u8, 12) != 1 { return 12 } 54 if nx_escl_has(cbuf, cn, ">RGB24<" as *u8, 7) != 1 { return 13 } 55 if nx_escl_has(cbuf, cn, ">application/pdf<" as *u8, 17) != 1 { return 14 } 56 57 // ===== negative controls ===== 58 if nx_escl_has(cbuf, cn, ">image/tiff<" as *u8, 12) != 0 { return 15 } // format not advertised 59 if nx_escl_caps_int(cbuf, cn, "<scan:MaxDepth>" as *u8, 15) != (0 - 1) { return 16 } // absent tag -> -1 60 61 t_puts("nx_escl: PASS ScanSettings emit (300dpi / 2550x3300 / Grayscale8 / image/jpeg / Platen) + ScannerCapabilities parse (MaxWidth 2550, MaxHeight 3508, gray/RGB24, jpeg/pdf); absent format->0, absent tag->-1\n") 62 return 0 63}