summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJames Shaw <jshaw@netsurf-browser.org>2007-07-21 16:28:14 +0000
committerJames Shaw <jshaw@netsurf-browser.org>2007-07-21 16:28:14 +0000
commitb375addd8ce9048e0c85ddcd34276a81145ddd7d (patch)
tree1ad1d0ac336a2ba08fa20c8bb34c72a12d200060 /test
parent0bd7e6290e4d185e08bc9c3b3b4956280164e31d (diff)
downloadlibdom-b375addd8ce9048e0c85ddcd34276a81145ddd7d.tar.gz
libdom-b375addd8ce9048e0c85ddcd34276a81145ddd7d.tar.bz2
Add cast for attribute result variable
svn path=/trunk/dom/; revision=3451
Diffstat (limited to 'test')
-rw-r--r--test/transform/test-to-c.xsl100
-rw-r--r--test/xml/documentcreateelement.xml44
2 files changed, 128 insertions, 16 deletions
diff --git a/test/transform/test-to-c.xsl b/test/transform/test-to-c.xsl
index 469633b..d5d59f3 100644
--- a/test/transform/test-to-c.xsl
+++ b/test/transform/test-to-c.xsl
@@ -140,8 +140,11 @@ Language construct templates
-->
<xsl:template match="*[local-name() = 'var']" mode="body">
-<xsl:text> struct </xsl:text><xsl:call-template name="convert_var_type"> <xsl:with-param name="var_type" select="@type"/>
-</xsl:call-template> *<xsl:value-of select="@name"/>;
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="convert_var_declaration">
+ <xsl:with-param name="var_type" select="@type"/>
+ </xsl:call-template>
+ <xsl:value-of select="@name"/>;
</xsl:template>
<xsl:template match="*[local-name() = 'if']" mode="body">
@@ -191,17 +194,18 @@ DOM templates
<xsl:param name="method"/>
<xsl:variable name="current" select="."/>
<xsl:variable name="obj" select="@obj"/>
- <!--<xsl:variable name="var" select="@var"/>-->
+ <xsl:variable name="var" select="//*[local-name() = 'var' and @name = $obj]"/>
<xsl:text> </xsl:text>
<xsl:call-template name="convert_method_name">
- <xsl:with-param name="method_target"><xsl:value-of select="//*[local-name() = 'var' and @name = $obj]/@type"/></xsl:with-param>
+ <xsl:with-param name="method_target"><xsl:value-of select="$var/@type"/></xsl:with-param>
<xsl:with-param name="method_name"><xsl:value-of select="$method/@name"/></xsl:with-param>
</xsl:call-template>
<xsl:text>(</xsl:text><xsl:value-of select="@obj"/>
<xsl:for-each select="$method/parameters/param">
<xsl:variable name="paramDef" select="."/>
- <xsl:text>, </xsl:text><xsl:value-of select="$current/@*[name() = $paramDef/@name]"/>
+ <xsl:text>, </xsl:text>
+ <xsl:value-of select="$current/@*[name() = $paramDef/@name]"/>
</xsl:for-each>
<xsl:if test="@var">
<xsl:text>, &amp;</xsl:text><xsl:value-of select="@var"/>
@@ -233,8 +237,9 @@ DOM templates
<xsl:template name="produce-specific-attribute">
<!-- <xsl:param name="vardefs"/> -->
<xsl:param name="attribute"/>
- <xsl:variable name="obj" select="@obj"/>
+ <xsl:variable name="obj" select="@obj"/>
<xsl:variable name="value" select="@value"/>
+ <xsl:variable name="var" select="@var"/>
<xsl:variable name="obj_type" select="//*[local-name() = 'var' and @name = $obj]/@type"/>
<xsl:variable name="interface_type" select="$domspec/library/interface[attribute = $attribute]/@name"/>
<!-- check if attribute name starts with is -->
@@ -257,15 +262,20 @@ DOM templates
</xsl:call-template>
<xsl:text>(</xsl:text>
<!-- cast to target interface if this is different from the type of the variable @obj -->
- <xsl:if test="$obj_type != $interface_type">
- <xsl:text>(struct </xsl:text>
- <xsl:call-template name="convert_var_type">
- <xsl:with-param name="var_type"><xsl:value-of select="$interface_type"/></xsl:with-param>
- </xsl:call-template>
- <xsl:text> *) </xsl:text>
- </xsl:if>
- <!-- TODO: cast to the type expected by the interface if necessary -->
- <xsl:value-of select="@obj"/><xsl:text>, &amp;</xsl:text><xsl:value-of select="@var"/>
+ <xsl:call-template name="cast">
+ <xsl:with-param name="vartype" select="$obj_type"/>
+ <xsl:with-param name="reqtype" select="$interface_type"/>
+ </xsl:call-template>
+ <xsl:value-of select="@obj"/>
+ <xsl:text>, </xsl:text>
+ <!-- TODO: cast the result to the that expected by the function
+ e.g. int nodeType; dom_node_get_node_type(node, (dom_node_type *) &nodeType);
+ -->
+ <xsl:call-template name="attribute-result-cast">
+ <xsl:with-param name="vartype" select="//*[local-name() = 'var' and @name = $var]/@type"/>
+ <xsl:with-param name="attribute" select="$attribute"/>
+ </xsl:call-template>
+ <xsl:text>&amp;</xsl:text><xsl:value-of select="@var"/>
<xsl:text>);
assert(err == DOM_NO_ERR);
</xsl:text>
@@ -273,6 +283,39 @@ DOM templates
</xsl:if>
</xsl:template>
+<xsl:template name="cast">
+ <xsl:param name="vartype"/>
+ <xsl:param name="reqtype"/>
+ <xsl:choose>
+ <xsl:when test="$vartype = $reqtype">
+
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>(</xsl:text>
+ <xsl:call-template name="convert_var_declaration">
+ <xsl:with-param name="var_type"><xsl:value-of select="$reqtype"/></xsl:with-param>
+ </xsl:call-template>
+ <xsl:text>) </xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="attribute-result-cast">
+ <!-- the type of the target result variable, as defined by <var @type> -->
+ <xsl:param name="vartype"/>
+ <!-- an <attribute> from the $domspec -->
+ <xsl:param name="attribute"/>
+ <xsl:choose>
+ <xsl:when test="$attribute/@name = 'nodeType'">
+ <xsl:text>(</xsl:text>
+ <xsl:call-template name="convert_var_declaration">
+ <xsl:with-param name="var_type" select="'NodeType'"/>
+ </xsl:call-template>
+ <xsl:text>) </xsl:text>
+ </xsl:when>
+ </xsl:choose>
+</xsl:template>
+
<!--
================================
@@ -346,6 +389,28 @@ Assert templates
<!-- helper templates -->
+<xsl:template name="convert_var_declaration">
+ <xsl:param name="var_type"/>
+ <!-- TODO: move these definitions out to a separate XML file -->
+ <xsl:variable name="is_struct" select="$var_type != 'int' and $var_type != 'NodeType'"/>
+ <xsl:variable name="is_pointer" select="$var_type != 'int'"/>
+ <xsl:message>is_struct <xsl:value-of select="$is_struct"/></xsl:message>
+ <xsl:if test="$is_struct">
+ <xsl:text>struct </xsl:text>
+ </xsl:if>
+ <xsl:call-template name="convert_var_type">
+ <xsl:with-param name="var_type" select="$var_type"/>
+ </xsl:call-template>
+ <xsl:text> </xsl:text>
+ <xsl:if test="$is_pointer">
+ <xsl:text>*</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<!--
+Convert a variable type to its equivalent C name. C names are lower case
+separated by underscores.
+-->
<xsl:template name="convert_var_type">
<!-- TODO: convert certain types, e.g. from DocumentType to dom_document_type -->
<xsl:param name="var_type"/>
@@ -365,6 +430,9 @@ Assert templates
<xsl:when test="$var_type = 'Node'">
<xsl:text>dom_node</xsl:text>
</xsl:when>
+ <xsl:when test="$var_type = 'NodeType'">
+ <xsl:text>dom_node_type</xsl:text>
+ </xsl:when>
<xsl:otherwise>
<xsl:value-of select="$var_type"/>
</xsl:otherwise>
@@ -398,7 +466,7 @@ For example, dom_document_create_element
<xsl:template name="convert_method_name">
<xsl:param name="method_target"/>
<xsl:param name="method_name"/>
- <xsl:message><xsl:value-of select="$method_name"/></xsl:message>
+
<xsl:call-template name="convert_var_type">
<xsl:with-param name="var_type"><xsl:value-of select="$method_target"/></xsl:with-param>
</xsl:call-template>
diff --git a/test/xml/documentcreateelement.xml b/test/xml/documentcreateelement.xml
new file mode 100644
index 0000000..9139ad2
--- /dev/null
+++ b/test/xml/documentcreateelement.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2001 World Wide Web Consortium,
+(Massachusetts Institute of Technology, Institut National de
+Recherche en Informatique et en Automatique, Keio University). All
+Rights Reserved. This program is distributed under the W3C's Software
+Intellectual Property License. This program is distributed in the
+hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+PURPOSE.
+See W3C License http://www.w3.org/Consortium/Legal/ for more details.
+--><!DOCTYPE test SYSTEM "dom1.dtd">
+
+<test xmlns="http://www.w3.org/2001/DOM-Test-Suite/Level-1" name="documentcreateelement">
+<metadata>
+<title>documentCreateElement</title>
+<creator>NIST</creator>
+<description>
+ The "createElement(tagName)" method creates an Element
+ of the type specified.
+ Retrieve the entire DOM document and invoke its
+ "createElement(tagName)" method with tagName="address".
+ The method should create an instance of an Element node
+ whose tagName is "address". The NodeName, NodeType
+ and NodeValue are returned.
+</description>
+<contributor>Mary Brady</contributor>
+<date qualifier="created">2001-08-17</date>
+<subject resource="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-2141741547"/>
+</metadata>
+<var name="doc" type="Document"/>
+<var name="newElement" type="Element"/>
+<var name="newElementName" type="DOMString"/>
+<var name="newElementType" type="int"/>
+<var name="newElementValue" type="DOMString"/>
+<load var="doc" href="staff" willBeModified="true"/>
+<createElement obj="doc" var="newElement" tagName="&quot;address&quot;"/>
+<nodeName obj="newElement" var="newElementName"/>
+<assertEquals actual="newElementName" expected="&quot;address&quot;" ignoreCase="false" id="name"/>
+<nodeType obj="newElement" var="newElementType"/>
+<assertEquals actual="newElementType" expected="1" ignoreCase="false" id="type"/>
+<nodeValue obj="newElement" var="newElementValue"/>
+<assertNull actual="newElementValue" id="valueInitiallyNull"/>
+</test>