1 #include "test.h"
2 #include <stdio.h>
3
4 #include "../src/clusterinfo.h"
5 #include "../src/globalvars.h"
6 #include "../src/bandmap.h"
7 #include "../src/lancode.h"
8 #include "../src/dxcc.h"
9
10 // OBJECT ../src/clusterinfo.o
11 // OBJECT ../src/get_time.o
12 // OBJECT ../src/err_utils.o
13
14
15 int LINES=25; /* test for 25 lines */
16
17 long timecorr;
getctynr(char * checkcall)18 int getctynr(char *checkcall) {
19 return 0;
20 }
21
22 extern char spot_ptr[MAX_SPOTS][82];
23 extern int nr_of_spots;
24 extern int announcefilter;
25 extern int xplanet;
26 extern int trx_control;
27 extern freq_t freq;
28
29 char thisnode = 'A';
30 freq_t node_frequencies[MAXNODES];
31 extern char call[20];
32 extern int cluster;
33
34 #include <pthread.h>
35 pthread_mutex_t spot_ptr_mutex = PTHREAD_MUTEX_INITIALIZER;
36 pthread_mutex_t bm_mutex = PTHREAD_MUTEX_INITIALIZER;
37
38 bm_config_t bm_config = { .livetime = 900 };
39
40 GList *allspots = NULL; // not used yet
41
42 /* mockups */
43 static char nicebox_boxname[100];
nicebox(int y,int x,int height,int width,char * boxname)44 void nicebox(int y, int x, int height, int width, char *boxname) {
45 strcpy(nicebox_boxname, boxname);
46 }
47
48 static int bandmap_show_called;
bandmap_show()49 void bandmap_show() {
50 bandmap_show_called = 1;
51 }
52
53 static int printcall_called;
printcall()54 void printcall() {
55 printcall_called = 1;
56 }
57
modify_attr(int attr)58 int modify_attr(int attr) {
59 return attr;
60 }
61
62 static dxcc_data dummy_dxcc = {
63 "Noland",
64 1,
65 2,
66 "NO",
67 34,
68 56,
69 7,
70 "QQ",
71 false
72 };
73
dxcc_by_index(unsigned int index)74 dxcc_data *dxcc_by_index(unsigned int index) {
75 return &dummy_dxcc;
76 }
77
78 /* setup/teardown */
79
put_dx_line(char * p,int index)80 static void put_dx_line(char *p, int index) {
81 sprintf(p,
82 "DX de QQ3QQQ: %2d010.0 AA%dAAA COMMENT 12%02dZ",
83 (index % 2) == 0 ? 7 : 14,
84 index % 10,
85 index % 60);
86 }
87
put_anno_line(char * p,int index,char * to)88 static void put_anno_line(char *p, int index, char *to) {
89 sprintf(p,
90 "To %s de QQ3QQQ: message 12%02dZ",
91 to,
92 index % 60);
93 }
94
put_wwv_line(char * p,int index)95 static void put_wwv_line(char *p, int index) {
96 sprintf(p,
97 "WWV de Q0QQ: SFI=68,A=12,K=3,No Storms 12%02dZ",
98 index % 60);
99 }
100
put_short_line(char * p,int index)101 static void put_short_line(char *p, int index) {
102 sprintf(p,
103 "length<20 12%02dZ",
104 index % 60);
105 }
106
setup_default(void ** state)107 int setup_default(void **state) {
108 strcpy(call, "N0CALL\n"); // !!! do not forget trailing \n
109
110 xplanet = 0;
111
112 clear_mvprintw_history();
113
114 // generate 25 various cluster spots
115 nr_of_spots = 25;
116
117 for (int i = 0; i < MAX_SPOTS; ++i) {
118 char *spot = spot_ptr[i];
119 if (i >= nr_of_spots) {
120 spot[0] = 0;
121 continue;
122 }
123
124 if (i == 17) {
125 put_short_line(spot, i);
126 } else if (i == 19) {
127 put_anno_line(spot, i, "N0CALL");
128 } else if (i == 21) {
129 put_anno_line(spot, i, "ALL");
130 } else if (i == 23) {
131 put_wwv_line(spot, i);
132 } else {
133 put_dx_line(spot, i);
134 }
135
136 }
137
138 trx_control = 1;
139 freq = 7123800.0; // Hz
140
141 nicebox_boxname[0] = 0;
142 printcall_called = 0;
143 bandmap_show_called = 0;
144
145 return 0;
146 }
147
check_mvprintw_output(int index,int y,int x,const char * text)148 static void check_mvprintw_output(int index, int y, int x, const char *text) {
149 char buffer[7];
150 sprintf(buffer, "%02d|%02d|", y, x);
151 assert_memory_equal(mvprintw_history[index], buffer, 6);
152 assert_string_equal(mvprintw_history[index] + 6, text);
153 }
154
155 /* test CLUSTER mode with FILTER_DX setting */
test_cluster_show_dx(void ** state)156 void test_cluster_show_dx(void **state) {
157
158 cluster = CLUSTER;
159 announcefilter = FILTER_DX;
160
161 clusterinfo();
162
163 // check that only DX spots are shown
164 check_mvprintw_output(7, 15, 1, spot_ptr[13]);
165 check_mvprintw_output(6, 16, 1, spot_ptr[14]);
166 check_mvprintw_output(5, 17, 1, spot_ptr[15]);
167 check_mvprintw_output(4, 18, 1, spot_ptr[16]);
168 // #17 missing (short)
169 check_mvprintw_output(3, 19, 1, spot_ptr[18]);
170 // #19 missing (talk)
171 check_mvprintw_output(2, 20, 1, spot_ptr[20]);
172 // #21 missing (announcement)
173 check_mvprintw_output(1, 21, 1, spot_ptr[22]);
174 // #23 missing (WWV)
175 check_mvprintw_output(0, 22, 1, spot_ptr[24]);
176
177 assert_string_equal(nicebox_boxname, "Cluster");
178
179 assert_true(printcall_called);
180 assert_false(bandmap_show_called);
181 }
182
183 /* test CLUSTER mode with FILTER_TALK setting */
test_cluster_show_talk(void ** state)184 void test_cluster_show_talk(void **state) {
185
186 cluster = CLUSTER;
187 announcefilter = FILTER_TALK;
188
189 clusterinfo();
190
191 // check that DX spots + talk message are shown
192 check_mvprintw_output(7, 15, 1, spot_ptr[14]);
193 check_mvprintw_output(6, 16, 1, spot_ptr[15]);
194 check_mvprintw_output(5, 17, 1, spot_ptr[16]);
195 // #17 missing (short)
196 check_mvprintw_output(4, 18, 1, spot_ptr[18]);
197 check_mvprintw_output(3, 19, 1, spot_ptr[19]);
198 check_mvprintw_output(2, 20, 1, spot_ptr[20]);
199 // #21 missing (announcement)
200 check_mvprintw_output(1, 21, 1, spot_ptr[22]);
201 // #23 missing (WWV)
202 check_mvprintw_output(0, 22, 1, spot_ptr[24]);
203
204 assert_string_equal(nicebox_boxname, "Cluster");
205
206 assert_true(printcall_called);
207 }
208
209 /* test CLUSTER mode with FILTER_ANN setting */
test_cluster_show_ann(void ** state)210 void test_cluster_show_ann(void **state) {
211
212 cluster = CLUSTER;
213 announcefilter = FILTER_ANN;
214
215 clusterinfo();
216
217 // check that DX spots + announcements are shown
218 check_mvprintw_output(7, 15, 1, spot_ptr[15]);
219 check_mvprintw_output(6, 16, 1, spot_ptr[16]);
220 // #17 missing (short)
221 check_mvprintw_output(5, 17, 1, spot_ptr[18]);
222 check_mvprintw_output(4, 18, 1, spot_ptr[19]);
223 check_mvprintw_output(3, 19, 1, spot_ptr[20]);
224 check_mvprintw_output(2, 20, 1, spot_ptr[21]);
225 check_mvprintw_output(1, 21, 1, spot_ptr[22]);
226 // #23 missing (WWV)
227 check_mvprintw_output(0, 22, 1, spot_ptr[24]);
228
229 assert_string_equal(nicebox_boxname, "Cluster");
230
231 assert_true(printcall_called);
232 }
233
234 /* test CLUSTER mode with FILTER_ALL setting */
test_cluster_show_all(void ** state)235 void test_cluster_show_all(void **state) {
236
237 cluster = CLUSTER;
238 announcefilter = FILTER_ALL;
239
240 clusterinfo();
241
242 // check that all spots are shown except the too short one
243 check_mvprintw_output(7, 15, 1, spot_ptr[16]);
244 // #17 missing (short)
245 check_mvprintw_output(6, 16, 1, spot_ptr[18]);
246 check_mvprintw_output(5, 17, 1, spot_ptr[19]);
247 check_mvprintw_output(4, 18, 1, spot_ptr[20]);
248 check_mvprintw_output(3, 19, 1, spot_ptr[21]);
249 check_mvprintw_output(2, 20, 1, spot_ptr[22]);
250 check_mvprintw_output(1, 21, 1, spot_ptr[23]);
251 check_mvprintw_output(0, 22, 1, spot_ptr[24]);
252
253 assert_string_equal(nicebox_boxname, "Cluster");
254
255 assert_true(printcall_called);
256 }
257
258 /* test CLUSTER mode with just 6 spots */
test_cluster_show_all_6(void ** state)259 void test_cluster_show_all_6(void **state) {
260
261 cluster = CLUSTER;
262 announcefilter = FILTER_ALL;
263
264 nr_of_spots = 6;
265
266 clusterinfo();
267
268 // check that all 6 spots are shown
269 check_mvprintw_output(5, 15, 1, spot_ptr[0]);
270 check_mvprintw_output(4, 16, 1, spot_ptr[1]);
271 check_mvprintw_output(3, 17, 1, spot_ptr[2]);
272 check_mvprintw_output(2, 18, 1, spot_ptr[3]);
273 check_mvprintw_output(1, 19, 1, spot_ptr[4]);
274 check_mvprintw_output(0, 20, 1, spot_ptr[5]);
275 // lines 21 and 22 are empty
276
277 assert_string_equal(nicebox_boxname, "Cluster");
278
279 assert_true(printcall_called);
280 }
281
282 /* test FREQWINDOW mode */
test_freqwindow(void ** state)283 void test_freqwindow(void **state) {
284
285 cluster = FREQWINDOW;
286
287 clusterinfo();
288
289 // frequency shown rounded to kHz
290 check_mvprintw_output(0, 15, 4, " Stn A : 7124");
291
292 assert_string_equal(nicebox_boxname, "Frequencies");
293
294 assert_true(printcall_called);
295 assert_false(bandmap_show_called);
296 }
297