about summary refs log tree commit diff stats
path: root/test/src/assoc_req_tests.c
diff options
context:
space:
mode:
authorMarc <foxtrot@malloc.me>2022-01-09 15:21:47 +0000
committerGitHub <noreply@github.com>2022-01-09 15:21:47 +0000
commit0bd924735125b34b74c893936b89cfae02e3379d (patch)
treec8140bf65c24791874fa9b0e194773178a34da83 /test/src/assoc_req_tests.c
parent8e09d29df19312583747a3de00fe4269c17e6586 (diff)
parent11c7393bebe4df6e2061f69787f4a7dd5c31f077 (diff)
downloadlibwifi-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/assoc_req_tests.c')
-rw-r--r--test/src/assoc_req_tests.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/test/src/assoc_req_tests.c b/test/src/assoc_req_tests.c new file mode 100644 index 0000000..fc6379f --- /dev/null +++ b/test/src/assoc_req_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_req_gen_full() {
13 struct libwifi_assoc_req assoc_req = {0};
14
15 int ret = libwifi_create_assoc_req(&assoc_req, bcast, to, "Some SSID", 11);
16 if (ret != 0) {
17 fprintf(stderr, "Failed to create assoc_req: %s\n", strerror(ret));
18 return ret;
19 }
20
21 int assoc_req_len = libwifi_get_assoc_req_length(&assoc_req);
22 if (assoc_req_len <= 0) {
23 fprintf(stderr, "Invalid assoc_req length: %d\n", assoc_req_len);
24 return assoc_req_len;
25 }
26
27 unsigned char *buf = malloc(assoc_req_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_req(&assoc_req, buf, assoc_req_len);
34 if (dump_len <= 0) {
35 fprintf(stderr, "Failed to dump assoc_req\n");
36 return ret;
37 }
38
39 return 0;
40}
41
42int test_assoc_req_add_tag() {
43 struct libwifi_assoc_req assoc_req = {0};
44
45 int ret = libwifi_create_assoc_req(&assoc_req, bcast, to, "Some SSID", 11);
46 if (ret != 0) {
47 fprintf(stderr, "Failed to create assoc_req: %s\n", strerror(ret));
48 return ret;
49 }
50
51 ret = libwifi_quick_add_tag(&assoc_req.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15);
52 if (ret != 0) {
53 fprintf(stderr, "Failed to add assoc_req tagged parameter: %s\n", strerror(ret));
54 return ret;
55 }
56
57 int assoc_req_len = libwifi_get_assoc_req_length(&assoc_req);
58 if (assoc_req_len <= 0) {
59 fprintf(stderr, "Invalid assoc_req length: %d\n", assoc_req_len);
60 return assoc_req_len;
61 }
62
63 unsigned char *buf = malloc(assoc_req_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_req(&assoc_req, buf, assoc_req_len);
70 if (dump_len <= 0) {
71 fprintf(stderr, "Failed to dump assoc_req\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_req-gen-full") == 0) {
85 return test_assoc_req_gen_full();
86 } else if (strcmp(argv[1], "--assoc_req-gen-tags") == 0) {
87 return test_assoc_req_add_tag();
88 }
89
90 return -1;
91}