80 lines
2.6 KiB
C++
80 lines
2.6 KiB
C++
/*
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
* Test the string formatting functions.
|
|
*/
|
|
#include <core/string.h>
|
|
#include "test.h"
|
|
|
|
static char buf[25];
|
|
|
|
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");
|
|
}
|
|
|
|
void test_sec2str_long()
|
|
{
|
|
|
|
unsigned int minute = 60;
|
|
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");
|
|
|
|
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");
|
|
|
|
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");
|
|
|
|
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");
|
|
}
|
|
|
|
void test_lowercase()
|
|
{
|
|
test_equal(string :: lowercase(" "), "");
|
|
test_equal(string :: lowercase(" test \
|
|
text"), "test text");
|
|
test_equal(string :: lowercase("test/text"), "test text");
|
|
test_equal(string :: lowercase("Test, Text"), "test text");
|
|
test_equal(string :: lowercase("Test? Text!"), "test text");
|
|
test_equal(string :: lowercase("Test?123 Text!456"), "test123 text456");
|
|
test_equal(string :: lowercase("Test?123 Text!456"), "test123 text456");
|
|
test_equal(string :: lowercase("Test(text);123-456"), "test text 123 456");
|
|
test_equal(string :: lowercase("Test((text));;123--456"), "test text 123 456");
|
|
test_equal(string :: lowercase("! __test(TEXT) + __test(\"TEXT\")"),
|
|
"test text test text");
|
|
test_equal(string :: lowercase("Test~tEXt\\123"), "test text 123");
|
|
|
|
}
|
|
|
|
DECLARE_UNIT_TESTS(
|
|
UNIT_TEST("Seconds to String", test_sec2str),
|
|
UNIT_TEST("Seconds to String (Long)", test_sec2str_long),
|
|
UNIT_TEST("String Lowercase", test_lowercase),
|
|
);
|