Clean up unit testing.
[libdcp.git] / test / rewrite_subs.cc
1 #include <iostream>
2 #include "dcp.h"
3 #include "cpl.h"
4 #include "reel.h"
5 #include "subtitle_asset.h"
6 #include "exceptions.h"
7
8 using std::cout;
9 using std::cerr;
10 using std::list;
11 using boost::shared_ptr;
12 using namespace libdcp;
13
14 int
15 main (int argc, char* argv[])
16 {
17         try {
18                 if (argc < 2) {
19                         cerr << "Syntax: " << argv[0] << " <dcp>\n";
20                         exit (EXIT_FAILURE);
21                 }
22                 
23                 DCP* dcp = new DCP (argv[1]);
24                 dcp->read (false);
25                 
26                 list<shared_ptr<CPL> > cpls = dcp->cpls ();
27                 for (list<boost::shared_ptr<CPL> >::iterator i = cpls.begin(); i != cpls.end(); ++i) {
28                         
29                         list<shared_ptr<Reel> > reels = (*i)->reels ();
30                         for (list<shared_ptr<Reel> >::iterator j = reels.begin(); j != reels.end(); ++j) {
31                                 
32                                 if ((*j)->main_subtitle()) {
33                                         (*j)->main_subtitle()->write_xml ();
34                                 }
35                         }
36                 }
37         }
38
39         catch (FileError& e)
40         {
41                 cerr << e.what() << " (" << e.filename() << ") when reading " << argv[1] << "\n";
42                 exit (EXIT_FAILURE);
43         }
44         catch (DCPReadError& e)
45         {
46                 cerr << e.what() << " when reading " << argv[1] << "\n";
47                 exit (EXIT_FAILURE);
48         }
49         
50         return 0;
51 }