2004-03-24 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.XML / Test / System.Xml.Xsl / XslTransformTests.cs
1 //
2 // System.Xml.Xsl.XslTransformTests.cs
3 //
4 // Author:
5 //   Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
6 //
7 // (C) 2002 Atsushi Enomoto
8 //
9
10 using System;
11 using System.Xml;
12 using System.Xml.XPath;
13 using System.Xml.Xsl;
14 using NUnit.Framework;
15
16 namespace MonoTests.System.Xml.Xsl
17 {
18         [TestFixture]
19         public class XslTransformTests : Assertion
20         {
21                 XmlDocument doc;
22                 XslTransform xslt;
23                 XmlDocument result;
24
25                 [SetUp]
26                 public void GetReady()
27                 {
28                         doc = new XmlDocument ();
29                         xslt = new XslTransform ();
30                         result = new XmlDocument ();
31                 }
32
33                 [Test]
34                 public void TestBasicTransform ()
35                 {
36                         doc.LoadXml ("<root/>");
37                         xslt.Load ("Test/XmlFiles/xsl/empty.xsl");
38                         xslt.Transform ("Test/XmlFiles/xsl/empty.xsl", "Test/XmlFiles/xsl/result.xml");
39                         result.Load ("Test/XmlFiles/xsl/result.xml");
40                         AssertEquals ("count", 2, result.ChildNodes.Count);
41                 }
42
43                 [Test]
44                 [ExpectedException (typeof (XsltCompileException))]
45                 public void InvalidStylesheet ()
46                 {
47                         XmlDocument doc = new XmlDocument ();
48                         doc.LoadXml ("<xsl:element xmlns:xsl='http://www.w3.org/1999/XSL/Transform' />");
49                         XslTransform t = new XslTransform ();
50                         t.Load (doc);
51                 }
52
53                 [Test]
54                 [ExpectedException (typeof (XsltCompileException))]
55                 public void EmptyStylesheet ()
56                 {
57                         XmlDocument doc = new XmlDocument ();
58                         XslTransform t = new XslTransform ();
59                         t.Load (doc);
60                 }
61
62                 [Test]
63                 [ExpectedException (typeof (XsltCompileException))]
64                 public void InvalidStylesheet2 ()
65                 {
66                         string xml = @"<root>text</root>";
67                         string xsl = @"<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
68         <xsl:template match='/root'>
69                 <xsl:call-template name='foo'>
70                         <xsl:with-param name='name' value='text()' />
71                 </xsl:call-template>
72         </xsl:template>
73         <xsl:template name='foo'>
74                 <xsl:param name='name' />
75                 <result>
76                         <xsl:if test='1'>
77                                 <xsl:variable name='last' value='text()' />
78                                 <xsl:value-of select='$last' />
79                         </xsl:if>
80                 </result>
81         </xsl:template>
82 </xsl:stylesheet>
83 ";
84                         XslTransform xslt = new XslTransform ();
85                         xslt.Load (new XPathDocument (new XmlTextReader (xsl, XmlNodeType.Document, null)));
86                 }
87
88         }
89 }