nx_book_test.nx source
↩ module page · 52 lines · 2232 B
1// nx_book_test.nx -- smoke for nx_book.
2
3import "nx_syscalls.nx"
4import "nx_book.nx"
5
6func main() -> i64 {
7 if NX_BK_N_KINDS != 12 { return 1 }
8 if NX_BS_N_SEVS != 4 { return 2 }
9 if nx_bk_kind_is_valid(NX_BK_TWIN_KEY_AUTHORIZED) != 1 { return 3 }
10 if nx_bk_kind_is_valid(12) != 0 { return 4 }
11 if nx_bk_severity_is_valid(NX_BS_ALERT) != 1 { return 5 }
12 if nx_bk_severity_is_valid(4) != 0 { return 6 }
13
14 let b: *NxBook = nx_book_new(16)
15 if b.count != 0 { return 7 }
16
17 // Record entries of various kinds + severities
18 nx_book_record(b, 1, 1000, NX_BK_TWIN_KEY_AUTHORIZED, NX_BS_NOTICE, 100, 0xa1)
19 nx_book_record(b, 2, 1100, NX_BK_XENO_ALERT, NX_BS_ALERT, 200, 0xb2)
20 nx_book_record(b, 3, 1200, NX_BK_SCAM_FLAGGED, NX_BS_WARNING, 300, 0xc3)
21 nx_book_record(b, 4, 1300, NX_BK_AI_PROPOSAL_BLOCKED, NX_BS_ALERT, 400, 0xd4)
22 if b.count != 4 { return 8 }
23
24 // Counts by kind / severity
25 if nx_book_count_by_kind(b, NX_BK_TWIN_KEY_AUTHORIZED) != 1 { return 9 }
26 if nx_book_count_by_kind(b, NX_BK_XENO_ALERT) != 1 { return 10 }
27 if nx_book_count_by_kind(b, NX_BK_FAILOVER_EXECUTED) != 0 { return 11 }
28 if nx_book_count_by_severity(b, NX_BS_ALERT) != 2 { return 12 }
29 if nx_book_count_by_severity(b, NX_BS_NOTICE) != 1 { return 13 }
30 if nx_book_count_by_severity(b, NX_BS_INFO) != 0 { return 14 }
31
32 // Unseen alerts: 2 entries are ALERT and not yet marked seen
33 if nx_book_count_unseen(b) != 4 { return 15 }
34 if nx_book_count_alerts_unseen(b) != 2 { return 16 }
35
36 // Mark one ALERT as seen
37 nx_book_mark_seen(b, 2)
38 if nx_book_count_alerts_unseen(b) != 1 { return 17 }
39 if nx_book_count_unseen(b) != 3 { return 18 }
40
41 // Bad kind / severity refused
42 if nx_book_record(b, 99, 0, 99, NX_BS_INFO, 0, 0) != NX_BK_ERR_BAD_KIND { return 19 }
43 if nx_book_record(b, 99, 0, NX_BK_TWIN_KEY_AUTHORIZED, 99, 0, 0) != NX_BK_ERR_BAD_KIND { return 20 }
44
45 // FULL
46 let small: *NxBook = nx_book_new(2)
47 nx_book_record(small, 1, 1, NX_BK_XENO_ALERT, NX_BS_INFO, 1, 0)
48 nx_book_record(small, 2, 2, NX_BK_XENO_ALERT, NX_BS_INFO, 2, 0)
49 if nx_book_record(small, 3, 3, NX_BK_XENO_ALERT, NX_BS_INFO, 3, 0) != NX_BK_ERR_FULL { return 21 }
50
51 return 0
52}