nx_color_meter_test.nx source
↩ module page · 62 lines · 2872 B
1// nx_color_meter_test.nx -- gate for per-color (CMYK) toner coverage (nx_color_meter). Pure-color KATs prove
2// the GCR separation is honest; unique exit codes per invariant:
3// 1-4 cyan(0,255,255) -> C only 5-8 black(0,0,0) -> K only (GCR pulls gray->black toner)
4// 10-13 white -> nothing 20-23 red(255,0,0) -> M + Y
5// 30 50% gray -> K ~= 498039 ppm (~50%) 40-43 per-color ISO-19798 ledger + status
6// expect_exit: 0 ; license_tier: ORIGINAL ; genealogy_id: project-printer-management-ipp-sclass-2026-06-20
7
8import "nx_syscalls.nx"
9import "nx_color_meter.nx"
10
11func 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 }
12
13func px(rgb: *u8, r: i64, g: i64, b: i64) -> i64 { rgb[0] = r as u8; rgb[1] = g as u8; rgb[2] = b as u8; return 0 }
14
15func main() -> i64 {
16 let rgb: *u8 = sys_mmap(16)
17 let o: *i64 = sys_mmap(64) as *i64
18
19 // cyan -> C only
20 px(rgb, 0, 255, 255); nx_color_coverage(rgb, 1, o)
21 if o[NX_CMY_C] != 1000000 { return 1 }
22 if o[NX_CMY_M] != 0 { return 2 }
23 if o[NX_CMY_Y] != 0 { return 3 }
24 if o[NX_CMY_K] != 0 { return 4 }
25
26 // black -> K only (GCR: gray/black consumes BLACK toner, not a CMY mix)
27 px(rgb, 0, 0, 0); nx_color_coverage(rgb, 1, o)
28 if o[NX_CMY_C] != 0 { return 5 }
29 if o[NX_CMY_M] != 0 { return 6 }
30 if o[NX_CMY_Y] != 0 { return 7 }
31 if o[NX_CMY_K] != 1000000 { return 8 }
32
33 // white -> nothing
34 px(rgb, 255, 255, 255); nx_color_coverage(rgb, 1, o)
35 if o[NX_CMY_C] != 0 { return 10 }
36 if o[NX_CMY_K] != 0 { return 11 }
37
38 // red -> magenta + yellow
39 px(rgb, 255, 0, 0); nx_color_coverage(rgb, 1, o)
40 if o[NX_CMY_C] != 0 { return 20 }
41 if o[NX_CMY_M] != 1000000 { return 21 }
42 if o[NX_CMY_Y] != 1000000 { return 22 }
43 if o[NX_CMY_K] != 0 { return 23 }
44
45 // 50% gray -> K ~= 498039 ppm (127/255), CMY 0
46 px(rgb, 128, 128, 128); nx_color_coverage(rgb, 1, o)
47 if o[NX_CMY_C] != 0 { return 30 }
48 if o[NX_CMY_K] != 498039 { return 31 }
49
50 // per-color ISO-19798 ledger + status
51 if nx_color_remaining_bp(1000, 0) != 10000 { return 40 } // fresh -> 100%
52 if nx_color_remaining_bp(1000, 25000000) != 5000 { return 41 } // half a 1000pg cartridge -> 50%
53 if nx_color_remaining_bp(1000, 50000000) != 0 { return 42 } // spent -> 0%
54 if nx_color_remaining_bp(0, 0) != (0 - 1) { return 43 } // unknown yield -> -1
55 if nx_color_status(10000) != NX_CSUP_OK { return 44 }
56 if nx_color_status(500) != NX_CSUP_LOW { return 45 }
57 if nx_color_status(0) != NX_CSUP_EMPTY { return 46 }
58 if nx_color_status(0 - 1) != NX_CSUP_UNKNOWN { return 47 }
59
60 t_puts("nx_color_meter: PASS per-color CMYK coverage (cyan->C, black->K via GCR, red->M+Y, gray->K=498039) + ISO-19798 per-color ledger/status\n")
61 return 0
62}