project_files/hwc/rtl/tests/check_sysutils.c
author koda
Wed, 07 Nov 2012 18:04:27 +0000
branchwebgl
changeset 7983 02f36c3e7f6c
child 10015 4feced261c68
permissions -rw-r--r--
add xymeng's rtl port
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/sysutils.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
static int is_string_equal(string255 s1, string255 s2)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    16
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    17
	return (s1.len == s2.len) && (strcmp(s1.str, s2.str) == 0);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    18
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    19
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    20
START_TEST (test_trim)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    21
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    22
	string255 t;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    23
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    24
	t = fpcrtl_trim(make_string(""));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    25
	fail_if(strcmp(t.str, ""), "trim(\"\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    26
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    27
	t = fpcrtl_trim(make_string("ab"));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    28
	fail_if(strcmp(t.str, "ab"), "trim(\"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_trim(make_string(" "));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    31
	fail_if(strcmp(t.str, ""), "trim(\" \")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    32
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    33
	t = fpcrtl_trim(make_string("   "));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    34
	fail_if(strcmp(t.str, ""), "trim(\"   \")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    35
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    36
	t = fpcrtl_trim(make_string(" ab"));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    37
	fail_if(strcmp(t.str, "ab"), "trim(\" ab\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    38
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    39
	t = fpcrtl_trim(make_string("ab  "));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    40
	fail_if(strcmp(t.str, "ab"), "trim(\"ab  \")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    41
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    42
	t = fpcrtl_trim(make_string("  ab  "));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    43
	fail_if(strcmp(t.str, "ab"), "trim(\"  ab  \")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    44
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    45
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    46
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    47
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    48
START_TEST (test_strToInt)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    49
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    50
	fail_unless(fpcrtl_strToInt(make_string("123")) == 123, "strToInt(\"123\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    51
	fail_unless(fpcrtl_strToInt(make_string("0")) == 0, "strToInt(\"0\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    52
	fail_unless(fpcrtl_strToInt(make_string("-123")) == -123, "strToInt(\"-123\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    53
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    54
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    55
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    56
START_TEST (test_extractFileName)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    57
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    58
	fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("abc")), make_string("abc")), "extractFileName(\"abc\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    59
	fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("a:abc")), make_string("abc")), "extractFileName(\"a:abc\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    60
	fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("/abc")), make_string("abc")), "extractFileName(\"/abc\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    61
	fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("\\abc")), make_string("abc")), "extractFileName(\"\\abc\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    62
	fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("/usr/bin/abc")), make_string("abc")), "extractFileName(\"/usr/bin/abc\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    63
	fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("c:\\def\\abc")), make_string("abc")), "extractFileName(\"c:\\def\\abc\")");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    64
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    65
END_TEST
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    66
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    67
Suite* sysutils_suite(void)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    68
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    69
	Suite *s = suite_create("sysutils");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    70
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    71
	TCase *tc_core = tcase_create("Core");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    72
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    73
	tcase_add_test(tc_core, test_trim);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    74
	tcase_add_test(tc_core, test_strToInt);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    75
	tcase_add_test(tc_core, test_extractFileName);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    76
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    77
	suite_add_tcase(s, tc_core);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    78
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    79
	return s;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    80
}