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/reassoc_resp_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/reassoc_resp_tests.c')
-rw-r--r-- | test/src/reassoc_resp_tests.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/test/src/reassoc_resp_tests.c b/test/src/reassoc_resp_tests.c new file mode 100644 index 0000000..8167916 --- /dev/null +++ b/test/src/reassoc_resp_tests.c | |||
@@ -0,0 +1,91 @@ | |||
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_reassoc_resp_gen_full() { | ||
13 | struct libwifi_reassoc_resp reassoc_resp = {0}; | ||
14 | |||
15 | int ret = libwifi_create_reassoc_resp(&reassoc_resp, bcast, to, 11); | ||
16 | if (ret != 0) { | ||
17 | fprintf(stderr, "Failed to create reassoc_resp: %s\n", strerror(ret)); | ||
18 | return ret; | ||
19 | } | ||
20 | |||
21 | int reassoc_resp_len = libwifi_get_reassoc_resp_length(&reassoc_resp); | ||
22 | if (reassoc_resp_len <= 0) { | ||
23 | fprintf(stderr, "Invalid reassoc_resp length: %d\n", reassoc_resp_len); | ||
24 | return reassoc_resp_len; | ||
25 | } | ||
26 | |||
27 | unsigned char *buf = malloc(reassoc_resp_len); | ||
28 | if (buf == NULL) { | ||
29 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
30 | return -1; | ||
31 | } | ||
32 | |||
33 | int dump_len = libwifi_dump_reassoc_resp(&reassoc_resp, buf, reassoc_resp_len); | ||
34 | if (dump_len <= 0) { | ||
35 | fprintf(stderr, "Failed to dump reassoc_resp\n"); | ||
36 | return ret; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | int test_reassoc_resp_add_tag() { | ||
43 | struct libwifi_reassoc_resp reassoc_resp = {0}; | ||
44 | |||
45 | int ret = libwifi_create_reassoc_resp(&reassoc_resp, bcast, to, 11); | ||
46 | if (ret != 0) { | ||
47 | fprintf(stderr, "Failed to create reassoc_resp: %s\n", strerror(ret)); | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | ret = libwifi_quick_add_tag(&reassoc_resp.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); | ||
52 | if (ret != 0) { | ||
53 | fprintf(stderr, "Failed to add reassoc_resp tagged parameter: %s\n", strerror(ret)); | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | int reassoc_resp_len = libwifi_get_reassoc_resp_length(&reassoc_resp); | ||
58 | if (reassoc_resp_len <= 0) { | ||
59 | fprintf(stderr, "Invalid reassoc_resp length: %d\n", reassoc_resp_len); | ||
60 | return reassoc_resp_len; | ||
61 | } | ||
62 | |||
63 | unsigned char *buf = malloc(reassoc_resp_len); | ||
64 | if (buf == NULL) { | ||
65 | fprintf(stderr, "Failed to allocate buffer\n"); | ||
66 | return -1; | ||
67 | } | ||
68 | |||
69 | int dump_len = libwifi_dump_reassoc_resp(&reassoc_resp, buf, reassoc_resp_len); | ||
70 | if (dump_len <= 0) { | ||
71 | fprintf(stderr, "Failed to dump reassoc_resp\n"); | ||
72 | return ret; | ||
73 | } | ||
74 | |||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | int main(int argc, char **argv) { | ||
79 | if (argc < 2) { | ||
80 | printf("Specify test\n"); | ||
81 | return -1; | ||
82 | } | ||
83 | |||
84 | if (strcmp(argv[1], "--reassoc_resp-gen-full") == 0) { | ||
85 | return test_reassoc_resp_gen_full(); | ||
86 | } else if (strcmp(argv[1], "--reassoc_resp-gen-tags") == 0) { | ||
87 | return test_reassoc_resp_add_tag(); | ||
88 | } | ||
89 | |||
90 | return -1; | ||
91 | } | ||