Try to make tests more locale-independent.
[libdcp.git] / run / tests
1 #!/bin/bash -e
2 #
3 # Run our test suite, which (amongst other things)
4 # builds a couple of DCPs.
5 # The outputs are compared against the ones
6 # in test/ref/DCP, and an error is given
7 # if anything is different.
8
9 private=../libdcp-test-private
10 work=build/test
11 dcpinfo=build/tools/dcpinfo
12
13 export LD_LIBRARY_PATH=build/src:build/asdcplib/src:$LD_LIBRARY_PATH
14
15 # Run the unit tests in test/
16 if [ "$1" == "--debug" ]; then
17     shift
18     gdb --args $work/tests $private
19 elif [ "$1" == "--valgrind" ]; then
20     shift
21     valgrind --tool="memcheck" $work/tests $private
22 else
23     $work/tests $private $*
24 fi
25
26 # Check a MXF written by the unit tests
27 diff $work/baz/video1.mxf $work/baz/video2.mxf
28 if [ "$?" != "0" ]; then
29     echo "FAIL: MXFs from recovery incorrect"
30     exit 1
31 fi
32
33 # Check the first DCP written by the unit tests
34 diff -ur test/ref/DCP/foo $work/DCP/foo
35 if [ "$?" != "0" ]; then
36     echo "FAIL: files differ"
37     exit 1
38 fi
39
40 # Check the second DCP written by the unit tests
41 diff -ur test/ref/DCP/bar $work/DCP/bar
42 if [ "$?" != "0" ]; then
43     echo "FAIL: files differ"
44     exit 1
45 fi
46     
47 # Everything beyond this point needs $private to exist
48 if [ ! -e "$private/info.log" ]; then
49     echo ""
50     echo "Private data not found: some tests will not run."
51     exit 1
52 fi
53
54 # Run dcpinfo on all the DCPs in private/metadata, writing $work/info.log
55 rm -f $work/info.log
56 for d in `find $private/metadata -mindepth 1 -maxdepth 1 -type d | sort -fd`; do
57     if [ `basename $d` != ".git" ]; then
58         $dcpinfo -s $d >> $work/info.log
59         if [ "$?" != "0" ]; then
60             echo "FAIL: dcpinfo failed for $d"
61             exit 1
62         fi
63     fi
64 done
65
66 # Check info.log is what it should be
67 diff -q $work/info.log $private/info.log
68 if [ "$?" != "0" ]; then
69     echo "FAIL: dcpinfo output incorrect"
70     exit 1
71 fi
72
73 # Copy test/private into build/ then re-write the subtitles of every DCP using 
74 # $work/rewrite_subs.  This tests round-trip of subtitle reading/writing.
75 rm -f $work/info2.log
76 rm -rf $work/private
77 mkdir $work/private
78 cp -r $private/* $work/private
79 for d in `find $work/private/metadata -mindepth 1 -maxdepth 1 -type d | sort -fd`; do
80     if [ `basename $d` != ".git" ]; then
81         $work/rewrite_subs $d
82         $dcpinfo -s $d >> $work/info2.log
83     fi
84 done
85
86 # Fudge the output
87 sed -i "s/DCP: build\/test/DCP: test/g" $work/info2.log
88
89 # And check it
90 diff -q $work/info2.log $private/info.log
91 if [ "$?" != "0" ]; then
92     echo "FAIL: dcpinfo output from rewrite incorrect"
93     exit 1
94 fi
95
96 # Dump the subs of JourneyToJah... (which has MXF-wrapped subtitles)
97 # and check that they are right
98 $dcpinfo -s $private/JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV >> $work/jah.log
99
100 echo "PASS"