Update configure and Makefiles for the corrected name "interpreter".
[Faustine.git] / interpreter / lib / src / libsndfile-1.0.25 / programs / test-sndfile-metadata-set.py
1 #!/usr/bin/python
2
3 # Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 #
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are
9 # met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in
15 # the documentation and/or other materials provided with the
16 # distribution.
17 # * Neither the author nor the names of any contributors may be used
18 # to endorse or promote products derived from this software without
19 # specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 # Simple test script for the sndfile-metadata-set program.
34
35 import commands, os, sys
36 import time, datetime
37
38 def print_test_name (name):
39 print " %-30s :" % name,
40
41 def assert_info (filename, arg, value):
42 cmd = "./sndfile-metadata-get %s %s" % (arg, filename)
43 status, output = commands.getstatusoutput (cmd)
44 if status:
45 print "\n\nError : command '%s' should not have failed." % cmd
46 sys.exit (1)
47 if output.find (value) < 0:
48 print "\n\nError : not able to find '%s'." % value
49 print output
50 sys.exit (1)
51 return
52
53
54 def check_executable (name):
55 if not (os.path.isfile (name)):
56 print "\n\nError : Can't find executable '%s'. Have you run make?" % name
57 sys.exit (1)
58
59 def test_empty_fail ():
60 print_test_name ("Empty fail test")
61 cmd = "./sndfile-metadata-set --bext-description Alpha sine.wav"
62 status, output = commands.getstatusoutput (cmd)
63 if not status:
64 print "\n\nError : command '%s' should have failed." % cmd
65 sys.exit (1)
66 print "ok"
67
68 def test_copy ():
69 print_test_name ("Copy test")
70 cmd = "./sndfile-metadata-set --bext-description \"First Try\" sine.wav output.wav"
71 status, output = commands.getstatusoutput (cmd)
72 if status:
73 print "\n\nError : command '%s' should not have failed." % cmd
74 sys.exit (1)
75 assert_info ("output.wav", "--bext-description", "First Try")
76 print "ok"
77
78 def test_update (tests):
79 print_test_name ("Update test")
80 for arg, value in tests:
81 cmd = "./sndfile-metadata-set %s \"%s\" output.wav" % (arg, value)
82 status, output = commands.getstatusoutput (cmd)
83 if status:
84 print "\n\nError : command '%s' should not have failed." % cmd
85 sys.exit (1)
86 assert_info ("output.wav", arg, value)
87 print "ok"
88
89 def test_post_mod (tests):
90 print_test_name ("Post mod test")
91 for arg, value in tests:
92 assert_info ("output.wav", arg, value)
93 print "ok"
94
95 def test_auto_date ():
96 print_test_name ("Auto date test")
97 cmd = "./sndfile-metadata-set --bext-auto-time-date sine.wav date-time.wav"
98 status, output = commands.getstatusoutput (cmd)
99 if status:
100 print "\n\nError : command '%s' should not have failed." % cmd
101 sys.exit (1)
102 target = datetime.date.today ().__str__ ()
103 assert_info ("date-time.wav", "--bext-orig-date", target)
104 print "ok"
105
106
107 #-------------------------------------------------------------------------------
108
109 def test_coding_history ():
110 print_test_name ("Coding history test")
111 cmd = "./sndfile-metadata-set --bext-coding-hist \"alpha beta\" output.wav"
112 status, output = commands.getstatusoutput (cmd)
113 if status:
114 print "\n\nError : command '%s' should not have failed." % cmd
115 sys.exit (1)
116 cmd = "./sndfile-metadata-get --bext-coding-hist output.wav"
117 status, output = commands.getstatusoutput (cmd)
118 if status:
119 print "\n\nError : command '%s' should not have failed." % cmd
120 sys.exit (1)
121 print "ok"
122
123 #-------------------------------------------------------------------------------
124
125 def test_rewrite ():
126 print_test_name ("Rewrite test")
127 cmd = "./sndfile-metadata-set --bext-originator \"Really, really long string\" output.wav"
128 status, output = commands.getstatusoutput (cmd)
129 if status:
130 print "\n\nError : command '%s' should not have failed." % cmd
131 sys.exit (1)
132 cmd = "./sndfile-metadata-set --bext-originator \"Short\" output.wav"
133 status, output = commands.getstatusoutput (cmd)
134 if status:
135 print "\n\nError : command '%s' should not have failed." % cmd
136 sys.exit (1)
137 cmd = "./sndfile-metadata-get --bext-originator output.wav"
138 status, output = commands.getstatusoutput (cmd)
139 if status:
140 print "\n\nError : command '%s' should not have failed." % cmd
141 sys.exit (1)
142 if output.find ("really long") > 0:
143 print "\n\nError : output '%s' should not contain 'really long'." % output
144 sys.exit (1)
145 print "ok"
146
147 #===============================================================================
148
149 test_dir = "programs"
150
151 if os.path.isdir (test_dir):
152 os.chdir (test_dir)
153
154 for f in [ "sndfile-metadata-set", "sndfile-metadata-get", "../examples/make_sine" ]:
155 check_executable (f)
156
157 os.system ("../examples/make_sine")
158 if not os.path.isfile ("sine.wav"):
159 print "\n\nError : Can't file file 'sine.wav'."
160 sys.exit (1)
161
162 print ""
163
164 test_empty_fail ()
165 test_copy ()
166
167 tests = [
168 ("--bext-description", "Alpha"), ("--bext-originator", "Beta"), ("--bext-orig-ref", "Charlie"),
169 ("--bext-umid", "Delta"), ("--bext-orig-date", "2001-10-01"), ("--bext-orig-time", "01:02:03"),
170 ("--str-title", "Echo"), ("--str-artist", "Fox trot")
171 ]
172
173 test_auto_date ()
174 test_update (tests)
175 test_post_mod (tests)
176
177 test_update ([ ("--str-artist", "Fox") ])
178
179 # This never worked.
180 # test_coding_history ()
181
182 test_rewrite ()
183
184
185 print ""
186
187 sys.exit (0)
188