tests: Build date test with ctest
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
fc88f68d6b
commit
4fb854d0b1
|
@ -7,3 +7,4 @@ endfunction()
|
|||
core_unit_test(Version)
|
||||
core_unit_test(String)
|
||||
core_unit_test(File)
|
||||
core_unit_test(Date)
|
||||
|
|
|
@ -26,7 +26,7 @@ Export("core_objs", "CoreTest")
|
|||
|
||||
core_objs += [ env.Object("../../core/string.c") ]
|
||||
core_objs += [ env.Object("../../core/file.c") ]
|
||||
res += [ CoreTest("date") ]
|
||||
core_objs += [ env.Object("../../core/date.c") ]
|
||||
res += [ CoreTest("idle") ]
|
||||
res += [ CoreTest("database") ]
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <core/date.h>
|
||||
#include <tests/test.h>
|
||||
#include <locale.h>
|
||||
|
@ -18,44 +17,40 @@ void test_date()
|
|||
.d_day = 0,
|
||||
};
|
||||
struct file f = FILE_INIT("date", 0, 0);
|
||||
gchar *str;
|
||||
|
||||
date_today(NULL);
|
||||
date_set(NULL, 0, 0, 0);
|
||||
setlocale(LC_TIME, "C");
|
||||
file_open(&f, OPEN_WRITE);
|
||||
|
||||
date_set(&date, 1988, 6, 17);
|
||||
test_equal(date.d_year, 1988);
|
||||
test_equal(date.d_month, 6);
|
||||
test_equal(date.d_day, 17);
|
||||
test_equal(date.d_stamp, 285607876);
|
||||
g_assert_cmpuint(date.d_year, ==, 1988);
|
||||
g_assert_cmpuint(date.d_month, ==, 6);
|
||||
g_assert_cmpuint(date.d_day, ==, 17);
|
||||
g_assert_cmpuint(date.d_stamp, ==, 285607876);
|
||||
date_write(&f, &date);
|
||||
file_writef(&f, "\n");
|
||||
|
||||
date_today(&date);
|
||||
test_equal(date.d_year, today->tm_year + 1900);
|
||||
test_equal(date.d_month, today->tm_mon + 1);
|
||||
test_equal(date.d_day, today->tm_mday);
|
||||
g_assert_cmpuint(date.d_year, ==, today->tm_year + 1900);
|
||||
g_assert_cmpuint(date.d_month, ==, today->tm_mon + 1);
|
||||
g_assert_cmpuint(date.d_day, ==, today->tm_mday);
|
||||
date_write(&f, &date);
|
||||
|
||||
file_close(&f);
|
||||
file_open(&f, OPEN_READ);
|
||||
|
||||
date_read(&f, &date);
|
||||
test_equal(date.d_year, 1988);
|
||||
test_equal(date.d_month, 6);
|
||||
test_equal(date.d_day, 17);
|
||||
test_equal(date.d_stamp, 285607876);
|
||||
g_assert_cmpuint(date.d_year, ==, 1988);
|
||||
g_assert_cmpuint(date.d_month, ==, 6);
|
||||
g_assert_cmpuint(date.d_day, ==, 17);
|
||||
g_assert_cmpuint(date.d_stamp, ==, 285607876);
|
||||
|
||||
str = date_string(&date);
|
||||
test_equal(str, "06/17/88");
|
||||
g_free(str);
|
||||
g_assert_cmpstr_free(date_string(&date), ==, "06/17/88");
|
||||
|
||||
date_read(&f, &date);
|
||||
test_equal(date.d_year, today->tm_year + 1900);
|
||||
test_equal(date.d_month, today->tm_mon + 1);
|
||||
test_equal(date.d_day, today->tm_mday);
|
||||
g_assert_cmpuint(date.d_year, ==, today->tm_year + 1900);
|
||||
g_assert_cmpuint(date.d_month, ==, today->tm_mon + 1);
|
||||
g_assert_cmpuint(date.d_day, ==, today->tm_mday);
|
||||
file_close(&f);
|
||||
}
|
||||
|
||||
|
@ -73,22 +68,27 @@ void test_compare()
|
|||
};
|
||||
|
||||
/* Check year comparison. */
|
||||
test_equal(date_compare(&a, &b), 5);
|
||||
test_equal(date_compare(&b, &a), -5);
|
||||
g_assert_cmpint(date_compare(&a, &b), ==, 5);
|
||||
g_assert_cmpint(date_compare(&b, &a), ==, -5);
|
||||
|
||||
/* Check month comparison. */
|
||||
b.d_year = a.d_year;
|
||||
test_equal(date_compare(&a, &b), -6);
|
||||
test_equal(date_compare(&b, &a), 6);
|
||||
g_assert_cmpint(date_compare(&a, &b), ==, -6);
|
||||
g_assert_cmpint(date_compare(&b, &a), ==, 6);
|
||||
|
||||
/* Check day comparison. */
|
||||
b.d_month = a.d_month;
|
||||
test_equal(date_compare(&a, &a), 0);
|
||||
test_equal(date_compare(&a, &b), 7);
|
||||
test_equal(date_compare(&b, &a), -7);
|
||||
g_assert_cmpint(date_compare(&a, &a), ==, 0);
|
||||
g_assert_cmpint(date_compare(&a, &b), ==, 7);
|
||||
g_assert_cmpint(date_compare(&b, &a), ==, -7);
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Date", test_date),
|
||||
UNIT_TEST("Date Comparison", test_compare),
|
||||
);
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
setlocale(LC_TIME, "C");
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_func("/Core/Date", test_date);
|
||||
g_test_add_func("/Core/Date/Comparison", test_compare);
|
||||
return g_test_run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue