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