Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Oct 15, 2024
1 parent 6a2e9bc commit a5dbdff
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/app/backend/pcmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void pcmanager_unregister_listener(pcmanager_t *manager, const pcmanager_listene
* @param userdata
* @return
*/
bool pcmanager_manual_add(pcmanager_t *manager, host_t *host, pcmanager_callback_t callback, void *userdata);
bool pcmanager_manual_add(pcmanager_t *manager, hostport_t *host, pcmanager_callback_t callback, void *userdata);

/**
* @brief Generates a PIN code, and start pairing process.
Expand Down
16 changes: 8 additions & 8 deletions src/app/backend/pcmanager/known_hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ void pcmanager_load_known_hosts(pcmanager_t *manager) {
bool selected_set = false;
for (known_host_t *cur = hosts; cur; cur = cur->next) {
const char *mac = cur->mac, *hostname = cur->hostname;
const host_t *address = cur->address;
const hostport_t *address = cur->address;
char address_buf[256] = {0};
host_to_string(address, address_buf, sizeof(address_buf));
hostport_to_string(address, address_buf, sizeof(address_buf));
if (!mac || !hostname || !address) {
commons_log_warn("PCManager", "Unknown host entry: mac=%s, hostname=%s, address=%s", mac, hostname,
address_buf);
Expand All @@ -48,8 +48,8 @@ void pcmanager_load_known_hosts(pcmanager_t *manager) {
server->uuid = uuidstr_tostr(&cur->uuid);
server->mac = mac;
server->hostname = hostname;
server->serverInfo.address = strdup(host_get_hostname(address));
server->extPort = host_get_port(address);
server->serverInfo.address = strdup(hostport_get_hostname(address));
server->extPort = hostport_get_port(address);

pclist_t *node = pclist_insert_known(manager, &cur->uuid, server);

Expand Down Expand Up @@ -80,7 +80,7 @@ void pcmanager_save_known_hosts(pcmanager_t *manager) {
continue;
}
const SERVER_DATA *server = cur->server;
host_t *address = host_new(server->serverInfo.address, server->extPort);
hostport_t *address = hostport_new(server->serverInfo.address, server->extPort);
if (address == NULL) {
continue;
}
Expand All @@ -90,9 +90,9 @@ void pcmanager_save_known_hosts(pcmanager_t *manager) {
ini_write_string(fp, "hostname", server->hostname);

char address_buf[260] = {0};
host_to_string(address, address_buf, sizeof(address_buf));
hostport_to_string(address, address_buf, sizeof(address_buf));
ini_write_string(fp, "address", address_buf);
host_free(address);
hostport_free(address);

if (!selected_set && cur->selected) {
ini_write_bool(fp, "selected", true);
Expand Down Expand Up @@ -127,7 +127,7 @@ static int known_hosts_handle(known_host_t **list, const char *section, const ch
} else if (INI_NAME_MATCH("hostname")) {
host->hostname = SDL_strdup(value);
} else if (INI_NAME_MATCH("address")) {
host->address = host_parse(value);
host->address = hostport_parse(value);
} else if (INI_NAME_MATCH("selected")) {
host->selected = INI_IS_TRUE(value);
} else if (INI_NAME_MATCH("favorite")) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/pcmanager/known_hosts.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct known_host_t {
uuidstr_t uuid;
char *mac;
char *hostname;
host_t *address;
hostport_t *address;
bool selected;
appid_list_t *favs;
appid_list_t *hidden;
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/pcmanager/pairing.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool pcmanager_pair(pcmanager_t *manager, const uuidstr_t *uuid, char *pin, pcma
return true;
}

bool pcmanager_manual_add(pcmanager_t *manager, host_t *host, pcmanager_callback_t callback, void *userdata) {
bool pcmanager_manual_add(pcmanager_t *manager, hostport_t *host, pcmanager_callback_t callback, void *userdata) {
if (host == NULL) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/backend/pcmanager/worker/manual_add.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ int worker_add_by_host(worker_context_t *context) {
}

int updated_by_host(worker_context_t *context, bool force) {
const host_t *host = context->arg1;
return pcmanager_update_by_host(context, host_get_hostname(host), host_get_port(host), force);
const hostport_t *host = context->arg1;
return pcmanager_update_by_host(context, hostport_get_hostname(host), hostport_get_port(host), force);
}
6 changes: 3 additions & 3 deletions src/app/ui/launcher/add.dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void dialog_cb(lv_event_t *event) {
}
uint16_t btn = lv_msgbox_get_active_btn(dialog);
if (btn == 1) {
host_t *host = host_parse(lv_textarea_get_text(controller->input));
hostport_t *host = hostport_parse(lv_textarea_get_text(controller->input));
if (!host) {
return;
}
Expand All @@ -115,10 +115,10 @@ static void dialog_cb(lv_event_t *event) {

static void input_changed_cb(lv_event_t *event) {
add_dialog_controller_t *controller = lv_event_get_user_data(event);
host_t *host = host_parse(lv_textarea_get_text(controller->input));
hostport_t *host = hostport_parse(lv_textarea_get_text(controller->input));
if (host) {
lv_btnmatrix_clear_btn_ctrl(controller->btns, 1, LV_BTNMATRIX_CTRL_DISABLED);
host_free(host);
hostport_free(host);
} else {
lv_btnmatrix_set_btn_ctrl(controller->btns, 1, LV_BTNMATRIX_CTRL_DISABLED);
}
Expand Down
12 changes: 5 additions & 7 deletions tests/app/backend/pcmanager/test_known_hosts.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "unity.h"
#include "backend/pcmanager/known_hosts.h"
#include "hostport.h"

void setUp(void) {

Expand All @@ -10,16 +11,13 @@ void tearDown(void) {
}

void test_parse() {
char buf[64];
known_host_t *hosts = known_hosts_parse(FIXTURES_PATH_PREFIX "hosts_read.ini");
sockaddr_get_ip_str(hosts->address, buf, sizeof(buf));
TEST_ASSERT_EQUAL_STRING("192.168.1.100", buf);
TEST_ASSERT_EQUAL(0, sockaddr_get_port(hosts->address));
TEST_ASSERT_EQUAL_STRING("192.168.1.100", hostport_get_hostname(hosts->address));
TEST_ASSERT_EQUAL(0, hostport_get_port(hosts->address));

known_host_t *next = hosts->next;
sockaddr_get_ip_str(next->address, buf, sizeof(buf));
TEST_ASSERT_EQUAL_STRING("192.168.1.101", buf);
TEST_ASSERT_EQUAL(47985, sockaddr_get_port(next->address));
TEST_ASSERT_EQUAL_STRING("192.168.1.101", hostport_get_hostname(next->address));
TEST_ASSERT_EQUAL(47985, hostport_get_port(next->address));

known_hosts_free(hosts, known_hosts_node_free);
}
Expand Down
2 changes: 1 addition & 1 deletion third_party/commons

0 comments on commit a5dbdff

Please sign in to comment.