-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
119 lines (97 loc) · 3.65 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "./include/web/server.h"
#include "./include/web/client.h"
#include "tests/tcp/test001.c"
#include "tests/tcp/test002.c"
#include "tests/udp/test001.c"
#include "tests/udp/test002.c"
#include "tests/http/test001.c"
#include "tests/ws/test001.c"
#include <time.h>
char *MAPPINGS[] = {
"[TCP TEST CASE 001]",
"[TCP TEST CASE 002]",
"[UDP TEST CASE 001]",
"[UDP TEST CASE 002]",
"[HTTP TEST CASE 001]",
"[WS TEST CASE 001]",
};
char *BANNER = "\
███╗ ██╗███████╗████████╗ ██████╗\n\
████╗ ██║██╔════╝╚══██╔══╝██╔════╝\n\
██╔██╗ ██║█████╗ ██║ ██║ \n\
██║╚██╗██║██╔══╝ ██║ ██║ \n\
██║ ╚████║███████╗ ██║ ╚██████╗\n\
╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═════╝\n";
int main()
{
int testsuite_result[6] = {0};
testsuite_result[0] = tcp_test001();
testsuite_result[1] = tcp_test002();
testsuite_result[2] = udp_test001();
testsuite_result[3] = udp_test002();
testsuite_result[4] = http_test001();
testsuite_result[5] = ws_test001();
printf("\n\n\n%s", BANNER);
printf("\n\n\n---RESULTS---\n");
int testsuite_passed = 1;
for (int i = 0; i < 6; ++i)
{
if (testsuite_result[i] == 1)
{
testsuite_passed = 0;
printf(ANSI_RED "%s failed\n%s", MAPPINGS[i], ANSI_RESET);
}
else
{
printf(ANSI_GREEN "%s passed\n%s", MAPPINGS[i], ANSI_RESET);
}
};
if (testsuite_passed == 1)
{
printf(ANSI_GREEN "\n\nTEST SUITE PASSED!\n");
}
else
{
printf(ANSI_RED "\n\nTEST SUITE FAILED! fix me.\n%s", ANSI_RESET);
};
// return 0;
// struct web_server server = {0};
// struct sockaddr_in server_address = {
// .sin_family = AF_INET,
// .sin_port = htons(5001),
// .sin_addr.s_addr = INADDR_ANY,
// };
// if (web_server_init(&server, (struct sockaddr *)&server_address, BACKLOG) != 0)
// {
// netc_perror("web_server_init");
// return 1;
// };
// struct web_server_route main = {
// .path = "/ziggy",
// .on_http_message = http_handling_moment,
// .on_ws_handshake_request = ws_start_handling_moment,
// .on_ws_malformed_frame = ws_start_failing_moment,
// .on_ws_message = ws_start_handling_messages_moment,
// .on_ws_close = ws_start_handling_closes_moment,
// };
// web_server_create_route(&server, &main);
// pthread_t thread;
// pthread_create(&thread, NULL, ws_server_start, &server);
// pthread_join(thread, NULL);
// struct web_client client = {0};
// client.on_http_connect = ws_client_on_http_connect;
// client.on_ws_connect = ws_client_on_ws_connect;
// client.on_http_malformed_response = ws_client_on_http_malformed_response;
// client.on_ws_malformed_frame = ws_client_on_ws_malformed_frame;
// client.on_ws_message = ws_client_on_ws_message;
// client.on_http_response = ws_client_on_http_response;
// client.on_ws_disconnect = ws_client_on_close;
// struct sockaddr_in cliaddr = {
// .sin_family = AF_INET,
// .sin_port = htons(5001)
// };
// if (inet_pton(AF_INET, "127.0.0.1", &cliaddr.sin_addr) < 0) perror("inet_pton");
// if (web_client_init(&client, (struct sockaddr *)&cliaddr) < 0) netc_perror("web_client_init");
// web_client_start(&client);
return 0;
};