1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
! Phase 4 parse-unit regression driver ("unit parse->pack assert").
! Exercises parse_control_frame for the 9 Phase 4
! keys + the tricky cases: bool true/false, his_call vs his_call_standard
! substring non-collision (both orderings), wrong-type detection (bool/string/
! int), and value-vs-key aliasing (a string value equal to a key token must NOT
! be mistaken for that key). Compiled + run by
! test/run-phase4-parse-unit.sh against lib/streaming_control.f90.
!
! SCOPE: this guards the JSON -> configure_fields PARSE (the module-public entry
! point). The configure_fields -> params APPLY routing now lives in the module-
! public streaming_apply::apply_configure_fields (extracted from the
! former nested-internal apply_configure_) and is asserted by
! test/run-apply-routing-unit.sh — so the 9 inert Phase 4 fields' apply routing
! IS now unit-guarded, not just code-review + no-regression.
program p4_parse_test
use streaming_control, only: parse_control_frame, configure_fields, &
control_type_error, CTRL_CONFIGURE
implicit none
integer :: nfail
nfail = 0
call frame_A()
call frame_B()
call frame_C()
call frame_D()
call frame_E()
call frame_F()
call frame_G()
call frame_H()
call frame_I()
write(*,'(a)') '------------------------------------------------------------'
if (nfail .eq. 0) then
write(*,'(a)') 'ALL PHASE 4 PARSE-UNIT CHECKS PASSED'
else
write(*,'(a,i0,a)') 'PHASE 4 PARSE-UNIT: ', nfail, ' CHECK(S) FAILED'
call exit(1)
end if
contains
subroutine ok(label, cond)
character(len=*), intent(in) :: label
logical, intent(in) :: cond
if (cond) then
write(*,'(a,a)') ' PASS ', label
else
write(*,'(a,a)') ' FAIL ', label
nfail = nfail + 1
end if
end subroutine ok
! Frame A: all 9 keys, bools true.
subroutine frame_A()
type(configure_fields) :: cfg
type(control_type_error) :: terr
integer :: action
character(len=*), parameter :: b = &
'{"t":"configure","mode":"FT8","his_call":"DX1ABC","his_grid":"FN20",' // &
'"my_b_call":"KJ5HST/P","his_b_call":"DX1ABC/P","my_call_standard":true,' //&
'"his_call_standard":true,"tx_audio_offset_hz":1234,' // &
'"jt65_jt9_split_hz":2500,"max_drift_hz":8}'
write(*,'(a)') 'Frame A: all 9 keys present, bools true'
call parse_control_frame(b, action, cfg, terr)
call ok('action == CTRL_CONFIGURE', action .eq. CTRL_CONFIGURE)
call ok('terr not present', .not. terr%present)
call ok('his_call == DX1ABC', cfg%his_call_set .and. trim(cfg%his_call) .eq. 'DX1ABC')
call ok('his_grid == FN20', cfg%his_grid_set .and. trim(cfg%his_grid) .eq. 'FN20')
call ok('my_b_call == KJ5HST/P', cfg%my_b_call_set .and. trim(cfg%my_b_call) .eq. 'KJ5HST/P')
call ok('his_b_call == DX1ABC/P', cfg%his_b_call_set.and. trim(cfg%his_b_call).eq. 'DX1ABC/P')
call ok('my_call_standard == true', cfg%my_call_standard_set .and. cfg%my_call_standard)
call ok('his_call_standard == true', cfg%his_call_standard_set .and. cfg%his_call_standard)
call ok('tx_audio_offset_hz == 1234',cfg%tx_audio_offset_hz_set .and. cfg%tx_audio_offset_hz .eq. 1234)
call ok('jt65_jt9_split_hz == 2500', cfg%jt65_jt9_split_hz_set .and. cfg%jt65_jt9_split_hz .eq. 2500)
call ok('max_drift_hz == 8', cfg%max_drift_hz_set .and. cfg%max_drift_hz .eq. 8)
end subroutine frame_A
! Frame B: bools false (distinguish "set to false" from "absent").
subroutine frame_B()
type(configure_fields) :: cfg
type(control_type_error) :: terr
integer :: action
character(len=*), parameter :: b = &
'{"t":"configure","my_call_standard":false,"his_call_standard":false}'
write(*,'(a)') 'Frame B: bools explicitly false'
call parse_control_frame(b, action, cfg, terr)
call ok('terr not present', .not. terr%present)
call ok('my_call_standard set, value false', cfg%my_call_standard_set .and. (.not. cfg%my_call_standard))
call ok('his_call_standard set, value false', cfg%his_call_standard_set .and. (.not. cfg%his_call_standard))
end subroutine frame_B
! Frame C: his_call AND his_call_standard both present, BOTH orderings.
! "his_call" is a substring of "his_call_standard" — the closing quote in the
! key token must prevent the shorter key from matching the longer one.
subroutine frame_C()
type(configure_fields) :: cfg
type(control_type_error) :: terr
integer :: action
character(len=*), parameter :: b1 = &
'{"t":"configure","his_call":"W1AW","his_call_standard":true}'
character(len=*), parameter :: b2 = &
'{"t":"configure","his_call_standard":true,"his_call":"W1AW"}'
write(*,'(a)') 'Frame C: his_call vs his_call_standard substring non-collision'
call parse_control_frame(b1, action, cfg, terr)
call ok('order1: terr not present', .not. terr%present)
call ok('order1: his_call == W1AW', cfg%his_call_set .and. trim(cfg%his_call) .eq. 'W1AW')
call ok('order1: his_call_standard == true', cfg%his_call_standard_set .and. cfg%his_call_standard)
call parse_control_frame(b2, action, cfg, terr)
call ok('order2: terr not present', .not. terr%present)
call ok('order2: his_call == W1AW', cfg%his_call_set .and. trim(cfg%his_call) .eq. 'W1AW')
call ok('order2: his_call_standard == true', cfg%his_call_standard_set .and. cfg%his_call_standard)
end subroutine frame_C
! Frame D: bool key carrying a number -> configure_type_error.
subroutine frame_D()
type(configure_fields) :: cfg
type(control_type_error) :: terr
integer :: action
character(len=*), parameter :: b = '{"t":"configure","my_call_standard":5}'
write(*,'(a)') 'Frame D: my_call_standard:5 (number) -> type error'
call parse_control_frame(b, action, cfg, terr)
call ok('terr present', terr%present)
call ok('key == my_call_standard',trim(terr%key) .eq. 'my_call_standard')
call ok('expected == bool', trim(terr%expected) .eq. 'bool')
call ok('got == number', trim(terr%got) .eq. 'number')
end subroutine frame_D
! Frame E: bool key carrying a string -> configure_type_error.
subroutine frame_E()
type(configure_fields) :: cfg
type(control_type_error) :: terr
integer :: action
character(len=*), parameter :: b = '{"t":"configure","his_call_standard":"true"}'
write(*,'(a)') 'Frame E: his_call_standard:"true" (string) -> type error'
call parse_control_frame(b, action, cfg, terr)
call ok('terr present', terr%present)
call ok('key == his_call_standard',trim(terr%key) .eq. 'his_call_standard')
call ok('expected == bool', trim(terr%expected) .eq. 'bool')
call ok('got == string', trim(terr%got) .eq. 'string')
end subroutine frame_E
! Frame F: string key carrying a number -> configure_type_error.
subroutine frame_F()
type(configure_fields) :: cfg
type(control_type_error) :: terr
integer :: action
character(len=*), parameter :: b = '{"t":"configure","his_call":123}'
write(*,'(a)') 'Frame F: his_call:123 (number) -> type error'
call parse_control_frame(b, action, cfg, terr)
call ok('terr present', terr%present)
call ok('key == his_call', trim(terr%key) .eq. 'his_call')
call ok('expected == string',trim(terr%expected) .eq. 'string')
call ok('got == number', trim(terr%got) .eq. 'number')
end subroutine frame_F
! Frame G: int key carrying a string -> configure_type_error.
subroutine frame_G()
type(configure_fields) :: cfg
type(control_type_error) :: terr
integer :: action
character(len=*), parameter :: b = '{"t":"configure","max_drift_hz":"abc"}'
write(*,'(a)') 'Frame G: max_drift_hz:"abc" (string) -> type error'
call parse_control_frame(b, action, cfg, terr)
call ok('terr present', terr%present)
call ok('key == max_drift_hz', trim(terr%key) .eq. 'max_drift_hz')
call ok('expected == int', trim(terr%expected) .eq. 'int')
call ok('got == string', trim(terr%got) .eq. 'string')
end subroutine frame_G
! Frame H: value-vs-key aliasing — his_call VALUE equals the "max_drift_hz"
! token, with no real max_drift_hz key. The value must NOT be mistaken for the
! key: max_drift_hz stays unset (benign extraction miss) and NO false type
! error is raised (anchored find_key_ ignores the value). Aliasing guard.
subroutine frame_H()
type(configure_fields) :: cfg
type(control_type_error) :: terr
integer :: action
character(len=*), parameter :: b = '{"t":"configure","his_call":"max_drift_hz"}'
write(*,'(a)') 'Frame H: his_call value == "max_drift_hz" token (aliasing guard)'
call parse_control_frame(b, action, cfg, terr)
call ok('terr not present (no false decline)', .not. terr%present)
call ok('his_call == max_drift_hz', cfg%his_call_set .and. trim(cfg%his_call) .eq. 'max_drift_hz')
call ok('max_drift_hz stays UNSET', .not. cfg%max_drift_hz_set)
end subroutine frame_H
! Frame I: Phase 4 keys absent -> all unset, no error (keys are optional).
subroutine frame_I()
type(configure_fields) :: cfg
type(control_type_error) :: terr
integer :: action
character(len=*), parameter :: b = '{"t":"configure","mode":"FT8"}'
write(*,'(a)') 'Frame I: Phase 4 keys absent -> unset'
call parse_control_frame(b, action, cfg, terr)
call ok('terr not present', .not. terr%present)
call ok('his_call unset', .not. cfg%his_call_set)
call ok('his_grid unset', .not. cfg%his_grid_set)
call ok('my_b_call unset', .not. cfg%my_b_call_set)
call ok('his_b_call unset', .not. cfg%his_b_call_set)
call ok('my_call_standard unset', .not. cfg%my_call_standard_set)
call ok('his_call_standard unset', .not. cfg%his_call_standard_set)
call ok('tx_audio_offset_hz unset', .not. cfg%tx_audio_offset_hz_set)
call ok('jt65_jt9_split_hz unset', .not. cfg%jt65_jt9_split_hz_set)
call ok('max_drift_hz unset', .not. cfg%max_drift_hz_set)
end subroutine frame_I
end program p4_parse_test
|