From c7a1e1178a38905497039b1110cf34b580b3c462 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Fri, 3 Nov 2023 22:05:19 +0100 Subject: [PATCH] avm2: TLF GroupElement tests --- .../avm2/text_engine_groupelement/Test.as | 160 ++++++++++++++++++ .../avm2/text_engine_groupelement/output.txt | 64 +++++++ .../avm2/text_engine_groupelement/test.swf | Bin 0 -> 1895 bytes .../avm2/text_engine_groupelement/test.toml | 1 + 4 files changed, 225 insertions(+) create mode 100644 tests/tests/swfs/avm2/text_engine_groupelement/Test.as create mode 100644 tests/tests/swfs/avm2/text_engine_groupelement/output.txt create mode 100644 tests/tests/swfs/avm2/text_engine_groupelement/test.swf create mode 100644 tests/tests/swfs/avm2/text_engine_groupelement/test.toml diff --git a/tests/tests/swfs/avm2/text_engine_groupelement/Test.as b/tests/tests/swfs/avm2/text_engine_groupelement/Test.as new file mode 100644 index 000000000000..36404e7b3a05 --- /dev/null +++ b/tests/tests/swfs/avm2/text_engine_groupelement/Test.as @@ -0,0 +1,160 @@ +package { + import flash.display.Sprite; + public class Test extends Sprite { } +} + +import flash.text.engine.GroupElement; +import flash.text.engine.TextElement; +import flash.text.engine.ContentElement; + +function createGroup() { + var vector = new Vector.() + vector.push(new TextElement("aaaaa")) + vector.push(new TextElement("bbbbb")) + vector.push(new TextElement("ccccc")) + return new GroupElement(vector); +} + +trace("/// replaceElements(0, 0, null)") +var group = createGroup(); +trace("result: " + group.replaceElements(0, 0, null)); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " "+ group.getElementAt(i).text); +} + +trace("/// replaceElements(50, 50, null)") +var group = createGroup(); +trace("result: " + group.replaceElements(50, 50, null)); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " "+ group.getElementAt(i).text); +} + +trace("/// replaceElements(0, 1, null)") +var group = createGroup(); +trace("result: " + group.replaceElements(0, 1, null)); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " "+ group.getElementAt(i).text); +} + +trace("/// replaceElements(0, 3, null)") +var group = createGroup(); +trace("result: " + group.replaceElements(0, 3, null)); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " "+ group.getElementAt(i).text); +} + +/* +trace("/// replaceElements(3, 0, null)") +var group = createGroup(); +trace("result: " + group.replaceElements(3, 0, null)); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " " + group.getElementAt(i)); +} +*/ + +trace("/// replaceElements(1, 1, replacement)") +var group = createGroup(); +var replacement = new Vector.; +replacement.push(new TextElement("foobar")); +trace("result: " + group.replaceElements(1, 1, replacement)); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " "+ group.getElementAt(i).text); +} + +trace("/// replaceElements(1, 2, replacement)") +var group = createGroup(); +var replacement = new Vector.; +replacement.push(new TextElement("foobar")); +trace("result: " + group.replaceElements(1, 2, replacement)); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " "+ group.getElementAt(i).text); +} + +trace("/// replaceElements(3, 3, replacement)") +var group = createGroup(); +var replacement = new Vector.; +replacement.push(new TextElement("foobar")); +trace("result: " + group.replaceElements(3, 3, replacement)); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " "+ group.getElementAt(i).text); +} + +trace("/// replaceElements(1, 1, replacements)") +var group = createGroup(); +var replacements = new Vector.(); +replacements.push(new TextElement("11111")); +replacements.push(new TextElement("22222")); +trace("result: " + group.replaceElements(1, 1, replacements)); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " "+ group.getElementAt(i).text); +} + +trace("/// replaceElements(1, 2, replacements)") +var group = createGroup(); +var replacements = new Vector.(); +replacements.push(new TextElement("11111")); +replacements.push(new TextElement("22222")); +trace("result: " + group.replaceElements(1, 2, replacements)); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " "+ group.getElementAt(i).text); +} + +trace("/// splitTextElement(1, 2)"); +var group = createGroup(); +trace("result: " + group.splitTextElement(1, 2).text); +for (var i = 0; i < group.elementCount; i++) { + trace(i + " "+ group.getElementAt(i).text); +} + +trace("/// replaceElements (begin index out-of-bounds)"); +try { + var group = createGroup(); + group.replaceElements(42, 43, null); +} catch (e) { + trace(e) +} + +trace("/// replaceElements (end index out-of-bounds)") +try { + var group = createGroup(); + var replacement = new Vector.; + replacement.push(new TextElement("foobar")); + replacement.push(new TextElement("hello world")); + group.replaceElements(3, 4, replacement); +} catch (e) { + trace(e); +} + +trace("/// getElementAt (out-of-bounds)"); +try { + var group = createGroup(); + group.getElementAt(42); +} catch (e) { + trace(e) +} + +trace("/// splitTextElement (element index out-of-bounds)"); +try { + var group = createGroup(); + group.splitTextElement(42, 0); +} catch (e) { + trace(e) +} + +trace("/// splitTextElement (text index out-of-bounds)"); +try { + var group = createGroup(); + group.splitTextElement(0, 42); +} catch (e) { + trace(e) +} + +trace("/// splitTextElement (not TextElement)"); +var vector = new Vector.() +vector.push(new GroupElement()) +var group = new GroupElement(vector); +try { + group.splitTextElement(0, 1); +} catch (e) { + trace(e); +} \ No newline at end of file diff --git a/tests/tests/swfs/avm2/text_engine_groupelement/output.txt b/tests/tests/swfs/avm2/text_engine_groupelement/output.txt new file mode 100644 index 000000000000..3e51d6a3aae8 --- /dev/null +++ b/tests/tests/swfs/avm2/text_engine_groupelement/output.txt @@ -0,0 +1,64 @@ +/// replaceElements(0, 0, null) +result: null +0 aaaaa +1 bbbbb +2 ccccc +/// replaceElements(50, 50, null) +result: null +0 aaaaa +1 bbbbb +2 ccccc +/// replaceElements(0, 1, null) +result: [object TextElement] +0 bbbbb +1 ccccc +/// replaceElements(0, 3, null) +result: [object TextElement],[object TextElement],[object TextElement] +/// replaceElements(1, 1, replacement) +result: +0 aaaaa +1 foobar +2 bbbbb +3 ccccc +/// replaceElements(1, 2, replacement) +result: [object TextElement] +0 aaaaa +1 foobar +2 ccccc +/// replaceElements(3, 3, replacement) +result: +0 aaaaa +1 bbbbb +2 ccccc +3 foobar +/// replaceElements(1, 1, replacements) +result: +0 aaaaa +1 11111 +2 22222 +3 bbbbb +4 ccccc +/// replaceElements(1, 2, replacements) +result: [object TextElement] +0 aaaaa +1 11111 +2 22222 +3 ccccc +/// splitTextElement(1, 2) +result: bbb +0 aaaaa +1 bb +2 bbb +3 ccccc +/// replaceElements (begin index out-of-bounds) +RangeError: Error #2006: The supplied index is out of bounds. +/// replaceElements (end index out-of-bounds) +RangeError: Error #2006: The supplied index is out of bounds. +/// getElementAt (out-of-bounds) +RangeError: Error #2006: The supplied index is out of bounds. +/// splitTextElement (element index out-of-bounds) +RangeError: Error #2006: The supplied index is out of bounds. +/// splitTextElement (text index out-of-bounds) +RangeError: Error #2006: The supplied index is out of bounds. +/// splitTextElement (not TextElement) +ArgumentError: Error #2004: One of the parameters is invalid. diff --git a/tests/tests/swfs/avm2/text_engine_groupelement/test.swf b/tests/tests/swfs/avm2/text_engine_groupelement/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..d2d683ee40524b8099e1cab03c14c5d52ca92653 GIT binary patch literal 1895 zcmV-t2blOnS5qe74*&po0gYE(Y#Uh>zIT2+{*Tk7Zj-j`bZa(o5_=q{Nt-kcPUCpD z0b0~_cgqT6#`c}q+sTZX87C<}0xcjR79@Ta#4ZBL3*rHZ2i|x=Jn(>!P>RGNUU>nY z)(D9QgcQ!b_GBhbM$47&%-nO&`M&SobLLKRfP}vyl>8||7cnZ2P9TK7F!nc$(5ltc zRvwfq^1-fd*efu)J=JoY&WfV!@9*dL7xJdHqs%WaFDr$jQY_}cBWFJ`9Q7b)*w?1k z7(kiW4XfR8+NL2>K(%gmo!e7W1Jq{Y7_`&1bOzaMC`2c_#Bgk7K0gmY&BlsmTDz*V zrgl1dyP;Az70KL)Pw@d-B4ZTr3n9`f{mpRiQiY%f!F}$z4OqRCnUu z{oKdax3^!t|DcQxN1y^uv~ue2{3_buj*gCAi}ElPf-a;U|84=Q1fi7&|NY*Z@bug0 zLt;DV*W-2qAv(i`DU_#9mCzn(z=CC^W$qHiF?SWv^Vl&v3QOIsThu$R+M!pNA7WrI z&J>rg4)UQk%{s|9Aas3uK`9mrOG>@l)}6KytJT0%tL1?txnUX()Xr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