From 9d83ad93d04a1e16fe4a2acadf5f9f10bef6d1b9 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sat, 5 Jun 2021 21:25:06 +0530 Subject: [cleanup] Mark unused files --- test/swftests.unused/.gitignore | 1 + test/swftests.unused/ArrayAccess.as | 19 ++++++++ test/swftests.unused/ClassCall.as | 17 +++++++ test/swftests.unused/ClassConstruction.as | 15 ++++++ test/swftests.unused/ConstArrayAccess.as | 18 +++++++ test/swftests.unused/ConstantInt.as | 12 +++++ test/swftests.unused/DictCall.as | 10 ++++ test/swftests.unused/EqualsOperator.as | 10 ++++ test/swftests.unused/LocalVars.as | 13 +++++ test/swftests.unused/MemberAssignment.as | 22 +++++++++ test/swftests.unused/NeOperator.as | 24 ++++++++++ test/swftests.unused/PrivateCall.as | 21 ++++++++ test/swftests.unused/PrivateVoidCall.as | 22 +++++++++ test/swftests.unused/StaticAssignment.as | 13 +++++ test/swftests.unused/StaticRetrieval.as | 16 +++++++ test/swftests.unused/StringBasics.as | 11 +++++ test/swftests.unused/StringCharCodeAt.as | 11 +++++ test/swftests.unused/StringConversion.as | 11 +++++ test/swftests/.gitignore | 1 - test/swftests/ArrayAccess.as | 19 -------- test/swftests/ClassCall.as | 17 ------- test/swftests/ClassConstruction.as | 15 ------ test/swftests/ConstArrayAccess.as | 18 ------- test/swftests/ConstantInt.as | 12 ----- test/swftests/DictCall.as | 10 ---- test/swftests/EqualsOperator.as | 10 ---- test/swftests/LocalVars.as | 13 ----- test/swftests/MemberAssignment.as | 22 --------- test/swftests/NeOperator.as | 24 ---------- test/swftests/PrivateCall.as | 21 -------- test/swftests/PrivateVoidCall.as | 22 --------- test/swftests/StaticAssignment.as | 13 ----- test/swftests/StaticRetrieval.as | 16 ------- test/swftests/StringBasics.as | 11 ----- test/swftests/StringCharCodeAt.as | 11 ----- test/swftests/StringConversion.as | 11 ----- test/test_aes.py | 1 - test/test_swfinterp.py | 80 ------------------------------- test/test_swfinterp.py.disabled | 80 +++++++++++++++++++++++++++++++ 39 files changed, 346 insertions(+), 347 deletions(-) create mode 100644 test/swftests.unused/.gitignore create mode 100644 test/swftests.unused/ArrayAccess.as create mode 100644 test/swftests.unused/ClassCall.as create mode 100644 test/swftests.unused/ClassConstruction.as create mode 100644 test/swftests.unused/ConstArrayAccess.as create mode 100644 test/swftests.unused/ConstantInt.as create mode 100644 test/swftests.unused/DictCall.as create mode 100644 test/swftests.unused/EqualsOperator.as create mode 100644 test/swftests.unused/LocalVars.as create mode 100644 test/swftests.unused/MemberAssignment.as create mode 100644 test/swftests.unused/NeOperator.as create mode 100644 test/swftests.unused/PrivateCall.as create mode 100644 test/swftests.unused/PrivateVoidCall.as create mode 100644 test/swftests.unused/StaticAssignment.as create mode 100644 test/swftests.unused/StaticRetrieval.as create mode 100644 test/swftests.unused/StringBasics.as create mode 100644 test/swftests.unused/StringCharCodeAt.as create mode 100644 test/swftests.unused/StringConversion.as delete mode 100644 test/swftests/.gitignore delete mode 100644 test/swftests/ArrayAccess.as delete mode 100644 test/swftests/ClassCall.as delete mode 100644 test/swftests/ClassConstruction.as delete mode 100644 test/swftests/ConstArrayAccess.as delete mode 100644 test/swftests/ConstantInt.as delete mode 100644 test/swftests/DictCall.as delete mode 100644 test/swftests/EqualsOperator.as delete mode 100644 test/swftests/LocalVars.as delete mode 100644 test/swftests/MemberAssignment.as delete mode 100644 test/swftests/NeOperator.as delete mode 100644 test/swftests/PrivateCall.as delete mode 100644 test/swftests/PrivateVoidCall.as delete mode 100644 test/swftests/StaticAssignment.as delete mode 100644 test/swftests/StaticRetrieval.as delete mode 100644 test/swftests/StringBasics.as delete mode 100644 test/swftests/StringCharCodeAt.as delete mode 100644 test/swftests/StringConversion.as delete mode 100644 test/test_swfinterp.py create mode 100644 test/test_swfinterp.py.disabled (limited to 'test') diff --git a/test/swftests.unused/.gitignore b/test/swftests.unused/.gitignore new file mode 100644 index 000000000..da97ff7ca --- /dev/null +++ b/test/swftests.unused/.gitignore @@ -0,0 +1 @@ +*.swf diff --git a/test/swftests.unused/ArrayAccess.as b/test/swftests.unused/ArrayAccess.as new file mode 100644 index 000000000..e22caa386 --- /dev/null +++ b/test/swftests.unused/ArrayAccess.as @@ -0,0 +1,19 @@ +// input: [["a", "b", "c", "d"]] +// output: ["c", "b", "a", "d"] + +package { +public class ArrayAccess { + public static function main(ar:Array):Array { + var aa:ArrayAccess = new ArrayAccess(); + return aa.f(ar, 2); + } + + private function f(ar:Array, num:Number):Array{ + var x:String = ar[0]; + var y:String = ar[num % ar.length]; + ar[0] = y; + ar[num] = x; + return ar; + } +} +} diff --git a/test/swftests.unused/ClassCall.as b/test/swftests.unused/ClassCall.as new file mode 100644 index 000000000..aef58daf3 --- /dev/null +++ b/test/swftests.unused/ClassCall.as @@ -0,0 +1,17 @@ +// input: [] +// output: 121 + +package { +public class ClassCall { + public static function main():int{ + var f:OtherClass = new OtherClass(); + return f.func(100,20); + } +} +} + +class OtherClass { + public function func(x: int, y: int):int { + return x+y+1; + } +} diff --git a/test/swftests.unused/ClassConstruction.as b/test/swftests.unused/ClassConstruction.as new file mode 100644 index 000000000..436479f8f --- /dev/null +++ b/test/swftests.unused/ClassConstruction.as @@ -0,0 +1,15 @@ +// input: [] +// output: 0 + +package { +public class ClassConstruction { + public static function main():int{ + var f:Foo = new Foo(); + return 0; + } +} +} + +class Foo { + +} diff --git a/test/swftests.unused/ConstArrayAccess.as b/test/swftests.unused/ConstArrayAccess.as new file mode 100644 index 000000000..07dc3f460 --- /dev/null +++ b/test/swftests.unused/ConstArrayAccess.as @@ -0,0 +1,18 @@ +// input: [] +// output: 4 + +package { +public class ConstArrayAccess { + private static const x:int = 2; + private static const ar:Array = ["42", "3411"]; + + public static function main():int{ + var c:ConstArrayAccess = new ConstArrayAccess(); + return c.f(); + } + + public function f(): int { + return ar[1].length; + } +} +} diff --git a/test/swftests.unused/ConstantInt.as b/test/swftests.unused/ConstantInt.as new file mode 100644 index 000000000..e0bbb6166 --- /dev/null +++ b/test/swftests.unused/ConstantInt.as @@ -0,0 +1,12 @@ +// input: [] +// output: 2 + +package { +public class ConstantInt { + private static const x:int = 2; + + public static function main():int{ + return x; + } +} +} diff --git a/test/swftests.unused/DictCall.as b/test/swftests.unused/DictCall.as new file mode 100644 index 000000000..c2d174cc2 --- /dev/null +++ b/test/swftests.unused/DictCall.as @@ -0,0 +1,10 @@ +// input: [{"x": 1, "y": 2}] +// output: 3 + +package { +public class DictCall { + public static function main(d:Object):int{ + return d.x + d.y; + } +} +} diff --git a/test/swftests.unused/EqualsOperator.as b/test/swftests.unused/EqualsOperator.as new file mode 100644 index 000000000..837a69a46 --- /dev/null +++ b/test/swftests.unused/EqualsOperator.as @@ -0,0 +1,10 @@ +// input: [] +// output: false + +package { +public class EqualsOperator { + public static function main():Boolean{ + return 1 == 2; + } +} +} diff --git a/test/swftests.unused/LocalVars.as b/test/swftests.unused/LocalVars.as new file mode 100644 index 000000000..b2911a9f3 --- /dev/null +++ b/test/swftests.unused/LocalVars.as @@ -0,0 +1,13 @@ +// input: [1, 2] +// output: 3 + +package { +public class LocalVars { + public static function main(a:int, b:int):int{ + var c:int = a + b + b; + var d:int = c - b; + var e:int = d; + return e; + } +} +} diff --git a/test/swftests.unused/MemberAssignment.as b/test/swftests.unused/MemberAssignment.as new file mode 100644 index 000000000..dcba5e3ff --- /dev/null +++ b/test/swftests.unused/MemberAssignment.as @@ -0,0 +1,22 @@ +// input: [1] +// output: 2 + +package { +public class MemberAssignment { + public var v:int; + + public function g():int { + return this.v; + } + + public function f(a:int):int{ + this.v = a; + return this.v + this.g(); + } + + public static function main(a:int): int { + var v:MemberAssignment = new MemberAssignment(); + return v.f(a); + } +} +} diff --git a/test/swftests.unused/NeOperator.as b/test/swftests.unused/NeOperator.as new file mode 100644 index 000000000..61dcbc4e9 --- /dev/null +++ b/test/swftests.unused/NeOperator.as @@ -0,0 +1,24 @@ +// input: [] +// output: 123 + +package { +public class NeOperator { + public static function main(): int { + var res:int = 0; + if (1 != 2) { + res += 3; + } else { + res += 4; + } + if (2 != 2) { + res += 10; + } else { + res += 20; + } + if (9 == 9) { + res += 100; + } + return res; + } +} +} diff --git a/test/swftests.unused/PrivateCall.as b/test/swftests.unused/PrivateCall.as new file mode 100644 index 000000000..f1c110a37 --- /dev/null +++ b/test/swftests.unused/PrivateCall.as @@ -0,0 +1,21 @@ +// input: [] +// output: 9 + +package { +public class PrivateCall { + public static function main():int{ + var f:OtherClass = new OtherClass(); + return f.func(); + } +} +} + +class OtherClass { + private function pf():int { + return 9; + } + + public function func():int { + return this.pf(); + } +} diff --git a/test/swftests.unused/PrivateVoidCall.as b/test/swftests.unused/PrivateVoidCall.as new file mode 100644 index 000000000..2cc016797 --- /dev/null +++ b/test/swftests.unused/PrivateVoidCall.as @@ -0,0 +1,22 @@ +// input: [] +// output: 9 + +package { +public class PrivateVoidCall { + public static function main():int{ + var f:OtherClass = new OtherClass(); + f.func(); + return 9; + } +} +} + +class OtherClass { + private function pf():void { + ; + } + + public function func():void { + this.pf(); + } +} diff --git a/test/swftests.unused/StaticAssignment.as b/test/swftests.unused/StaticAssignment.as new file mode 100644 index 000000000..b061c219d --- /dev/null +++ b/test/swftests.unused/StaticAssignment.as @@ -0,0 +1,13 @@ +// input: [1] +// output: 1 + +package { +public class StaticAssignment { + public static var v:int; + + public static function main(a:int):int{ + v = a; + return v; + } +} +} diff --git a/test/swftests.unused/StaticRetrieval.as b/test/swftests.unused/StaticRetrieval.as new file mode 100644 index 000000000..c8352d819 --- /dev/null +++ b/test/swftests.unused/StaticRetrieval.as @@ -0,0 +1,16 @@ +// input: [] +// output: 1 + +package { +public class StaticRetrieval { + public static var v:int; + + public static function main():int{ + if (v) { + return 0; + } else { + return 1; + } + } +} +} diff --git a/test/swftests.unused/StringBasics.as b/test/swftests.unused/StringBasics.as new file mode 100644 index 000000000..d27430b13 --- /dev/null +++ b/test/swftests.unused/StringBasics.as @@ -0,0 +1,11 @@ +// input: [] +// output: 3 + +package { +public class StringBasics { + public static function main():int{ + var s:String = "abc"; + return s.length; + } +} +} diff --git a/test/swftests.unused/StringCharCodeAt.as b/test/swftests.unused/StringCharCodeAt.as new file mode 100644 index 000000000..c20d74d65 --- /dev/null +++ b/test/swftests.unused/StringCharCodeAt.as @@ -0,0 +1,11 @@ +// input: [] +// output: 9897 + +package { +public class StringCharCodeAt { + public static function main():int{ + var s:String = "abc"; + return s.charCodeAt(1) * 100 + s.charCodeAt(); + } +} +} diff --git a/test/swftests.unused/StringConversion.as b/test/swftests.unused/StringConversion.as new file mode 100644 index 000000000..c976f5042 --- /dev/null +++ b/test/swftests.unused/StringConversion.as @@ -0,0 +1,11 @@ +// input: [] +// output: 2 + +package { +public class StringConversion { + public static function main():int{ + var s:String = String(99); + return s.length; + } +} +} diff --git a/test/swftests/.gitignore b/test/swftests/.gitignore deleted file mode 100644 index da97ff7ca..000000000 --- a/test/swftests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.swf diff --git a/test/swftests/ArrayAccess.as b/test/swftests/ArrayAccess.as deleted file mode 100644 index e22caa386..000000000 --- a/test/swftests/ArrayAccess.as +++ /dev/null @@ -1,19 +0,0 @@ -// input: [["a", "b", "c", "d"]] -// output: ["c", "b", "a", "d"] - -package { -public class ArrayAccess { - public static function main(ar:Array):Array { - var aa:ArrayAccess = new ArrayAccess(); - return aa.f(ar, 2); - } - - private function f(ar:Array, num:Number):Array{ - var x:String = ar[0]; - var y:String = ar[num % ar.length]; - ar[0] = y; - ar[num] = x; - return ar; - } -} -} diff --git a/test/swftests/ClassCall.as b/test/swftests/ClassCall.as deleted file mode 100644 index aef58daf3..000000000 --- a/test/swftests/ClassCall.as +++ /dev/null @@ -1,17 +0,0 @@ -// input: [] -// output: 121 - -package { -public class ClassCall { - public static function main():int{ - var f:OtherClass = new OtherClass(); - return f.func(100,20); - } -} -} - -class OtherClass { - public function func(x: int, y: int):int { - return x+y+1; - } -} diff --git a/test/swftests/ClassConstruction.as b/test/swftests/ClassConstruction.as deleted file mode 100644 index 436479f8f..000000000 --- a/test/swftests/ClassConstruction.as +++ /dev/null @@ -1,15 +0,0 @@ -// input: [] -// output: 0 - -package { -public class ClassConstruction { - public static function main():int{ - var f:Foo = new Foo(); - return 0; - } -} -} - -class Foo { - -} diff --git a/test/swftests/ConstArrayAccess.as b/test/swftests/ConstArrayAccess.as deleted file mode 100644 index 07dc3f460..000000000 --- a/test/swftests/ConstArrayAccess.as +++ /dev/null @@ -1,18 +0,0 @@ -// input: [] -// output: 4 - -package { -public class ConstArrayAccess { - private static const x:int = 2; - private static const ar:Array = ["42", "3411"]; - - public static function main():int{ - var c:ConstArrayAccess = new ConstArrayAccess(); - return c.f(); - } - - public function f(): int { - return ar[1].length; - } -} -} diff --git a/test/swftests/ConstantInt.as b/test/swftests/ConstantInt.as deleted file mode 100644 index e0bbb6166..000000000 --- a/test/swftests/ConstantInt.as +++ /dev/null @@ -1,12 +0,0 @@ -// input: [] -// output: 2 - -package { -public class ConstantInt { - private static const x:int = 2; - - public static function main():int{ - return x; - } -} -} diff --git a/test/swftests/DictCall.as b/test/swftests/DictCall.as deleted file mode 100644 index c2d174cc2..000000000 --- a/test/swftests/DictCall.as +++ /dev/null @@ -1,10 +0,0 @@ -// input: [{"x": 1, "y": 2}] -// output: 3 - -package { -public class DictCall { - public static function main(d:Object):int{ - return d.x + d.y; - } -} -} diff --git a/test/swftests/EqualsOperator.as b/test/swftests/EqualsOperator.as deleted file mode 100644 index 837a69a46..000000000 --- a/test/swftests/EqualsOperator.as +++ /dev/null @@ -1,10 +0,0 @@ -// input: [] -// output: false - -package { -public class EqualsOperator { - public static function main():Boolean{ - return 1 == 2; - } -} -} diff --git a/test/swftests/LocalVars.as b/test/swftests/LocalVars.as deleted file mode 100644 index b2911a9f3..000000000 --- a/test/swftests/LocalVars.as +++ /dev/null @@ -1,13 +0,0 @@ -// input: [1, 2] -// output: 3 - -package { -public class LocalVars { - public static function main(a:int, b:int):int{ - var c:int = a + b + b; - var d:int = c - b; - var e:int = d; - return e; - } -} -} diff --git a/test/swftests/MemberAssignment.as b/test/swftests/MemberAssignment.as deleted file mode 100644 index dcba5e3ff..000000000 --- a/test/swftests/MemberAssignment.as +++ /dev/null @@ -1,22 +0,0 @@ -// input: [1] -// output: 2 - -package { -public class MemberAssignment { - public var v:int; - - public function g():int { - return this.v; - } - - public function f(a:int):int{ - this.v = a; - return this.v + this.g(); - } - - public static function main(a:int): int { - var v:MemberAssignment = new MemberAssignment(); - return v.f(a); - } -} -} diff --git a/test/swftests/NeOperator.as b/test/swftests/NeOperator.as deleted file mode 100644 index 61dcbc4e9..000000000 --- a/test/swftests/NeOperator.as +++ /dev/null @@ -1,24 +0,0 @@ -// input: [] -// output: 123 - -package { -public class NeOperator { - public static function main(): int { - var res:int = 0; - if (1 != 2) { - res += 3; - } else { - res += 4; - } - if (2 != 2) { - res += 10; - } else { - res += 20; - } - if (9 == 9) { - res += 100; - } - return res; - } -} -} diff --git a/test/swftests/PrivateCall.as b/test/swftests/PrivateCall.as deleted file mode 100644 index f1c110a37..000000000 --- a/test/swftests/PrivateCall.as +++ /dev/null @@ -1,21 +0,0 @@ -// input: [] -// output: 9 - -package { -public class PrivateCall { - public static function main():int{ - var f:OtherClass = new OtherClass(); - return f.func(); - } -} -} - -class OtherClass { - private function pf():int { - return 9; - } - - public function func():int { - return this.pf(); - } -} diff --git a/test/swftests/PrivateVoidCall.as b/test/swftests/PrivateVoidCall.as deleted file mode 100644 index 2cc016797..000000000 --- a/test/swftests/PrivateVoidCall.as +++ /dev/null @@ -1,22 +0,0 @@ -// input: [] -// output: 9 - -package { -public class PrivateVoidCall { - public static function main():int{ - var f:OtherClass = new OtherClass(); - f.func(); - return 9; - } -} -} - -class OtherClass { - private function pf():void { - ; - } - - public function func():void { - this.pf(); - } -} diff --git a/test/swftests/StaticAssignment.as b/test/swftests/StaticAssignment.as deleted file mode 100644 index b061c219d..000000000 --- a/test/swftests/StaticAssignment.as +++ /dev/null @@ -1,13 +0,0 @@ -// input: [1] -// output: 1 - -package { -public class StaticAssignment { - public static var v:int; - - public static function main(a:int):int{ - v = a; - return v; - } -} -} diff --git a/test/swftests/StaticRetrieval.as b/test/swftests/StaticRetrieval.as deleted file mode 100644 index c8352d819..000000000 --- a/test/swftests/StaticRetrieval.as +++ /dev/null @@ -1,16 +0,0 @@ -// input: [] -// output: 1 - -package { -public class StaticRetrieval { - public static var v:int; - - public static function main():int{ - if (v) { - return 0; - } else { - return 1; - } - } -} -} diff --git a/test/swftests/StringBasics.as b/test/swftests/StringBasics.as deleted file mode 100644 index d27430b13..000000000 --- a/test/swftests/StringBasics.as +++ /dev/null @@ -1,11 +0,0 @@ -// input: [] -// output: 3 - -package { -public class StringBasics { - public static function main():int{ - var s:String = "abc"; - return s.length; - } -} -} diff --git a/test/swftests/StringCharCodeAt.as b/test/swftests/StringCharCodeAt.as deleted file mode 100644 index c20d74d65..000000000 --- a/test/swftests/StringCharCodeAt.as +++ /dev/null @@ -1,11 +0,0 @@ -// input: [] -// output: 9897 - -package { -public class StringCharCodeAt { - public static function main():int{ - var s:String = "abc"; - return s.charCodeAt(1) * 100 + s.charCodeAt(); - } -} -} diff --git a/test/swftests/StringConversion.as b/test/swftests/StringConversion.as deleted file mode 100644 index c976f5042..000000000 --- a/test/swftests/StringConversion.as +++ /dev/null @@ -1,11 +0,0 @@ -// input: [] -// output: 2 - -package { -public class StringConversion { - public static function main():int{ - var s:String = String(99); - return s.length; - } -} -} diff --git a/test/test_aes.py b/test/test_aes.py index 4fd87ce22..d2e51af29 100644 --- a/test/test_aes.py +++ b/test/test_aes.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 - from __future__ import unicode_literals # Allow direct execution diff --git a/test/test_swfinterp.py b/test/test_swfinterp.py deleted file mode 100644 index 5d5b21e6d..000000000 --- a/test/test_swfinterp.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python3 -from __future__ import unicode_literals - -# Allow direct execution -import os -import sys -import unittest -sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - - -import errno -import io -import json -import re -import subprocess - -from yt_dlp.swfinterp import SWFInterpreter - - -TEST_DIR = os.path.join( - os.path.dirname(os.path.abspath(__file__)), 'swftests') - - -class TestSWFInterpreter(unittest.TestCase): - pass - - -def _make_testfunc(testfile): - m = re.match(r'^(.*)\.(as)$', testfile) - if not m: - return - test_id = m.group(1) - - def test_func(self): - as_file = os.path.join(TEST_DIR, testfile) - swf_file = os.path.join(TEST_DIR, test_id + '.swf') - if ((not os.path.exists(swf_file)) - or os.path.getmtime(swf_file) < os.path.getmtime(as_file)): - # Recompile - try: - subprocess.check_call([ - 'mxmlc', '-output', swf_file, - '-static-link-runtime-shared-libraries', as_file]) - except OSError as ose: - if ose.errno == errno.ENOENT: - print('mxmlc not found! Skipping test.') - return - raise - - with open(swf_file, 'rb') as swf_f: - swf_content = swf_f.read() - swfi = SWFInterpreter(swf_content) - - with io.open(as_file, 'r', encoding='utf-8') as as_f: - as_content = as_f.read() - - def _find_spec(key): - m = re.search( - r'(?m)^//\s*%s:\s*(.*?)\n' % re.escape(key), as_content) - if not m: - raise ValueError('Cannot find %s in %s' % (key, testfile)) - return json.loads(m.group(1)) - - input_args = _find_spec('input') - output = _find_spec('output') - - swf_class = swfi.extract_class(test_id) - func = swfi.extract_function(swf_class, 'main') - res = func(input_args) - self.assertEqual(res, output) - - test_func.__name__ = str('test_swf_' + test_id) - setattr(TestSWFInterpreter, test_func.__name__, test_func) - - -for testfile in os.listdir(TEST_DIR): - _make_testfunc(testfile) - -if __name__ == '__main__': - unittest.main() diff --git a/test/test_swfinterp.py.disabled b/test/test_swfinterp.py.disabled new file mode 100644 index 000000000..5d5b21e6d --- /dev/null +++ b/test/test_swfinterp.py.disabled @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +from __future__ import unicode_literals + +# Allow direct execution +import os +import sys +import unittest +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + + +import errno +import io +import json +import re +import subprocess + +from yt_dlp.swfinterp import SWFInterpreter + + +TEST_DIR = os.path.join( + os.path.dirname(os.path.abspath(__file__)), 'swftests') + + +class TestSWFInterpreter(unittest.TestCase): + pass + + +def _make_testfunc(testfile): + m = re.match(r'^(.*)\.(as)$', testfile) + if not m: + return + test_id = m.group(1) + + def test_func(self): + as_file = os.path.join(TEST_DIR, testfile) + swf_file = os.path.join(TEST_DIR, test_id + '.swf') + if ((not os.path.exists(swf_file)) + or os.path.getmtime(swf_file) < os.path.getmtime(as_file)): + # Recompile + try: + subprocess.check_call([ + 'mxmlc', '-output', swf_file, + '-static-link-runtime-shared-libraries', as_file]) + except OSError as ose: + if ose.errno == errno.ENOENT: + print('mxmlc not found! Skipping test.') + return + raise + + with open(swf_file, 'rb') as swf_f: + swf_content = swf_f.read() + swfi = SWFInterpreter(swf_content) + + with io.open(as_file, 'r', encoding='utf-8') as as_f: + as_content = as_f.read() + + def _find_spec(key): + m = re.search( + r'(?m)^//\s*%s:\s*(.*?)\n' % re.escape(key), as_content) + if not m: + raise ValueError('Cannot find %s in %s' % (key, testfile)) + return json.loads(m.group(1)) + + input_args = _find_spec('input') + output = _find_spec('output') + + swf_class = swfi.extract_class(test_id) + func = swfi.extract_function(swf_class, 'main') + res = func(input_args) + self.assertEqual(res, output) + + test_func.__name__ = str('test_swf_' + test_id) + setattr(TestSWFInterpreter, test_func.__name__, test_func) + + +for testfile in os.listdir(TEST_DIR): + _make_testfunc(testfile) + +if __name__ == '__main__': + unittest.main() -- cgit v1.2.3