From 4fb854d0b10bbe44cf9b7e1a75320c746039c1cb Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 7 Mar 2016 08:10:20 -0500 Subject: [PATCH] tests: Build date test with ctest Signed-off-by: Anna Schumaker --- tests/core/CMakeLists.txt | 1 + tests/core/Sconscript | 2 +- tests/core/date.c | 62 +++++++++++++++++++-------------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 3c60499d..35ba1fd3 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -7,3 +7,4 @@ endfunction() core_unit_test(Version) core_unit_test(String) core_unit_test(File) +core_unit_test(Date) diff --git a/tests/core/Sconscript b/tests/core/Sconscript index 9bce201c..911582e7 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -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") ] diff --git a/tests/core/date.c b/tests/core/date.c index 96b4dbed..90d7ba14 100644 --- a/tests/core/date.c +++ b/tests/core/date.c @@ -2,7 +2,6 @@ * Copyright 2015 (c) Anna Schumaker. */ #define _GNU_SOURCE - #include #include #include @@ -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(); +}