Add namespaces and tweak CPL namespace so Xerces checks CompositionMetadataAsset.
[libdcp.git] / run / tests
1 #!/bin/bash
2 #
3 # Run our test suite.
4
5 # Private test data; this is stuff that is non-distributable
6 private=../libdcp-test-private
7 # Work directory
8 work=build/test
9 # Path to tools
10 dcpinfo=build/tools/dcpinfo
11 dcpverify=build/tools/dcpverify
12
13 export LD_LIBRARY_PATH=build/src:/home/c.hetherington/lib:$LD_LIBRARY_PATH
14
15 # Make sure we have the required tools
16 for c in xmlsec1 xmldiff xmllint; do
17   hash $c 2>/dev/null || { echo >&2 "$c required but not found; aborting"; exit 1; }
18 done
19
20 echo "--- Unit tests"
21
22 # Run the unit tests in test/
23 if [ "$1" == "--debug" ]; then
24     shift
25     gdb --args $work/tests $private $*
26 elif [ "$1" == "--valgrind" ]; then
27     shift
28     valgrind --tool="memcheck" $work/tests $private $*
29 elif [ "$1" == "--callgrind" ]; then
30     shift
31     valgrind --tool="callgrind" $work/tests $private $*
32 else
33     $work/tests $* -- $private
34     if [ "$?" != "0" ]; then
35         echo "FAIL: unit tests"
36         exit 1
37     fi
38 fi
39
40 if [ "$*" != "" ]; then
41     echo "Skipping post-test checks as not all unit tests were run."
42     exit 0
43 fi
44
45 echo "--- Other tests"
46
47 # Check a MXF written by the unit tests
48 diff $work/baz/video1.mxf $work/baz/video2.mxf
49 if [ "$?" != "0" ]; then
50     echo "FAIL: MXFs from recovery incorrect"
51     exit 1
52 fi
53
54 # Check the DCP written by dcp_test1
55 diff -ur test/ref/DCP/dcp_test1 $work/DCP/dcp_test1
56 if [ "$?" != "0" ]; then
57     echo "FAIL: files differ"
58     exit 1
59 fi
60
61 # Check the DCP written by dcp_test2
62 diff -ur test/ref/DCP/dcp_test2 $work/DCP/dcp_test2
63 if [ "$?" != "0" ]; then
64     echo "FAIL: files differ"
65     exit 1
66 fi
67
68 # Check the DCP written by dcp_test5
69 diff -ur test/ref/DCP/dcp_test5 $work/DCP/dcp_test5
70 if [ "$?" != "0" ]; then
71     echo "FAIL: files differ"
72     exit 1
73 fi
74
75 # Check the DCP written by dcp_test7
76 diff -ur test/ref/DCP/dcp_test7 $work/DCP/dcp_test7
77 if [ "$?" != "0" ]; then
78     echo "FAIL: files differ"
79     exit 1
80 fi
81
82 # Check the DCP written by encryption_test
83 diff -ur test/ref/DCP/encryption_test $work/DCP/encryption_test
84 if [ "$?" != "0" ]; then
85     echo "FAIL: files differ"
86     exit 1
87 fi
88
89 # Everything beyond this point needs $private to exist
90 if [ ! -e "$private/info.log" ]; then
91     echo ""
92     echo "Private data not found: some tests will not run."
93     exit 1
94 fi
95
96 # Run dcpinfo on all the DCPs in private/metadata, writing $work/info.log
97 # This writes details of the CPLs and all subtitle details, so it checks
98 # if the code is reading subtitle files correctly.
99 rm -f $work/info.log
100 for d in `find $private/metadata -mindepth 1 -maxdepth 1 -type d | sort -f -d`; do
101     if [ `basename $d` != ".git" ]; then
102         $dcpinfo --ignore-missing-assets -s $d >> $work/info.log
103         if [ "$?" != "0" ]; then
104             echo "FAIL: dcpinfo failed for $d"
105             exit 1
106         fi
107     fi
108 done
109
110 # Run dcpverify on all the DCPs in private/metadata
111 for d in `find $private/metadata -mindepth 1 -maxdepth 1 -type d | sort -f -d`; do
112     if [ `basename $d` != ".git" ]; then
113         $dcpverify --ignore-missing-assets -q $d
114         if [ "$?" != "0" ]; then
115             echo "FAIL: dcpverify failed for $d"
116             exit 1
117         fi
118     fi
119 done
120
121 # Check info.log is what it should be
122 diff -q $work/info.log $private/info.log
123 if [ "$?" != "0" ]; then
124     echo "FAIL: dcpinfo output incorrect"
125     exit 1
126 fi
127
128 # Copy $private/metadata into build/metadata then re-write the subtitles
129 # of every DCP using $work/rewrite_subs.  This tests round-trip of
130 # subtitle reading/writing.
131 rm -f $work/info2.log
132 rm -rf $work/private
133 mkdir $work/private
134 cp -r $private/metadata $work/private/
135 for d in `find $work/private/metadata -mindepth 1 -maxdepth 1 -type d | sort -f -d`; do
136     if [ `basename $d` != ".git" ]; then
137         $work/rewrite_subs $d
138         $dcpinfo --ignore-missing-assets -s $d >> $work/info2.log
139     fi
140 done
141
142 # Fudge the output
143 sed -i "s/DCP: build\/test/DCP: test/g" $work/info2.log
144
145 # And check it
146 diff -q $work/info2.log $private/info2.log
147 if [ "$?" != "0" ]; then
148     echo "FAIL: dcpinfo output from rewrite incorrect"
149     exit 1
150 fi
151
152 # Dump the subs of JourneyToJah... (which has MXF-wrapped SMPTE subtitles)
153 # and check that they are right
154 $dcpinfo -s $private/data/JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV >> $work/jah.log
155
156 # Parse some problematic subs and check that we get it right
157 run/test/subs_in_out $private/TunaBoat_Icelandic_Reel1_V1_8sec.xml > $work/tuna.xml
158 diff -q $private/TunaBoat_Icelandic_Reel1_V1_8sec.parsed.xml $work/tuna.xml
159 if [ "$?" != "0" ]; then
160     echo "FAIL: output of parse check 1 invalid"
161     exit 1
162 fi
163
164 echo "PASS"