about summary refs log tree commit diff stats
path: root/test/src/assoc_resp_tests.c
diff options
context:
space:
mode:
authorMarc <foxtrot@malloc.me>2021-12-17 18:52:36 +0000
committerMarc <foxtrot@malloc.me>2021-12-17 19:31:25 +0000
commitcd1df65dc36ac35d526de195284d5ebf18e1f92b (patch)
treefc0c163cd9f86d452fec1eb90d48a22d67cf4256 /test/src/assoc_resp_tests.c
parent8e09d29df19312583747a3de00fe4269c17e6586 (diff)
downloadlibwifi-cd1df65dc36ac35d526de195284d5ebf18e1f92b.tar.gz
libwifi-cd1df65dc36ac35d526de195284d5ebf18e1f92b.tar.bz2
libwifi-cd1df65dc36ac35d526de195284d5ebf18e1f92b.zip
test: Add ctests for generation functions.
This commit also enforces error code checking on functions inside of
the generation functions, such as for `libwifi_quick_add_tag`.
Diffstat (limited to 'test/src/assoc_resp_tests.c')
-rw-r--r--test/src/assoc_resp_tests.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/test/src/assoc_resp_tests.c b/test/src/assoc_resp_tests.c new file mode 100644 index 0000000..3a261ed --- /dev/null +++ b/test/src/assoc_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"
9const unsigned char to[] = TO_MAC;
10const unsigned char bcast[] = BCAST_MAC;
11
12int test_assoc_resp_gen_full() {
13 struct libwifi_assoc_resp assoc_resp = {0};
14
15 int ret = libwifi_create_assoc_resp(&assoc_resp, bcast, to, 11);
16 if (ret != 0) {
17 fprintf(stderr, "Failed to create assoc_resp: %s\n", strerror(ret));
18 return ret;
19 }
20
21 int assoc_resp_len = libwifi_get_assoc_resp_length(&assoc_resp);
22 if (assoc_resp_len <= 0) {
23 fprintf(stderr, "Invalid assoc_resp length: %d\n", assoc_resp_len);
24 return assoc_resp_len;
25 }
26
27 unsigned char *buf = malloc(assoc_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_assoc_resp(&assoc_resp, buf, assoc_resp_len);
34 if (dump_len <= 0) {
35 fprintf(stderr, "Failed to dump assoc_resp\n");
36 return ret;
37 }
38
39 return 0;
40}
41
42int test_assoc_resp_add_tag() {
43 struct libwifi_assoc_resp assoc_resp = {0};
44
45 int ret = libwifi_create_assoc_resp(&assoc_resp, bcast, to, 11);
46 if (ret != 0) {
47 fprintf(stderr, "Failed to create assoc_resp: %s\n", strerror(ret));
48 return ret;
49 }
50
51 ret = libwifi_quick_add_tag(&assoc_resp.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15);
52 if (ret != 0) {
53 fprintf(stderr, "Failed to add assoc_resp tagged parameter: %s\n", strerror(ret));
54 return ret;
55 }
56
57 int assoc_resp_len = libwifi_get_assoc_resp_length(&assoc_resp);
58 if (assoc_resp_len <= 0) {
59 fprintf(stderr, "Invalid assoc_resp length: %d\n", assoc_resp_len);
60 return assoc_resp_len;
61 }
62
63 unsigned char *buf = malloc(assoc_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_assoc_resp(&assoc_resp, buf, assoc_resp_len);
70 if (dump_len <= 0) {
71 fprintf(stderr, "Failed to dump assoc_resp\n");
72 return ret;
73 }
74
75 return 0;
76}
77
78int main(int argc, char **argv) {
79 if (argc < 2) {
80 printf("Specify test\n");
81 return -1;
82 }
83
84 if (strcmp(argv[1], "--assoc_resp-gen-full") == 0) {
85 return test_assoc_resp_gen_full();
86 } else if (strcmp(argv[1], "--assoc_resp-gen-tags") == 0) {
87 return test_assoc_resp_add_tag();
88 }
89
90 return -1;
91}