You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by mi...@apache.org on 2016/06/18 15:56:50 UTC
[1/2] git commit: [flex-tlf] [refs/heads/develop] - FLEX-35100 Unit
testing my assumptions of TextBlock.createTextLine() and
TextBlock.recreateTextLine().
Repository: flex-tlf
Updated Branches:
refs/heads/develop 3ce6a7b71 -> cb2794edb
FLEX-35100
Unit testing my assumptions of TextBlock.createTextLine() and TextBlock.recreateTextLine().
Project: http://git-wip-us.apache.org/repos/asf/flex-tlf/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-tlf/commit/9526d456
Tree: http://git-wip-us.apache.org/repos/asf/flex-tlf/tree/9526d456
Diff: http://git-wip-us.apache.org/repos/asf/flex-tlf/diff/9526d456
Branch: refs/heads/develop
Commit: 9526d4561fe8c83733adc74622ef9bfca36443d3
Parents: 3ce6a7b
Author: Mihai Chira <mi...@apache.org>
Authored: Sat Jun 18 16:25:27 2016 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Sat Jun 18 16:25:27 2016 +0200
----------------------------------------------------------------------
automation_tests/src/AllTestsSuite.as | 2 +
.../UnitTest/Tests/TextBlock_FLEX_35100_Test.as | 378 +++++++++++++++++++
2 files changed, 380 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/9526d456/automation_tests/src/AllTestsSuite.as
----------------------------------------------------------------------
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 @@ package
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 @@ package
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;
}
}
http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/9526d456/automation_tests/src/UnitTest/Tests/TextBlock_FLEX_35100_Test.as
----------------------------------------------------------------------
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
+ }
+ }
+}
[2/2] git commit: [flex-tlf] [refs/heads/develop] - FLEX-35100 CAUSE:
TextBlock.createTextLine() orTextBlock.recreateTextLine() return null when
there's no more text to create lines for (as indicated by the previousLine
parameter) or the TextBlock's cont
Posted by mi...@apache.org.
FLEX-35100
CAUSE: TextBlock.createTextLine() orTextBlock.recreateTextLine() return null when there's no more text to create lines for (as indicated by the previousLine parameter) or the TextBlock's content's text is null or "". (It's also possible when the width parameter is insufficient, but in this case the fitSomething parameter is true, which excludes this case).
SOLUTION: Added a null check for textLine.
Project: http://git-wip-us.apache.org/repos/asf/flex-tlf/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-tlf/commit/cb2794ed
Tree: http://git-wip-us.apache.org/repos/asf/flex-tlf/tree/cb2794ed
Diff: http://git-wip-us.apache.org/repos/asf/flex-tlf/diff/cb2794ed
Branch: refs/heads/develop
Commit: cb2794edbda69257b9660132d27931220049a355
Parents: 9526d45
Author: Mihai Chira <mi...@apache.org>
Authored: Sat Jun 18 16:37:17 2016 +0200
Committer: Mihai Chira <mi...@apache.org>
Committed: Sat Jun 18 16:37:17 2016 +0200
----------------------------------------------------------------------
textLayout/src/flashx/textLayout/compose/TextFlowLine.as | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/cb2794ed/textLayout/src/flashx/textLayout/compose/TextFlowLine.as
----------------------------------------------------------------------
diff --git a/textLayout/src/flashx/textLayout/compose/TextFlowLine.as b/textLayout/src/flashx/textLayout/compose/TextFlowLine.as
index c3c73f0..dbc935c 100644
--- a/textLayout/src/flashx/textLayout/compose/TextFlowLine.as
+++ b/textLayout/src/flashx/textLayout/compose/TextFlowLine.as
@@ -933,7 +933,10 @@ package flashx.textLayout.compose
}
else
textLine = swfContext.callInContext(textBlock.createTextLine, textBlock, [ previousLine, _targetWidth, effLineOffset, true ]);
-
+
+ if(textLine == null)
+ return null;
+
textLine.x = this.x;
CONFIG::debug { Debugging.traceFTEAssign(textLine,"x", this.x); }
textLine.y = createShapeY(bp);