first commit

This commit is contained in:
2024-03-25 21:05:36 +01:00
commit 1014d2526c
22 changed files with 2998 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
#include <iostream>
#include "test_utils.hpp"
#include "../src/netutils.hpp"
#include <winsock2.h>
#include <ws2tcpip.h>
extern "C"
int LLVMFuzzerTestOneInput(const char *data,
size_t size)
{
IPv4 ip;
bool ok = ip.parse(data, size);
char buf[256];
if (size < sizeof(buf)) {
memcpy(buf, data, size);
buf[size] = '\0';
struct in_addr buf2;
switch (inet_pton(AF_INET, buf, &buf2)) {
case 1:
test(ok);
test(ip.data == buf2.s_addr);
break;
case 0:
case -1:
test(!ok);
break;
}
}
return 0; // Values other than 0 and -1 are reserved for future use.
}
+34
View File
@@ -0,0 +1,34 @@
#include <iostream>
#include "test_utils.hpp"
#include "../src/netutils.hpp"
#include <winsock2.h>
#include <ws2tcpip.h>
extern "C"
int LLVMFuzzerTestOneInput(const char *data,
size_t size)
{
IPv6 ip;
bool ok = ip.parse(data, size);
char buf[512];
if (size < sizeof(buf)) {
memcpy(buf, data, size);
buf[size] = '\0';
struct in6_addr buf2;
switch (inet_pton(AF_INET6, buf, &buf2)) {
case 1:
test(ok);
test(!memcmp(&ip.data, &buf2, 16));
break;
case 0:
case -1:
test(!ok);
break;
}
}
return 0; // Values other than 0 and -1 are reserved for future use.
}
+16
View File
@@ -0,0 +1,16 @@
#include <iostream>
#include "test_utils.hpp"
#include "../src/netutils.hpp"
int main()
{
IPv4 ip;
test(ip.parse("") == false);
test(ip.parse("@") == false);
test(ip.parse("1") == false);
test(ip.parse("500") == false);
test(ip.parse("45.") == false);
test(ip.parse("45.54.56.98") == true);
std::cout << "Passed\n";
return 0;
}
+109
View File
@@ -0,0 +1,109 @@
#include <cstdlib>
#include <iostream>
#include "test_utils.hpp"
#include "../src/queue.hpp"
int main()
{
{
Queue<int, 0> q;
test(q.push(10) == false);
test(q.size() == 0);
test(q.empty() == true);
test(q.pop() == false);
}
{
Queue<int, 1> q;
test(q.size() == 0);
test(q.empty() == true);
test(q.push(10) == true);
test(q.size() == 1);
test(q.empty() == false);
test(q.push(4) == false);
test(q.size() == 1);
test(q.empty() == false);
test(q.pop() == true);
test(q.pop() == false);
}
{
Queue<int, 4> q;
test(q.push(1) == true);
test(q.size() == 1);
test(q.push(2) == true);
test(q.size() == 2);
test(q.push(3) == true);
test(q.size() == 3);
test(q.push(4) == true);
test(q.size() == 4);
int x;
test(q.pop(x) == true);
test(x == 1);
test(q.size() == 3);
test(q.push(5) == true);
test(q.size() == 4);
test(q.pop(x) == true);
test(x == 2);
test(q.size() == 3);
test(q.push(6) == true);
test(q.size() == 4);
test(q.pop(x) == true);
test(x == 3);
test(q.size() == 3);
test(q.push(7) == true);
test(q.size() == 4);
test(q.pop(x) == true);
test(x == 4);
test(q.size() == 3);
test(q.push(8) == true);
test(q.size() == 4);
test(q.pop(x) == true);
test(x == 5);
test(q.size() == 3);
test(q.push(9) == true);
test(q.size() == 4);
test(q.pop(x) == true);
test(x == 6);
test(q.size() == 3);
test(q.push(10) == true);
test(q.size() == 4);
test(q.pop(x) == true);
test(x == 7);
test(q.size() == 3);
test(q.pop(x) == true);
test(x == 8);
test(q.size() == 2);
test(q.pop(x) == true);
test(x == 9);
test(q.size() == 1);
test(q.pop(x) == true);
test(x == 10);
test(q.size() == 0);
test(q.pop(x) == false);
}
std::cout << "Passed\n";
}
+10
View File
@@ -0,0 +1,10 @@
#include <cstdlib>
#include <iostream>
void test_(bool expr, const char *text, const char *file, int line)
{
if (!expr) {
std::cout << "Failure in " << file << ":" << line << " [" << text << "]\n";
abort();
}
}
+3
View File
@@ -0,0 +1,3 @@
void test_(bool expr, const char *text, const char *file, int line);
#define test(expr) test_(expr, #expr, __FILE__, __LINE__)