summaryrefslogtreecommitdiff
path: root/source/test/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'source/test/unittests')
-rw-r--r--source/test/unittests/bigint.test.c77
-rw-r--r--source/test/unittests/file.test.c86
-rw-r--r--source/test/unittests/string_ref.test.c5
3 files changed, 99 insertions, 69 deletions
diff --git a/source/test/unittests/bigint.test.c b/source/test/unittests/bigint.test.c
index 87bbc60..66cd87a 100644
--- a/source/test/unittests/bigint.test.c
+++ b/source/test/unittests/bigint.test.c
@@ -1,45 +1,74 @@
+#define KIT_BIGINT_SIZE 256
#include "../../kit/bigint.h"
#define KIT_TEST_FILE bigint
#include "../../kit_test/test.h"
-TEST("bigint hex add") {
- SZ(foo, "4242424242424242424242424242424242424242");
- SZ(bar, "1111111111111111111111111111111111111111");
- SZ(sum, "5353535353535353535353535353535353535353");
+static_assert(sizeof(bigint_t) == 256, "KIT_BIGINT_SIZE check");
- REQUIRE(bi_equal(bi_add(bi_hex(foo), bi_hex(bar)), bi_hex(sum)));
+TEST("bigint hex add") {
+ REQUIRE(bi_equal(
+ bi_add(HEX("4242424242424242424242424242424242424242"),
+ HEX("1111111111111111111111111111111111111111")),
+ HEX("5353535353535353535353535353535353535353")));
}
TEST("bigint hex sub") {
- SZ(foo, "4242424242424242424242424242424242424242");
- SZ(bar, "1111111111111111111111111111111111111111");
- SZ(dif, "3131313131313131313131313131313131313131");
-
- REQUIRE(bi_equal(bi_sub(bi_hex(foo), bi_hex(bar)), bi_hex(dif)));
+ REQUIRE(bi_equal(
+ bi_sub(HEX("4242424242424242424242424242424242424242"),
+ HEX("1111111111111111111111111111111111111111")),
+ HEX("3131313131313131313131313131313131313131")));
}
TEST("bigint base58") {
- SZ(foo, "31");
-
- REQUIRE(bi_equal(bi_base58(foo), bi_uword(58 * 2)));
+ REQUIRE(bi_equal(BASE58("31"), bi_uword(58 * 2)));
}
TEST("bigint base58 add") {
- SZ(foo, "4242424242424242424242424242424242424242");
- SZ(bar, "2222222222222222222222222222222222222222");
- SZ(sum, "5353535353535353535353535353535353535353");
-
- REQUIRE(bi_equal(bi_add(bi_base58(foo), bi_base58(bar)),
- bi_base58(sum)));
+ REQUIRE(bi_equal(
+ bi_add(BASE58("4242424242424242424242424242424242424242"),
+ BASE58("2222222222222222222222222222222222222222")),
+ BASE58("5353535353535353535353535353535353535353")));
}
TEST("bigint base58 sub") {
- SZ(foo, "42");
- SZ(bar, "22");
- SZ(dif, "31");
+ REQUIRE(bi_equal(
+ bi_sub(BASE58("4242424242424242424242424242424242424242"),
+ BASE58("2222222222222222222222222222222222222222")),
+ BASE58("3131313131313131313131313131313131313131")));
+}
+
+TEST("bigint base58 mul") {
+ REQUIRE(bi_equal(bi_mul(BASE58("2111111111111111111111"),
+ BASE58("foofoofoofoofoo")),
+ BASE58("foofoofoofoofoo111111111111111111111")));
+}
+
+TEST("bigint div") {
+ REQUIRE(
+ bi_equal(bi_div(HEX("100"), HEX("10")).quotient, HEX("10")));
+
+ REQUIRE(bi_equal(bi_div(bi_mul(BASE58("foofoofoofoofoofoo"),
+ BASE58("barbarbarbarbarbar")),
+ BASE58("barbarbarbarbarbar"))
+ .quotient,
+ BASE58("foofoofoofoofoofoo")));
+
+ REQUIRE(bi_equal(bi_div(bi_mul(BASE58("foofoofoofoofoofoofoofoo"),
+ BASE58("barbarbarbarbarbar")),
+ BASE58("barbarbarbarbarbar"))
+ .quotient,
+ BASE58("foofoofoofoofoofoofoofoo")));
- REQUIRE(bi_equal(bi_sub(bi_base58(foo), bi_base58(bar)),
- bi_base58(dif)));
+ REQUIRE(bi_equal(
+ bi_div(
+ bi_mul(BASE58("foofoofoofoofoofoofoofoofoofoofoofoofoofoofo"
+ "ofoofoofoo"),
+ BASE58("barbarbarbarbarbarbarbarbarbarbarbarbarbarba"
+ "rbar")),
+ BASE58("barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar"))
+ .quotient,
+ BASE58(
+ "foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo")));
}
diff --git a/source/test/unittests/file.test.c b/source/test/unittests/file.test.c
index 5b37ab4..3b6d6d0 100644
--- a/source/test/unittests/file.test.c
+++ b/source/test/unittests/file.test.c
@@ -12,8 +12,8 @@
#endif
TEST("file path normalize one") {
- SZ(foo, "foo/bar/../baz");
- SZ(foo_norm, "foo" S_DELIM_ "baz");
+ str_t foo = SZ("foo/bar/../baz");
+ str_t foo_norm = SZ("foo" S_DELIM_ "baz");
string_t bar = path_norm(foo, kit_alloc_default());
@@ -23,8 +23,8 @@ TEST("file path normalize one") {
}
TEST("file path normalize two") {
- SZ(foo, "foo/bar/../../baz");
- SZ(foo_norm, "baz");
+ str_t foo = SZ("foo/bar/../../baz");
+ str_t foo_norm = SZ("baz");
string_t bar = path_norm(foo, kit_alloc_default());
@@ -34,8 +34,8 @@ TEST("file path normalize two") {
}
TEST("file path normalize parent") {
- SZ(foo, "../baz");
- SZ(foo_norm, ".." S_DELIM_ "baz");
+ str_t foo = SZ("../baz");
+ str_t foo_norm = SZ(".." S_DELIM_ "baz");
string_t bar = path_norm(foo, kit_alloc_default());
@@ -45,8 +45,8 @@ TEST("file path normalize parent") {
}
TEST("file path normalize double parent") {
- SZ(foo, "foo/../../baz");
- SZ(foo_norm, ".." S_DELIM_ "baz");
+ str_t foo = SZ("foo/../../baz");
+ str_t foo_norm = SZ(".." S_DELIM_ "baz");
string_t bar = path_norm(foo, kit_alloc_default());
@@ -56,8 +56,8 @@ TEST("file path normalize double parent") {
}
TEST("file path normalize windows delim") {
- SZ(foo, "foo\\bar\\..\\baz");
- SZ(foo_norm, "foo" S_DELIM_ "baz");
+ str_t foo = SZ("foo\\bar\\..\\baz");
+ str_t foo_norm = SZ("foo" S_DELIM_ "baz");
string_t bar = path_norm(foo, kit_alloc_default());
@@ -67,9 +67,9 @@ TEST("file path normalize windows delim") {
}
TEST("file path join no delim") {
- SZ(foo, "foo");
- SZ(bar, "bar");
- SZ(joined, "foo" S_DELIM_ "bar");
+ str_t foo = SZ("foo");
+ str_t bar = SZ("bar");
+ str_t joined = SZ("foo" S_DELIM_ "bar");
string_t foobar = path_join(foo, bar, kit_alloc_default());
@@ -79,9 +79,9 @@ TEST("file path join no delim") {
}
TEST("file path join delim left") {
- SZ(foo, "foo/");
- SZ(bar, "bar");
- SZ(joined, "foo" S_DELIM_ "bar");
+ str_t foo = SZ("foo/");
+ str_t bar = SZ("bar");
+ str_t joined = SZ("foo" S_DELIM_ "bar");
string_t foobar = path_join(foo, bar, kit_alloc_default());
@@ -91,9 +91,9 @@ TEST("file path join delim left") {
}
TEST("file path join delim right") {
- SZ(foo, "foo");
- SZ(bar, "/bar");
- SZ(joined, "foo" S_DELIM_ "bar");
+ str_t foo = SZ("foo");
+ str_t bar = SZ("/bar");
+ str_t joined = SZ("foo" S_DELIM_ "bar");
string_t foobar = path_join(foo, bar, kit_alloc_default());
@@ -103,9 +103,9 @@ TEST("file path join delim right") {
}
TEST("file path join delim both") {
- SZ(foo, "foo/");
- SZ(bar, "/bar");
- SZ(joined, "foo" S_DELIM_ "bar");
+ str_t foo = SZ("foo/");
+ str_t bar = SZ("/bar");
+ str_t joined = SZ("foo" S_DELIM_ "bar");
string_t foobar = path_join(foo, bar, kit_alloc_default());
@@ -123,9 +123,9 @@ TEST("file path user") {
}
TEST("file path index relative") {
- SZ(foobar, "foo/bar");
- SZ(foo, "foo");
- SZ(bar, "bar");
+ str_t foobar = SZ("foo/bar");
+ str_t foo = SZ("foo");
+ str_t bar = SZ("bar");
REQUIRE(AR_EQUAL(path_index(foobar, 0), foo));
REQUIRE(AR_EQUAL(path_index(foobar, 1), bar));
@@ -133,9 +133,9 @@ TEST("file path index relative") {
}
TEST("file path index absolute") {
- SZ(foobar, "/foo/bar");
- SZ(foo, "foo");
- SZ(bar, "bar");
+ str_t foobar = SZ("/foo/bar");
+ str_t foo = SZ("foo");
+ str_t bar = SZ("bar");
REQUIRE(AR_EQUAL(path_index(foobar, 0), foo));
REQUIRE(AR_EQUAL(path_index(foobar, 1), bar));
@@ -143,10 +143,10 @@ TEST("file path index absolute") {
}
TEST("file path index windows disk name") {
- SZ(foobar, "c:\\foo\\bar");
- SZ(disk, "c:");
- SZ(foo, "foo");
- SZ(bar, "bar");
+ str_t foobar = SZ("c:\\foo\\bar");
+ str_t disk = SZ("c:");
+ str_t foo = SZ("foo");
+ str_t bar = SZ("bar");
REQUIRE(AR_EQUAL(path_index(foobar, 0), disk));
REQUIRE(AR_EQUAL(path_index(foobar, 1), foo));
@@ -155,10 +155,10 @@ TEST("file path index windows disk name") {
}
TEST("file path take relative") {
- SZ(foobar, "foo/bar/");
- SZ(foo, "foo");
- SZ(bar, "foo/bar");
- SZ(bar_end, "foo/bar/");
+ str_t foobar = SZ("foo/bar/");
+ str_t foo = SZ("foo");
+ str_t bar = SZ("foo/bar");
+ str_t bar_end = SZ("foo/bar/");
REQUIRE(AR_EQUAL(path_take(foobar, 0), foo));
REQUIRE(AR_EQUAL(path_take(foobar, 1), bar));
@@ -166,19 +166,19 @@ TEST("file path take relative") {
}
TEST("file path take absolute") {
- SZ(foobar, "/foo/bar");
- SZ(foo, "/foo");
- SZ(bar, "/foo/bar");
+ str_t foobar = SZ("/foo/bar");
+ str_t foo = SZ("/foo");
+ str_t bar = SZ("/foo/bar");
REQUIRE(AR_EQUAL(path_take(foobar, 0), foo));
REQUIRE(AR_EQUAL(path_take(foobar, 1), bar));
}
TEST("file path take windows disk name") {
- SZ(foobar, "c:\\foo\\bar");
- SZ(disk, "c:");
- SZ(foo, "c:\\foo");
- SZ(bar, "c:\\foo\\bar");
+ str_t foobar = SZ("c:\\foo\\bar");
+ str_t disk = SZ("c:");
+ str_t foo = SZ("c:\\foo");
+ str_t bar = SZ("c:\\foo\\bar");
REQUIRE(AR_EQUAL(path_take(foobar, 0), disk));
REQUIRE(AR_EQUAL(path_take(foobar, 1), foo));
diff --git a/source/test/unittests/string_ref.test.c b/source/test/unittests/string_ref.test.c
index 7c49996..5ec9414 100644
--- a/source/test/unittests/string_ref.test.c
+++ b/source/test/unittests/string_ref.test.c
@@ -4,7 +4,7 @@
#include "../../kit_test/test.h"
TEST("static string wrap") {
- SZ(ref, "foo bar");
+ str_t ref = SZ("foo bar");
REQUIRE(ref.size == 7);
REQUIRE(ref.values[0] == 'f');
@@ -17,6 +17,7 @@ TEST("static string wrap") {
}
TEST("string literal") {
- SZ(foo, "foo");
+ str_t foo = SZ("foo");
str_t bar = foo;
+ (void) bar;
}