FLEX-35100
Unit testing my assumptions of TextBlock.createTextLine() and TextBlock.recreateTextLine().
diff --git a/automation_tests/src/AllTestsSuite.as b/automation_tests/src/AllTestsSuite.as
index 62f2f45..b0dbf9a 100644
--- a/automation_tests/src/AllTestsSuite.as
+++ b/automation_tests/src/AllTestsSuite.as
@@ -57,6 +57,7 @@
import UnitTest.Tests.StyleTest;
import UnitTest.Tests.TCYTest;
import UnitTest.Tests.TabTest;
+ import UnitTest.Tests.TextBlock_FLEX_35100_Test;
import UnitTest.Tests.TextContainerManagerTest;
import UnitTest.Tests.TextFlowEditTest;
import UnitTest.Tests.TextFlowTextLineFactoryTest;
@@ -114,6 +115,7 @@
public var scrollToRangeTest:ScrollToRangeTest;
public var pasteWithMultiParagraph:PasteWithMutliParagraph_FLEX_34876_Test;
public var flex_34807:FLEX_34807_Test;
+ public var flex_35100:TextBlock_FLEX_35100_Test;
}
}
diff --git a/automation_tests/src/UnitTest/Tests/TextBlock_FLEX_35100_Test.as b/automation_tests/src/UnitTest/Tests/TextBlock_FLEX_35100_Test.as
new file mode 100644
index 0000000..17f9789
--- /dev/null
+++ b/automation_tests/src/UnitTest/Tests/TextBlock_FLEX_35100_Test.as
@@ -0,0 +1,378 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package UnitTest.Tests {
+ import UnitTest.ExtendedClasses.VellumTestCase;
+ import UnitTest.Fixtures.TestConfig;
+
+ import flash.text.engine.ElementFormat;
+
+ import flash.text.engine.TextBlock;
+ import flash.text.engine.TextElement;
+ import flash.text.engine.TextLine;
+ import flash.text.engine.TextLineCreationResult;
+
+ import org.flexunit.assertThat;
+ import org.flexunit.asserts.assertEquals;
+ import org.flexunit.asserts.assertNotNull;
+ import org.flexunit.asserts.assertNull;
+
+ public class TextBlock_FLEX_35100_Test extends VellumTestCase {
+
+ private static const WIDTH_FOR_TWO_LINES:int = 50;
+ private static var _sut:TextBlock;
+
+ public function TextBlock_FLEX_35100_Test()
+ {
+ super("", "TextBlock_FLEX_35100_Tests", TestConfig.getInstance());
+
+ metaData = {};
+ }
+
+ [Before]
+ override public function setUpTest():void
+ {
+ super.setUpTest();
+ _sut = new TextBlock(new TextElement("Hello world!", new ElementFormat()));
+ }
+
+ [After]
+ override public function tearDownTest():void
+ {
+ super.tearDownTest();
+ _sut = null;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ //
+ // createTextLine()
+ //
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+ [Test]
+ public function test_createTextLine_returns_a_valid_TextLine_when_previousLine_is_null_and_TextBlock_not_empty():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null);
+
+ //then
+ assertNotNull(textLine);
+ }
+
+ [Test]
+ public function test_createTextLine_returns_null_when_width_too_little():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null, 1);
+
+ //then
+ assertNull(textLine);
+ }
+
+ [Test]
+ public function test_createTextLine_returns_null_when_width_0():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null, 0);
+
+ //then
+ assertNull(textLine);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function test_createTextLine_throws_ArgumentError_when_width_negative():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null, -10);
+
+ //then - ArgumentError thrown
+ }
+
+ [Test]
+ public function test_createTextLine_works_when_fitSomething_true_despite_width_negative():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null, -10, 0, true);
+
+ //then
+ assertNotNull(textLine);
+ assertThat(textLine.rawTextLength > 0);
+ }
+
+ [Test]
+ public function test_createTextLine_works_when_fitSomething_true_despite_width_insufficient():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null, 1, 0, true);
+
+ //then
+ assertNotNull(textLine);
+ assertThat(textLine.rawTextLength > 0);
+ }
+
+ [Test]
+ public function test_createTextLine_creates_only_one_TextLine_for_short_text_and_default_width():void
+ {
+ //when
+ var firstTextLine:TextLine = _sut.createTextLine(null);
+ var secondTextLine:TextLine = _sut.createTextLine(firstTextLine);
+
+ //then
+ assertNull(secondTextLine);
+ assertEquals(TextLineCreationResult.COMPLETE, _sut.textLineCreationResult);
+ }
+
+ [Test]
+ public function test_createTextLine_creates_only_one_TextLine_for_short_text_and_default_width_despite_fitSomething_true():void
+ {
+ //when
+ var firstTextLine:TextLine = _sut.createTextLine(null);
+ var secondTextLine:TextLine = _sut.createTextLine(firstTextLine, 10000, 0, true);
+
+ //then
+ assertNull(secondTextLine);
+ assertEquals(TextLineCreationResult.COMPLETE, _sut.textLineCreationResult);
+ }
+
+ [Test]
+ public function test_createTextLine_returns_null_when_previousLine_is_null_and_TextBlock_empty():void
+ {
+ //given
+ _sut.content = new TextElement("", new ElementFormat());
+
+ //when
+ var textLine:TextLine = _sut.createTextLine(null);
+
+ //then
+ assertNull(textLine);
+ }
+
+ [Test]
+ public function test_createTextLine_returns_null_when_previousLine_is_null_and_TextBlock_empty_despite_fitSomething_true():void
+ {
+ //given
+ _sut.content = new TextElement("", new ElementFormat());
+
+ //when
+ var textLine:TextLine = _sut.createTextLine(null, 1000, 0, true);
+
+ //then
+ assertNull(textLine);
+ }
+
+ [Test]
+ public function test_createTextLine_returns_null_when_previousLine_is_null_and_TextBlock_has_null_text():void
+ {
+ //given
+ _sut.content = new TextElement(null, new ElementFormat());
+
+ //when
+ var textLine:TextLine = _sut.createTextLine(null);
+
+ //then
+ assertNull(textLine);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function test_createTextLine_throws_ArgumentError_when_previousLine_from_different_TextBlock():void
+ {
+ //given
+ var firstTextLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ new TextBlock(new TextElement("Hello World!", new ElementFormat())).createTextLine(firstTextLine);
+
+ //then - ArgumentError thrown
+ }
+
+
+ ////////////////////////////////////////////////////////////////////////////////
+ //
+ // recreateTextLine()
+ //
+ ////////////////////////////////////////////////////////////////////////////////
+
+ [Test]
+ public function test_recreateTextLine_returns_the_same_TextLine_instance_passed_to_it():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null);
+ var recreatedTextLine:TextLine = _sut.recreateTextLine(textLine, null);
+
+ //then
+ assertEquals(textLine, recreatedTextLine);
+ }
+
+ [Test]
+ public function test_recreateTextLine_returns_null_when_TextBlock_empty():void
+ {
+ //given
+ var textLine:TextLine = _sut.createTextLine(null);
+
+ //when
+ _sut.content = new TextElement("", new ElementFormat());
+ var recreatedTextLine:TextLine = _sut.recreateTextLine(textLine, null);
+
+ //then
+ assertNull(recreatedTextLine);
+ }
+
+ [Test]
+ public function test_recreateTextLine_returns_null_when_TextBlock_empty_despite_fitSomething_true():void
+ {
+ //given
+ var textLine:TextLine = _sut.createTextLine(null);
+
+ //when
+ _sut.content = new TextElement("", new ElementFormat());
+ var recreatedTextLine:TextLine = _sut.recreateTextLine(textLine, null, 1000, 0, true);
+
+ //then
+ assertNull(recreatedTextLine);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function test_recreateTextLine_throws_Argument_Error_when_previousLine_from_different_TextBlock_content():void
+ {
+ //given
+ var firstLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ var secondLine:TextLine = _sut.createTextLine(firstLine, WIDTH_FOR_TWO_LINES);
+
+ //when
+ _sut.content = new TextElement("Creative Design and development", new ElementFormat());
+ var recreatedSecondLine:TextLine = _sut.recreateTextLine(secondLine, firstLine, WIDTH_FOR_TWO_LINES);
+
+ //then - ArgumentError is thrown
+ }
+
+ [Test(expects="ArgumentError")]
+ public function test_recreateTextLine_throws_Argument_Error_when_line_parameter_is_null():void
+ {
+ //given
+ var firstLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ var secondLine:TextLine = _sut.createTextLine(firstLine, WIDTH_FOR_TWO_LINES);
+
+ //when
+ var recreatedSecondLine:TextLine = _sut.recreateTextLine(null, firstLine, WIDTH_FOR_TWO_LINES);
+
+ //then
+ assertNull(recreatedSecondLine);
+ }
+
+ [Test]
+ public function test_recreateTextLine_returns_null_when_width_too_little():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ var recreatedTextLine:TextLine = _sut.recreateTextLine(textLine, null, 1);
+
+ //then
+ assertNull(recreatedTextLine);
+ }
+
+ [Test]
+ public function test_recreateTextLine_returns_null_when_width_0():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ var recreatedTextLine:TextLine = _sut.recreateTextLine(textLine, null, 0);
+
+ //then
+ assertNull(recreatedTextLine);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function test_recreateTextLine_throws_ArgumentError_when_width_negative():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ var recreatedTextLine:TextLine = _sut.recreateTextLine(textLine, null, -10);
+
+ //then - ArgumentError thrown
+ }
+
+ [Test]
+ public function test_recreateTextLine_works_when_fitSomething_true_despite_width_negative():void
+ {
+ //when
+ var textLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ var recreatedTextLine:TextLine = _sut.recreateTextLine(textLine, null, -10, 0, true);
+
+ //then
+ assertNotNull(recreatedTextLine);
+ assertThat(recreatedTextLine.rawTextLength > 0);
+ }
+
+ [Test]
+ public function test_recreateTextLine_returns_null_when_previousLine_was_last_line():void
+ {
+ //when
+ var firstLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ var secondLine:TextLine = _sut.createTextLine(firstLine, WIDTH_FOR_TWO_LINES);
+
+ var copyOfFirstThenThird:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ copyOfFirstThenThird = _sut.recreateTextLine(copyOfFirstThenThird, secondLine, WIDTH_FOR_TWO_LINES);
+
+ //then
+ assertNull(copyOfFirstThenThird);
+ assertEquals(TextLineCreationResult.COMPLETE, _sut.textLineCreationResult);
+ }
+
+ [Test]
+ public function test_recreateTextLine_returns_null_when_previousLine_was_last_line_despite_fitSomething_true():void
+ {
+ //when
+ var firstLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ var secondLine:TextLine = _sut.createTextLine(firstLine, WIDTH_FOR_TWO_LINES);
+
+ var copyOfFirstThenThird:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ copyOfFirstThenThird = _sut.recreateTextLine(copyOfFirstThenThird, secondLine, WIDTH_FOR_TWO_LINES, 0, true);
+
+ //then
+ assertNull(copyOfFirstThenThird);
+ assertEquals(TextLineCreationResult.COMPLETE, _sut.textLineCreationResult);
+ }
+
+ [Test(expects="ArgumentError")]
+ public function test_recreateTextLine_throws_ArgumentError_when_previousLine_is_the_same_as_the_line_to_recreate():void
+ {
+ //when
+ var firstTextLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ var secondTextLine:TextLine = _sut.createTextLine(firstTextLine, WIDTH_FOR_TWO_LINES);
+
+ assertNotNull(secondTextLine);
+
+ var firstLineRecreatedAsSecond:TextLine = _sut.recreateTextLine(firstTextLine, firstTextLine, WIDTH_FOR_TWO_LINES);
+
+ //then - error should be thrown
+ }
+
+ [Test(expects="ArgumentError")]
+ public function test_recreateTextLine_throws_ArgumentError_when_textLine_comes_from_different_block():void
+ {
+ //when
+ var firstTextLine:TextLine = _sut.createTextLine(null, WIDTH_FOR_TWO_LINES);
+ var secondTextLine:TextLine = _sut.createTextLine(firstTextLine, WIDTH_FOR_TWO_LINES);
+
+ assertNotNull(secondTextLine);
+
+ var firstLineRecreatedAsSecond:TextLine = new TextBlock(new TextElement("Hello World!", new ElementFormat())).recreateTextLine(secondTextLine, firstTextLine, WIDTH_FOR_TWO_LINES);
+
+ //then - error should be thrown
+ }
+ }
+}