project_files/hwc/rtl/tests/check_misc.c
author koda
Tue, 13 Nov 2012 23:56:50 +0100
branchwebgl
changeset 8050 c82b68016c68
parent 7983 02f36c3e7f6c
child 10015 4feced261c68
permissions -rw-r--r--
link main on osx
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     1
#include <check.h>
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     2
#include <stdlib.h>
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     3
#include <stdio.h>
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     4
#include "check_check.h"
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     5
#include "../src/misc.h"
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     6
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     7
static string255 make_string(const char* str)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     8
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     9
	string255 s;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    10
	s.len = strlen(str);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    11
	memcpy(s.str, str, s.len + 1);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    12
	return s;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    13
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    14
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    15
START_TEST(test_strconcat)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    16
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    17
	string255 t;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    18
	t = fpcrtl_strconcat(make_string(""), make_string(""));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    19
	fail_if(strcmp(t.str, ""), "strconcat(\"\", \"\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    20
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    21
	t = fpcrtl_strconcat(make_string(""), make_string("a"));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    22
	fail_if(strcmp(t.str, "a"), "strconcat(\"\", \"a\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    23
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    24
	t = fpcrtl_strconcat(make_string("a"), make_string(""));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    25
	fail_if(strcmp(t.str, "a"), "strconcat(\"a\", \"\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    26
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    27
	t = fpcrtl_strconcat(make_string("ab"), make_string(""));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    28
	fail_if(strcmp(t.str, "ab"), "strconcat(\"ab\", \"\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    29
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    30
	t = fpcrtl_strconcat(make_string("ab"), make_string("cd"));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    31
	fail_if(strcmp(t.str, "abcd"), "strconcat(\"ab\", \"cd\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    32
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    33
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    34
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    35
START_TEST (test_strappend)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    36
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    37
	string255 t;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    38
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    39
	t = fpcrtl_strappend(make_string(""), 'c');
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    40
	fail_if(strcmp(t.str, "c"), "strappend(\"\", 'c')");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    41
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    42
	t = fpcrtl_strappend(make_string("ab"), 'c');
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    43
	fail_if(strcmp(t.str, "abc"), "strappend(\"ab\", 'c')");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    44
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    45
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    46
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    47
START_TEST (test_strprepend)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    48
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    49
	string255 t;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    50
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    51
	t = fpcrtl_strprepend('c', make_string(""));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    52
	fail_if(strcmp(t.str, "c"), "strprepend('c', \"\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    53
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    54
	t = fpcrtl_strprepend('c', make_string("ab"));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    55
	fail_if(strcmp(t.str, "cab"), "strprepend('c', \"ab\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    56
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    57
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    58
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    59
START_TEST (test_strcompare)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    60
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    61
	fail_unless(fpcrtl_strcompare(make_string(""), make_string("")), "strcompare(\"\", \"\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    62
	fail_unless(fpcrtl_strcompare(make_string("a"), make_string("a")), "strcompare(\"a\", \"a\"");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    63
	fail_unless(!fpcrtl_strcompare(make_string("a"), make_string("b")), "strcompare(\"a\", \"b\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    64
	fail_unless(!fpcrtl_strcompare(make_string("a"), make_string("ab")), "strcompare(\"a\", \"ab\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    65
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    66
	fail_unless(fpcrtl_strcomparec(make_string(" "), ' '), "strcomparec(\" \", ' ')");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    67
	fail_unless(fpcrtl_strcomparec(make_string("a"), 'a'), "strcomparec(\"a\", 'a')");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    68
	fail_unless(!fpcrtl_strcomparec(make_string("  "), ' '), "strcomparec(\"  \", ' '");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    69
	fail_unless(!fpcrtl_strcomparec(make_string(""), ' '), "strcomparec(\"\", ' ')");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    70
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    71
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    72
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    73
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    74
Suite* misc_suite(void)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    75
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    76
	Suite *s = suite_create("misc");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    77
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    78
	TCase *tc_core = tcase_create("Core");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    79
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    80
	tcase_add_test(tc_core, test_strconcat);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    81
	tcase_add_test(tc_core, test_strappend);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    82
	tcase_add_test(tc_core, test_strprepend);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    83
	tcase_add_test(tc_core, test_strcompare);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    84
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    85
	suite_add_tcase(s, tc_core);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    86
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    87
	return s;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    88
}