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-03 09:31:48 -04:00
|
|
|
static char buf[25];
|
2015-09-02 08:02:41 -04:00
|
|
|
|
|
|
|
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-09-03 09:31:48 -04:00
|
|
|
void test_sec2str_long()
|
2015-01-29 08:27:25 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
unsigned int minute = 60;
|
|
|
|
unsigned int hour = 3600;
|
|
|
|
unsigned int day = 86400;
|
|
|
|
|
2015-09-03 09:31:48 -04:00
|
|
|
test_equal(swap(string_sec2str_long(day)), "1 day");
|
|
|
|
test_equal(swap(string_sec2str_long(2 * day)), "2 days");
|
2015-01-29 08:27:25 -05:00
|
|
|
|
2015-09-03 09:31:48 -04:00
|
|
|
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");
|
2015-01-29 08:27:25 -05:00
|
|
|
|
2015-09-03 09:31:48 -04:00
|
|
|
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");
|
2015-01-29 08:27:25 -05:00
|
|
|
|
2015-09-03 09:31:48 -04:00
|
|
|
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");
|
2015-01-29 08:27:25 -05:00
|
|
|
}
|
|
|
|
|
2015-01-30 09:32:27 -05:00
|
|
|
void test_lowercase()
|
|
|
|
{
|
2015-09-08 09:14:39 -04:00
|
|
|
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\")")),
|
2015-01-30 09:32:27 -05:00
|
|
|
"test text test text");
|
2015-09-08 09:14:39 -04:00
|
|
|
test_equal(swap(string_lowercase("Test~tEXt\\123")), "test text 123");
|
2015-01-30 09:32:27 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-21 12:26:15 -04:00
|
|
|
DECLARE_UNIT_TESTS(
|
|
|
|
UNIT_TEST("Seconds to String", test_sec2str),
|
2015-09-03 09:31:48 -04:00
|
|
|
UNIT_TEST("Seconds to String (Long)", test_sec2str_long),
|
2015-08-21 12:26:15 -04:00
|
|
|
UNIT_TEST("String Lowercase", test_lowercase),
|
|
|
|
);
|