2006-10-27 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 27 Oct 2006 20:51:56 +0000 (20:51 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 27 Oct 2006 20:51:56 +0000 (20:51 -0000)
* XsltContext.cs : finally created a non-copyright-infringing test
  for bug #46751 and fixed it.

* XPathNavigatorTests.cs : added (kind of) test for bug #46751.

svn path=/trunk/mcs/; revision=67045

mcs/class/System.XML/System.Xml.Xsl/ChangeLog
mcs/class/System.XML/System.Xml.Xsl/XsltContext.cs
mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog
mcs/class/System.XML/Test/System.Xml.XPath/XPathNavigatorTests.cs

index 08d3246933290e4637ebf3166dd24df8397d6e5f..03c49bf2101568268276198f137612cef655893b 100644 (file)
@@ -1,3 +1,8 @@
+2006-10-27  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XsltContext.cs : finally created a non-copyright-infringing test
+         for bug #46751 and fixed it.
+
 2006-07-06  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XslCompiledTransform.cs : making stub more complete :|
index 126b432376b0611f35239f1dc236f1d3c001cb6b..5dbdef680b15a256c68e268f3416931755c1049d 100644 (file)
@@ -74,7 +74,7 @@ namespace System.Xml.Xsl
                \r
                internal virtual IXsltContextVariable ResolveVariable (XmlQualifiedName name)\r
                {\r
-                       return ResolveVariable (name.Name, name.Namespace);\r
+                       return ResolveVariable (LookupPrefix (name.Namespace), name.Name);\r
                }\r
                \r
                internal virtual IXsltContextFunction ResolveFunction (XmlQualifiedName name, XPathResultType [] argTypes)\r
index cc97397dae9c5f5e13bf4e5950dbbd6ae0b4a6cc..2a2f4aa8d269c8fc31d72ee7a947cfb6bfc3c4a6 100644 (file)
@@ -1,3 +1,7 @@
+2006-10-27  Atsushi Enomoto <atsushi@ximian.com>
+
+       * XPathNavigatorTests.cs : added (kind of) test for bug #46751.
+
 2006-10-11  Atsushi Enomoto <atsushi@ximian.com>
 
        * XPathEditableNavigatorTests.cs : added test for CanEdit, based on
index 484012241ba04f5ea9a06eb8be2d86005d4f216b..8373e7c3c6c44bb115c0a39dd3cb1275c3b51395 100644 (file)
@@ -13,6 +13,7 @@ using System;
 using System.IO;
 using System.Xml;
 using System.Xml.XPath;
+using System.Xml.Xsl;
 
 using NUnit.Framework;
 
@@ -284,6 +285,128 @@ namespace MonoTests.System.Xml
                                nav.NodeType);
                }
 
+               [Test]
+               public void VariableReference ()
+               {
+                       XPathDocument xpd = new XPathDocument (
+                               new StringReader ("<root>sample text</root>"));
+                       XPathNavigator nav = xpd.CreateNavigator ();
+
+                       XPathExpression expr = nav.Compile ("foo(string(.),$idx)");
+                       XsltArgumentList args = new XsltArgumentList ();
+                       args.AddParam ("idx", "", 5);
+                       MyContext ctx = new MyContext (nav.NameTable as NameTable, args);
+                       ctx.AddNamespace ("x", "urn:foo");
+
+                       expr.SetContext (ctx);
+
+                       XPathNodeIterator iter = nav.Select ("/root");
+                       iter.MoveNext ();
+                       AssertEquals ("e", iter.Current.Evaluate (expr));
+               }
+
+               class MyContext : XsltContext
+               {
+                       XsltArgumentList args;
+
+                       public MyContext (NameTable nt, XsltArgumentList args)
+                               : base (nt)
+                       {
+                               this.args = args;
+                       }
+
+                       public override IXsltContextFunction ResolveFunction (
+                               string prefix, string name, XPathResultType [] argtypes)
+                       {
+                               if (name == "foo")
+                                       return new MyFunction (argtypes);
+                               return null;
+                       }
+
+                       public override IXsltContextVariable ResolveVariable (string prefix, string name)
+                       {
+                               return new MyVariable (name);
+                       }
+
+                       public override bool PreserveWhitespace (XPathNavigator nav)
+                       {
+                               return false;
+                       }
+
+                       public override int CompareDocument (string uri1, string uri2)
+                       {
+                               return String.CompareOrdinal (uri1, uri2);
+                       }
+
+                       public override bool Whitespace {
+                               get { return false; }
+                       }
+
+                       public object GetParam (string name, string ns)
+                       {
+                               return args.GetParam (name, ns);
+                       }
+               }
+
+               public class MyFunction : IXsltContextFunction
+               {
+                       XPathResultType [] argtypes;
+
+                       public MyFunction (XPathResultType [] argtypes)
+                       {
+                               this.argtypes = argtypes;
+                       }
+
+                       public XPathResultType [] ArgTypes {
+                               get { return argtypes; }
+                       }
+
+                       public int Maxargs {
+                               get { return 2; }
+                       }
+
+                       public int Minargs {
+                               get { return 2; }
+                       }
+
+                       public XPathResultType ReturnType {
+                               get { return XPathResultType.String; }
+                       }
+
+                       public object Invoke (XsltContext xsltContext,
+                               object [] args, XPathNavigator instanceContext)
+                       {
+                               return ((string) args [0]) [(int) (double) args [1]].ToString ();
+                       }
+               }
+
+               public class MyVariable : IXsltContextVariable
+               {
+                       string name;
+
+                       public MyVariable (string name)
+                       {
+                               this.name = name;
+                       }
+
+                       public object Evaluate (XsltContext ctx)
+                       {
+                               return ((MyContext) ctx).GetParam (name, String.Empty);
+                       }
+
+                       public bool IsLocal {
+                               get { return false; }
+                       }
+
+                       public bool IsParam {
+                               get { return false; }
+                       }
+
+                       public XPathResultType VariableType {
+                               get { return XPathResultType.Any; }
+                       }
+               }
+
 #if NET_2_0
                [Test]
                public void ValueAsBoolean ()