code wiki / (root) / nx_ipp_submit_test.nx

nx_ipp_submit_test.nx source

↩ module page · 65 lines · 3512 B

1// nx_ipp_submit_test.nx -- offline gate for job-submission request builders (R-RASTER-1). 2// Unique exit codes per invariant: 3// 1x Validate-Job: op-id 0x0004, end-tag present, operation attrs round-trip (charset/printer-uri/ 4// requesting-user-name/job-name/document-format=image/urf with correct value-tags) 5// 2x Print-Job: op-id 0x0002, and a URF document appended after the end-tag starts with 'U' (0x55), 6// i.e. the document rides in the body immediately after the IPP request (RFC 8011 4.2.1) 7// expect_exit: 0 license_tier: ORIGINAL 8 9import "nx_syscalls.nx" 10import "nx_ipp_codec.nx" 11import "nx_ipp_submit.nx" 12import "nx_pwg_rle.nx" 13import "nx_urf.nx" 14 15func 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 } 16 17func main() -> i64 { 18 let sc: *i64 = sys_mmap(64) as *i64 19 let p_tag: *i64 = sc 20 let p_voff: *i64 = ((sc as i64) + 8) as *i64 21 let p_vlen: *i64 = ((sc as i64) + 16) as *i64 22 23 // ===== KAT 1: Validate-Job ===== 24 let req: *u8 = sys_mmap(2048) 25 let vlen: i64 = nx_ipp_build_validate_job(req, 1, 2, 3, 4, "/ipp/print", "nishi", "job1", "image/urf") 26 if nx_ipp_op_id(req) != NX_IPP_OP_VALIDATE_JOB { return 1 } 27 if (req[vlen - 1] as i64) != 0x03 { return 2 } // end-of-attributes-tag 28 29 if nx_ipp_find(req, vlen, "document-format", p_tag, p_voff, p_vlen) != NX_IPP_OK { return 3 } 30 if p_tag[0] != NX_IPP_VT_MIMETYPE { return 4 } 31 if nx_ipp_name_eq(req, p_voff[0], "image/urf", 9) != 1 { return 5 } 32 33 if nx_ipp_find(req, vlen, "printer-uri", p_tag, p_voff, p_vlen) != NX_IPP_OK { return 6 } 34 if p_tag[0] != NX_IPP_VT_URI { return 7 } 35 if nx_ipp_name_eq(req, p_voff[0], "ipp://1.2.3.4/ipp/print", 23) != 1 { return 8 } 36 37 if nx_ipp_find(req, vlen, "requesting-user-name", p_tag, p_voff, p_vlen) != NX_IPP_OK { return 9 } 38 if nx_ipp_name_eq(req, p_voff[0], "nishi", 5) != 1 { return 10 } 39 40 if nx_ipp_find(req, vlen, "job-name", p_tag, p_voff, p_vlen) != NX_IPP_OK { return 11 } 41 if nx_ipp_name_eq(req, p_voff[0], "job1", 4) != 1 { return 12 } 42 43 if nx_ipp_find(req, vlen, "attributes-charset", p_tag, p_voff, p_vlen) != NX_IPP_OK { return 13 } 44 if nx_ipp_name_eq(req, p_voff[0], "utf-8", 5) != 1 { return 14 } 45 46 // ===== KAT 2: Print-Job + appended URF document ===== 47 let req2: *u8 = sys_mmap(4096) 48 let plen: i64 = nx_ipp_build_print_job(req2, 1, 2, 3, 4, "/ipp/print", "nishi", "job2", "image/urf") 49 if nx_ipp_op_id(req2) != NX_IPP_OP_PRINT_JOB { return 20 } 50 if (req2[plen - 1] as i64) != 0x03 { return 21 } 51 // document-format still resolves scanning only the request header 52 if nx_ipp_find(req2, plen, "document-format", p_tag, p_voff, p_vlen) != NX_IPP_OK { return 22 } 53 if nx_ipp_name_eq(req2, p_voff[0], "image/urf", 9) != 1 { return 23 } 54 55 // build a tiny URF page (6x3) directly after the request -> it must start with 'U' (0x55) 56 let bm: *u8 = sys_mmap(64) 57 var b: i64 = 0 58 while b < 18 { bm[b] = (16 + b) as u8; b = b + 1 } 59 let doclen: i64 = nx_urf_encode_gray_page(((req2 as i64) + plen) as *u8, bm, 6, 3, 300, NX_URF_DUP_LONG, NX_URF_Q_NORMAL) 60 if (req2[plen] as i64) != 0x55 { return 24 } // 'U' of UNIRAST, right after end-tag 61 if doclen <= 44 { return 25 } // at least file+page header + some data 62 63 t_puts("nx_ipp_submit: 2/2 KAT groups PASS (validate-job + print-job request round-trip + URF doc appended)\n") 64 return 0 65}