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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
program test_packjt77_schema_decoder
use packjt77_schema
use packjt77
use packjt77_test_helpers
implicit none
integer :: ntests
ntests=0
call expect_type1_exact_fields()
call expect_type2_tag_decode()
call expect_invalid_binary_and_tag_fail()
call expect_type1_grid_boundary()
call expect_wspr_dispatch()
call expect_wspr_selector_padding_and_power_checks()
call expect_type5_grid_range_check()
call expect_type5_raw_invalid_serial_rejected()
call expect_failure_has_no_shared_state_side_effects()
write(*,1000) ntests
1000 format('packjt77 schema decoder tests passed: ',i0)
contains
subroutine expect_type1_exact_fields()
character(len=77) :: c77
type(pack77_type12_fields) :: fields
integer :: i3,n3
logical :: ok
c77='00001001101111011110001101010000011000010100100111011100000010100001100110001'
call decode_pack77_tag(c77,i3,n3,ok)
call assert_true('Type 1 tag decode',ok)
call assert_int('Type 1 i3',1,i3)
call assert_int('Type 1 n3',0,n3)
call decode_pack77_type1(c77,fields,ok)
call assert_true('Type 1 field decode',ok)
call assert_int('Type 1 n28a',10214965,fields%n28a)
call assert_int('Type 1 ipa',0,fields%ipa)
call assert_int('Type 1 n28b',12751800,fields%n28b)
call assert_int('Type 1 ipb',0,fields%ipb)
call assert_int('Type 1 ir',0,fields%ir)
call assert_int('Type 1 igrid4',10342,fields%igrid4)
ntests=ntests+1
end subroutine expect_type1_exact_fields
subroutine expect_type2_tag_decode()
character(len=77) :: c77
type(pack77_type12_fields) :: fields
integer :: i3,n3
logical :: ok
c77='00001001101111011110001101010000011000010100100111011100000010100001100110010'
call decode_pack77_tag(c77,i3,n3,ok)
call assert_true('Type 2 tag decode',ok)
call assert_int('Type 2 i3',2,i3)
call assert_int('Type 2 n3',0,n3)
call decode_pack77_type2(c77,fields,ok)
call assert_true('Type 2 field decode',ok)
call assert_int('Type 2 n28a',10214965,fields%n28a)
call assert_int('Type 2 igrid4',10342,fields%igrid4)
ntests=ntests+1
end subroutine expect_type2_tag_decode
subroutine expect_invalid_binary_and_tag_fail()
character(len=77) :: c77
type(pack77_type12_fields) :: fields
integer :: i3,n3
logical :: ok
c77='00001001101111011110001101010000011000010100100111011100000010100001100110001'
c77(10:10)='x'
call decode_pack77_tag(c77,i3,n3,ok)
call assert_true('non-binary tag rejected',.not.ok)
c77='00001001101111011110001101010000011000010100100111011100000010100001100110001'
c77(75:77)='010'
call decode_pack77_type1(c77,fields,ok)
call assert_true('wrong fixed i3 rejected',.not.ok)
ntests=ntests+1
end subroutine expect_invalid_binary_and_tag_fail
subroutine expect_type1_grid_boundary()
character(len=37) :: input, decoded
character(len=77) :: c77
logical :: ok
input='K1ABC W9XYZ FN42'
block
type(pack77_result) :: encoded
encoded=pack77_result_from_api(input)
call assert_pack77_result('pack77',input,encoded)
call assert_int('Type 1 boundary i3',1,encoded%i3)
call assert_int('Type 1 boundary n3',0,encoded%n3)
c77=encoded%c77
end block
write(c77(60:74),'(b15.15)') 32399
decoded=' '
ok=.false.
call unpack77_configured(c77,0,decoded,ok, &
unpack77_options(record_hashes=.false.,record_recent_calls=.false.))
call assert_true('Type 1 grid boundary succeeds',ok)
call assert_text_equal('Type 1 grid boundary decode', &
'K1ABC W9XYZ RR99',decoded)
write(c77(60:74),'(b15.15)') 32400
decoded=' '
ok=.true.
call unpack77_configured(c77,0,decoded,ok, &
unpack77_options(record_hashes=.false.,record_recent_calls=.false.))
call assert_true('Type 1 invalid grid boundary fails',.not.ok)
ntests=ntests+1
end subroutine expect_type1_grid_boundary
subroutine expect_wspr_dispatch()
character(len=77) :: c77
integer :: selector
integer, parameter :: expected(0:7)=[1,2,3,2,1,2,3,2]
type(pack77_wspr_type3_fields) :: type3_fields
logical :: ok
c77=repeat('0',77)
c77(72:77)='110000'
do selector=0,7
write(c77(48:50),'(b3.3)') selector
call assert_int('WSPR subtype selector',expected(selector), &
pack77_wspr_payload_type(c77))
call assert_int('WSPR prevalidated subtype selector',expected(selector), &
pack77_wspr_payload_type(c77,.true.))
enddo
c77(48:50)='110'
call decode_pack77_wspr_type3(c77,type3_fields,ok,.true.)
call assert_true('dispatched invalid WSPR selector rejected',.not.ok)
c77(48:50)='010'
c77(1:1)='x'
call assert_int('WSPR dispatch rejects nonbinary payload',0, &
pack77_wspr_payload_type(c77))
c77(1:1)='0'
c77(50:50)='x'
call assert_int('WSPR dispatch rejects nonbinary selector',0, &
pack77_wspr_payload_type(c77))
ntests=ntests+1
end subroutine expect_wspr_dispatch
subroutine expect_wspr_selector_padding_and_power_checks()
character(len=77) :: c77
type(pack77_wspr_type1_fields) :: type1_fields
type(pack77_wspr_type3_fields) :: type3_fields
logical :: ok
c77=repeat('0',77)
c77(72:77)='110000'
c77(48:50)='110'
call decode_pack77_wspr_type1(c77,type1_fields,ok)
call assert_true('invalid WSPR Type 1 selector rejected',.not.ok)
call decode_pack77_wspr_type3(c77,type3_fields,ok)
call assert_true('invalid WSPR Type 3 selector rejected',.not.ok)
c77=repeat('0',77)
c77(72:77)='110000'
c77(48:50)='010'
c77(51:51)='1'
call decode_pack77_wspr_type3(c77,type3_fields,ok)
call assert_true('nonzero WSPR padding rejected',.not.ok)
c77=repeat('0',77)
c77(44:48)='11111'
c77(49:50)='00'
c77(72:77)='110000'
call decode_pack77_wspr_type1(c77,type1_fields,ok)
call assert_true('invalid WSPR raw power rejected',.not.ok)
ntests=ntests+1
end subroutine expect_wspr_selector_padding_and_power_checks
subroutine expect_type5_grid_range_check()
character(len=77) :: c77
type(pack77_type5_fields) :: fields
logical :: ok
c77=repeat('0',77)
c77(50:74)=repeat('1',25)
c77(75:77)='101'
call decode_pack77_type5(c77,fields,ok)
call assert_true('Type 5 invalid grid rejected',.not.ok)
ntests=ntests+1
end subroutine expect_type5_grid_range_check
subroutine expect_type5_raw_invalid_serial_rejected()
character(len=77) :: c77
character(len=37) :: decoded
logical :: ok, unpack_ok
call encode_pack77_type5(0,0,0,0,1,0,c77,ok)
call assert_true('Type 5 raw serial one encoded',ok)
write(c77(39:49),'(b11.11)') 0
decoded=' '
unpack_ok=.true.
call unpack77(c77,0,decoded,unpack_ok)
call assert_true('Type 5 raw serial zero rejected',.not.unpack_ok)
ntests=ntests+1
end subroutine expect_type5_raw_invalid_serial_rejected
subroutine expect_failure_has_no_shared_state_side_effects()
character(len=77) :: c77
type(pack77_wspr_type3_fields) :: fields
logical :: ok
call clear_all_state('','')
c77=repeat('0',77)
c77(48:50)='010'
c77(51:51)='1'
c77(72:77)='110000'
call decode_pack77_wspr_type3(c77,fields,ok)
call assert_true('schema decode failure rejected',.not.ok)
call assert_shared_hash_tables_empty('decoder failure')
ntests=ntests+1
end subroutine expect_failure_has_no_shared_state_side_effects
end program test_packjt77_schema_decoder
|