summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test-to-c.xsl102
1 files changed, 82 insertions, 20 deletions
diff --git a/test/test-to-c.xsl b/test/test-to-c.xsl
index 6c26730..f8d74b0 100644
--- a/test/test-to-c.xsl
+++ b/test/test-to-c.xsl
@@ -69,6 +69,11 @@ we generate an <xsl:message> reporting that the element is not known.
</xsl:template>
<xsl:template match="*[local-name() = 'test']">
+<xsl:text>#include &lt;dom/dom.h&gt;
+#include "testutils.h"
+
+</xsl:text>
+
<xsl:apply-templates select="*[local-name() = 'metadata']"/>
<xsl:text>
int main(int argc, char **argv)
@@ -82,8 +87,18 @@ int main(int argc, char **argv)
</xsl:text>
</xsl:template>
+<xsl:template match="comment()[contains(., 'Copyright')]">
+/*
+This source file was generated by test-to-c.xsl
+and is a derived work from the source document.
+The source document contained the following notice:
+
+<xsl:value-of select="."/>
+*/
+</xsl:template>
+
<xsl:template match="*[local-name() = 'metadata']">
- <xsl:text>/**
+<xsl:text>/**
</xsl:text>
<xsl:call-template name="emit-description">
<xsl:with-param name="description" select="translate(*[local-name() = 'description'], '&#9;', ' ')"/>
@@ -92,7 +107,29 @@ int main(int argc, char **argv)
</xsl:template>
<!-- swallowing templates in body mode -->
-<xsl:template match="*[local-name()='metadata']" mode="body"/>
+<xsl:template match="*[local-name() = 'metadata']" mode="body"/>
+
+<xsl:template match="*[local-name() = 'load']" mode="body">
+ <!--
+ TODO: need to handle the case where we load more than one testObject.
+ append a counter to the variable name?
+ -->
+ <xsl:text>
+ TestObject testObject = test_object_create(argc, argv, "</xsl:text><xsl:value-of select="@href"/><xsl:text>.xml", false);
+ assert(testObject != NULL);
+
+ </xsl:text><xsl:value-of select="@var"/><xsl:text> = test_object_get_doc(testObject);
+ assert(</xsl:text><xsl:value-of select="@var"/><xsl:text> != NULL);
+</xsl:text>
+</xsl:template>
+
+<!--
+not sure what <contentType> is used for,
+but it's implemented in subclasses of DOMTestDocumentBuilderFactory.getContentType()
+-->
+<xsl:template match="*[local-name() = 'contentType']" mode="body">
+ <xsl:text>strcmp(test_object_get_mimetype(testObject), "</xsl:text><xsl:value-of select="@type"/><xsl:text>") == 0</xsl:text>
+</xsl:template>
<!--
================================
@@ -113,9 +150,9 @@ Language construct templates
<xsl:text> }</xsl:text>
<xsl:for-each select="*[local-name() = 'else']">
<xsl:text> else {
- </xsl:text>
+</xsl:text>
<xsl:apply-templates mode="body"/>
- <xsl:text>}</xsl:text>
+ <xsl:text> }</xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text>
@@ -127,10 +164,6 @@ DOM templates
================================
-->
-<xsl:template match="*[local-name() = 'contentType']" mode="body">
- <xsl:text>strcmp(TODO, "</xsl:text><xsl:value-of select="@type"/><xsl:text>") == 0</xsl:text>
-</xsl:template>
-
<xsl:template name="produce-method">
<!-- TODO: implement me -->
</xsl:template>
@@ -207,22 +240,44 @@ Assert templates
</xsl:template>
<xsl:template match="*[local-name() = 'assertEquals']" mode="body">
- <!--
- TODO: this is hard, because we need to know what the types of the objects are
- that we're comparing
- -->
<xsl:variable name="actual" select="@actual"/>
<xsl:variable name="var_type" select="//*[local-name() = 'var' and @name = $actual]/@type"/>
+ <!-- implement equality test depending upon $var_type -->
<xsl:choose>
<xsl:when test="$var_type = 'DOMString'">
- <xsl:text> struct dom_string *match;
- err = dom_string_create_from_const_ptr(doc <!-- TODO: how do we obtain a handle to doc? We could lookup //var[@type = 'Document', but what if there's more than one? -->, </xsl:text><xsl:value-of select="@expected"/><xsl:text>,
+ <xsl:text>
+ struct dom_string *match;
+ struct dom_document *actualDoc;
+ err = dom_node_get_owner_document(</xsl:text><xsl:value-of select="@actual"/><xsl:text>, &amp;actualDoc);
+ assert(err == DOM_NO_ERR);
+
+ err = dom_string_create_from_const_ptr(actualDoc, </xsl:text><xsl:value-of select="@expected"/><xsl:text>,
SLEN(</xsl:text><xsl:value-of select="@expected"/><xsl:text>), &amp;match);
assert(err == DOM_NO_ERR); <!-- TODO: pull this line out, since it's reused everywhere -->
- assert(dom_string_cmp(</xsl:text><xsl:value-of select="@actual"/><xsl:text>, match) == 0); <!-- TODO: handle case insensitivity if @insensitive is set-->
+
+ assert(</xsl:text>
+ <xsl:choose>
+ <xsl:when test="@ignoreCase = 'true'">
+ <xsl:text>dom_string_icmp</xsl:text>
+ </xsl:when>
+ <xsl:when test="@ignoreCase = 'auto'">
+ <!--
+ TODO: implement auto case comparison (see java's DOMTestCase.assertEqualsAutoCase()
+ -->
+ <xsl:message>&lt;assertEquals ignoreCase='auto'&gt; not supported</xsl:message>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>dom_string_cmp</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text>(</xsl:text><xsl:value-of select="@actual"/><xsl:text>, match) == 0);
</xsl:text>
</xsl:when>
+ <xsl:when test="$var_type = 'int'">
+ <xsl:text>
+ assert(</xsl:text><xsl:value-of select="@actual"/><xsl:text> == </xsl:text><xsl:value-of select="@expected"/><xsl:text>);</xsl:text>
+ </xsl:when>
<xsl:otherwise>
<xsl:message terminate="no">Warning in assertEquals template: don't know how to compare variable type '<xsl:value-of select="$var_type"/>'</xsl:message>
</xsl:otherwise>
@@ -234,19 +289,20 @@ Assert templates
<xsl:template name="convert_var_type">
<!-- TODO: convert certain types, e.g. from DocumentType to dom_document_type -->
<xsl:param name="var_type"/>
- <xsl:text>dom_</xsl:text>
<xsl:choose>
<xsl:when test="$var_type = 'Document'">
- <xsl:text>document</xsl:text>
+ <xsl:text>dom_document</xsl:text>
</xsl:when>
<xsl:when test="$var_type = 'DocumentType'">
- <xsl:text>document_type</xsl:text>
+ <xsl:text>dom_document_type</xsl:text>
</xsl:when>
<xsl:when test="$var_type = 'DOMString'">
- <xsl:text>string</xsl:text>
+ <xsl:text>dom_string</xsl:text>
+ </xsl:when>
+ <xsl:when test="$var_type = 'Element'">
+ <xsl:text>dom_element</xsl:text>
</xsl:when>
<xsl:otherwise>
- <xsl:message terminate="no">Warning in convert_var_type template: unrecognised variable type '<xsl:value-of select="$var_type"/>'</xsl:message>
<xsl:value-of select="$var_type"/>
</xsl:otherwise>
</xsl:choose>
@@ -256,9 +312,15 @@ Assert templates
<xsl:param name="attribute_name"/>
<xsl:message><xsl:value-of select="$attribute_name"/></xsl:message>
<xsl:choose>
+ <xsl:when test="$attribute_name = 'nodeName'">
+ <xsl:text>node_name</xsl:text>
+ </xsl:when>
<xsl:when test="$attribute_name = 'nodeValue'">
<xsl:text>node_value</xsl:text>
</xsl:when>
+ <xsl:when test="$attribute_name = 'nodeType'">
+ <xsl:text>node_type</xsl:text>
+ </xsl:when>
<xsl:otherwise>
<!-- assume no conversion is needed -->
<xsl:text><xsl:value-of select="$attribute_name"/></xsl:text>