diff options
author | Marc <foxtrot@malloc.me> | 2022-01-09 15:21:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-09 15:21:47 +0000 |
commit | 0bd924735125b34b74c893936b89cfae02e3379d (patch) | |
tree | c8140bf65c24791874fa9b0e194773178a34da83 /test/src/action_tests.c | |
parent | 8e09d29df19312583747a3de00fe4269c17e6586 (diff) | |
parent | 11c7393bebe4df6e2061f69787f4a7dd5c31f077 (diff) | |
download | libwifi-0bd924735125b34b74c893936b89cfae02e3379d.tar.gz libwifi-0bd924735125b34b74c893936b89cfae02e3379d.tar.bz2 libwifi-0bd924735125b34b74c893936b89cfae02e3379d.zip |
Merge pull request #3 from libwifi/test
test: Add ctests for parse and generate functions.
Diffstat (limited to 'test/src/action_tests.c')
-rw-r--r-- | test/src/action_tests.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/test/src/action_tests.c b/test/src/action_tests.c new file mode 100644 index 0000000..997095d --- /dev/null +++ b/test/src/action_tests.c | |||
@@ -0,0 +1,87 @@ | |||
1 | #include "../../src/libwifi.h" | ||
2 | |||
3 | #include <errno.h> | ||
4 | #include <stdio.h> | ||
5 | #include <string.h> | ||
6 | |||
7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" | ||
8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" | ||
9 | const unsigned char to[] = TO_MAC; | ||
10 | const unsigned char bcast[] = BCAST_MAC; | ||
11 | |||
12 | int test_action_gen_full() { | ||
13 | struct libwifi_action action = {0}; | ||
14 | |||
15 | int ret = libwifi_create_action(&action, bcast, to, ACTION_HT); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create action: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int action_len = libwifi_get_action_length(&action); | ||
22 | if (action_len <= 0) { | ||
23 | fprintf(stderr, "Invalid action length: %d\n", action_len); | ||
24 | return action_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(action_len); | ||
28 | if (buf == NULL) { | ||
29 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
30 | return -1; | ||
31 | } | ||
32 | |||
33 | int dump_len = libwifi_dump_action(&action, buf, action_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump action\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_action_add_detail() { | ||
43 | struct libwifi_action action = {0}; | ||
44 | |||
45 | int ret = libwifi_create_action(&action, bcast, to, ACTION_HT); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create action: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_add_action_detail(&action.fixed_parameters.details, (const unsigned char *) "HELLO WORLD", strlen("HELLO WORLD")); | ||
52 | |||
53 | int action_len = libwifi_get_action_length(&action); | ||
54 | if (action_len <= 0) { | ||
55 | fprintf(stderr, "Invalid action length: %d\n", action_len); | ||
56 | return action_len; | ||
57 | } | ||
58 | |||
59 | unsigned char *buf = malloc(action_len); | ||
60 | if (buf == NULL) { | ||
61 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
62 | return -1; | ||
63 | } | ||
64 | |||
65 | int dump_len = libwifi_dump_action(&action, buf, action_len); | ||
66 | if (dump_len <= 0) { | ||
67 | fprintf(stderr, "Failed to dump action\n"); | ||
68 | return ret; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | int main(int argc, char **argv) { | ||
75 | if (argc < 2) { | ||
76 | printf("Specify test\n"); | ||
77 | return -1; | ||
78 | } | ||
79 | |||
80 | if (strcmp(argv[1], "--action-gen-full") == 0) { | ||
81 | return test_action_gen_full(); | ||
82 | } else if (strcmp(argv[1], "--action-gen-details") == 0) { | ||
83 | return test_action_add_detail(); | ||
84 | } | ||
85 | |||
86 | return -1; | ||
87 | } | ||