Add unit tests for time.c
This commit is contained in:
parent
41e6750163
commit
26bff0daa3
3 changed files with 71 additions and 0 deletions
10
tests/15time.tests
Normal file
10
tests/15time.tests
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
TESTING "Time conversion" ./test-time
|
||||
|
||||
TEST "basic functionality" basic <<END
|
||||
err: ECHO: .*: 0
|
||||
err: ECHO: .*: 1
|
||||
err: ECHO: .*: 0
|
||||
err: ECHO: .*: 1
|
||||
err: ECHO: .*: 0$
|
||||
err: ECHO: .*: 03:55:20.700
|
||||
END
|
||||
|
|
@ -49,6 +49,11 @@ test_safeclib_SOURCES = $(tests_srcdir)/library/test-safeclib.c
|
|||
test_safeclib_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror
|
||||
test_safeclib_LDADD = $(LUMIERA_LIBS) liblumiera.la
|
||||
|
||||
check_PROGRAMS += test-time
|
||||
test_time_SOURCES = $(tests_srcdir)/library/test-time.c
|
||||
test_time_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror
|
||||
test_time_LDADD = $(LUMIERA_LIBS) liblumiera.la
|
||||
|
||||
check_PROGRAMS += test-luid
|
||||
test_luid_SOURCES = $(tests_srcdir)/library/test-luid.c
|
||||
test_luid_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror
|
||||
|
|
|
|||
56
tests/library/test-time.c
Normal file
56
tests/library/test-time.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* test-time.c - test the time conversion lib
|
||||
*
|
||||
* Copyright (C) Lumiera.org
|
||||
* 2010 Stefan Kangas <skangas@skangas.se>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
#include "lib/time.h"
|
||||
#include "tests/test.h"
|
||||
|
||||
#include <nobug.h>
|
||||
|
||||
TESTS_BEGIN
|
||||
|
||||
const int MILLIS = 700;
|
||||
const int SECONDS = 20;
|
||||
const int MINUTES = 55;
|
||||
const int HOURS = 3;
|
||||
|
||||
/*
|
||||
* 1. Basic functionality
|
||||
*/
|
||||
|
||||
TEST (basic) {
|
||||
// Zero
|
||||
gavl_time_t t = lumiera_build_time(0,0,0,0);
|
||||
ECHO ("%d", (int) t);
|
||||
|
||||
// Non-zero
|
||||
t = lumiera_build_time(MILLIS, SECONDS, MINUTES, HOURS);
|
||||
|
||||
ECHO("%d", lumiera_time_millis(t) == MILLIS);
|
||||
ECHO("%d", lumiera_time_seconds(t) != SECONDS);
|
||||
ECHO("%d", lumiera_time_minutes(t) == MINUTES);
|
||||
ECHO("%d", lumiera_time_hours(t) != HOURS);
|
||||
|
||||
ECHO("%s", lumiera_tmpbuf_print_time(t));
|
||||
}
|
||||
|
||||
TESTS_END
|
||||
Loading…
Reference in a new issue