Various comment fixes to tests.
[dcpomatic.git] / test / ffmpeg_decoder_seek_test.cc
1 /*
2     Copyright (C) 2014 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 /** @file  test/ffmpeg_decoder_seek_test.cc
21  *  @brief Check that get_video() returns the frame indexes that we ask for
22  *  for FFmpegDecoder.
23  *
24  *  This doesn't check that the contents of those frames are right, which
25  *  it probably should.
26  */
27
28 #include <vector>
29 #include <boost/test/unit_test.hpp>
30 #include <boost/filesystem.hpp>
31 #include "lib/ffmpeg_content.h"
32 #include "lib/ffmpeg_decoder.h"
33 #include "lib/log.h"
34 #include "lib/film.h"
35 #include "test.h"
36
37 using std::cerr;
38 using std::vector;
39 using boost::shared_ptr;
40 using boost::optional;
41
42 static void
43 check (FFmpegDecoder& decoder, int frame)
44 {
45         optional<ContentVideo> v;
46         v = decoder.get_video (frame, true);
47         BOOST_CHECK (v);
48         BOOST_CHECK_EQUAL (v->frame, frame);
49 }
50
51 static void
52 test (boost::filesystem::path file, vector<int> frames)
53 {
54         boost::filesystem::path path = private_data / file;
55         if (!boost::filesystem::exists (path)) {
56                 cerr << "Skipping test: " << path.string() << " not found.\n";
57                 return;
58         }
59
60         shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string());
61         shared_ptr<FFmpegContent> content (new FFmpegContent (film, path)); 
62         film->examine_and_add_content (content);
63         wait_for_jobs ();
64         shared_ptr<Log> log (new NullLog);
65         FFmpegDecoder decoder (content, log);
66
67         for (vector<int>::const_iterator i = frames.begin(); i != frames.end(); ++i) {
68                 check (decoder, *i);
69         }
70 }
71
72 BOOST_AUTO_TEST_CASE (ffmpeg_decoder_seek_test)
73 {
74         vector<int> frames;
75         
76         frames.clear ();
77         frames.push_back (0);
78         frames.push_back (42);
79         frames.push_back (999);
80         frames.push_back (0);
81
82         test ("boon_telly.mkv", frames);
83         test ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", frames);
84         
85         frames.clear ();
86         frames.push_back (15);
87         frames.push_back (42);
88         frames.push_back (999);
89         frames.push_back (15);
90         
91         test ("prophet_clip.mkv", frames);
92 }
93