190a469d0e8494577014043ec2d3838efb9b7412
[dcpomatic.git] / test / video_decoder_fill_test.cc
1 /*
2     Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <boost/test/unit_test.hpp>
21 #include "lib/image_decoder.h"
22 #include "lib/image_content.h"
23 #include "lib/film.h"
24 #include "test.h"
25 #include <iostream>
26
27 using std::list;
28 using std::cout;
29 using boost::shared_ptr;
30
31 BOOST_AUTO_TEST_CASE (video_decoder_fill_test1)
32 {
33         shared_ptr<Film> film = new_test_film ("video_decoder_fill_test");
34         shared_ptr<ImageContent> c (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
35         ImageDecoder decoder (c, film->log());
36
37         decoder.fill_one_eye (0, 4, EYES_BOTH);
38         BOOST_CHECK_EQUAL (decoder._decoded_video.size(), 4U);
39         list<ContentVideo>::iterator i = decoder._decoded_video.begin();
40         for (int j = 0; j < 4; ++j) {
41                 BOOST_CHECK_EQUAL (i->frame, j);
42                 ++i;
43         }
44
45         decoder._decoded_video.clear ();
46
47         decoder.fill_one_eye (0, 7, EYES_BOTH);
48         BOOST_CHECK_EQUAL (decoder._decoded_video.size(), 7);
49         i = decoder._decoded_video.begin();
50         for (int j = 0; j < 7; ++j) {
51                 BOOST_CHECK_EQUAL (i->frame, j);
52                 ++i;
53         }
54 }
55
56 BOOST_AUTO_TEST_CASE (video_decoder_fill_test2)
57 {
58         shared_ptr<Film> film = new_test_film ("video_decoder_fill_test");
59         shared_ptr<ImageContent> c (new ImageContent (film, "test/data/simple_testcard_640x480.png"));
60         ImageDecoder decoder (c, film->log());
61
62         decoder.fill_both_eyes (0, 4, EYES_LEFT);
63         BOOST_CHECK_EQUAL (decoder._decoded_video.size(), 8);
64         list<ContentVideo>::iterator i = decoder._decoded_video.begin();
65         for (int j = 0; j < 8; ++j) {
66                 BOOST_CHECK_EQUAL (i->frame, j / 2);
67                 BOOST_CHECK_EQUAL (i->eyes, (j % 2) == 0 ? EYES_LEFT : EYES_RIGHT);
68                 ++i;
69         }
70
71         decoder.fill_both_eyes (0, 7, EYES_RIGHT);
72         BOOST_CHECK_EQUAL (decoder._decoded_video.size(), 15);
73         i = decoder._decoded_video.begin();
74         for (int j = 0; j < 15; ++j) {
75                 BOOST_CHECK_EQUAL (i->frame, j / 2);
76                 BOOST_CHECK_EQUAL (i->eyes, (j % 2) == 0 ? EYES_LEFT : EYES_RIGHT);
77                 ++i;
78         }
79 }