lumiera_/tests/library/test-time.c

93 lines
3 KiB
C
Raw Normal View History

2010-12-06 16:19:17 +01:00
/*
* 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 FRAMES = 15;
2010-12-06 16:19:17 +01:00
const int MILLIS = 700;
const int SECONDS = 20;
const int MINUTES = 55;
const int HOURS = 3;
const float FPS = 24.0;
2010-12-06 16:19:17 +01:00
/*
* 1. Basic functionality
*/
TEST (basic)
{
// Zero
gavl_time_t t = lumiera_build_time (0,0,0,0);
2010-12-06 16:19:17 +01:00
CHECK ((gavl_time_t) t == 0);
CHECK (lumiera_time_millis (t) == 0);
CHECK (lumiera_time_seconds (t) == 0);
CHECK (lumiera_time_minutes (t) == 0);
CHECK (lumiera_time_hours (t) == 0);
CHECK (lumiera_time_frames (t, FPS) == 0);
CHECK (lumiera_time_frames (t, FPS+5) == 0);
CHECK (lumiera_time_frame_count (t, FPS) == 0);
CHECK (lumiera_time_frame_count (t, FPS+5) == 0);
2010-12-06 16:19:17 +01:00
ECHO ("%s", lumiera_tmpbuf_print_time (t));
2010-12-06 16:19:17 +01:00
// Non-zero
t = lumiera_build_time (MILLIS, SECONDS, MINUTES, HOURS);
CHECK (lumiera_time_millis (t) == MILLIS);
CHECK (lumiera_time_seconds (t) == SECONDS);
CHECK (lumiera_time_minutes (t) == MINUTES);
CHECK (lumiera_time_hours (t) == HOURS);
CHECK (lumiera_time_frames (t, FPS) == (int)((FPS * MILLIS) / 1000));
CHECK (lumiera_time_frames (t, FPS+5) == (int)(((FPS+5) * MILLIS) / 1000));
CHECK (lumiera_time_frame_count (t, FPS) == 338897);
CHECK (lumiera_time_frame_count (t, FPS+5) == 409500);
ECHO ("%s", lumiera_tmpbuf_print_time (t));
}
/*
* 2. Frame rate dependent calculations.
*/
TEST (fps)
{
gavl_time_t t = lumiera_build_time_fps (FPS, FRAMES, SECONDS, MINUTES, HOURS);
CHECK (lumiera_time_millis (t) == (int)(FRAMES * (1000.0 / FPS)));
CHECK (lumiera_time_seconds (t) == SECONDS);
CHECK (lumiera_time_minutes (t) == MINUTES);
CHECK (lumiera_time_hours (t) == HOURS);
CHECK (lumiera_time_frames (t, FPS) == FRAMES);
CHECK (lumiera_time_frames (t, FPS+5) == (int)(((FPS+5) * 625) / 1000));
CHECK (lumiera_time_frame_count (t, FPS) == 338895);
CHECK (lumiera_time_frame_count (t, FPS+5) == 409498);
2010-12-06 16:19:17 +01:00
}
TESTS_END