Permalink
Browse files

Falcon tests: Added some functional tests for the <XMLList> tag.

Added one test and fixed a bug related to <XML format="xml"> tag, which produces an XMLNode. However, there is an XML namespace issue preventing the test from passing (because when the tag gets converted into an XML string Falcon is adding empty namespace attributes that the old compiler didn't) so this test is marked @Ignore.

git-svn-id: https://svn.apache.org/repos/asf/incubator/flex/falcon/trunk@1425203 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 3a3b72c commit 6bb5658d91a5045f8ecb7e49892ddfde0435057f Gordon Smith committed Dec 21, 2012
@@ -0,0 +1,156 @@
+/*
+ *
+ * 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 mxml.tags;
+
+import org.junit.Test;
+
+/**
+ * Feature tests for the MXML {@code <XMLList>} tag.
+ *
+ * @author Gordon Smith
+ */
+public class MXMLXMLListTagTests extends MXMLInstanceTagTestsBase
+{
+ @Test
+ public void MXMLXMLListTag_empty()
+ {
+ String[] declarations = new String[]
+ {
+ "<fx:XMLList id='x1'>",
+ "</fx:XMLList>"
+ };
+ String[] asserts = new String[]
+ {
+ // An empty tag produces an XMLList with length 0.
+ "assertEqual('x1 is XMLList', x1 is XMLList, true);",
+ "assertEqual('x1.length()', x1.length(), 0);",
+ };
+ String mxml = getMXML(declarations, asserts);
+ compileAndRun(mxml);
+ }
+
+ @Test
+ public void MXMLXMLListTag_oneEmptyTag()
+ {
+ String[] declarations = new String[]
+ {
+ "<fx:XMLList id='x1' xmlns=''>",
+ " <aaa/>",
+ "</fx:XMLList>"
+ };
+ String[] asserts = new String[]
+ {
+ "assertEqual('x1 is XMLList', x1 is XMLList, true);",
+ "assertEqual('x1.length()', x1.length(), 1);",
+ "assertEqual('x1[0].nodeKind()', x1[0].nodeKind(), 'element');",
+ "assertEqual('x1[0].localName()', x1[0].localName(), 'aaa');",
+ "assertEqual('x1[0].namespace().uri', x1[0].namespace().uri, '');",
+ "assertEqual('x1[0].attributes().length()', x1[0].attributes().length(), 0);",
+ "assertEqual('x1[0].children().length()', x1[0].children().length(), 0);",
+
+ };
+ String mxml = getMXML(declarations, asserts);
+ compileAndRun(mxml);
+ }
+
+ @Test
+ public void MXMLXMLListTag_twoEmptyTags()
+ {
+ String[] declarations = new String[]
+ {
+ "<fx:XMLList id='x1' xmlns=''>",
+ " <aaa/>",
+ " <aaa/>",
+ "</fx:XMLList>"
+ };
+ String[] asserts = new String[]
+ {
+ "assertEqual('x1 is XMLList', x1 is XMLList, true);",
+ "assertEqual('x1.length()', x1.length(), 2);",
+ "assertEqual('x1[0].nodeKind()', x1[0].nodeKind(), 'element');",
+ "assertEqual('x1[0].localName()', x1[0].localName(), 'aaa');",
+ "assertEqual('x1[0].namespace().uri', x1[0].namespace().uri, '');",
+ "assertEqual('x1[0].attribute().length()', x1[0].attributes().length(), 0);",
+ "assertEqual('x1[0].children().length()', x1[0].children().length(), 0);",
+ "assertEqual('x1[1].nodeKind()', x1[1].nodeKind(), 'element');",
+ "assertEqual('x1[1].localName()', x1[1].localName(), 'aaa');",
+ "assertEqual('x1[1].namespace().uri', x1[1].namespace().uri, '');",
+ "assertEqual('x1[1].attributes().length', x1[1].attributes().length(), 0);",
+ "assertEqual('x1[1].children().length()', x1[1].children().length(), 0);",
+
+ };
+ String mxml = getMXML(declarations, asserts);
+ compileAndRun(mxml);
+ }
+
+ @Test
+ public void MXMLXMLListTag_oneTagWithAttributes()
+ {
+ String[] declarations = new String[]
+ {
+ "<fx:XMLList id='x1' xmlns=''>",
+ " <aaa a='1' b='2'/>",
+ "</fx:XMLList>"
+ };
+ String[] asserts = new String[]
+ {
+ "assertEqual('x1 is XMLList', x1 is XMLList, true);",
+ "assertEqual('x1.length()', x1.length(), 1);",
+ "assertEqual('x1[0].nodeKind()', x1[0].nodeKind(), 'element');",
+ "assertEqual('x1[0].localName()', x1[0].localName(), 'aaa');",
+ "assertEqual('x1[0].namespace().uri', x1[0].namespace().uri, '');",
+ "assertEqual('x1[0].attributes().length()', x1[0].attributes().length(), 2);",
+ "assertEqual('x1[0].@a.toString()', x1[0].@a.toString(), '1');",
+ "assertEqual('x1[0].@b.toString()', x1[0].@b.toString(), '2');",
+ "assertEqual('x1[0].children().length()', x1[0].children().length(), 0);"
+ };
+ String mxml = getMXML(declarations, asserts);
+ compileAndRun(mxml);
+ }
+
+ @Test
+ public void MXMLXMLListTag_oneTagWithChildren()
+ {
+ String[] declarations = new String[]
+ {
+ "<fx:XMLList id='x1' xmlns=''>",
+ " <aaa>",
+ " <bbb>xxx</bbb>",
+ " <bbb>yyy</bbb>",
+ " </aaa>",
+ "</fx:XMLList>"
+ };
+ String[] asserts = new String[]
+ {
+ "assertEqual('x1 is XMLList', x1 is XMLList, true);",
+ "assertEqual('x1.length()', x1.length(), 1);",
+ "assertEqual('x1[0].nodeKind()', x1[0].nodeKind(), 'element');",
+ "assertEqual('x1[0].localName()', x1[0].localName(), 'aaa');",
+ "assertEqual('x1[0].namespace().uri', x1[0].namespace().uri, '');",
+ "assertEqual('x1[0].attributes().length()', x1[0].attributes().length(), 0);",
+ "assertEqual('x1[0].children().length()', x1[0].children().length(), 2);",
+ "assertEqual('x1[0].bbb[0].toString()', x1[0].bbb[0].toString(), 'xxx');",
+ "assertEqual('x1[0].bbb[1].toString()', x1[0].bbb[1].toString(), 'yyy');"
+
+ };
+ String mxml = getMXML(declarations, asserts);
+ compileAndRun(mxml);
+ }
+}
@@ -19,6 +19,7 @@
package mxml.tags;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -28,8 +29,27 @@
*/
public class MXMLXMLTagTests extends MXMLInstanceTagTestsBase
{
+ // This <Script> function is used by some of the asserts in the tests below
+ // to count the number of properties of an <Object>.
+ private static String[] scriptDeclarations = new String[]
+ {
+ "private function countProperties(o:Object):int",
+ "{",
+ " var count:int = 0;",
+ " for (var p:String in o)",
+ " {",
+ " count++;",
+ " }",
+ " return count;",
+ "}"
+ };
+
+ //
+ // These tests are for XML tags with an implicit format="e4x"
+ //
+
@Test
- public void MXMLXMLTag_empty()
+ public void MXMLXMLTag_formatE4X_empty()
{
String[] declarations = new String[]
{
@@ -45,7 +65,7 @@ public void MXMLXMLTag_empty()
}
@Test
- public void MXMLXMLTag_emptyRootTag()
+ public void MXMLXMLTag_formatE4X_emptyRootTag()
{
String[] declarations = new String[]
{
@@ -62,7 +82,7 @@ public void MXMLXMLTag_emptyRootTag()
}
@Test
- public void MXMLXMLTag_oneTagWithText()
+ public void MXMLXMLTag_formatE4X_oneTagWithText()
{
String[] declarations = new String[]
{
@@ -82,7 +102,7 @@ public void MXMLXMLTag_oneTagWithText()
}
@Test
- public void MXMLXMLTag_oneTagWithAttributes()
+ public void MXMLXMLTag_formatE4X_oneTagWithAttributes()
{
String[] declarations = new String[]
{
@@ -103,7 +123,7 @@ public void MXMLXMLTag_oneTagWithAttributes()
}
@Test
- public void MXMLXMLTag_oneTagWithTwoChildTags()
+ public void MXMLXMLTag_formatE4X_oneTagWithTwoChildTags()
{
String[] declarations = new String[]
{
@@ -125,4 +145,38 @@ public void MXMLXMLTag_oneTagWithTwoChildTags()
String mxml = getMXML(declarations, asserts);
compileAndRun(mxml);
}
+
+ //
+ // These tests are for XML tags with format="xml",
+ // which produce a tree of XMLNode objects.
+ // These tests have to be compiled against framework.swc
+ // in order to get the mx.utils.XMLUtils class.
+ //
+
+ // This test seems to be failing because our xmlString is
+ // <root xmlns=""/>
+ // while the old compiler's was
+ // <root/>
+ @Ignore
+ @Test
+ public void MXMLXMLTag_formatXML_emptyRootTag()
+ {
+ String[] declarations = new String[]
+ {
+ "<fx:XML id='x1' xmlns='' format='xml'>",
+ " <root/>",
+ "</fx:XML>"
+ };
+ String[] asserts = new String[]
+ {
+ "assertEqual('x1 is XMLNode', x1 is XMLNode, true);",
+ "trace(x1.localName === null);",
+ "assertEqual('x1.localName', x1.localName, 'root');",
+ "assertEqual('x1.namespaceURI', x1.namespaceURI, null);",
+ "assertEqual('countProperties(x1.attributes)', countProperties(x1.attributes), 0);",
+ "assertEqual('x1.childNodes.length', x1.childNodes.length, 0);"
+ };
+ String mxml = getMXML(declarations, scriptDeclarations, asserts);
+ compileAndRun(mxml, true, false, false, null);
+ }
}
@@ -4225,16 +4225,19 @@ private void processMXMLXML(IMXMLXMLNode node, Context context)
}
else if (node.getXMLType() == IMXMLXMLNode.XML_TYPE.E4X)
{
+ // new XML(xmlString);
context.addInstruction(OP_findpropstrict, ABCGeneratingReducer.xmlType);
context.addInstruction(OP_pushstring, xmlString);
context.addInstruction(OP_constructprop, new Object[] { ABCGeneratingReducer.xmlType, 1 });
}
else if (node.getXMLType() == IMXMLXMLNode.XML_TYPE.OLDXML)
{
+ // mx.utils.XMLUtil.createXMLDocument(xmlString).firstChild
FlexProject flexProject = (FlexProject)getProject();
context.addInstruction(OP_getlex, flexProject.getXMLUtilClassName());
context.addInstruction(OP_pushstring, node.getXMLString());
context.addInstruction(OP_callproperty, CREATE_XML_DOCUMENT_CALL_OPERANDS);
+ context.addInstruction(OP_getproperty, new Name("firstChild"));
}
// Traverse the children - these will be any MXMLBindingNode that were created for

0 comments on commit 6bb5658

Please sign in to comment.