cannam@85: #!/usr/bin/python cannam@85: cannam@85: # Copyright (C) 2008-2011 Erik de Castro Lopo cannam@85: # cannam@85: # All rights reserved. cannam@85: # cannam@85: # Redistribution and use in source and binary forms, with or without cannam@85: # modification, are permitted provided that the following conditions are cannam@85: # met: cannam@85: # cannam@85: # * Redistributions of source code must retain the above copyright cannam@85: # notice, this list of conditions and the following disclaimer. cannam@85: # * Redistributions in binary form must reproduce the above copyright cannam@85: # notice, this list of conditions and the following disclaimer in cannam@85: # the documentation and/or other materials provided with the cannam@85: # distribution. cannam@85: # * Neither the author nor the names of any contributors may be used cannam@85: # to endorse or promote products derived from this software without cannam@85: # specific prior written permission. cannam@85: # cannam@85: # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS cannam@85: # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED cannam@85: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR cannam@85: # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR cannam@85: # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, cannam@85: # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, cannam@85: # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; cannam@85: # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, cannam@85: # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR cannam@85: # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF cannam@85: # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cannam@85: cannam@85: # Simple test script for the sndfile-metadata-set program. cannam@85: cannam@85: import commands, os, sys cannam@85: import time, datetime cannam@85: cannam@85: def print_test_name (name): cannam@85: print " %-30s :" % name, cannam@85: cannam@85: def assert_info (filename, arg, value): cannam@85: cmd = "./sndfile-metadata-get %s %s" % (arg, filename) cannam@85: status, output = commands.getstatusoutput (cmd) cannam@85: if status: cannam@85: print "\n\nError : command '%s' should not have failed." % cmd cannam@85: sys.exit (1) cannam@85: if output.find (value) < 0: cannam@85: print "\n\nError : not able to find '%s'." % value cannam@85: print output cannam@85: sys.exit (1) cannam@85: return cannam@85: cannam@85: cannam@85: def check_executable (name): cannam@85: if not (os.path.isfile (name)): cannam@85: print "\n\nError : Can't find executable '%s'. Have you run make?" % name cannam@85: sys.exit (1) cannam@85: cannam@85: def test_empty_fail (): cannam@85: print_test_name ("Empty fail test") cannam@85: cmd = "./sndfile-metadata-set --bext-description Alpha sine.wav" cannam@85: status, output = commands.getstatusoutput (cmd) cannam@85: if not status: cannam@85: print "\n\nError : command '%s' should have failed." % cmd cannam@85: sys.exit (1) cannam@85: print "ok" cannam@85: cannam@85: def test_copy (): cannam@85: print_test_name ("Copy test") cannam@85: cmd = "./sndfile-metadata-set --bext-description \"First Try\" sine.wav output.wav" cannam@85: status, output = commands.getstatusoutput (cmd) cannam@85: if status: cannam@85: print "\n\nError : command '%s' should not have failed." % cmd cannam@85: sys.exit (1) cannam@85: assert_info ("output.wav", "--bext-description", "First Try") cannam@85: print "ok" cannam@85: cannam@85: def test_update (tests): cannam@85: print_test_name ("Update test") cannam@85: for arg, value in tests: cannam@85: cmd = "./sndfile-metadata-set %s \"%s\" output.wav" % (arg, value) cannam@85: status, output = commands.getstatusoutput (cmd) cannam@85: if status: cannam@85: print "\n\nError : command '%s' should not have failed." % cmd cannam@85: sys.exit (1) cannam@85: assert_info ("output.wav", arg, value) cannam@85: print "ok" cannam@85: cannam@85: def test_post_mod (tests): cannam@85: print_test_name ("Post mod test") cannam@85: for arg, value in tests: cannam@85: assert_info ("output.wav", arg, value) cannam@85: print "ok" cannam@85: cannam@85: def test_auto_date (): cannam@85: print_test_name ("Auto date test") cannam@85: cmd = "./sndfile-metadata-set --bext-auto-time-date sine.wav date-time.wav" cannam@85: status, output = commands.getstatusoutput (cmd) cannam@85: if status: cannam@85: print "\n\nError : command '%s' should not have failed." % cmd cannam@85: sys.exit (1) cannam@85: target = datetime.date.today ().__str__ () cannam@85: assert_info ("date-time.wav", "--bext-orig-date", target) cannam@85: print "ok" cannam@85: cannam@85: cannam@85: #------------------------------------------------------------------------------- cannam@85: cannam@85: def test_coding_history (): cannam@85: print_test_name ("Coding history test") cannam@85: cmd = "./sndfile-metadata-set --bext-coding-hist \"alpha beta\" output.wav" cannam@85: status, output = commands.getstatusoutput (cmd) cannam@85: if status: cannam@85: print "\n\nError : command '%s' should not have failed." % cmd cannam@85: sys.exit (1) cannam@85: cmd = "./sndfile-metadata-get --bext-coding-hist output.wav" cannam@85: status, output = commands.getstatusoutput (cmd) cannam@85: if status: cannam@85: print "\n\nError : command '%s' should not have failed." % cmd cannam@85: sys.exit (1) cannam@85: print "ok" cannam@85: cannam@85: #------------------------------------------------------------------------------- cannam@85: cannam@85: def test_rewrite (): cannam@85: print_test_name ("Rewrite test") cannam@85: cmd = "./sndfile-metadata-set --bext-originator \"Really, really long string\" output.wav" cannam@85: status, output = commands.getstatusoutput (cmd) cannam@85: if status: cannam@85: print "\n\nError : command '%s' should not have failed." % cmd cannam@85: sys.exit (1) cannam@85: cmd = "./sndfile-metadata-set --bext-originator \"Short\" output.wav" cannam@85: status, output = commands.getstatusoutput (cmd) cannam@85: if status: cannam@85: print "\n\nError : command '%s' should not have failed." % cmd cannam@85: sys.exit (1) cannam@85: cmd = "./sndfile-metadata-get --bext-originator output.wav" cannam@85: status, output = commands.getstatusoutput (cmd) cannam@85: if status: cannam@85: print "\n\nError : command '%s' should not have failed." % cmd cannam@85: sys.exit (1) cannam@85: if output.find ("really long") > 0: cannam@85: print "\n\nError : output '%s' should not contain 'really long'." % output cannam@85: sys.exit (1) cannam@85: print "ok" cannam@85: cannam@85: #=============================================================================== cannam@85: cannam@85: test_dir = "programs" cannam@85: cannam@85: if os.path.isdir (test_dir): cannam@85: os.chdir (test_dir) cannam@85: cannam@85: for f in [ "sndfile-metadata-set", "sndfile-metadata-get", "../examples/make_sine" ]: cannam@85: check_executable (f) cannam@85: cannam@85: os.system ("../examples/make_sine") cannam@85: if not os.path.isfile ("sine.wav"): cannam@85: print "\n\nError : Can't file file 'sine.wav'." cannam@85: sys.exit (1) cannam@85: cannam@85: print "" cannam@85: cannam@85: test_empty_fail () cannam@85: test_copy () cannam@85: cannam@85: tests = [ cannam@85: ("--bext-description", "Alpha"), ("--bext-originator", "Beta"), ("--bext-orig-ref", "Charlie"), cannam@85: ("--bext-umid", "Delta"), ("--bext-orig-date", "2001-10-01"), ("--bext-orig-time", "01:02:03"), cannam@85: ("--str-title", "Echo"), ("--str-artist", "Fox trot") cannam@85: ] cannam@85: cannam@85: test_auto_date () cannam@85: test_update (tests) cannam@85: test_post_mod (tests) cannam@85: cannam@85: test_update ([ ("--str-artist", "Fox") ]) cannam@85: cannam@85: # This never worked. cannam@85: # test_coding_history () cannam@85: cannam@85: test_rewrite () cannam@85: cannam@85: cannam@85: print "" cannam@85: cannam@85: sys.exit (0) cannam@85: