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