summaryrefslogtreecommitdiff
path: root/test/time_test.cc
blob: 977ebd275614b84cdda30c8c2c30469085d1a4a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>

    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.

*/

#include <boost/test/unit_test.hpp>
#include "metric_time.h"
#include "frame_time.h"
#include "time_pair.h"

/* Check time construction */
BOOST_AUTO_TEST_CASE (time_construction_test)
{
	{
		sub::MetricTime t (3, 5, 7, 40);
		BOOST_CHECK_EQUAL (t.hours(), 3);
		BOOST_CHECK_EQUAL (t.minutes(), 5);
		BOOST_CHECK_EQUAL (t.seconds(), 7);
		BOOST_CHECK_EQUAL (t.milliseconds(), 40);
	}

	{
		sub::MetricTime t (591353, 1, 2, 3);
		BOOST_CHECK_EQUAL (t.hours(), 591353);
		BOOST_CHECK_EQUAL (t.minutes(), 1);
		BOOST_CHECK_EQUAL (t.seconds(), 2);
		BOOST_CHECK_EQUAL (t.milliseconds(), 3);
	}
}

/* Check time conversions */
BOOST_AUTO_TEST_CASE (time_conversion_test)
{
	sub::TimePair p;
	
	/* 40ms = 1 frame at 25fps */
	p.set_metric (sub::MetricTime (3, 5, 7, 40));
	BOOST_CHECK_EQUAL (p.frame (25), sub::FrameTime (3, 5, 7, 1));
	p.set_frame (sub::FrameTime  (3, 5, 7, 1));
	BOOST_CHECK_EQUAL (p.metric (25), sub::MetricTime (3, 5, 7, 40));

	/* 120ms = 3 frames at 25fps */
	p.set_metric (sub::MetricTime (3, 5, 7, 120));
	BOOST_CHECK_EQUAL (p.frame (25), sub::FrameTime (3, 5, 7, 3));
	p.set_frame (sub::FrameTime (3, 5, 7, 3));
	BOOST_CHECK_EQUAL (p.metric (25), sub::MetricTime (3, 5, 7, 120));
}