core/string: Add a test for several sec2str_long() fields
I also remove the swap() function I was using to reallocate strings out of a static buffer. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
21f13b32c0
commit
b1ef40679b
|
@ -5,29 +5,24 @@
|
|||
#include <core/string.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
static char buf[25];
|
||||
#define str_test_equal(lhs, rhs) \
|
||||
test_strings_equal(lhs, g_strdup(rhs), __LINE__)
|
||||
|
||||
static inline char *swap(gchar *res)
|
||||
{
|
||||
strcpy(buf, res);
|
||||
g_free(res);
|
||||
return buf;
|
||||
}
|
||||
|
||||
void test_sec2str()
|
||||
{
|
||||
test_equal(swap(string_sec2str(0)), "0:00");
|
||||
test_equal(swap(string_sec2str(5)), "0:05");
|
||||
test_equal(swap(string_sec2str(10)), "0:10");
|
||||
test_equal(swap(string_sec2str(60)), "1:00");
|
||||
test_equal(swap(string_sec2str(65)), "1:05");
|
||||
test_equal(swap(string_sec2str(75)), "1:15");
|
||||
test_equal(swap(string_sec2str(600)), "10:00");
|
||||
test_equal(swap(string_sec2str(605)), "10:05");
|
||||
test_equal(swap(string_sec2str(615)), "10:15");
|
||||
test_equal(swap(string_sec2str(660)), "11:00");
|
||||
test_equal(swap(string_sec2str(665)), "11:05");
|
||||
test_equal(swap(string_sec2str(675)), "11:15");
|
||||
str_test_equal(string_sec2str(0), "0:00");
|
||||
str_test_equal(string_sec2str(5), "0:05");
|
||||
str_test_equal(string_sec2str(10), "0:10");
|
||||
str_test_equal(string_sec2str(60), "1:00");
|
||||
str_test_equal(string_sec2str(65), "1:05");
|
||||
str_test_equal(string_sec2str(75), "1:15");
|
||||
str_test_equal(string_sec2str(600), "10:00");
|
||||
str_test_equal(string_sec2str(605), "10:05");
|
||||
str_test_equal(string_sec2str(615), "10:15");
|
||||
str_test_equal(string_sec2str(660), "11:00");
|
||||
str_test_equal(string_sec2str(665), "11:05");
|
||||
str_test_equal(string_sec2str(675), "11:15");
|
||||
}
|
||||
|
||||
void test_sec2str_long()
|
||||
|
@ -37,38 +32,42 @@ void test_sec2str_long()
|
|||
unsigned int hour = 3600;
|
||||
unsigned int day = 86400;
|
||||
|
||||
test_equal(swap(string_sec2str_long(day)), "1 day");
|
||||
test_equal(swap(string_sec2str_long(2 * day)), "2 days");
|
||||
str_test_equal(string_sec2str_long(day), "1 day");
|
||||
str_test_equal(string_sec2str_long(2 * day), "2 days");
|
||||
|
||||
test_equal(swap(string_sec2str_long(day + hour)), "1 day, 1 hour");
|
||||
test_equal(swap(string_sec2str_long(hour)), "1 hour");
|
||||
test_equal(swap(string_sec2str_long(2 * hour)), "2 hours");
|
||||
str_test_equal(string_sec2str_long(day + hour), "1 day, 1 hour");
|
||||
str_test_equal(string_sec2str_long(hour), "1 hour");
|
||||
str_test_equal(string_sec2str_long(2 * hour), "2 hours");
|
||||
|
||||
test_equal(swap(string_sec2str_long(hour + minute)), "1 hour, 1 minute");
|
||||
test_equal(swap(string_sec2str_long(minute)), "1 minute");
|
||||
test_equal(swap(string_sec2str_long(2 * minute)), "2 minutes");
|
||||
str_test_equal(string_sec2str_long(hour + minute), "1 hour, 1 minute");
|
||||
str_test_equal(string_sec2str_long(minute), "1 minute");
|
||||
str_test_equal(string_sec2str_long(2 * minute), "2 minutes");
|
||||
|
||||
test_equal(swap(string_sec2str_long(minute + 1)), "1 minute, 1 second");
|
||||
test_equal(swap(string_sec2str_long(0)), "");
|
||||
test_equal(swap(string_sec2str_long(1)), "1 second");
|
||||
test_equal(swap(string_sec2str_long(2)), "2 seconds");
|
||||
str_test_equal(string_sec2str_long(minute + 1), "1 minute, 1 second");
|
||||
str_test_equal(string_sec2str_long(0), "");
|
||||
str_test_equal(string_sec2str_long(1), "1 second");
|
||||
str_test_equal(string_sec2str_long(2), "2 seconds");
|
||||
|
||||
str_test_equal(
|
||||
string_sec2str_long((22 * day) + (4 * hour) + (12 * minute) + 32),
|
||||
"22 days, 4 hours, 12 minutes, 32 seconds");
|
||||
}
|
||||
|
||||
void test_lowercase()
|
||||
{
|
||||
test_equal(swap(string_lowercase(" ")), "");
|
||||
test_equal(swap(string_lowercase(" test \
|
||||
text")), "test text");
|
||||
test_equal(swap(string_lowercase("test/text")), "test text");
|
||||
test_equal(swap(string_lowercase("Test, Text")), "test text");
|
||||
test_equal(swap(string_lowercase("Test? Text!")), "test text");
|
||||
test_equal(swap(string_lowercase("Test?123 Text!456")), "test123 text456");
|
||||
test_equal(swap(string_lowercase("Test?123 Text!456")), "test123 text456");
|
||||
test_equal(swap(string_lowercase("Test(text);123-456")), "test text 123 456");
|
||||
test_equal(swap(string_lowercase("Test((text));;123--456")), "test text 123 456");
|
||||
test_equal(swap(string_lowercase("! __test(TEXT) + __test(\"TEXT\")")),
|
||||
str_test_equal(string_lowercase(" "), "");
|
||||
str_test_equal(string_lowercase(" test \
|
||||
text"), "test text");
|
||||
str_test_equal(string_lowercase("test/text"), "test text");
|
||||
str_test_equal(string_lowercase("Test, Text"), "test text");
|
||||
str_test_equal(string_lowercase("Test? Text!"), "test text");
|
||||
str_test_equal(string_lowercase("Test?123 Text!456"), "test123 text456");
|
||||
str_test_equal(string_lowercase("Test?123 Text!456"), "test123 text456");
|
||||
str_test_equal(string_lowercase("Test(text);123-456"), "test text 123 456");
|
||||
str_test_equal(string_lowercase("Test((text));;123--456"), "test text 123 456");
|
||||
str_test_equal(string_lowercase("! __test(TEXT) + __test(\"TEXT\")"),
|
||||
"test text test text");
|
||||
test_equal(swap(string_lowercase("Test~tEXt\\123")), "test text 123");
|
||||
str_test_equal(string_lowercase("Test~tEXt\\123"), "test text 123");
|
||||
}
|
||||
|
||||
void test_compare()
|
||||
|
|
Loading…
Reference in New Issue