2015-01-26 09:40:48 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
|
|
* Test the string formatting functions.
|
|
|
|
*/
|
|
|
|
#include <core/string.h>
|
2015-08-21 12:26:15 -04:00
|
|
|
#include "test.h"
|
2015-01-26 09:40:48 -05:00
|
|
|
|
2015-09-02 08:02:41 -04:00
|
|
|
static char buf[6];
|
|
|
|
|
|
|
|
static inline char *swap(gchar *res)
|
|
|
|
{
|
|
|
|
strcpy(buf, res);
|
|
|
|
g_free(res);
|
|
|
|
return buf;
|
|
|
|
}
|
2015-01-26 09:40:48 -05:00
|
|
|
|
2015-01-27 08:34:32 -05:00
|
|
|
void test_sec2str()
|
|
|
|
{
|
2015-09-02 08:02:41 -04:00
|
|
|
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");
|
2015-01-27 08:34:32 -05:00
|
|
|
}
|
|
|
|
|
2015-01-29 08:27:25 -05:00
|
|
|
void test_sec2str_detailed()
|
|
|
|
{
|
|
|
|
|
|
|
|
unsigned int minute = 60;
|
|
|
|
unsigned int hour = 3600;
|
|
|
|
unsigned int day = 86400;
|
|
|
|
|
|
|
|
test_equal(string :: sec2str_detailed(day), "1 day");
|
|
|
|
test_equal(string :: sec2str_detailed(2 * day), "2 days");
|
|
|
|
|
|
|
|
test_equal(string :: sec2str_detailed(day + hour), "1 day, 1 hour");
|
|
|
|
test_equal(string :: sec2str_detailed(hour), "1 hour");
|
|
|
|
test_equal(string :: sec2str_detailed(2 * hour), "2 hours");
|
|
|
|
|
|
|
|
test_equal(string :: sec2str_detailed(hour + minute), "1 hour, 1 minute");
|
|
|
|
test_equal(string :: sec2str_detailed(minute), "1 minute");
|
|
|
|
test_equal(string :: sec2str_detailed(2 * minute), "2 minutes");
|
|
|
|
|
|
|
|
test_equal(string :: sec2str_detailed(minute + 1), "1 minute, 1 second");
|
2015-09-02 08:13:21 -04:00
|
|
|
test_equal(string :: sec2str_detailed(0), "");
|
2015-01-29 08:27:25 -05:00
|
|
|
test_equal(string :: sec2str_detailed(1), "1 second");
|
|
|
|
test_equal(string :: sec2str_detailed(2), "2 seconds");
|
|
|
|
}
|
|
|
|
|
2015-01-30 09:32:27 -05:00
|
|
|
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");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-21 12:26:15 -04:00
|
|
|
DECLARE_UNIT_TESTS(
|
|
|
|
UNIT_TEST("Seconds to String", test_sec2str),
|
|
|
|
UNIT_TEST("Seconds to String (Detailed)", test_sec2str_detailed),
|
|
|
|
UNIT_TEST("String Lowercase", test_lowercase),
|
|
|
|
);
|