| 1 |
#!/usr/bin/python |
| 2 |
# |
| 3 |
# Project: lib Instrument Patch Python testing suite |
| 4 |
# File: Converter.py |
| 5 |
# Descr: Object converter tests |
| 6 |
# Author: Element Green <[email protected]> |
| 7 |
# Date: 2016-07-04 |
| 8 |
# License: Public Domain |
| 9 |
# |
| 10 |
import Test |
| 11 |
import gi |
| 12 |
|
| 13 |
from gi.repository import GObject |
| 14 |
|
| 15 |
gi.require_version ('Ipatch', '1.1') |
| 16 |
from gi.repository import Ipatch |
| 17 |
|
| 18 |
# Common converter source to destination type mappings |
| 19 |
CONVERTER_TYPES = ( |
| 20 |
("IpatchFile", "IpatchBase"), |
| 21 |
("IpatchBase", "IpatchFile"), |
| 22 |
("IpatchItem", "IpatchSF2VoiceCache"), |
| 23 |
("IpatchSndFile", "IpatchItem") |
| 24 |
) |
| 25 |
|
| 26 |
# Main |
| 27 |
if __name__ == "__main__": |
| 28 |
parser = Test.createArgParser ('libInstPatch Converter tests') |
| 29 |
args = Test.parseArgs (parser) |
| 30 |
|
| 31 |
Ipatch.init () |
| 32 |
|
| 33 |
convinfo = [Ipatch.get_converter_info (t) for t in Ipatch.find_converters (GObject.TYPE_NONE, GObject.TYPE_NONE, 0)] |
| 34 |
convinfo.sort (key=lambda info: GObject.type_name (info.conv_type)) |
| 35 |
|
| 36 |
if len (convinfo) == 0: |
| 37 |
Test.error ("No converters found!") |
| 38 |
|
| 39 |
Test.msg ("Found %d converters\n" % len (convinfo)) |
| 40 |
|
| 41 |
summaryCounts = [0] * len (CONVERTER_TYPES) |
| 42 |
summaryOther = 0 |
| 43 |
|
| 44 |
# Show converter details |
| 45 |
for convindex in xrange (0, len (convinfo)): |
| 46 |
conv = convinfo[convindex] |
| 47 |
|
| 48 |
s = GObject.type_name (conv.conv_type) + "\n" |
| 49 |
|
| 50 |
if conv.src_count == Ipatch.ConverterCount.ONE_OR_MORE: count = '+' |
| 51 |
elif conv.src_count == Ipatch.ConverterCount.ZERO_OR_MORE: count = '*' |
| 52 |
else: count = str (conv.src_count) |
| 53 |
|
| 54 |
if conv.src_match == GObject.TYPE_INVALID: |
| 55 |
s += " src[%s]=%s " % (count, GObject.type_name (conv.src_type)) |
| 56 |
else: s += " src[%s]=%s - %s" \ |
| 57 |
% (count, GObject.type_name (conv.src_match), GObject.type_name (conv.src_type)) |
| 58 |
|
| 59 |
if conv.flags & Ipatch.ConverterFlags.SRC_DERIVED: |
| 60 |
s += "+ DESCENDANTS\n" |
| 61 |
else: s += "\n" |
| 62 |
|
| 63 |
if conv.dest_count == Ipatch.ConverterCount.ONE_OR_MORE: count = '+' |
| 64 |
elif conv.dest_count == Ipatch.ConverterCount.ZERO_OR_MORE: count = '*' |
| 65 |
else: count = str (conv.dest_count) |
| 66 |
|
| 67 |
if conv.dest_match == GObject.TYPE_INVALID: |
| 68 |
s += " dst[%s]=%s" % (count, GObject.type_name (conv.dest_type)) |
| 69 |
else: s += " dst[%s]=%s - %s" \ |
| 70 |
% (count, GObject.type_name (conv.dest_match), GObject.type_name (conv.dest_type)) |
| 71 |
|
| 72 |
if conv.flags & Ipatch.ConverterFlags.DEST_DERIVED: |
| 73 |
s += "+ DESCENDANTS" |
| 74 |
|
| 75 |
Test.info (s) |
| 76 |
|
| 77 |
for i in xrange (0, len (CONVERTER_TYPES)): |
| 78 |
convTypes = CONVERTER_TYPES[i] |
| 79 |
|
| 80 |
if GObject.type_is_a (conv.src_type, GObject.type_name (convTypes[0])) \ |
| 81 |
and GObject.type_is_a (conv.dest_type, GObject.type_name (convTypes[1])): |
| 82 |
summaryCounts[i] += 1 |
| 83 |
break |
| 84 |
else: summaryOther += 1 |
| 85 |
|
| 86 |
Test.info ("") |
| 87 |
|
| 88 |
Test.msg ("Converter type summary:") |
| 89 |
|
| 90 |
for i in xrange (0, len (CONVERTER_TYPES)): |
| 91 |
convTypes = CONVERTER_TYPES[i] |
| 92 |
Test.msg ("%s -> %s: %d" % (convTypes[0], convTypes[1], summaryCounts[i])) |
| 93 |
|
| 94 |
if summaryOther > 0: |
| 95 |
Test.msg ("Other: %d" % (convTypes[0], convTypes[1], summaryCounts[i])) |
| 96 |
|
| 97 |
Test.exit () |
| 98 |
|