annotate src/libsndfile-1.0.25/programs/test-sndfile-metadata-set.py @ 83:ae30d91d2ffe

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