build: re-enable namespace-specific tests
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/error.h>
|
||||
#include <fx/error.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
+54
-15
@@ -1,10 +1,13 @@
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/hash.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static void print_digest(
|
||||
const char *func_name, fx_hash_function func, const char *msg,
|
||||
size_t msg_len, size_t digest_len)
|
||||
const char *func_name,
|
||||
fx_hash_function func,
|
||||
const char *msg,
|
||||
size_t msg_len,
|
||||
size_t digest_len)
|
||||
{
|
||||
unsigned char digest[128];
|
||||
|
||||
@@ -27,8 +30,10 @@ static void print_digest(
|
||||
char digest_str[256];
|
||||
for (size_t i = 0; i < digest_len; i++) {
|
||||
snprintf(
|
||||
digest_str + (i * 2), sizeof digest_str - (i * 2),
|
||||
"%02x", digest[i]);
|
||||
digest_str + (i * 2),
|
||||
sizeof digest_str - (i * 2),
|
||||
"%02x",
|
||||
digest[i]);
|
||||
}
|
||||
|
||||
printf("%s(%s) = %s\n", func_name, msg, digest_str);
|
||||
@@ -44,30 +49,64 @@ int main(void)
|
||||
print_digest("MD5", FX_HASH_MD5, msg, msg_len, FX_DIGEST_LENGTH_MD5);
|
||||
print_digest("SHA1", FX_HASH_SHA1, msg, msg_len, FX_DIGEST_LENGTH_SHA1);
|
||||
print_digest(
|
||||
"SHA224", FX_HASH_SHA2_224, msg, msg_len, FX_DIGEST_LENGTH_SHA2_224);
|
||||
"SHA224",
|
||||
FX_HASH_SHA2_224,
|
||||
msg,
|
||||
msg_len,
|
||||
FX_DIGEST_LENGTH_SHA2_224);
|
||||
print_digest(
|
||||
"SHA256", FX_HASH_SHA2_256, msg, msg_len, FX_DIGEST_LENGTH_SHA2_256);
|
||||
"SHA256",
|
||||
FX_HASH_SHA2_256,
|
||||
msg,
|
||||
msg_len,
|
||||
FX_DIGEST_LENGTH_SHA2_256);
|
||||
print_digest(
|
||||
"SHA384", FX_HASH_SHA2_384, msg, msg_len, FX_DIGEST_LENGTH_SHA2_384);
|
||||
"SHA384",
|
||||
FX_HASH_SHA2_384,
|
||||
msg,
|
||||
msg_len,
|
||||
FX_DIGEST_LENGTH_SHA2_384);
|
||||
print_digest(
|
||||
"SHA512", FX_HASH_SHA2_512, msg, msg_len, FX_DIGEST_LENGTH_SHA2_512);
|
||||
"SHA512",
|
||||
FX_HASH_SHA2_512,
|
||||
msg,
|
||||
msg_len,
|
||||
FX_DIGEST_LENGTH_SHA2_512);
|
||||
print_digest(
|
||||
"SHA3-224", FX_HASH_SHA3_224, msg, msg_len,
|
||||
"SHA3-224",
|
||||
FX_HASH_SHA3_224,
|
||||
msg,
|
||||
msg_len,
|
||||
FX_DIGEST_LENGTH_SHA3_224);
|
||||
print_digest(
|
||||
"SHA3-256", FX_HASH_SHA3_256, msg, msg_len,
|
||||
"SHA3-256",
|
||||
FX_HASH_SHA3_256,
|
||||
msg,
|
||||
msg_len,
|
||||
FX_DIGEST_LENGTH_SHA3_256);
|
||||
print_digest(
|
||||
"SHA3-384", FX_HASH_SHA3_384, msg, msg_len,
|
||||
"SHA3-384",
|
||||
FX_HASH_SHA3_384,
|
||||
msg,
|
||||
msg_len,
|
||||
FX_DIGEST_LENGTH_SHA3_384);
|
||||
print_digest(
|
||||
"SHA3-512", FX_HASH_SHA3_512, msg, msg_len,
|
||||
"SHA3-512",
|
||||
FX_HASH_SHA3_512,
|
||||
msg,
|
||||
msg_len,
|
||||
FX_DIGEST_LENGTH_SHA3_512);
|
||||
print_digest(
|
||||
"SHAKE128", FX_HASH_SHAKE128, msg, msg_len,
|
||||
"SHAKE128",
|
||||
FX_HASH_SHAKE128,
|
||||
msg,
|
||||
msg_len,
|
||||
FX_DIGEST_LENGTH_SHAKE128);
|
||||
print_digest(
|
||||
"SHAKE256", FX_HASH_SHAKE256, msg, msg_len,
|
||||
"SHAKE256",
|
||||
FX_HASH_SHAKE256,
|
||||
msg,
|
||||
msg_len,
|
||||
FX_DIGEST_LENGTH_SHAKE256);
|
||||
|
||||
return 0;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/random.h>
|
||||
#include <fx/random.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define NRAND_NUMBERS 12
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <assert.h>
|
||||
#include <fx/core/ringbuffer.h>
|
||||
#include <fx/ringbuffer.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include <fx/core/rope.h>
|
||||
#include <fx/rope.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
#include <fx/core/bstr.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/bstr.h>
|
||||
#include <fx/stream.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <fx/string.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("-------------\n");
|
||||
fx_string *str = fx_string_create_from_cstr("Hello, world!\n");
|
||||
printf("%s\n", fx_string_get_cstr(str));
|
||||
printf("len:%zu, max:%zu\n",
|
||||
fx_string_get_size(str, FX_STRLEN_NORMAL),
|
||||
fx_string_get_capacity(str));
|
||||
|
||||
fx_string_insert_cstr(str, "WOW!", 4);
|
||||
|
||||
printf("-------------\n");
|
||||
printf("%s\n", fx_string_get_cstr(str));
|
||||
printf("len:%zu, max:%zu\n",
|
||||
fx_string_get_size(str, FX_STRLEN_NORMAL),
|
||||
fx_string_get_capacity(str));
|
||||
|
||||
fx_string_replace(str, 4, 4, "+");
|
||||
|
||||
printf("-------------\n");
|
||||
printf("%s\n", fx_string_get_cstr(str));
|
||||
printf("len:%zu, max:%zu\n",
|
||||
fx_string_get_size(str, FX_STRLEN_NORMAL),
|
||||
fx_string_get_capacity(str));
|
||||
printf("-------------\n");
|
||||
|
||||
fx_string_unref(str);
|
||||
|
||||
fx_stringstream *strv = fx_stringstream_create();
|
||||
fx_stream_write_cstr(strv, "Hello", NULL);
|
||||
fx_stream_write_cstr(strv, ", world", NULL);
|
||||
fx_stream_write_cstr(strv, "!", NULL);
|
||||
|
||||
char *s = fx_stringstream_steal(strv);
|
||||
fx_stringstream_unref(strv);
|
||||
|
||||
printf("%s\n", s);
|
||||
free(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <fx/string.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("здравс\u26A0твуите\n");
|
||||
fx_string *str = fx_string_create_from_cstr("здравствуите");
|
||||
const char *s = fx_string_get_cstr(str);
|
||||
printf("%s\n", s);
|
||||
printf("len: %zu\n", fx_string_get_size(str, FX_STRLEN_NORMAL));
|
||||
printf("codepoints: %zu\n",
|
||||
fx_string_get_size(str, FX_STRLEN_CODEPOINTS));
|
||||
|
||||
const char *delims[] = {"в"};
|
||||
size_t nr_delims = sizeof delims / sizeof delims[0];
|
||||
|
||||
fx_iterator *it = fx_string_tokenise(str, delims, nr_delims, 0);
|
||||
fx_foreach(const char *, tok, it)
|
||||
{
|
||||
printf("%s\n", tok);
|
||||
}
|
||||
fx_iterator_unref(it);
|
||||
fx_string_unref(str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
#include <CuTest.h>
|
||||
#include <fx/core/bst.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
struct test_tree_node {
|
||||
int value;
|
||||
fx_bst_node node;
|
||||
};
|
||||
|
||||
struct test_queue_entry {
|
||||
int value;
|
||||
fx_queue_entry entry;
|
||||
};
|
||||
|
||||
FX_BST_DEFINE_SIMPLE_INSERT(struct test_tree_node, node, value, test_tree_insert);
|
||||
|
||||
void test_bst_insert(CuTest *tc)
|
||||
{
|
||||
fx_bst tree = {0};
|
||||
struct test_tree_node nodes[3] = {0};
|
||||
|
||||
for (int i = 0; i < sizeof nodes / sizeof *nodes; i++) {
|
||||
nodes[i].value = i;
|
||||
}
|
||||
|
||||
test_tree_insert(&tree, &nodes[0]);
|
||||
|
||||
CuAssertPtrEquals(tc, NULL, nodes[0].node.n_left);
|
||||
CuAssertPtrEquals(tc, NULL, nodes[0].node.n_right);
|
||||
CuAssertIntEquals(tc, 1, nodes[0].node.n_height);
|
||||
|
||||
test_tree_insert(&tree, &nodes[1]);
|
||||
|
||||
CuAssertPtrEquals(tc, NULL, nodes[0].node.n_left);
|
||||
CuAssertPtrEquals(tc, &nodes[1].node, nodes[0].node.n_right);
|
||||
CuAssertIntEquals(tc, 2, nodes[0].node.n_height);
|
||||
|
||||
CuAssertPtrEquals(tc, NULL, nodes[1].node.n_left);
|
||||
CuAssertPtrEquals(tc, NULL, nodes[1].node.n_right);
|
||||
CuAssertIntEquals(tc, 1, nodes[1].node.n_height);
|
||||
|
||||
test_tree_insert(&tree, &nodes[2]);
|
||||
|
||||
CuAssertPtrEquals(tc, &nodes[0].node, nodes[1].node.n_left);
|
||||
CuAssertPtrEquals(tc, &nodes[2].node, nodes[1].node.n_right);
|
||||
CuAssertIntEquals(tc, 2, nodes[1].node.n_height);
|
||||
|
||||
CuAssertPtrEquals(tc, NULL, nodes[0].node.n_left);
|
||||
CuAssertPtrEquals(tc, NULL, nodes[0].node.n_right);
|
||||
CuAssertIntEquals(tc, 1, nodes[0].node.n_height);
|
||||
|
||||
CuAssertPtrEquals(tc, NULL, nodes[2].node.n_left);
|
||||
CuAssertPtrEquals(tc, NULL, nodes[2].node.n_right);
|
||||
CuAssertIntEquals(tc, 1, nodes[2].node.n_height);
|
||||
}
|
||||
|
||||
void test_bst_iterate(CuTest *tc)
|
||||
{
|
||||
static const size_t nr_nodes = 256;
|
||||
srand(time(NULL));
|
||||
|
||||
fx_bst tree = {0};
|
||||
struct test_tree_node *nodes = calloc(nr_nodes, sizeof *nodes);
|
||||
CuAssertPtrNotNull(tc, nodes);
|
||||
|
||||
for (int i = 0; i < nr_nodes; i++) {
|
||||
nodes[i].value = rand();
|
||||
test_tree_insert(&tree, &nodes[i]);
|
||||
}
|
||||
|
||||
int prev = -1;
|
||||
fx_bst_node *bnode = fx_bst_first(&tree);
|
||||
while (bnode) {
|
||||
struct test_tree_node *node
|
||||
= fx_unbox(struct test_tree_node, bnode, node);
|
||||
CuAssertPtrNotNull(tc, node);
|
||||
|
||||
if (prev == -1) {
|
||||
prev = node->value;
|
||||
bnode = fx_bst_next(bnode);
|
||||
continue;
|
||||
}
|
||||
|
||||
CuAssertTrue(tc, prev <= node->value);
|
||||
prev = node->value;
|
||||
bnode = fx_bst_next(bnode);
|
||||
}
|
||||
|
||||
free(nodes);
|
||||
}
|
||||
|
||||
void test_queue_insert(CuTest *tc)
|
||||
{
|
||||
struct test_queue_entry entries[5] = {0};
|
||||
for (int i = 0; i < sizeof entries / sizeof *entries; i++) {
|
||||
entries[i].value = i;
|
||||
}
|
||||
|
||||
fx_queue q = FX_QUEUE_INIT;
|
||||
|
||||
fx_queue_push_back(&q, &entries[0].entry);
|
||||
fx_queue_push_back(&q, &entries[2].entry);
|
||||
fx_queue_push_back(&q, &entries[4].entry);
|
||||
fx_queue_insert_after(&q, &entries[3].entry, &entries[2].entry);
|
||||
fx_queue_insert_before(&q, &entries[1].entry, &entries[2].entry);
|
||||
|
||||
CuAssertPtrEquals(tc, NULL, entries[0].entry.qe_prev);
|
||||
CuAssertPtrEquals(tc, &entries[1].entry, entries[0].entry.qe_next);
|
||||
|
||||
CuAssertPtrEquals(tc, &entries[0].entry, entries[1].entry.qe_prev);
|
||||
CuAssertPtrEquals(tc, &entries[2].entry, entries[1].entry.qe_next);
|
||||
|
||||
CuAssertPtrEquals(tc, &entries[1].entry, entries[2].entry.qe_prev);
|
||||
CuAssertPtrEquals(tc, &entries[3].entry, entries[2].entry.qe_next);
|
||||
|
||||
CuAssertPtrEquals(tc, &entries[2].entry, entries[3].entry.qe_prev);
|
||||
CuAssertPtrEquals(tc, &entries[4].entry, entries[3].entry.qe_next);
|
||||
|
||||
CuAssertPtrEquals(tc, &entries[3].entry, entries[4].entry.qe_prev);
|
||||
CuAssertPtrEquals(tc, NULL, entries[4].entry.qe_next);
|
||||
}
|
||||
|
||||
void test_queue_iterate(CuTest *tc)
|
||||
{
|
||||
fx_queue q = FX_QUEUE_INIT;
|
||||
struct test_queue_entry entries[32] = {0};
|
||||
|
||||
for (int i = 0; i < sizeof entries / sizeof *entries; i++) {
|
||||
entries[i].value = i;
|
||||
fx_queue_push_back(&q, &entries[i].entry);
|
||||
}
|
||||
|
||||
int prev = -1;
|
||||
struct fx_queue_entry *entry = fx_queue_first(&q);
|
||||
while (entry) {
|
||||
struct test_queue_entry *e
|
||||
= fx_unbox(struct test_queue_entry, entry, entry);
|
||||
CuAssertPtrNotNull(tc, e);
|
||||
|
||||
if (prev == -1) {
|
||||
prev = e->value;
|
||||
goto skip;
|
||||
}
|
||||
|
||||
CuAssertTrue(tc, prev < e->value);
|
||||
prev = e->value;
|
||||
skip:
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
void test_stringstream_1(CuTest *tc)
|
||||
{
|
||||
char buf[1024];
|
||||
fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf);
|
||||
|
||||
fx_stream_write_cstr(s, "hello", NULL);
|
||||
fx_stream_write_fmt(s, NULL, "(%d + %.1f)", 32, 2.3);
|
||||
|
||||
char *end = fx_stringstream_steal(s);
|
||||
fx_stringstream_unref(s);
|
||||
|
||||
CuAssertStrEquals(tc, "hello(32 + 2.3)", end);
|
||||
}
|
||||
|
||||
void test_stringstream_2(CuTest *tc)
|
||||
{
|
||||
char buf[1024];
|
||||
fx_stringstream *s = fx_stringstream_create_with_buffer(buf, sizeof buf);
|
||||
|
||||
fx_stream_write_cstr(s, "{\n", NULL);
|
||||
fx_stream_push_indent(s, 1);
|
||||
|
||||
fx_stream_write_cstr(s, "a = 32,\n", NULL);
|
||||
fx_stream_write_cstr(s, "b = 64\n", NULL);
|
||||
|
||||
fx_stream_pop_indent(s);
|
||||
fx_stream_write_cstr(s, "}", NULL);
|
||||
|
||||
char *str = fx_stringstream_steal(s);
|
||||
fx_stringstream_unref(s);
|
||||
|
||||
CuAssertStrEquals(tc, "{\n a = 32,\n b = 64\n}", str);
|
||||
}
|
||||
|
||||
CuSuite *get_all_tests(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
||||
SUITE_ADD_TEST(suite, test_bst_insert);
|
||||
SUITE_ADD_TEST(suite, test_bst_iterate);
|
||||
SUITE_ADD_TEST(suite, test_queue_insert);
|
||||
SUITE_ADD_TEST(suite, test_queue_iterate);
|
||||
SUITE_ADD_TEST(suite, test_stringstream_1);
|
||||
SUITE_ADD_TEST(suite, test_stringstream_2);
|
||||
|
||||
return suite;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <fx/uuid.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fx_uuid *uuid = fx_uuid_create_from_cstr(
|
||||
"5b80ad1f-367f-4a1f-88f3-b3a6f8d1f63d");
|
||||
char str[FX_UUID_STRING_MAX];
|
||||
fx_uuid_to_cstr(uuid, str);
|
||||
printf("%s\n", str);
|
||||
|
||||
fx_uuid_unref(uuid);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user