Skip to content

Commit

Permalink
tests: Add test for MovieClip._lockroot in avm1
Browse files Browse the repository at this point in the history
  • Loading branch information
zeh authored and Herschel committed Dec 2, 2020
1 parent a0d56aa commit c018ac0
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/tests/regression_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ swf_tests! {
(movieclip_prototype_extension, "avm1/movieclip_prototype_extension", 1),
(movieclip_hittest, "avm1/movieclip_hittest", 1),
(movieclip_hittest_shapeflag, "avm1/movieclip_hittest_shapeflag", 10),
#[ignore] (movieclip_lockroot, "avm1/movieclip_lockroot", 10),
#[ignore] (textfield_text, "avm1/textfield_text", 1),
(recursive_prototypes, "avm1/recursive_prototypes", 2),
(stage_object_children, "avm1/stage_object_children", 2),
Expand Down
7 changes: 7 additions & 0 deletions core/tests/swfs/avm1/movieclip_lockroot/child.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function setLock(lock) {
this._lockroot = lock;
}

function test(lock) {
trace("Child: level is " + this + ", root is " + _root + ", _lockroot is " + this._lockroot + ", parent is " + this._parent);
}
Binary file added core/tests/swfs/avm1/movieclip_lockroot/child.fla
Binary file not shown.
Binary file added core/tests/swfs/avm1/movieclip_lockroot/child.swf
Binary file not shown.
29 changes: 29 additions & 0 deletions core/tests/swfs/avm1/movieclip_lockroot/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Parent: level is _level0, root is _level0, _lockroot is false
Parent: setting _lockroot to true sets it to true.
Parent: setting _lockroot to false sets it to false.
Parent: setting _lockroot to undefined sets it to false.
Parent: setting _lockroot to null sets it to false.
Parent: setting _lockroot to NaN sets it to false.
Parent: setting _lockroot to -1 sets it to true.
Parent: setting _lockroot to 0 sets it to false.
Parent: setting _lockroot to 1 sets it to true.
Parent: setting _lockroot to 1337 sets it to true.
Parent: setting _lockroot to "true" sets it to true.
Parent: setting _lockroot to "false" sets it to true.
Parent: setting _lockroot to "foo" sets it to true.
Parent: setting _lockroot to "" sets it to false.
Parent: setting _lockroot to "0" sets it to true.
Parent: setting _lockroot to [object Object] sets it to true.
Child: level is _level0.child1, root is _level0, _lockroot is false, parent is _level0
Child: level is _level0.child2, root is _level0.child2, _lockroot is true, parent is _level0
Child: level is _level0.child3, root is _level0.child3, _lockroot is true, parent is _level0
Child: level is _level0.child1.child1, root is _level0, _lockroot is false, parent is _level0.child1
Child: level is _level0.child1.child2, root is _level0.child1.child2, _lockroot is true, parent is _level0.child1
Child: level is _level0.child1.child3, root is _level0.child1.child3, _lockroot is true, parent is _level0.child1
Child: level is _level0.child2.child1, root is _level0.child2, _lockroot is false, parent is _level0.child2
Child: level is _level0.child2.child2, root is _level0.child2.child2, _lockroot is true, parent is _level0.child2
Child: level is _level0.child2.child3, root is _level0.child2.child3, _lockroot is true, parent is _level0.child2
Child: level is _level0.child3.child1, root is _level0.child3, _lockroot is false, parent is _level0.child3
Child: level is _level0.child3.child2, root is _level0.child3.child2, _lockroot is true, parent is _level0.child3
Child: level is _level0.child3.child3, root is _level0.child3.child3, _lockroot is true, parent is _level0.child3
All tests done.
122 changes: 122 additions & 0 deletions core/tests/swfs/avm1/movieclip_lockroot/test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
var levels = 1;

function testSet(value) {
var valueLabel = typeof value == "string" ? "\"" + value + "\"" : value;
this._lockroot = false;
this._lockroot = value;
if (this._lockroot) {
trace("Parent: setting _lockroot to " + valueLabel + " sets it to true.");
this._lockroot = false;
return;
}
this._lockroot = true;
this._lockroot = value;
if (!this._lockroot) {
trace("Parent: setting _lockroot to " + valueLabel + " sets it to false.");
return;
}

this._lockroot = false;
trace("Parent: setting _lockroot to " + valueLabel + " has no effect.");
}

function testSelf() {
// Prints _level0, _level0, false
trace("Parent: level is " + this + ", root is " + _root + ", _lockroot is " + this._lockroot);

// Edge case tests
testSet(true); /// true
testSet(false); // false
testSet(undefined); //false
testSet(null); // false
testSet(NaN); // false
testSet(-1); // true
testSet(0); // false
testSet(1); // true
testSet(1337); // true
testSet("true"); // true
testSet("false"); // true
testSet("foo"); // true
testSet(""); // false
testSet("0"); // true
testSet({}); // true
}

function testChildren() {
// 1 = normal child, lockroot unset
// 2 = lockroot set on container before loading (must inherit)
// 3 = lockroot set by child function

// Top
createEmptyMovieClip("child1", levels++);
child1.loadMovie("child.swf");
createEmptyMovieClip("child2", levels++);
child2._lockroot = true;
child2.loadMovie("child.swf");
createEmptyMovieClip("child3", levels++);
child3.loadMovie("child.swf");

// Wait for initial loads
setTimeout(createGrandChildren, 50);

// Test it all
setTimeout(testAllChildren, 250);
}

function createGrandChildren() {
// Each grandchild
_root.child1.createEmptyMovieClip("child1", levels++);
_root.child1.child1.loadMovie("child.swf");
_root.child1.createEmptyMovieClip("child2", levels++);
_root.child1.child2._lockroot = true;
_root.child1.child2.loadMovie("child.swf");
_root.child1.createEmptyMovieClip("child3", levels++);
_root.child1.child3.loadMovie("child.swf");

_root.child2.createEmptyMovieClip("child1", levels++);
_root.child2.child1.loadMovie("child.swf");
_root.child2.createEmptyMovieClip("child2", levels++);
_root.child2.child2._lockroot = true;
_root.child2.child2.loadMovie("child.swf");
_root.child2.createEmptyMovieClip("child3", levels++);
_root.child2.child3.loadMovie("child.swf");

_root.child3.createEmptyMovieClip("child1", levels++);
_root.child3.child1.loadMovie("child.swf");
_root.child3.createEmptyMovieClip("child2", levels++);
_root.child3.child2._lockroot = true;
_root.child3.child2.loadMovie("child.swf");
_root.child3.createEmptyMovieClip("child3", levels++);
_root.child3.child3.loadMovie("child.swf");
}

function testAllChildren() {
_root.child1.test(); // Root is _level0, lockroot false
_root.child2.test(); // Root is self, lockroot true
_root.child3.setLock(true);
_root.child3.test(); // Root is self, lockroot true

_root.child1.child1.test(); // Root is _level0, lockroot false
_root.child1.child2.test(); // Root is self, lockroot true
_root.child1.child3.setLock(true);
_root.child1.child3.test(); // Root is self, lockroot true

_root.child2.child1.test(); // Root is _parent, lockroot true
_root.child2.child2.test(); // Root is self, lockroot true
_root.child2.child3.setLock(true);
_root.child2.child3.test(); // Root is self, lockroot true

_root.child3.child1.test(); // Root is _parent, lockroot true
_root.child3.child2.test(); // Root is self, lockroot true
_root.child3.child3.setLock(true);
_root.child3.child3.test(); // Root is self, lockroot true

trace("All tests done.");
}

function test() {
testSelf();
testChildren();
}

test();
Binary file added core/tests/swfs/avm1/movieclip_lockroot/test.fla
Binary file not shown.
Binary file added core/tests/swfs/avm1/movieclip_lockroot/test.swf
Binary file not shown.

0 comments on commit c018ac0

Please sign in to comment.