2010-12-06 16:19:17 +01:00
/*
2013-01-07 05:43:01 +01:00
TEST - TIME - test the time conversion lib
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
Copyright ( C )
2025-05-27 20:43:52 +02:00
2010 , Stefan Kangas < skangas @ skangas . se >
2013-01-07 05:43:01 +01:00
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
* * Lumiera * * 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 . See the file COPYING for further details .
2013-01-07 05:43:01 +01:00
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2013-01-07 05:43:01 +01:00
2017-02-22 03:46:23 +01:00
/** @file test-time.c
* * C unit test to cover the basic low - level time handling operations
* * @ see time . h
* * @ see timevalue . hpp
* * @ see TimeValue_test high - level time entities
2016-11-03 18:26:43 +01:00
*/
2010-12-06 16:19:17 +01:00
2011-12-02 21:34:29 +01:00
# include "lib/test/test.h"
2010-12-06 16:19:17 +01:00
2025-05-17 23:12:47 +02:00
# include <inttypes.h>
2013-01-07 05:43:01 +01:00
# include <ctype.h>
2010-12-06 16:19:17 +01:00
# include <nobug.h>
2025-05-17 23:12:47 +02:00
typedef int64_t raw_time_64 ; //////////////////////////////////////////////////////////////////////////////TICKET #1259 turn time.h in to a C++ implementation header
# include "lib/time.h" /////////////////////////////////////////////////////////////////////////////////////TICKET #1259 this should not be a general purpose library, but rather an implementation base
2011-05-21 06:58:15 +02:00
static int
2025-05-17 23:12:47 +02:00
calculate_framecount ( raw_time_64 t , uint fps )
2011-05-21 06:58:15 +02:00
{
return lumiera_quantise_frames_fps ( t , 0 , fps ) ;
}
2010-12-06 16:19:17 +01:00
TESTS_BEGIN
2010-12-13 18:16:15 +01:00
const int FRAMES = 15 ;
2010-12-06 16:19:17 +01:00
const int SECONDS = 20 ;
const int MINUTES = 55 ;
const int HOURS = 3 ;
2011-05-21 06:58:15 +02:00
const int FPS = 24 ;
2010-12-06 16:19:17 +01:00
2010-12-13 18:22:12 +01:00
/*
* 3. NTSC drop - frame calculations .
*/
TEST ( ntsc_drop_frame )
{
// Make sure frame 0 begins at 0
2025-05-17 23:12:47 +02:00
raw_time_64 t = lumiera_build_time_ntsc_drop ( 0 , 0 , 0 , 0 ) ;
2010-12-13 18:22:12 +01:00
2025-05-17 23:12:47 +02:00
CHECK ( ( raw_time_64 ) t = = 0 ) ;
2011-05-21 06:58:15 +02:00
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 ( calculate_framecount ( t , FPS ) = = 0 ) ;
CHECK ( calculate_framecount ( t , FPS + 5 ) = = 0 ) ;
2010-12-13 18:22:12 +01:00
t = lumiera_build_time_ntsc_drop ( FRAMES , SECONDS , MINUTES , HOURS ) ;
2011-05-21 06:58:15 +02:00
// Calculate manually what result to expect....
int frames = FRAMES + 30 * SECONDS + 30 * 60 * MINUTES + 30 * 60 * 60 * HOURS ; // sum up using nominal 30fps
int minutes_to_drop_frames = ( MINUTES - MINUTES / 10 ) + ( HOURS * 54 ) ; // but every minute, with the exception of every 10 minutes...
frames - = 2 * minutes_to_drop_frames ; // ...drop 2 frames
int64_t expectedMillis = 1000LL * frames * 1001 / 30000 ; // now convert frames to time, using the real framerate
expectedMillis % = 1000 ; // look at the remainder..
CHECK ( lumiera_time_millis ( t ) = = expectedMillis ) ;
CHECK ( lumiera_time_seconds ( t ) = = SECONDS ) ; // while all other components should come out equal as set
CHECK ( lumiera_time_minutes ( t ) = = MINUTES ) ;
CHECK ( lumiera_time_hours ( t ) = = HOURS ) ;
// Reverse calculate frames for NTSC drop
//CHECK (lumiera_quantise_frames (t, 0, dropFrameDuration) == frames); // the total nominal frames
CHECK ( lumiera_time_ntsc_drop_frames ( t ) = = FRAMES ) ; // maximum one frame off due to rounding
2011-02-13 23:11:16 +01:00
// Cover the whole value range;
// Manually construct a drop-frame timecode
// Make sure our library function returns the same times.
2010-12-13 18:22:12 +01:00
int min ;
int sec ;
int frame ;
int hrs ;
for ( hrs = 0 ; hrs < = 24 ; hrs + = 6 )
2011-05-21 06:58:15 +02:00
for ( min = 0 ; min < = 59 ; min + = 1 )
for ( sec = 0 ; sec < = 59 ; sec + = 10 )
2010-12-13 18:22:12 +01:00
for ( frame = 0 ; frame < = 29 ; frame + + )
{
// Skip dropped frames
if ( min % 10 & & sec = = 0 & & frame < 2 )
continue ;
t = lumiera_build_time_ntsc_drop ( frame , sec , min , hrs ) ;
2011-05-21 06:58:15 +02:00
/*
ECHO ( " %02d:%02d:%02d;%02d "
, lumiera_time_ntsc_drop_hours ( t )
, lumiera_time_ntsc_drop_minutes ( t )
, lumiera_time_ntsc_drop_seconds ( t )
, lumiera_time_ntsc_drop_frames ( t )
) ;
*/
CHECK ( lumiera_time_ntsc_drop_frames ( t ) = = frame ) ;
2010-12-13 18:22:12 +01:00
CHECK ( lumiera_time_ntsc_drop_seconds ( t ) = = sec ) ;
CHECK ( lumiera_time_ntsc_drop_minutes ( t ) = = min ) ;
CHECK ( lumiera_time_ntsc_drop_hours ( t ) = = hrs % 24 ) ;
}
// Make sure we do not get non-existent frames
int i ;
for ( i = 0 ; i < 59 ; i + + )
{
int frame = ( i % 10 = = 0 ) ? 0 : 2 ;
t = lumiera_build_time_ntsc_drop ( frame , 0 , i , 0 ) ;
CHECK ( lumiera_time_ntsc_drop_frames ( t ) = = frame ) ;
}
2010-12-06 16:19:17 +01:00
}
TESTS_END