annotate src/libsndfile-1.0.27/programs/test-sndfile-metadata-set.py @ 168:ceec0dd9ec9c

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