3 # Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are
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
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.
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.
33 # Simple test script for the sndfile-metadata-set program.
35 import commands
, os
, sys
38 def print_test_name (name
):
39 print " %-30s :" % name
,
41 def assert_info (filename
, arg
, value
):
42 cmd
= "./sndfile-metadata-get %s %s" % (arg
, filename
)
43 status
, output
= commands
.getstatusoutput (cmd
)
45 print "\n\nError : command '%s' should not have failed." % cmd
47 if output
.find (value
) < 0:
48 print "\n\nError : not able to find '%s'." % value
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
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
)
64 print "\n\nError : command '%s' should have failed." % cmd
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
)
73 print "\n\nError : command '%s' should not have failed." % cmd
75 assert_info ("output.wav", "--bext-description", "First Try")
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
)
84 print "\n\nError : command '%s' should not have failed." % cmd
86 assert_info ("output.wav", arg
, value
)
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
)
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
)
100 print "\n\nError : command '%s' should not have failed." % cmd
102 target
= datetime
.date
.today ().__str
__ ()
103 assert_info ("date-time.wav", "--bext-orig-date", target
)
107 #-------------------------------------------------------------------------------
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
)
114 print "\n\nError : command '%s' should not have failed." % cmd
116 cmd
= "./sndfile-metadata-get --bext-coding-hist output.wav"
117 status
, output
= commands
.getstatusoutput (cmd
)
119 print "\n\nError : command '%s' should not have failed." % cmd
123 #-------------------------------------------------------------------------------
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
)
130 print "\n\nError : command '%s' should not have failed." % cmd
132 cmd
= "./sndfile-metadata-set --bext-originator \"Short\" output.wav"
133 status
, output
= commands
.getstatusoutput (cmd
)
135 print "\n\nError : command '%s' should not have failed." % cmd
137 cmd
= "./sndfile-metadata-get --bext-originator output.wav"
138 status
, output
= commands
.getstatusoutput (cmd
)
140 print "\n\nError : command '%s' should not have failed." % cmd
142 if output
.find ("really long") > 0:
143 print "\n\nError : output '%s' should not contain 'really long'." % output
147 #===============================================================================
149 test_dir
= "programs"
151 if os
.path
.isdir (test_dir
):
154 for f
in [ "sndfile-metadata-set", "sndfile-metadata-get", "../examples/make_sine" ]:
157 os
.system ("../examples/make_sine")
158 if not os
.path
.isfile ("sine.wav"):
159 print "\n\nError : Can't file file 'sine.wav'."
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")
175 test_post_mod (tests
)
177 test_update ([ ("--str-artist", "Fox") ])
180 # test_coding_history ()