-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
266 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#define _GNU_SOURCE | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdarg.h> | ||
#include <fcntl.h> | ||
#include <ctype.h> | ||
#include <unistd.h> | ||
#include <pthread.h> | ||
#include <stdbool.h> | ||
#include <errno.h> | ||
#include <net/if.h> | ||
#include <libgen.h> | ||
#include <setjmp.h> | ||
#include <cmocka.h> | ||
|
||
#include "utils/log.h" | ||
#include "utils/os.h" | ||
#include "dns/command_mapper.h" | ||
|
||
static void test_put_command_mapper(void **state) | ||
{ | ||
(void) state; | ||
|
||
hmap_command_conn *hmap = NULL; | ||
char *command = "test"; | ||
|
||
assert_int_equal(put_command_mapper(&hmap, command), 0); | ||
|
||
free_command_mapper(&hmap); | ||
} | ||
|
||
static void test_check_command_mapper(void **state) | ||
{ | ||
(void) state; | ||
|
||
hmap_command_conn *hmap = NULL; | ||
char *command1 = "test1"; | ||
char *command2 = "test2"; | ||
|
||
put_command_mapper(&hmap, command1); | ||
assert_int_equal(check_command_mapper(&hmap, command1), 1); | ||
assert_int_equal(check_command_mapper(&hmap, command2), 0); | ||
|
||
free_command_mapper(&hmap); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
(void) argc; /* unused */ | ||
(void) argv; /* unused */ | ||
|
||
log_set_quiet(false); | ||
|
||
const struct CMUnitTest tests[] = { | ||
cmocka_unit_test(test_put_command_mapper), | ||
cmocka_unit_test(test_check_command_mapper) | ||
}; | ||
|
||
return cmocka_run_group_tests(tests, NULL, NULL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#define _GNU_SOURCE | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdarg.h> | ||
#include <fcntl.h> | ||
#include <ctype.h> | ||
#include <unistd.h> | ||
#include <pthread.h> | ||
#include <stdbool.h> | ||
#include <errno.h> | ||
#include <net/if.h> | ||
#include <libgen.h> | ||
#include <setjmp.h> | ||
#include <cmocka.h> | ||
|
||
#include "utils/log.h" | ||
#include "utils/os.h" | ||
#include "dns/mdns_service.h" | ||
#include "capture/pcap_service.h" | ||
#include "utils/eloop.h" | ||
|
||
int __wrap_run_pcap(char *interface, bool immediate, bool promiscuous, | ||
int timeout, char *filter, bool nonblock, capture_callback_fn pcap_fn, | ||
void *fn_ctx, struct pcap_context** pctx) | ||
{ | ||
(void) interface; | ||
(void) immediate; | ||
(void) promiscuous; | ||
(void) timeout; | ||
(void) filter; | ||
(void) nonblock; | ||
(void) pcap_fn; | ||
(void) fn_ctx; | ||
|
||
*pctx = (struct pcap_context*) os_zalloc(sizeof(struct pcap_context)); | ||
return 0; | ||
} | ||
|
||
int __wrap_eloop_register_read_sock(int sock, eloop_sock_handler handler, | ||
void *eloop_data, void *user_data) | ||
{ | ||
(void) sock; | ||
(void) handler; | ||
(void) eloop_data; | ||
(void) user_data; | ||
|
||
return 0; | ||
} | ||
|
||
int __wrap_eloop_init(void) | ||
{ | ||
return 0; | ||
} | ||
|
||
void __wrap_eloop_destroy(void) {} | ||
void __wrap_eloop_run(void) {} | ||
|
||
static void test_run_mdns(void **state) | ||
{ | ||
(void) state; | ||
|
||
struct mdns_context context; | ||
context.ifname = os_strdup("wlan0"); | ||
assert_int_equal(run_mdns(&context), 0); | ||
os_free(context.ifname); | ||
close_mdns(&context); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
(void) argc; /* unused */ | ||
(void) argv; /* unused */ | ||
|
||
log_set_quiet(false); | ||
|
||
const struct CMUnitTest tests[] = { | ||
cmocka_unit_test(test_run_mdns), | ||
}; | ||
|
||
return cmocka_run_group_tests(tests, NULL, NULL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#define _GNU_SOURCE | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdarg.h> | ||
#include <fcntl.h> | ||
#include <ctype.h> | ||
#include <unistd.h> | ||
#include <pthread.h> | ||
#include <stdbool.h> | ||
#include <errno.h> | ||
#include <net/if.h> | ||
#include <libgen.h> | ||
#include <setjmp.h> | ||
#include <cmocka.h> | ||
#include <sys/socket.h> | ||
|
||
#include "utils/log.h" | ||
#include "utils/os.h" | ||
#include "dns/reflection_list.h" | ||
|
||
static void test_init_reflection_list(void **state) | ||
{ | ||
(void) state; | ||
|
||
struct reflection_list *list = NULL; | ||
|
||
list = init_reflection_list(); | ||
assert_non_null(list); | ||
|
||
free_reflection_list(list); | ||
} | ||
|
||
static void test_push_reflection_list(void **state) | ||
{ | ||
(void) state; | ||
|
||
struct reflection_list *el; | ||
struct reflection_list *list = init_reflection_list(); | ||
|
||
assert_int_equal(dl_list_len(&list->list), 0); | ||
assert_non_null(push_reflection_list(list, 0, "wlan0")); | ||
assert_int_equal(dl_list_len(&list->list), 1); | ||
el = dl_list_first(&list->list, struct reflection_list, list); | ||
assert_non_null(el); | ||
assert_string_equal(el->ifname, "wlan0"); | ||
free_reflection_list(list); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
(void) argc; /* unused */ | ||
(void) argv; /* unused */ | ||
|
||
log_set_quiet(false); | ||
|
||
const struct CMUnitTest tests[] = { | ||
cmocka_unit_test(test_init_reflection_list), | ||
cmocka_unit_test(test_push_reflection_list) | ||
}; | ||
|
||
return cmocka_run_group_tests(tests, NULL, NULL); | ||
} |