43 lines
940 B
C
43 lines
940 B
C
#include "jairee.h"
|
|
#include <stdio.h>
|
|
|
|
#define TEST(x) Test(#x, x, __FILE__, __LINE__)
|
|
|
|
static int n_tests_passed;
|
|
static int n_tests_failed;
|
|
|
|
static void Test(const char * message, int result, const char * file, int line)
|
|
{
|
|
if (result)
|
|
{
|
|
n_tests_passed++;
|
|
}
|
|
else
|
|
{
|
|
fprintf(stderr, "Test failure at %s:%d: \"%s\"\n", file, line, message);
|
|
n_tests_failed++;
|
|
}
|
|
}
|
|
|
|
static void test_asciiz_string()
|
|
{
|
|
jairee_string_t * s = jairee_string_from_asciiz("Test String");
|
|
size_t offset = 0;
|
|
TEST(s->len == 11u);
|
|
TEST(s->decode(s->str, &offset) == 'T');
|
|
TEST(offset == 1u);
|
|
offset = 10u;
|
|
TEST(s->decode(s->str, &offset) == 'g');
|
|
TEST(offset == 11u);
|
|
jairee_string_free(s);
|
|
}
|
|
|
|
int main(int argc, char * argv[])
|
|
{
|
|
test_asciiz_string();
|
|
|
|
printf("%d/%d tests passed\n", n_tests_passed, n_tests_passed + n_tests_failed);
|
|
|
|
return n_tests_failed == 0 ? 0 : 1;
|
|
}
|