|
| 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