2020-09-12 21:30:13 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2020-09-12 21:43:03 -05:00
|
|
|
#include <assert.h>
|
2020-09-12 21:30:13 -05:00
|
|
|
|
|
|
|
#include "purr.h"
|
|
|
|
|
2020-09-12 21:43:03 -05:00
|
|
|
static int compare_strings(const char *expected, const char *result, const char *function)
|
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
printf("%s(): ", function);
|
|
|
|
if (strcmp(expected, result)) {
|
|
|
|
rv = 1;
|
|
|
|
puts("failure");
|
|
|
|
printf("expected: %s\ngot: %s\n", expected, result);
|
|
|
|
} else {
|
|
|
|
puts("success");
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2020-09-12 21:30:13 -05:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
{
|
|
|
|
/* formats.c */
|
|
|
|
uint8_t buf[] = {0x12, 0x02, 0x12, 0x4c, 0xa8};
|
2020-09-12 21:43:03 -05:00
|
|
|
const char *expected = "1202124ca8";
|
|
|
|
const char *result = print_hex(buf, sizeof buf, false);
|
|
|
|
rv = compare_strings(expected, result, "print_hex") ? 1 : rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* urls.c */
|
|
|
|
const char *dirty = "https://hello.com/ash";
|
|
|
|
char clean[4096], path[4096], port[16];
|
|
|
|
int portn = clean_up_link(dirty, clean, path, port);
|
|
|
|
rv = compare_strings("hello.com", clean, "clean_up_link") ? 1 : rv;
|
|
|
|
rv = compare_strings("/ash", path, "clean_up_link") ? 1 : rv;
|
|
|
|
rv = compare_strings("443", port, "clean_up_link") ? 1 : rv;
|
|
|
|
assert(portn == HTTPS_PORT);
|
|
|
|
|
|
|
|
dirty = "http://hello.com";
|
|
|
|
portn = clean_up_link(dirty, clean, path, port);
|
|
|
|
rv = compare_strings("hello.com", clean, "clean_up_link") ? 1 : rv;
|
|
|
|
rv = compare_strings("/", path, "clean_up_link") ? 1 : rv;
|
|
|
|
rv = compare_strings("80", port, "clean_up_link") ? 1 : rv;
|
|
|
|
assert(portn == HTTP_PORT);
|
2020-09-12 21:30:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|