nx_arc_test.nx source
↩ module page · 139 lines · 6486 B
1// nx_arc_test.nx -- smoke for arc + stage substrate.
2
3import "nx_syscalls.nx"
4import "nx_tier.nx"
5import "nx_arc.nx"
6
7func main() -> nx_int {
8 // Build a 3-stage arc with 12 total pool IDs (4 location, 3 outfit,
9 // 2 pose, 2 expression, 1 camera laid out flat in pools[]).
10 let arc: *Arc = nx_arc_alloc(42, 3, NX_AS_AUTHORED, 0, 12)
11
12 if arc.arc_id != 42 { return 1 }
13 if arc.n_stages != 3 { return 2 }
14 if arc.source != NX_AS_AUTHORED { return 3 }
15 if arc.n_pool_ids != 12 { return 4 }
16
17 // Lay pool IDs into pools[]:
18 // pools[0..3] = location IDs (4): 100, 101, 102, 103
19 // pools[4..6] = outfit IDs (3): 200, 201, 202
20 // pools[7..8] = pose IDs (2): 300, 301
21 // pools[9..10] = expression IDs (2): 400, 401
22 // pools[11] = camera ID (1): 500
23 nx_arc_pool_set(arc, 0, 100)
24 nx_arc_pool_set(arc, 1, 101)
25 nx_arc_pool_set(arc, 2, 102)
26 nx_arc_pool_set(arc, 3, 103)
27 nx_arc_pool_set(arc, 4, 200)
28 nx_arc_pool_set(arc, 5, 201)
29 nx_arc_pool_set(arc, 6, 202)
30 nx_arc_pool_set(arc, 7, 300)
31 nx_arc_pool_set(arc, 8, 301)
32 nx_arc_pool_set(arc, 9, 400)
33 nx_arc_pool_set(arc, 10, 401)
34 nx_arc_pool_set(arc, 11, 500)
35
36 if nx_arc_pool_get(arc, 0) != 100 { return 10 }
37 if nx_arc_pool_get(arc, 5) != 201 { return 11 }
38 if nx_arc_pool_get(arc, 11) != 500 { return 12 }
39
40 // Out-of-range pool reads -> 0
41 if nx_arc_pool_get(arc, 12) != 0 { return 13 }
42 if nx_arc_pool_get(arc, 0 - 1) != 0 { return 14 }
43
44 // === Test 2: basic stage setters ================================
45 nx_arc_stage_set_basic(arc, 0,
46 1, // stage_number
47 NX_AW_UNAWARE, // awareness
48 NX_ET_DOMESTIC, // emotional_tone
49 0, 200, // min/max arousal Q10
50 5) // images before advance
51
52 if nx_arc_stage_get(arc, 0, NX_AST_F_STAGE_NUMBER) != 1 { return 20 }
53 if nx_arc_stage_get(arc, 0, NX_AST_F_AWARENESS) != NX_AW_UNAWARE { return 21 }
54 if nx_arc_stage_get(arc, 0, NX_AST_F_EMOTIONAL_TONE) != NX_ET_DOMESTIC { return 22 }
55 if nx_arc_stage_get(arc, 0, NX_AST_F_MIN_AROUSAL_Q10) != 0 { return 23 }
56 if nx_arc_stage_get(arc, 0, NX_AST_F_MAX_AROUSAL_Q10) != 200 { return 24 }
57 if nx_arc_stage_get(arc, 0, NX_AST_F_IMAGES_BEFORE_ADVANCE) != 5 { return 25 }
58
59 // === Test 3: pool wiring ========================================
60 // Stage 0 uses all 4 locations, all 3 outfits, all 2 poses
61 nx_arc_stage_set_pool(arc, 0, NX_ARC_POOL_LOCATION, 0, 4)
62 nx_arc_stage_set_pool(arc, 0, NX_ARC_POOL_OUTFIT, 4, 3)
63 nx_arc_stage_set_pool(arc, 0, NX_ARC_POOL_POSE, 7, 2)
64
65 let off_buf: *i64 = (sys_mmap(8)) as *i64
66 let len_buf: *i64 = (sys_mmap(8)) as *i64
67 nx_arc_stage_get_pool(arc, 0, NX_ARC_POOL_LOCATION, off_buf, len_buf)
68 if off_buf[0] != 0 { return 30 }
69 if len_buf[0] != 4 { return 31 }
70
71 nx_arc_stage_get_pool(arc, 0, NX_ARC_POOL_OUTFIT, off_buf, len_buf)
72 if off_buf[0] != 4 { return 32 }
73 if len_buf[0] != 3 { return 33 }
74
75 nx_arc_stage_get_pool(arc, 0, NX_ARC_POOL_POSE, off_buf, len_buf)
76 if off_buf[0] != 7 { return 34 }
77 if len_buf[0] != 2 { return 35 }
78
79 // Pool kinds that weren't set return (0, 0).
80 nx_arc_stage_get_pool(arc, 0, NX_ARC_POOL_EXPRESSION, off_buf, len_buf)
81 if off_buf[0] != 0 { return 36 }
82 if len_buf[0] != 0 { return 37 }
83
84 // Invalid pool kind -> -1
85 if nx_arc_stage_get_pool(arc, 0, 99, off_buf, len_buf) != 0 - 1 { return 38 }
86
87 // === Test 4: pool slice indexing ================================
88 // Confirm we can iterate stage 0's location pool: pools[0..4)
89 let loc_id_0: nx_int = nx_arc_pool_get(arc, 0)
90 let loc_id_3: nx_int = nx_arc_pool_get(arc, 3)
91 if loc_id_0 != 100 { return 40 }
92 if loc_id_3 != 103 { return 41 }
93
94 // === Test 5: out-of-range stage indices ========================
95 if nx_arc_stage_get(arc, 0 - 1, NX_AST_F_STAGE_NUMBER) != 0 { return 50 }
96 if nx_arc_stage_get(arc, 3, NX_AST_F_STAGE_NUMBER) != 0 { return 51 }
97 if nx_arc_stage_get(arc, 0, 99) != 0 { return 52 }
98 if nx_arc_stage_set(arc, 0 - 1, NX_AST_F_STAGE_NUMBER, 7) != 0 - 1 { return 53 }
99 if nx_arc_stage_set(arc, 0, 99, 7) != 0 - 1 { return 54 }
100
101 // === Test 6: sealed-enum validators ============================
102 if nx_as_source_is_valid(NX_AS_AUTHORED) != 1 { return 60 }
103 if nx_as_source_is_valid(NX_AS_COMPANION) != 1 { return 61 }
104 if nx_as_source_is_valid(NX_AS_N_SOURCES) != 0 { return 62 }
105 if nx_as_source_is_valid(99) != 0 { return 63 }
106
107 if nx_aw_level_is_valid(NX_AW_UNAWARE) != 1 { return 70 }
108 if nx_aw_level_is_valid(NX_AW_DIRECT_ENGAGEMENT) != 1 { return 71 }
109 if nx_aw_level_is_valid(NX_AW_N_LEVELS) != 0 { return 72 }
110
111 if nx_et_tone_is_valid(NX_ET_DOMESTIC) != 1 { return 80 }
112 if nx_et_tone_is_valid(NX_ET_AFTERGLOW) != 1 { return 81 }
113 if nx_et_tone_is_valid(NX_ET_N_TONES) != 0 { return 82 }
114
115 if nx_arc_pool_kind_is_valid(NX_ARC_POOL_LOCATION) != 1 { return 90 }
116 if nx_arc_pool_kind_is_valid(NX_ARC_POOL_CAMERA) != 1 { return 91 }
117 if nx_arc_pool_kind_is_valid(NX_ARC_POOL_N_KINDS) != 0 { return 92 }
118 if nx_arc_pool_kind_is_valid(99) != 0 { return 93 }
119
120 // === Test 7: a second stage, full multi-stage arc ===============
121 nx_arc_stage_set_basic(arc, 1,
122 2, NX_AW_PEEKING, NX_ET_TENDER,
123 200, 500, 7)
124 nx_arc_stage_set_basic(arc, 2,
125 3, NX_AW_EYE_CONTACT, NX_ET_INTENSE,
126 500, 1024, 4)
127
128 if nx_arc_stage_get(arc, 1, NX_AST_F_STAGE_NUMBER) != 2 { return 100 }
129 if nx_arc_stage_get(arc, 2, NX_AST_F_STAGE_NUMBER) != 3 { return 101 }
130 if nx_arc_stage_get(arc, 2, NX_AST_F_AWARENESS) != NX_AW_EYE_CONTACT { return 102 }
131 if nx_arc_stage_get(arc, 2, NX_AST_F_EMOTIONAL_TONE) != NX_ET_INTENSE { return 103 }
132 if nx_arc_stage_get(arc, 2, NX_AST_F_MAX_AROUSAL_Q10) != 1024 { return 104 }
133
134 // Stage 0's data should be unaffected by stage 1 + 2 writes
135 if nx_arc_stage_get(arc, 0, NX_AST_F_STAGE_NUMBER) != 1 { return 110 }
136 if nx_arc_stage_get(arc, 0, NX_AST_F_AWARENESS) != NX_AW_UNAWARE { return 111 }
137
138 return 0
139}