Skip to content

Commit ded929a

Browse files
committed
prefer Country during lookup of partialcall in spot list
1 parent 8a8791b commit ded929a

2 files changed

Lines changed: 145 additions & 1 deletion

File tree

src/bandmap.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,8 @@ spot *copy_spot(spot *data) {
970970
/** Search partialcall in filtered bandmap
971971
*
972972
* Lookup given partial call in the list of filtered bandmap spots.
973+
* First search for calls starting with the searchstring and do a second run
974+
* to search inside the call. That would prefer calls with the right country.
973975
* Return a copy of the first entry found (means with the lowest frequency).
974976
*
975977
* \param partialcall - part of call to look up
@@ -985,11 +987,12 @@ spot *bandmap_lookup(char *partialcall) {
985987

986988
pthread_mutex_lock(&bm_mutex);
987989

990+
/* first look for spots starting with partialcall */
988991
for (i = 0; i < spots->len; i++) {
989992
spot *data;
990993
data = g_ptr_array_index(spots, i);
991994

992-
if (strstr(data->call, partialcall) != NULL) {
995+
if (strncmp(data->call, partialcall, strlen(partialcall)) == 0) {
993996

994997
/* copy data into a new Spot structure */
995998
result = copy_spot(data);
@@ -998,6 +1001,22 @@ spot *bandmap_lookup(char *partialcall) {
9981001
}
9991002
}
10001003

1004+
if (!result) {
1005+
/* if nothing found look for substring match */
1006+
for (i = 0; i < spots->len; i++) {
1007+
spot *data;
1008+
data = g_ptr_array_index(spots, i);
1009+
1010+
if (strstr(data->call, partialcall) != NULL) {
1011+
1012+
/* copy data into a new Spot structure */
1013+
result = copy_spot(data);
1014+
1015+
break;
1016+
}
1017+
}
1018+
}
1019+
10011020
pthread_mutex_unlock(&bm_mutex);
10021021

10031022
}

test/test_bandmap.c

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include "test.h"
2+
#include <stdio.h>
3+
4+
#include "../src/bandmap.h"
5+
#include "../src/dxcc.h"
6+
#include "../src/qtcutil.h"
7+
8+
// OBJECT ../src/bandmap.o
9+
// OBJECT ../src/bands.o
10+
11+
12+
bool grab_up=false;
13+
14+
int getctynr(char *checkcall) {
15+
return 0;
16+
}
17+
18+
int lookup_worked(char *call) {
19+
return -1; /* not found */
20+
}
21+
22+
static dxcc_data dummy_dxcc = {
23+
"Noland",
24+
1,
25+
2,
26+
"NO",
27+
34,
28+
56,
29+
7,
30+
"QQ",
31+
false
32+
};
33+
34+
dxcc_data *dxcc_by_index(unsigned int index) {
35+
return &dummy_dxcc;
36+
}
37+
38+
char thisnode = 'A';
39+
40+
bool general_ismulti(spot *data) {
41+
return false;
42+
}
43+
44+
bool worked_in_current_minitest_period(int found) {
45+
return false;
46+
}
47+
48+
/* will not work for testing bm_isdupe and qtc_format */
49+
struct t_qtc_store_obj *qtc_get(char callsign[QTC_CALL_SIZE]) {
50+
return NULL;
51+
}
52+
53+
char qtc_get_value(struct t_qtc_store_obj *qtc_obj) {
54+
return 'N';
55+
}
56+
57+
int modify_attr(int attr) {
58+
return attr;
59+
}
60+
61+
62+
63+
int setup_default(void **state) {
64+
bm_init();
65+
66+
return 0;
67+
}
68+
69+
extern GPtrArray *spots;
70+
71+
int teardown_default(void **state) {
72+
/* empty array */
73+
int x = spots->len;
74+
for (int i = 0; i < x ; i++) {
75+
g_ptr_array_remove_index (spots, 0);
76+
}
77+
return 0;
78+
}
79+
80+
void add_spot(char * call, freq_t freq) {
81+
spot *entry = g_new(spot, 1);
82+
/* partial filled spot entry, enough for bandmap_lookup */
83+
entry -> call = g_strdup(call);
84+
entry -> freq = freq;
85+
86+
g_ptr_array_add(spots, entry);
87+
}
88+
89+
void populate_spots() {
90+
add_spot("VK9XYZ", 7023000.);
91+
add_spot("ZL0OEE", 7123000.);
92+
add_spot("K0VKZ", 14023000.);
93+
add_spot("OE0ZZ", 14123000.);
94+
}
95+
96+
void test_empty_spots(void **state) {
97+
assert_ptr_equal(NULL, bandmap_lookup("AA"));
98+
}
99+
100+
void test_not_in_spots(void **state) {
101+
populate_spots();
102+
assert_ptr_equal(NULL, bandmap_lookup("AA"));
103+
}
104+
105+
void test_find_anywhere_if_single(void **state) {
106+
populate_spots();
107+
108+
assert_string_equal("K0VKZ", bandmap_lookup("KZ")->call);
109+
assert_string_equal("ZL0OEE", bandmap_lookup("ZL")->call);
110+
}
111+
112+
/* old behaviour, should fail now */
113+
//void test_find_always_first(void **state) {
114+
// populate_spots();
115+
//
116+
// assert_string_equal("ZL0OEE", bandmap_lookup("OE")->call);
117+
// assert_string_equal("VK9XYZ", bandmap_lookup("VK")->call);
118+
//}
119+
120+
void test_prefer_country(void **state) {
121+
populate_spots();
122+
123+
assert_string_equal("OE0ZZ", bandmap_lookup("OE")->call);
124+
assert_string_equal("VK9XYZ", bandmap_lookup("VK")->call);
125+
}

0 commit comments

Comments
 (0)