+2008-03-31 Jonathan Pobst <monkey@jpobst.com>
+
+ * ToolBar.cs: Don't do our painting if UserPaint is set. If UserPaint
+ isn't set, don't call OnPaint. [Fixes bug #375300]
+
2008-03-30 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* BindingSource.cs: IsBindingSuspended, ResumeBinding and
internal override void OnPaintInternal (PaintEventArgs pevent)
{
+ if (GetStyle (ControlStyles.UserPaint))
+ return;
+
ThemeEngine.Current.DrawToolBar (pevent.Graphics, pevent.ClipRectangle, this);
+
+ // Toolbars do not raise OnPaint unless UserPaint is set
+ pevent.Handled = true;
}
internal void Redraw (bool recalculate)
+2008-03-31 Veerapuram Varadhan <vvaradhan@novell.com>
+
+ * DataView.cs: Reverting rev#98474 changes - as it broke quite a
+ few test profiles.
+
2008-03-23 Gert Driesen <drieseng@users.sourceforge.net>
* DataSet.cs: Corcompare fix.
/* ItemDeleted */\r
int newIndex;\r
newIndex = IndexOf (args.Row);\r
- if (Index != null)\r
- Index.Delete (args.Row);\r
+ UpdateIndex (true);\r
OnListChanged (new ListChangedEventArgs (ListChangedType.ItemDeleted, newIndex, -1));\r
}\r
\r
+2008-04-01 Marek Habersack <mhabersack@novell.com>
+
+ * HostingEnvironment.cs: initialize custom VPP on
+ registration.
+ Added an internal boolena property to signal if we're using a
+ custom VPP or not (HaveCustomVPP)
+
+2008-03-31 Marek Habersack <mhabersack@novell.com>
+
+ * VirtualPathProvider.cs: internal SetPrevious method renamed to
+ InitializeAndSetPrevious.
+
2008-03-27 Marek Habersack <mhabersack@novell.com>
* DefaultVirtualPathProvider.cs: support relative virtual paths in
new DefaultVirtualPathProvider ();
static int busy_count;
+ internal static bool HaveCustomVPP {
+ get;
+ private set;
+ }
+
public HostingEnvironment ()
{
// The documentation says that this is called once per domain by the ApplicationManager and
if (virtualPathProvider == null)
throw new ArgumentNullException ("virtualPathProvider");
- virtualPathProvider.SetPrevious (vpath_provider);
+ VirtualPathProvider previous = vpath_provider;
vpath_provider = virtualPathProvider;
+ vpath_provider.InitializeAndSetPrevious (previous);
+ if (!(virtualPathProvider is DefaultVirtualPathProvider))
+ HaveCustomVPP = true;
+ else
+ HaveCustomVPP = false;
}
public static IDisposable SetCultures (string virtualPath)
{
}
- internal void SetPrevious (VirtualPathProvider prev)
- {
- this.prev = prev;
- }
-
protected internal VirtualPathProvider Previous {
get { return prev; }
}
{
}
+ internal void InitializeAndSetPrevious (VirtualPathProvider prev)
+ {
+ Console.WriteLine ("{0}.InitializeAndSetPrevious ({1})", this, prev);
+ this.prev = prev;
+ Console.WriteLine ("\tprevious chain:");
+
+ VirtualPathProvider p = this.prev;
+ while (p != null) {
+ Console.WriteLine ("\t\t{0}", p);
+ p = p.Previous;
+ }
+
+ Initialize ();
+ }
+
public virtual string CombineVirtualPaths (string basePath, string relativePath)
{
return VirtualPathUtility.Combine (basePath, relativePath);
+2008-03-31 Marek Habersack <mhabersack@novell.com>
+
+ * StaticFileHandler.cs: added code to use custom
+ VirtualPathProvider, if present, to serve files from virtual
+ storage.
+
+ * HttpResponse.cs: added two internal TransmitFile overloads which
+ take a VirtualFile as a parameter.
+
2008-03-27 Marek Habersack <mhabersack@novell.com>
* HttpRequest.cs: make UrlComponents internal.
using System.Web.Configuration;
using System.Globalization;
using System.Security.Permissions;
+using System.Web.Hosting;
namespace System.Web {
output_stream.ApplyFilter (final_flush);
Flush (final_flush);
}
-
+#if NET_2_0
+ internal void TransmitFile (VirtualFile vf)
+ {
+ TransmitFile (vf, false);
+ }
+
+ internal void TransmitFile (VirtualFile vf, bool final_flush)
+ {
+ if (vf == null)
+ throw new ArgumentNullException ("vf");
+
+ using (Stream s = vf.Open ()) {
+ long len = s.Length;
+ byte[] buf = new byte [len];
+ int readBytes = s.Read (buf, 0, (int) len);
+ output_stream.Write (buf, 0, readBytes);
+ output_stream.ApplyFilter (final_flush);
+ Flush (final_flush);
+ }
+ }
+#endif
+
#region Session state support
internal void SetAppPathModifier (string app_modifier)
{
using System.Globalization;
using System.IO;
using System.Web.Util;
+using System.Web.Hosting;
namespace System.Web
{
{
HttpRequest request = context.Request;
HttpResponse response = context.Response;
+
+#if NET_2_0
+ if (HostingEnvironment.HaveCustomVPP) {
+ VirtualFile vf = null;
+ VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;
+ string vpath = request.FilePath;
+
+ if (vpp.FileExists (vpath))
+ vf = vpp.GetFile (vpath);
+
+ if (vf == null)
+ throw new HttpException (404, "Path '" + vpath + "' was not found.", vpath);
+
+ response.ContentType = MimeTypes.GetMimeType (vpath);
+ response.TransmitFile (vf);
+ return;
+ }
+#endif
+
string fileName = request.PhysicalPath;
FileInfo fi = new FileInfo (fileName);
if (!fi.Exists || !ValidFileName (fileName))
response.Redirect (request.Path + '/');
return;
}
-
+
string strHeader = request.Headers ["If-Modified-Since"];
try {
if (strHeader != null) {
try {
DateTime lastWT = fi.LastWriteTime.ToUniversalTime ();
response.AddHeader ("Last-Modified", lastWT.ToString ("r"));
-
response.ContentType = MimeTypes.GetMimeType (fileName);
response.TransmitFile (fileName, true);
} catch (Exception) {
+2008-03-31 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * XmlCodeExporterTests.cs: Remove CWL.
+
2008-03-30 Gert Driesen <drieseng@users.sourceforge.net>
* XmlSerializationReaderTests.cs: Marked HandleOutAttributeParameters
CodeDomProvider provider = new CSharpCodeProvider ();
ICodeGenerator generator = provider.CreateGenerator ();
generator.GenerateCodeFromNamespace (codeNamespace, sw, new CodeGeneratorOptions ());
- Console.WriteLine (sw.ToString ());
+
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}{0}" +
"/// <remarks/>{0}" +
+2008-03-31 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * XmlDocumentTests.cs: Fixed line endings.
+ * XmlAttributeCollectionTests.cs: Fixed line endings.
+ * XmlDocumentEventTests.cs: Fixed line endings.
+ * XmlNodeTests.cs: Fixed line endings.
+ * XsdValidatingReaderTests.cs: Fixed line endings.
+ * XmlDocumentTypeTests.cs: Fixed line endings.
+ * XmlEntityReferenceTests.cs: Fixed line endings.
+
+2008-03-31 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * XmlAttributeTests.cs: Use Assert instead of deprecated Assertion
+ class. Improved a few tests. Added link to MS bug report for regression
+ in .NET 2.0. Numbered tests.
+
2008-02-19 Atsushi Enomoto <atsushi@ximian.com>
* XmlParserContextTests.cs : they are working. case #3 should not
[Test]
public void InsertAfterReplacesInCorrectOrder ()
{
- XmlDocument testDoc = new XmlDocument ();\r
- XmlElement testElement = testDoc.CreateElement ("TestElement" );\r
- testDoc.AppendChild (testElement);\r
-\r
- XmlAttribute testAttr1 = testDoc.CreateAttribute ("TestAttribute1");\r
- testAttr1.Value = "First attribute";\r
- testElement.Attributes.Prepend (testAttr1);\r
-\r
- XmlAttribute testAttr2 = testDoc.CreateAttribute ("TestAttribute2");\r
- testAttr2.Value = "Second attribute";\r
- testElement.Attributes.InsertAfter (testAttr2, testAttr1);\r
-\r
- XmlAttribute testAttr3 = testDoc.CreateAttribute ("TestAttribute3");\r
- testAttr3.Value = "Third attribute";\r
- testElement.Attributes.InsertAfter (testAttr3, testAttr2);\r
-\r
- XmlAttribute outOfOrder = testDoc.CreateAttribute ("TestAttribute2");\r
- outOfOrder.Value = "Should still be second attribute";\r
- testElement.Attributes.InsertAfter (outOfOrder, testElement.Attributes [0]);\r
-\r
- AssertEquals ("First attribute", testElement.Attributes [0].Value);\r
- AssertEquals ("Should still be second attribute", testElement.Attributes [1].Value);\r
- AssertEquals ("Third attribute", testElement.Attributes [2].Value);\r
+ XmlDocument testDoc = new XmlDocument ();
+ XmlElement testElement = testDoc.CreateElement ("TestElement" );
+ testDoc.AppendChild (testElement);
+
+ XmlAttribute testAttr1 = testDoc.CreateAttribute ("TestAttribute1");
+ testAttr1.Value = "First attribute";
+ testElement.Attributes.Prepend (testAttr1);
+
+ XmlAttribute testAttr2 = testDoc.CreateAttribute ("TestAttribute2");
+ testAttr2.Value = "Second attribute";
+ testElement.Attributes.InsertAfter (testAttr2, testAttr1);
+
+ XmlAttribute testAttr3 = testDoc.CreateAttribute ("TestAttribute3");
+ testAttr3.Value = "Third attribute";
+ testElement.Attributes.InsertAfter (testAttr3, testAttr2);
+
+ XmlAttribute outOfOrder = testDoc.CreateAttribute ("TestAttribute2");
+ outOfOrder.Value = "Should still be second attribute";
+ testElement.Attributes.InsertAfter (outOfOrder, testElement.Attributes [0]);
+
+ AssertEquals ("First attribute", testElement.Attributes [0].Value);
+ AssertEquals ("Should still be second attribute", testElement.Attributes [1].Value);
+ AssertEquals ("Third attribute", testElement.Attributes [2].Value);
}
[Test]
{
string dtd = "<!DOCTYPE root [<!ELEMENT root EMPTY><!ATTLIST root attr CDATA 'default'>]>";
string xml = dtd + "<root/>";
- XmlDocument doc = new XmlDocument();\r
- doc.LoadXml (xml);\r
-\r
- doc.DocumentElement.Attributes ["attr"].Value = "modified";\r
- doc.DocumentElement.RemoveAttribute("attr");\r
-\r
- XmlAttribute defAttr = doc.DocumentElement.Attributes ["attr"];\r
- AssertNotNull (defAttr);\r
- AssertEquals ("default", defAttr.Value);\r
-
- defAttr.Value = "default"; // same value as default\r
- AssertEquals (true, defAttr.Specified);\r
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml (xml);
+
+ doc.DocumentElement.Attributes ["attr"].Value = "modified";
+ doc.DocumentElement.RemoveAttribute("attr");
+
+ XmlAttribute defAttr = doc.DocumentElement.Attributes ["attr"];
+ AssertNotNull (defAttr);
+ AssertEquals ("default", defAttr.Value);
+
+ defAttr.Value = "default"; // same value as default
+ AssertEquals (true, defAttr.Specified);
}
}
}
namespace MonoTests.System.Xml
{
[TestFixture]
- public class XmlAttributeTests : Assertion
+ public class XmlAttributeTests
{
XmlDocument doc;
XmlAttribute attr;
[Test]
public void Attributes ()
{
- AssertNull (attr.Attributes);
+ Assert.IsNull (attr.Attributes);
}
[Test]
{
attr = doc.CreateAttribute ("foo", "bar", "http://abc.def");
attr.Value = "baz";
- AssertEquals ("baz", attr.InnerXml);
- AssertEquals ("foo:bar=\"baz\"", attr.OuterXml);
+ Assert.AreEqual ("baz", attr.InnerXml, "#1");
+ Assert.AreEqual ("foo:bar=\"baz\"", attr.OuterXml, "#2");
}
[Test]
public void AttributeWithNoValue ()
{
XmlAttribute attribute = doc.CreateAttribute ("name");
- AssertEquals (String.Empty, attribute.Value);
- Assert (!attribute.HasChildNodes);
- AssertNull (attribute.FirstChild);
- AssertNull (attribute.LastChild);
- AssertEquals (0, attribute.ChildNodes.Count);
+ Assert.AreEqual (String.Empty, attribute.Value, "#1");
+ Assert.IsFalse (attribute.HasChildNodes, "#2");
+ Assert.IsNull (attribute.FirstChild, "#3");
+ Assert.IsNull (attribute.LastChild, "#4");
+ Assert.AreEqual (0, attribute.ChildNodes.Count, "#5");
}
[Test]
{
XmlAttribute attribute = doc.CreateAttribute ("name");
attribute.Value = "value";
- AssertEquals ("value", attribute.Value);
- Assert (attribute.HasChildNodes);
- AssertNotNull (attribute.FirstChild);
- AssertNotNull (attribute.LastChild);
- AssertEquals (1, attribute.ChildNodes.Count);
- AssertEquals (XmlNodeType.Text, attribute.ChildNodes [0].NodeType);
- AssertEquals ("value", attribute.ChildNodes [0].Value);
+ Assert.AreEqual ("value", attribute.Value, "#1");
+ Assert.IsTrue (attribute.HasChildNodes, "#2");
+ Assert.IsNotNull (attribute.FirstChild, "#3");
+ Assert.IsNotNull (attribute.LastChild, "#4");
+ Assert.AreEqual (1, attribute.ChildNodes.Count, "#5");
+ Assert.AreEqual (XmlNodeType.Text, attribute.ChildNodes [0].NodeType, "#6");
+ Assert.AreEqual ("value", attribute.ChildNodes [0].Value, "#7");
}
[Test]
- [ExpectedException (typeof (ArgumentException))]
public void CheckPrefixWithNamespace ()
{
XmlDocument doc = new XmlDocument ();
doc.LoadXml ("<root xmlns:foo='urn:foo' foo='attfoo' foo:foo='attfoofoo' />");
// hogehoge does not match to any namespace.
- AssertEquals ("xmlns:foo", doc.DocumentElement.Attributes [0].Name);
- doc.DocumentElement.Attributes [0].Prefix="hogehoge";
- doc.Save (Console.Out);
+ Assert.AreEqual ("xmlns:foo", doc.DocumentElement.Attributes [0].Name);
+ try {
+ doc.DocumentElement.Attributes [0].Prefix = "hogehoge";
+ doc.Save (TextWriter.Null);
+ Assert.Fail ("#1");
+ } catch (ArgumentException ex) {
+ // Cannot bind to the reserved namespace
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsNull (ex.ParamName, "#5");
+ }
}
[Test]
public void NamespaceAttributes ()
{
try {
- doc.CreateAttribute ("", "xmlns", "urn:foo");
- Assertion.Fail ("Creating xmlns attribute with invalid nsuri should be error.");
- } catch (Exception) {
+ doc.CreateAttribute (string.Empty, "xmlns", "urn:foo");
+ Assert.Fail ("#A1");
+ } catch (ArgumentException ex) {
+ // The namespace declaration attribute has an
+ // incorrect namespaceURI: urn:foo
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
+ Assert.IsNull (ex.InnerException, "#A3");
+ Assert.IsNotNull (ex.Message, "#A4");
+ Assert.IsNull (ex.ParamName, "#A5");
}
+
doc.LoadXml ("<root/>");
+
try {
doc.DocumentElement.SetAttribute ("xmlns", "urn:foo", "urn:bar");
- Assertion.Fail ("SetAttribute for xmlns with invalid nsuri should be error.");
- } catch (ArgumentException) {
+ Assert.Fail ("#B1");
+ } catch (ArgumentException ex) {
+ // The namespace declaration attribute has an
+ // incorrect namespaceURI: urn:foo
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+ Assert.IsNull (ex.InnerException, "#B3");
+ Assert.IsNotNull (ex.Message, "#B4");
+ Assert.IsNull (ex.ParamName, "#B5");
}
}
[Test]
public void HasChildNodes ()
{
- Assert (attr.HasChildNodes);
+ Assert.IsTrue (attr.HasChildNodes, "#1");
+ XmlAttribute attr2 = doc.CreateAttribute ("attr2");
+ Assert.IsFalse (attr2.HasChildNodes, "#2");
}
[Test]
public void Name ()
{
- AssertEquals ("attr1", attr.Name);
+ Assert.AreEqual ("attr1", attr.Name);
}
[Test]
public void NodeType ()
{
- AssertEquals (XmlNodeType.Attribute, attr.NodeType);
+ Assert.AreEqual (XmlNodeType.Attribute, attr.NodeType);
}
[Test]
public void OwnerDocument ()
{
- AssertSame (doc, attr.OwnerDocument);
+ Assert.AreSame (doc, attr.OwnerDocument);
}
[Test]
public void ParentNode ()
{
- AssertNull ("Attr parents not allowed", attr.ParentNode);
+ Assert.IsNull (attr.ParentNode, "Attr parents not allowed");
}
[Test]
public void Value ()
{
- AssertEquals ("val1", attr.Value);
+ Assert.AreEqual ("val1", attr.Value, "#1");
+ XmlAttribute attr2 = doc.CreateAttribute ("attr2");
+ Assert.AreEqual (string.Empty, attr2.Value, "#2");
}
[Test]
#if NET_2_0
- [Category ("NotDotNet")] // enbug in 2.0
+ [Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=336180
#endif
public void SetInnerTextAndXml ()
{
doc.LoadXml ("<root name='value' />");
XmlAttribute attr = doc.DocumentElement.Attributes ["name"];
attr.InnerText = "a&b";
- AssertEquals ("setInnerText", "a&b", attr.Value);
+ Assert.AreEqual ("a&b", attr.Value, "setInnerText");
attr.InnerXml = "a&b";
- AssertEquals ("setInnerXml", "a&b", attr.Value);
+ Assert.AreEqual ("a&b", attr.Value, "setInnerXml");
attr.InnerXml = "'a&b'";
- AssertEquals ("setInnerXml.InnerXml", "'a&b'", attr.InnerXml);
- AssertEquals ("setInnerXml.Value", "'a&b'", attr.Value);
+ Assert.AreEqual ("'a&b'", attr.InnerXml, "setInnerXml.InnerXml");
+ Assert.AreEqual ("'a&b'", attr.Value, "setInnerXml.Value");
attr.InnerXml = "\"a&b\"";
- AssertEquals ("Double_Quote", "\"a&b\"", attr.InnerXml);
+ Assert.AreEqual ("\"a&b\"", attr.InnerXml, "Double_Quote");
attr.InnerXml = "\"a&b'";
- AssertEquals ("DoubleQuoteStart_SingleQuoteEnd",
- "\"a&b'", attr.InnerXml);
+ Assert.AreEqual ("\"a&b'", attr.InnerXml, "DoubleQuoteStart_SingleQuoteEnd");
- attr.Value = "";
+ attr.Value = string.Empty;
XmlNodeChangedEventHandler evInserted = new XmlNodeChangedEventHandler (EventNodeInserted);
XmlNodeChangedEventHandler evChanged = new XmlNodeChangedEventHandler (EventNodeChanged);
XmlNodeChangedEventHandler evRemoved = new XmlNodeChangedEventHandler (EventNodeRemoved);
try {
// set_InnerText event
attr.InnerText = "fire";
- AssertEquals ("setInnerText.NodeInserted", false, inserted);
- AssertEquals ("setInnerText.NodeChanged", true, changed);
- AssertEquals ("setInnerText.NodeRemoved", false, removed);
+ Assert.IsFalse (inserted, "setInnerText.NodeInserted");
+ Assert.IsTrue (changed, "setInnerText.NodeChanged");
+ Assert.IsFalse (removed, "setInnerText.NodeRemoved");
inserted = changed = removed = false;
// set_InnerXml event
attr.InnerXml = "fire";
- AssertEquals ("setInnserXml.NodeInserted", true, inserted);
- AssertEquals ("setInnserXml.NodeChanged", false, changed);
- AssertEquals ("setInnserXml.NodeRemoved", true, removed);
+ Assert.IsTrue (inserted, "setInnserXml.NodeInserted");
+ Assert.IsFalse (changed, "setInnserXml.NodeChanged");
+ Assert.IsTrue (removed, "setInnserXml.NodeRemoved");
inserted = changed = removed = false;
} finally {
doc.NodeInserted -= evInserted;
}
}
-
-
private void OnSetInnerText (object o, XmlNodeChangedEventArgs e)
{
if(e.NewParent.Value == "fire")
public void WriteTo ()
{
doc.AppendChild (doc.CreateElement ("root"));
- doc.DocumentElement.SetAttribute ("attr","");
+ doc.DocumentElement.SetAttribute ("attr", string.Empty);
doc.DocumentElement.Attributes ["attr"].InnerXml = "&ent;";
StringWriter sw = new StringWriter ();
XmlTextWriter xtw = new XmlTextWriter (sw);
XmlAttribute attr = doc.DocumentElement.Attributes ["attr"];
attr.WriteTo (xtw);
xtw.Close ();
- Assertion.AssertEquals ("<result attr=\"&ent;\" />", sw.ToString ());
+ Assert.AreEqual ("<result attr=\"&ent;\" />", sw.ToString ());
}
[Test]
string xml = dtd + "<root><c foo='id1' bar='1' /><c foo='id2' bar='2'/></root>";
XmlValidatingReader vr = new XmlValidatingReader (xml, XmlNodeType.Document, null);
doc.Load (vr);
- AssertNotNull (doc.GetElementById ("id1"));
- AssertNotNull (doc.GetElementById ("id2"));
+ Assert.IsNotNull (doc.GetElementById ("id1"));
+ Assert.IsNotNull (doc.GetElementById ("id2"));
// MS.NET BUG: Later I try to append it to another element, but
// it should raise InvalidOperationException.
// (and if MS.NET conform to DOM 1.0, it should be XmlException.)
// XmlAttribute attr = doc.DocumentElement.FirstChild.Attributes [0];
XmlAttribute attr = doc.DocumentElement.FirstChild.Attributes.RemoveAt (0);
- AssertEquals ("id1", attr.Value);
+ Assert.AreEqual ("id1", attr.Value);
doc.DocumentElement.LastChild.Attributes.SetNamedItem (attr);
- AssertNotNull (doc.GetElementById ("id1"));
+ Assert.IsNotNull (doc.GetElementById ("id1"));
XmlElement elem2 = doc.GetElementById ("id2");
// MS.NET BUG: it doesn't remove replaced attribute with SetNamedItem!
// AssertNull (elem2);
// AssertEquals ("2", elem2.GetAttribute ("bar"));
// elem2.RemoveAttribute ("foo");
-// AssertEquals ("", elem2.GetAttribute ("foo"));
+// AssertEquals (string.Empty, elem2.GetAttribute ("foo"));
// MS.NET BUG: elem should be the element which has the attribute bar='1'!
XmlElement elem = doc.GetElementById ("id1");
doc.DocumentElement.AppendChild (elemNew);
// but once attribute is set, document recognizes this ID.
elemNew.SetAttribute ("foo", "id3");
- AssertNotNull (doc.GetElementById ("id3"));
+ Assert.IsNotNull (doc.GetElementById ("id3"));
elemNew.RemoveAttribute ("foo");
- AssertNull (doc.GetElementById ("id3"));
+ Assert.IsNull (doc.GetElementById ("id3"));
// MS.NET BUG: multiple IDs are allowed.
// In such case GetElementById fails.
// Finally...
doc.RemoveAll ();
- AssertNull (doc.GetElementById ("id1"));
- AssertNull (doc.GetElementById ("id2"));
- AssertNull (doc.GetElementById ("id3"));
+ Assert.IsNull (doc.GetElementById ("id1"));
+ Assert.IsNull (doc.GetElementById ("id2"));
+ Assert.IsNull (doc.GetElementById ("id3"));
}
int removeAllStep;
private void OnInsert (object o, XmlNodeChangedEventArgs e)
{
if (removeAllStep == 1)
- AssertEquals (XmlNodeType.Text, e.Node.NodeType);
+ Assert.AreEqual (XmlNodeType.Text, e.Node.NodeType);
else if (removeAllStep == 2) {
- AssertEquals ("foo", e.Node.Name);
- Assert (! ((XmlAttribute) e.Node).Specified);
- }
- else
- Fail ();
+ Assert.AreEqual ("foo", e.Node.Name);
+ Assert.IsFalse (((XmlAttribute) e.Node).Specified);
+ } else
+ Assert.Fail ();
removeAllStep++;
}
+
private void OnChange (object o, XmlNodeChangedEventArgs e)
{
- Fail ("Should not be called.");
+ Assert.Fail ("Should not be called.");
}
+
private void OnRemove (object o, XmlNodeChangedEventArgs e)
{
- AssertEquals (0, removeAllStep);
- AssertEquals ("foo", e.Node.Name);
+ Assert.AreEqual (0, removeAllStep, "#1");
+ Assert.AreEqual ("foo", e.Node.Name, "#2");
removeAllStep++;
}
{
doc.LoadXml ("<root attr=''/>");
XmlAttribute attr = doc.DocumentElement.GetAttributeNode ("attr");
- AssertNotNull (attr);
- AssertEquals (1, attr.ChildNodes.Count);
- AssertEquals (XmlNodeType.Text, attr.ChildNodes [0].NodeType);
- AssertEquals (String.Empty, attr.ChildNodes [0].Value);
+ Assert.IsNotNull (attr, "#1");
+ Assert.AreEqual (1, attr.ChildNodes.Count, "#2");
+ Assert.AreEqual (XmlNodeType.Text, attr.ChildNodes [0].NodeType, "#3");
+ Assert.AreEqual (String.Empty, attr.ChildNodes [0].Value, "#4");
}
[Test]
XmlAttribute a = doc.DocumentElement.Attributes [0];
a.Prefix ="hoge:hoge:hoge";
// This test is nothing more than ****.
- AssertEquals ("hoge:hoge:hoge", a.Prefix);
+ Assert.AreEqual ("hoge:hoge:hoge", a.Prefix);
// The resulting string is not XML (so broken), so
// it should not be tested.
// doc.Save (TextWriter.Null);
{
XmlDocument doc = new XmlDocument ();
doc.LoadXml ("<!DOCTYPE USS[<!ELEMENT USS EMPTY><!ATTLIST USS Id ID #REQUIRED>]><USS Id='foo'/>");
- AssertNotNull ("#1", doc.SelectSingleNode ("id ('foo')"));
+ Assert.IsNotNull (doc.SelectSingleNode ("id ('foo')"), "#1");
doc.DocumentElement.Attributes [0].Value = "bar";
- AssertNull ("#2", doc.SelectSingleNode ("id ('foo')"));
- AssertNotNull ("#3", doc.SelectSingleNode ("id ('bar')"));
+ Assert.IsNull (doc.SelectSingleNode ("id ('foo')"), "#2");
+ Assert.IsNotNull (doc.SelectSingleNode ("id ('bar')"), "#3");
doc.DocumentElement.Attributes [0].ChildNodes [0].Value = "baz";
// Tests below don't work fine under MS.NET
-// AssertNull ("#4", doc.SelectSingleNode ("id ('bar')"));
-// AssertNotNull ("#5", doc.SelectSingleNode ("id ('baz')"));
+// Assert.IsNull (doc.SelectSingleNode ("id ('bar')"), "#4");
+// Assert.IsNotNull (doc.SelectSingleNode ("id ('baz')"), "#5");
doc.DocumentElement.Attributes [0].AppendChild (doc.CreateTextNode ("baz"));
- AssertNull ("#6", doc.SelectSingleNode ("id ('baz')"));
-// AssertNull ("#6-2", doc.SelectSingleNode ("id ('bar')"));
-// AssertNotNull ("#7", doc.SelectSingleNode ("id ('bazbaz')"));
+ Assert.IsNull (doc.SelectSingleNode ("id ('baz')"), "#6");
+// Assert.IsNull (doc.SelectSingleNode ("id ('bar')"), "#7");
+// Assert.IsNotNull (doc.SelectSingleNode ("id ('bazbaz')"), "#7");
}
[Test] // http://lists.ximian.com/pipermail/mono-list/2006-May/031557.html
public void NonEmptyPrefixWithEmptyNS ()
{
XmlDocument xmlDoc = new XmlDocument ();
- xmlDoc.AppendChild (xmlDoc.CreateNode (XmlNodeType.XmlDeclaration, "", ""));
+ xmlDoc.AppendChild (xmlDoc.CreateNode (XmlNodeType.XmlDeclaration,
+ string.Empty, string.Empty));
XmlElement docElement = xmlDoc.CreateElement ("doc");
docElement.SetAttribute ("xmlns", "http://whatever.org/XMLSchema/foo");
XmlElement el = document.CreateElement ("root");\r
el.AppendChild (document.CreateTextNode ("simple text node."));\r
document.AppendChild (el);\r
- AssertEquals (
-@"Inserting: Text into Element.
-Inserted: Text into Element.
-Inserting: Element into Document.
-Inserted: Element into Document.
-", EventLog);\r
+ AssertEquals (\r
+ "Inserting: Text into Element.\n" +\r
+ "Inserted: Text into Element.\n" +\r
+ "Inserting: Element into Document.\n" +\r
+ "Inserted: Element into Document.\n",\r
+ EventLog);\r
}\r
\r
[Test]\r
- public void DefaultAttributeRemoval ()
- {
- XmlDocument doc = new XmlDocument ();
- doc.LoadXml ("<!DOCTYPE root [<!ELEMENT root (#PCDATA)><!ATTLIST root foo CDATA 'foo-def'>]><root></root>");
- SetEvents (doc);
- doc.DocumentElement.RemoveAll ();
- AssertEquals (
-@"Removing: Attribute from Element.
-Removed: Attribute from Element.
-Inserting: Text into Attribute.
-Inserted: Text into Attribute.
-Inserting: Attribute into Element.
-Inserted: Attribute into Element.
-", EventLog);
- }
+ public void DefaultAttributeRemoval ()\r
+ {\r
+ XmlDocument doc = new XmlDocument ();\r
+ doc.LoadXml ("<!DOCTYPE root [<!ELEMENT root (#PCDATA)><!ATTLIST root foo CDATA 'foo-def'>]><root></root>");\r
+ SetEvents (doc);\r
+ doc.DocumentElement.RemoveAll ();\r
+ AssertEquals (\r
+ "Removing: Attribute from Element.\n" +\r
+ "Removed: Attribute from Element.\n" +\r
+ "Inserting: Text into Attribute.\n" +\r
+ "Inserted: Text into Attribute.\n" +\r
+ "Inserting: Attribute into Element.\n" +\r
+ "Inserted: Attribute into Element.\n",\r
+ EventLog);\r
+ }\r
}\r
}\r
[Test]
public void GetElementsByTagNameNs2 ()
{
- document.LoadXml (@"<root>\r
- <x:a xmlns:x='urn:foo' id='a'>\r
- <y:a xmlns:y='urn:foo' id='b'/>\r
- <x:a id='c' />\r
- <z id='d' />\r
- text node\r
- <?a processing instruction ?>\r
- <x:w id='e'/>\r
- </x:a>\r
- </root>");\r
- // id='b' has different prefix. Should not caught by (name),\r
- // while should caught by (name, ns).\r
- XmlNodeList nl = document.GetElementsByTagName ("x:a");\r
- AssertEquals (2, nl.Count);\r
- AssertEquals ("a", nl [0].Attributes ["id"].Value);\r
- AssertEquals ("c", nl [1].Attributes ["id"].Value);\r
-
- nl = document.GetElementsByTagName ("a", "urn:foo");\r
- AssertEquals (3, nl.Count);\r
- AssertEquals ("a", nl [0].Attributes ["id"].Value);\r
- AssertEquals ("b", nl [1].Attributes ["id"].Value);\r
- AssertEquals ("c", nl [2].Attributes ["id"].Value);\r
+ document.LoadXml (@"<root>
+ <x:a xmlns:x='urn:foo' id='a'>
+ <y:a xmlns:y='urn:foo' id='b'/>
+ <x:a id='c' />
+ <z id='d' />
+ text node
+ <?a processing instruction ?>
+ <x:w id='e'/>
+ </x:a>
+ </root>");
+ // id='b' has different prefix. Should not caught by (name),
+ // while should caught by (name, ns).
+ XmlNodeList nl = document.GetElementsByTagName ("x:a");
+ AssertEquals (2, nl.Count);
+ AssertEquals ("a", nl [0].Attributes ["id"].Value);
+ AssertEquals ("c", nl [1].Attributes ["id"].Value);
+
+ nl = document.GetElementsByTagName ("a", "urn:foo");
+ AssertEquals (3, nl.Count);
+ AssertEquals ("a", nl [0].Attributes ["id"].Value);
+ AssertEquals ("b", nl [1].Attributes ["id"].Value);
+ AssertEquals ("c", nl [2].Attributes ["id"].Value);
// name wildcard
- nl = document.GetElementsByTagName ("*");\r
- AssertEquals (6, nl.Count);\r
- AssertEquals ("root", nl [0].Name);\r
- AssertEquals ("a", nl [1].Attributes ["id"].Value);\r
- AssertEquals ("b", nl [2].Attributes ["id"].Value);\r
- AssertEquals ("c", nl [3].Attributes ["id"].Value);\r
- AssertEquals ("d", nl [4].Attributes ["id"].Value);\r
- AssertEquals ("e", nl [5].Attributes ["id"].Value);\r
+ nl = document.GetElementsByTagName ("*");
+ AssertEquals (6, nl.Count);
+ AssertEquals ("root", nl [0].Name);
+ AssertEquals ("a", nl [1].Attributes ["id"].Value);
+ AssertEquals ("b", nl [2].Attributes ["id"].Value);
+ AssertEquals ("c", nl [3].Attributes ["id"].Value);
+ AssertEquals ("d", nl [4].Attributes ["id"].Value);
+ AssertEquals ("e", nl [5].Attributes ["id"].Value);
// wildcard - local and ns
- nl = document.GetElementsByTagName ("*", "*");\r
- AssertEquals (6, nl.Count);\r
- AssertEquals ("root", nl [0].Name);\r
- AssertEquals ("a", nl [1].Attributes ["id"].Value);\r
- AssertEquals ("b", nl [2].Attributes ["id"].Value);\r
- AssertEquals ("c", nl [3].Attributes ["id"].Value);\r
- AssertEquals ("d", nl [4].Attributes ["id"].Value);\r
- AssertEquals ("e", nl [5].Attributes ["id"].Value);\r
+ nl = document.GetElementsByTagName ("*", "*");
+ AssertEquals (6, nl.Count);
+ AssertEquals ("root", nl [0].Name);
+ AssertEquals ("a", nl [1].Attributes ["id"].Value);
+ AssertEquals ("b", nl [2].Attributes ["id"].Value);
+ AssertEquals ("c", nl [3].Attributes ["id"].Value);
+ AssertEquals ("d", nl [4].Attributes ["id"].Value);
+ AssertEquals ("e", nl [5].Attributes ["id"].Value);
// namespace wildcard - namespace
- nl = document.GetElementsByTagName ("*", "urn:foo");\r
- AssertEquals (4, nl.Count);\r
- AssertEquals ("a", nl [0].Attributes ["id"].Value);\r
- AssertEquals ("b", nl [1].Attributes ["id"].Value);\r
- AssertEquals ("c", nl [2].Attributes ["id"].Value);\r
- AssertEquals ("e", nl [3].Attributes ["id"].Value);\r
+ nl = document.GetElementsByTagName ("*", "urn:foo");
+ AssertEquals (4, nl.Count);
+ AssertEquals ("a", nl [0].Attributes ["id"].Value);
+ AssertEquals ("b", nl [1].Attributes ["id"].Value);
+ AssertEquals ("c", nl [2].Attributes ["id"].Value);
+ AssertEquals ("e", nl [3].Attributes ["id"].Value);
// namespace wildcard - local only. I dare say, such usage is not XML-ish!
- nl = document.GetElementsByTagName ("a", "*");\r
- AssertEquals (3, nl.Count);\r
- AssertEquals ("a", nl [0].Attributes ["id"].Value);\r
- AssertEquals ("b", nl [1].Attributes ["id"].Value);\r
- AssertEquals ("c", nl [2].Attributes ["id"].Value);\r
+ nl = document.GetElementsByTagName ("a", "*");
+ AssertEquals (3, nl.Count);
+ AssertEquals ("a", nl [0].Attributes ["id"].Value);
+ AssertEquals ("b", nl [1].Attributes ["id"].Value);
+ AssertEquals ("c", nl [2].Attributes ["id"].Value);
}
[Test]
[Test]
public void LoadEntityReference ()
{
- string xml = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)*><!ENTITY ent 'val'>]><root attr='a &ent; string'>&ent;</root>";\r
- XmlTextReader xtr = new XmlTextReader (xml, XmlNodeType.Document, null);\r
- XmlDocument doc = new XmlDocument ();\r
- doc.Load (xtr);\r
- AssertEquals ("#text node", XmlNodeType.EntityReference, \r
- doc.DocumentElement.FirstChild.NodeType);\r
- AssertEquals ("#attribute", XmlNodeType.EntityReference, \r
- doc.DocumentElement.Attributes [0].ChildNodes [1].NodeType);\r
+ string xml = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)*><!ENTITY ent 'val'>]><root attr='a &ent; string'>&ent;</root>";
+ XmlTextReader xtr = new XmlTextReader (xml, XmlNodeType.Document, null);
+ XmlDocument doc = new XmlDocument ();
+ doc.Load (xtr);
+ AssertEquals ("#text node", XmlNodeType.EntityReference,
+ doc.DocumentElement.FirstChild.NodeType);
+ AssertEquals ("#attribute", XmlNodeType.EntityReference,
+ doc.DocumentElement.Attributes [0].ChildNodes [1].NodeType);
}
[Test]
public void ReadNodeEmptyContent ()
{
- XmlTextReader xr = new XmlTextReader ("", XmlNodeType.Element, null);\r
- xr.Read ();\r
- Console.WriteLine (xr.NodeType);\r
- XmlNode n = document.ReadNode (xr);\r
- AssertNull (n);\r
+ XmlTextReader xr = new XmlTextReader ("", XmlNodeType.Element, null);
+ xr.Read ();
+ Console.WriteLine (xr.NodeType);
+ XmlNode n = document.ReadNode (xr);
+ AssertNull (n);
}
[Test]
public void ReadNodeWhitespace ()
{
- XmlTextReader xr = new XmlTextReader (" ", XmlNodeType.Element, null);\r
- xr.Read ();\r
- Console.WriteLine (xr.NodeType);\r
+ XmlTextReader xr = new XmlTextReader (" ", XmlNodeType.Element, null);
+ xr.Read ();
+ Console.WriteLine (xr.NodeType);
document.PreserveWhitespace = false; // Note this line.
- XmlNode n = document.ReadNode (xr);\r
- AssertNotNull (n);\r
- AssertEquals (XmlNodeType.Whitespace, n.NodeType);\r
+ XmlNode n = document.ReadNode (xr);
+ AssertNotNull (n);
+ AssertEquals (XmlNodeType.Whitespace, n.NodeType);
}
[Test]
[ExpectedException (typeof (XmlException))]
public void IncorrectInternalSubset ()
{
- XmlDocument doc = new XmlDocument ();\r
- XmlDocumentType doctype = doc.CreateDocumentType (\r
- "root", "public-hogehoge", null,\r
- "invalid_intsubset");\r
- doctype = doc.CreateDocumentType ("root",\r
- "public-hogehoge", null, \r
- "<!ENTITY % pe1 '>'> <!ELEMENT e EMPTY%pe1;");\r
+ XmlDocument doc = new XmlDocument ();
+ XmlDocumentType doctype = doc.CreateDocumentType (
+ "root", "public-hogehoge", null,
+ "invalid_intsubset");
+ doctype = doc.CreateDocumentType ("root",
+ "public-hogehoge", null,
+ "<!ENTITY % pe1 '>'> <!ELEMENT e EMPTY%pe1;");
}
[Test]
[Test]
public void DescendantsRecursively ()
{
- string dtd = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)*>"\r
- + "<!ENTITY ent 'value'>"\r
- + "<!ENTITY ent2 'my &ent; string'>"\r
- + "]>";\r
- string xml = dtd + "<root>&ent;</root>";\r
- XmlTextReader xtr = new XmlTextReader (xml, XmlNodeType.Document, null);\r
- XmlDocument doc = new XmlDocument ();\r
- doc.Load (xtr);\r
- XmlEntity ent = (XmlEntity) doc.DocumentType.Entities.GetNamedItem ("ent2");\r
- AssertEquals ("ent2", ent.Name);\r
- AssertEquals ("my ", ent.FirstChild.Value);\r
- AssertNotNull (ent.FirstChild.NextSibling.FirstChild);\r
- AssertEquals ("value", ent.FirstChild.NextSibling.FirstChild.Value);\r
+ string dtd = "<!DOCTYPE root [<!ELEMENT root (#PCDATA)*>"
+ + "<!ENTITY ent 'value'>"
+ + "<!ENTITY ent2 'my &ent; string'>"
+ + "]>";
+ string xml = dtd + "<root>&ent;</root>";
+ XmlTextReader xtr = new XmlTextReader (xml, XmlNodeType.Document, null);
+ XmlDocument doc = new XmlDocument ();
+ doc.Load (xtr);
+ XmlEntity ent = (XmlEntity) doc.DocumentType.Entities.GetNamedItem ("ent2");
+ AssertEquals ("ent2", ent.Name);
+ AssertEquals ("my ", ent.FirstChild.Value);
+ AssertNotNull (ent.FirstChild.NextSibling.FirstChild);
+ AssertEquals ("value", ent.FirstChild.NextSibling.FirstChild.Value);
}
[Test]
public void ChildNodes ()
{
- XmlTextReader xtr = new XmlTextReader ("<!DOCTYPE root [<!ENTITY ent 'ent-value'><!ENTITY el '<foo>hoge</foo><bar/>'>]><root/>",\r
- XmlNodeType.Document, null);\r
- XmlDocument doc = new XmlDocument ();\r
-\r
- doc.Load (xtr);\r
- XmlEntityReference ent = doc.CreateEntityReference ("ent");\r
- // ChildNodes are not added yet.\r
- AssertNull (ent.FirstChild);\r
- doc.DocumentElement.AppendChild (ent);\r
- // ChildNodes are added here.\r
- AssertNotNull (ent.FirstChild);\r
-\r
- ent = doc.CreateEntityReference ("foo");\r
- AssertNull (ent.FirstChild);\r
- // Entity value is empty when the matching DTD entity \r
- // node does not exist.\r
- doc.DocumentElement.AppendChild (ent);\r
- AssertNotNull (ent.FirstChild);\r
-\r
- AssertEquals (String.Empty, ent.FirstChild.Value);\r
+ XmlTextReader xtr = new XmlTextReader ("<!DOCTYPE root [<!ENTITY ent 'ent-value'><!ENTITY el '<foo>hoge</foo><bar/>'>]><root/>",
+ XmlNodeType.Document, null);
+ XmlDocument doc = new XmlDocument ();
+
+ doc.Load (xtr);
+ XmlEntityReference ent = doc.CreateEntityReference ("ent");
+ // ChildNodes are not added yet.
+ AssertNull (ent.FirstChild);
+ doc.DocumentElement.AppendChild (ent);
+ // ChildNodes are added here.
+ AssertNotNull (ent.FirstChild);
+
+ ent = doc.CreateEntityReference ("foo");
+ AssertNull (ent.FirstChild);
+ // Entity value is empty when the matching DTD entity
+ // node does not exist.
+ doc.DocumentElement.AppendChild (ent);
+ AssertNotNull (ent.FirstChild);
+
+ AssertEquals (String.Empty, ent.FirstChild.Value);
ent = doc.CreateEntityReference ("el");
- AssertEquals ("", ent.InnerText);\r
- doc.DocumentElement.AppendChild (ent);\r
- AssertEquals ("<foo>hoge</foo><bar />", ent.InnerXml);\r
- AssertEquals ("hoge", ent.InnerText);\r
- AssertEquals (XmlNodeType.Element, ent.FirstChild.NodeType);\r
+ AssertEquals ("", ent.InnerText);
+ doc.DocumentElement.AppendChild (ent);
+ AssertEquals ("<foo>hoge</foo><bar />", ent.InnerXml);
+ AssertEquals ("hoge", ent.InnerText);
+ AssertEquals (XmlNodeType.Element, ent.FirstChild.NodeType);
}
}
}
[Test]
public void Normalize2 ()
{
- XmlDocument doc = new XmlDocument ();\r
- doc.PreserveWhitespace = true;\r
- doc.LoadXml ("<root> </root>");\r
- XmlElement root = doc.DocumentElement;\r
- root.AppendChild (doc.CreateTextNode ("foo"));\r
- root.AppendChild (doc.CreateTextNode ("bar"));\r
- root.AppendChild (doc.CreateWhitespace (" "));\r
- root.AppendChild (doc.CreateTextNode ("baz"));\r
- doc.NodeInserted += new XmlNodeChangedEventHandler (OnChange);\r
- doc.NodeChanged += new XmlNodeChangedEventHandler (OnChange);\r
- doc.NodeRemoved += new XmlNodeChangedEventHandler (OnChange);\r
- AssertEquals ("Before Normalize()", 5, root.ChildNodes.Count);\r
- root.Normalize ();\r
- AssertEquals ("<root> foobar baz</root>", root.OuterXml);\r
- AssertEquals ("After Normalize()", 1, root.ChildNodes.Count);\r
+ XmlDocument doc = new XmlDocument ();
+ doc.PreserveWhitespace = true;
+ doc.LoadXml ("<root> </root>");
+ XmlElement root = doc.DocumentElement;
+ root.AppendChild (doc.CreateTextNode ("foo"));
+ root.AppendChild (doc.CreateTextNode ("bar"));
+ root.AppendChild (doc.CreateWhitespace (" "));
+ root.AppendChild (doc.CreateTextNode ("baz"));
+ doc.NodeInserted += new XmlNodeChangedEventHandler (OnChange);
+ doc.NodeChanged += new XmlNodeChangedEventHandler (OnChange);
+ doc.NodeRemoved += new XmlNodeChangedEventHandler (OnChange);
+ AssertEquals ("Before Normalize()", 5, root.ChildNodes.Count);
+ root.Normalize ();
+ AssertEquals ("<root> foobar baz</root>", root.OuterXml);
+ AssertEquals ("After Normalize()", 1, root.ChildNodes.Count);
}
int normalize2Count;
- private void OnChange (object o, XmlNodeChangedEventArgs e)\r
- {\r
- switch (normalize2Count) {\r
- case 0:\r
- AssertEquals ("Action0", XmlNodeChangedAction.Remove, e.Action);\r
- AssertEquals ("Value0", " ", e.Node.Value);\r
- break;\r
- case 1:\r
- AssertEquals ("Action1", XmlNodeChangedAction.Remove, e.Action);\r
- AssertEquals ("Value1", "bar", e.Node.Value);\r
- break;\r
- case 2:\r
- AssertEquals ("Action2", XmlNodeChangedAction.Remove, e.Action);\r
- AssertEquals ("Value2", " ", e.Node.Value);\r
- break;\r
- case 3:\r
- AssertEquals ("Action3", XmlNodeChangedAction.Remove, e.Action);\r
- AssertEquals ("Value3", "baz", e.Node.Value);\r
- break;\r
- case 4:\r
- AssertEquals ("Action4", XmlNodeChangedAction.Change, e.Action);\r
- AssertEquals ("Value4", " foobar baz", e.Node.Value);\r
- break;\r
- default:\r
- Fail (String.Format ("Unexpected event. Action = {0}, node type = {1}, node name = {2}, node value = {3}", e.Action, e.Node.NodeType, e.Node.Name, e.Node.Value));\r
- break;\r
- }\r
- normalize2Count++;\r
- }\r
+ private void OnChange (object o, XmlNodeChangedEventArgs e)
+ {
+ switch (normalize2Count) {
+ case 0:
+ AssertEquals ("Action0", XmlNodeChangedAction.Remove, e.Action);
+ AssertEquals ("Value0", " ", e.Node.Value);
+ break;
+ case 1:
+ AssertEquals ("Action1", XmlNodeChangedAction.Remove, e.Action);
+ AssertEquals ("Value1", "bar", e.Node.Value);
+ break;
+ case 2:
+ AssertEquals ("Action2", XmlNodeChangedAction.Remove, e.Action);
+ AssertEquals ("Value2", " ", e.Node.Value);
+ break;
+ case 3:
+ AssertEquals ("Action3", XmlNodeChangedAction.Remove, e.Action);
+ AssertEquals ("Value3", "baz", e.Node.Value);
+ break;
+ case 4:
+ AssertEquals ("Action4", XmlNodeChangedAction.Change, e.Action);
+ AssertEquals ("Value4", " foobar baz", e.Node.Value);
+ break;
+ default:
+ Fail (String.Format ("Unexpected event. Action = {0}, node type = {1}, node name = {2}, node value = {3}", e.Action, e.Node.NodeType, e.Node.Name, e.Node.Value));
+ break;
+ }
+ normalize2Count++;
+ }
[Test]
public void PrependChild()
vr.Read (); // bug\r
AssertEquals ("#4", "urn:a", vr.NamespaceURI);\r
}\r
-
- [Test]
- public void MultipleSchemaInSchemaLocation ()
- {
- XmlTextReader xtr = new XmlTextReader ("Test/XmlFiles/xsd/multi-schemaLocation.xml");
- XmlValidatingReader vr = new XmlValidatingReader (xtr);
- while (!vr.EOF)
- vr.Read ();
- }
+\r
+ [Test]\r
+ public void MultipleSchemaInSchemaLocation ()\r
+ {\r
+ XmlTextReader xtr = new XmlTextReader ("Test/XmlFiles/xsd/multi-schemaLocation.xml");\r
+ XmlValidatingReader vr = new XmlValidatingReader (xtr);\r
+ while (!vr.EOF)\r
+ vr.Read ();\r
+ }\r
\r
[Test]\r
public void ReadTypedValueSimpleTypeRestriction ()\r
+2008-03-31 Mark Probst <mark.probst@gmail.com>
+
+ * MonoMethod.cs: Don't do CAS security checks in Invoke for 2.1
+ profile.
+
2008-03-25 Zoltan Varga <vargaz@gmail.com>
* MonoCMethod.cs (Invoke): Avoid a crash if this is called on a ctor of an open
if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
throw new ArgumentException ("parameters");
+#if !NET_2_1
if (SecurityManager.SecurityEnabled) {
// sadly Attributes doesn't tell us which kind of security action this is so
// we must do it the hard way - and it also means that we can skip calling
// Attribute (which is another an icall)
SecurityManager.ReflectedLinkDemandInvoke (this);
}
+#endif
#if NET_2_0
if (ContainsGenericParameters)
+2008-04-01: Eyal Alaluf <eyala@mainsoft.com>
+
+ * Thread.cs: Put a NumberFormatter instance as a member of the current
+ thread so it can reused for performint ToString conversions.
+
2008-03-26 Massimiliano Mantione <massi@ximian.com>
* Thread.cs: Renamed "unused6" because it will be used to hold
the "mono_thread_manage" callback.
private int managed_id;
private IPrincipal _principal;
+ internal NumberFormatter _numberFormatter;
public static Context CurrentContext {
[SecurityPermission (SecurityAction.LinkDemand, Infrastructure=true)]
slots [slot.slot] = data;
}
+ internal NumberFormatter AcquireNumberFormatter() {
+ NumberFormatter res = _numberFormatter;
+ _numberFormatter = null;
+ if (res == null)
+ return new NumberFormatter (this);
+ return res;
+ }
+
+ internal void ReleaseNumberFormatter (NumberFormatter formatter) {
+ _numberFormatter = formatter;
+ }
+
public static AppDomain GetDomain() {
return AppDomain.CurrentDomain;
}
//
SetCachedCurrentCulture (culture);
in_currentculture = false;
+ if (_numberFormatter != null)
+ _numberFormatter.CurrentCulture = culture;
return culture;
}
}
in_currentculture = false;
}
+ if (_numberFormatter != null)
+ _numberFormatter.CurrentCulture = culture;
return culture;
}
} finally {
in_currentculture = false;
}
+ if (_numberFormatter != null)
+ _numberFormatter.CurrentCulture = value;
}
}
public override string ToString ()
{
- return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+ return NumberFormatter.NumberToString (m_value, null);
}
public string ToString (string format)
public string ToString (IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format, IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return NumberFormatter.NumberToString (format, m_value, nfi);
+ return NumberFormatter.NumberToString (format, m_value, provider);
}
// =========== IConvertible Methods =========== //
+2008-04-01 Eyal Alaluf <eyala@mainsoft.com>
+
+ * NumberFormatter.cs NumberFormatter.jvm.cs: Performance optimizations.
+ Reuse a per thread instance to format all the primitive types. Modify
+ class accordingly so the same
+ instance can be used multiple times.
+ * Int16.cs UInt64.cs Double.cs SByte.cs UInt16.cs Byte.csDecimal.cs
+ TimeSpan.cs Int32.cs Int64.cs Single.cs UInt32.cs: Change use of
+ NumberFormatter to adapt to above changes in class interface.
+
+2008-03-31 Mark Probst <mark.probst@gmail.com>
+
+ * MonoType.cs: Don't do CAS security checks in CheckMethodSecurity
+ for 2.1 profile.
+
2008-03-28 Marek Safar <marek.safar@gmail.com>
* Nullable.cs (Box): Do things explicitly and not rely on broken gmcs
public string ToString (string format, IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
-
- // use "G" for null or empty string
- if ((format == null) || (format.Length == 0))
- format = "G";
-
- return NumberFormatter.NumberToString (format, this, nfi);
+ return NumberFormatter.NumberToString (format, this, provider);
}
public override string ToString()
#endif
public override string ToString ()
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (null);
- return new NumberFormatter(null, m_value).FormatGeneral (nfi);
+ return NumberFormatter.NumberToString (m_value, null);
}
public string ToString (IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return new NumberFormatter(null, m_value).FormatGeneral (nfi);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return NumberFormatter.NumberToString (format, m_value, nfi);
+ return NumberFormatter.NumberToString (format, m_value, provider);
}
// =========== IConvertible Methods =========== //
public override string ToString ()
{
- return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+ return NumberFormatter.NumberToString (m_value, null);
}
public string ToString (IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider fp)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- return NumberFormatter.NumberToString(format, m_value, nfi);
+ return NumberFormatter.NumberToString(format, m_value, fp);
}
// =========== IConvertible Methods =========== //
public override string ToString ()
{
- return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+ return NumberFormatter.NumberToString (m_value, null);
}
public string ToString (IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider fp )
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- return NumberFormatter.NumberToString (format, m_value, nfi);
+ return NumberFormatter.NumberToString (format, m_value, fp);
}
// =========== IConvertible Methods =========== //
public override string ToString ()
{
- return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+ return NumberFormatter.NumberToString (m_value, null);
}
public string ToString (IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider fp)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- return NumberFormatter.NumberToString (format, m_value, nfi);
+ return NumberFormatter.NumberToString (format, m_value, fp);
}
// =========== IConvertible Methods =========== //
private MethodBase CheckMethodSecurity (MethodBase mb)
{
+#if NET_2_1
+ return mb;
+#else
if (!SecurityManager.SecurityEnabled || (mb == null))
return mb;
// this (unlike the Invoke step) is _and stays_ a LinkDemand (caller)
return SecurityManager.ReflectedLinkDemandQuery (mb) ? mb : null;
+#endif
}
void ReorderParamArrayArguments(ref object[] args, MethodBase method)
// Kazuki Oikawa (kazuki@panicode.com)
// Eyal Alaluf (eyala@mainsoft.com)
//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2008 Mainsoft Co. (http://www.mainsoft.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
-// NumberFormatter is shared with Grasshopper and hence the #if TARGET_JVM
-// The differentiating issues are:
-// * Mono runs faster when NumberFormatter is a struct. Grasshopper (and .Net
-// for that matter) run faster when its a class.
-// * No support for unsafe code in Grasshopper.
+// NumberFormatter is shared with Grasshopper and hence the #if TARGET_JVM for
+// marking the use of unsafe code that is not supported in Grasshopper.
#if !TARGET_JVM
-#define STRUCT
#define UNSAFE_TABLES
#endif
using System.Globalization;
using System.Text;
+using System.Threading;
using System.Runtime.CompilerServices;
namespace System
{
-#if STRUCT
- internal partial struct NumberFormatter
-#else
internal sealed partial class NumberFormatter
-#endif
{
#region Static Fields
#region Fields
- private readonly bool _NaN;
- private readonly bool _infinity;
- private readonly bool _isCustomFormat;
- private readonly bool _specifierIsUpper;
- private readonly char _specifier;
- private readonly sbyte _precision;
- private readonly sbyte _defPrecision;
+ private Thread _thread;
+ private NumberFormatInfo _nfi;
+ private bool _NaN;
+ private bool _infinity;
+ private bool _isCustomFormat;
+ private bool _specifierIsUpper;
private bool _positive;
- private sbyte _digitsLen;
- private sbyte _offset; // Represent the first digit offset.
+ private char _specifier;
+ private int _precision;
+ private int _defPrecision;
+
+ private int _digitsLen;
+ private int _offset; // Represent the first digit offset.
private int _decPointPos;
// The following fields are a hexadeimal representation of the digits.
private void InitDecHexDigits (uint value)
{
if (value >= HundredMillion) {
- uint div1 = value / HundredMillion;
- value = value - HundredMillion * div1;
- _val2 = ToDecHex ((int)div1);
+ int div1 = (int)(value / HundredMillion);
+ value -= HundredMillion * (uint)div1;
+ _val2 = FastToDecHex (div1);
}
_val1 = ToDecHex ((int)value);
}
{
if (value >= HundredMillion) {
long div1 = (long)(value / HundredMillion);
- value = value - HundredMillion * (ulong)div1;
+ value -= HundredMillion * (ulong)div1;
if (div1 >= HundredMillion) {
int div2 = (int)(div1 / HundredMillion);
div1 = div1 - div2 * (long)HundredMillion;
#if UNSAFE_TABLES
unsafe
#endif
- private static int FastToDecHex (int val)
+ private static uint FastToDecHex (int val)
{
- int res = 0;
- if (val >= 100) {
- // Uses 2^19 (524288) to compute val / 100 for val < 10000.
- int v = (val * 5243) >> 19;
- val -= v * 100;
- res = DecHexDigits [v] << 8;
- }
- return res | DecHexDigits [val];
+ if (val < 100)
+ return (uint)DecHexDigits [val];
+
+ // Uses 2^19 (524288) to compute val / 100 for val < 10000.
+ int v = (val * 5243) >> 19;
+ return (uint)((DecHexDigits [v] << 8) | DecHexDigits [val - v * 100]);
}
// Helper to translate an int in the range 0 .. 99999999 to its
// Hexadecimal digits representation.
private static uint ToDecHex (int val)
{
- int res = 0;
+ uint res = 0;
if (val >= 10000) {
int v = val / 10000;
val -= v * 10000;
res = FastToDecHex (v) << 16;
}
- return (uint)(res | FastToDecHex (val));
+ return res | FastToDecHex (val);
}
// Helper to count number of hexadecimal digits in a number.
private static int DecHexLen (uint val)
{
- int v = (int)val;
- if (v < 0)
- return 8;
- if (v < 0x10000)
- return FastDecHexLen (v);
- return 4 + FastDecHexLen (v >> 16);
+ if (val < 0x10000)
+ return FastDecHexLen ((int)val);
+ return 4 + FastDecHexLen ((int)(val >> 16));
}
// Count number of hexadecimal digits stored in _val1 .. _val4.
- private sbyte DecHexLen ()
+ private int DecHexLen ()
{
if (_val4 != 0)
- return (sbyte)(DecHexLen (_val4) + 24);
- if (_val3 != 0)
- return (sbyte)(DecHexLen (_val3) + 16);
- if (_val2 != 0)
- return (sbyte)(DecHexLen (_val2) + 8);
- if (_val1 != 0)
- return (sbyte)DecHexLen (_val1);
- return 0;
+ return DecHexLen (_val4) + 24;
+ else if (_val3 != 0)
+ return DecHexLen (_val3) + 16;
+ else if (_val2 != 0)
+ return DecHexLen (_val2) + 8;
+ else if (_val1 != 0)
+ return DecHexLen (_val1);
+ else
+ return 0;
}
// Helper to count the 10th scale (number of digits) in a number
// Parse the given format and initialize the following fields:
// _isCustomFormat, _specifierIsUpper, _specifier & _precision.
- private NumberFormatter (string format)
+ public NumberFormatter (Thread current)
+ {
+ _cbuf = new char [0];
+ if (current == null)
+ return;
+ _thread = current;
+ CurrentCulture = _thread.CurrentCulture;
+ }
+
+ private void Init (string format)
{
-#if STRUCT
- // Init all fields when using a struct.
_val1 = _val2 = _val3 = _val4 = 0;
- _defPrecision = 0;
_offset = 0;
- _decPointPos = _digitsLen = 0;
- _positive = _NaN = _infinity = false;
- _cbuf = null;
- _ind = 0;
-#endif
+ _NaN = _infinity = false;
_isCustomFormat = false;
_specifierIsUpper = true;
_precision = -1;
+
if (format == null || format.Length == 0) {
_specifier = 'G';
return;
}
_specifier = specifier;
if (format.Length > 1) {
- _precision = (sbyte)ParsePrecision (format);
+ _precision = ParsePrecision (format);
if (_precision == -2) { // Is it a custom format?
_isCustomFormat = true;
_specifier = '0';
}
}
- public NumberFormatter (string format, sbyte value)
- : this (format, (int)value)
- {
- _defPrecision = Int8DefPrecision;
- if (_specifier == 'X' && value < 0) {
- _val1 = (byte)value;
- _decPointPos = _digitsLen = 2;
- return;
- }
- }
-
- public NumberFormatter (string format, byte value)
- : this (format, (uint)value)
- {
- _defPrecision = UInt8DefPrecision;
- }
-
- public NumberFormatter (string format, short value)
- : this (format, (int)value)
+ private void InitHex (ulong value)
{
- _defPrecision = Int16DefPrecision;
- if (_specifier == 'X' && value < 0) {
- _val1 = (ushort)value;
- _decPointPos = _digitsLen = 4;
- return;
+ switch (_defPrecision) {
+ case Int8DefPrecision: value = (byte) value; break;
+ case Int16DefPrecision: value = (ushort) value; break;
+ case Int32DefPrecision: value = (uint) value; break;
}
+ _val1 = (uint)value;
+ _val2 = (uint)(value >> 32);
+ _decPointPos = _digitsLen = DecHexLen ();
+ if (value == 0)
+ _decPointPos = 1;
}
- public NumberFormatter (string format, ushort value)
- : this (format, (uint)value)
- {
- _defPrecision = UInt16DefPrecision;
- }
-
- public NumberFormatter (string format, int value)
- : this (format)
+ private void Init (string format, int value, int defPrecision)
{
- _defPrecision = Int32DefPrecision;
+ Init (format);
+ _defPrecision = defPrecision;
_positive = value >= 0;
- if (value == 0) {
- _decPointPos = 1;
- return;
- }
- if (_specifier == 'X') {
- _val1 = (uint)value;
- _decPointPos = _digitsLen = DecHexLen ();
+ if (value == 0 || _specifier == 'X') {
+ InitHex ((ulong)value);
return;
}
if (value < 0)
value = -value;
-
InitDecHexDigits ((uint)value);
_decPointPos = _digitsLen = DecHexLen ();
}
- public NumberFormatter (string format, uint value)
- : this (format)
+ private void Init (string format, uint value, int defPrecision)
{
- _defPrecision = UInt32DefPrecision;
+ Init (format);
+ _defPrecision = defPrecision;
_positive = true;
- if (value == 0) {
- _decPointPos = 1;
- return;
- }
- if (_specifier == 'X') {
- _val1 = value;
- _decPointPos = _digitsLen = DecHexLen ();
+ if (value == 0 || _specifier == 'X') {
+ InitHex (value);
return;
}
_decPointPos = _digitsLen = DecHexLen ();
}
- public NumberFormatter (string format, long value)
- : this (format)
+ private void Init (string format, long value)
{
+ Init (format);
_defPrecision = Int64DefPrecision;
_positive = value >= 0;
- if (value == 0) {
- _decPointPos = 1;
- return;
- }
- if (_specifier == 'X') {
- _val1 = (uint)value;
- _val2 = (uint)(value >> 32);
- _decPointPos = _digitsLen = DecHexLen ();
+ if (value == 0 || _specifier == 'X') {
+ InitHex ((ulong)value);
return;
}
if (value < 0)
value = -value;
-
InitDecHexDigits ((ulong)value);
_decPointPos = _digitsLen = DecHexLen ();
}
- public NumberFormatter (string format, ulong value)
- : this (format)
+ private void Init (string format, ulong value)
{
+ Init (format);
_defPrecision = UInt64DefPrecision;
_positive = true;
- if (value == 0) {
- _decPointPos = 1;
- return;
- }
- if (_specifier == 'X') {
- _val1 = (uint)value;
- _val2 = (uint)(value >> 32);
- _decPointPos = _digitsLen = DecHexLen ();
+ if (value == 0 || _specifier == 'X') {
+ InitHex ((ulong)value);
return;
}
_decPointPos = _digitsLen = DecHexLen ();
}
- public NumberFormatter (string format, float value)
- : this (format, value, SingleDefPrecision)
- {
- }
-
- public NumberFormatter (string format, double value)
- : this (format, value, DoubleDefPrecision)
- {
- }
-
#if UNSAFE_TABLES // No unsafe code under TARGET_JVM
unsafe
#endif
- public NumberFormatter (string format, double value, sbyte defPrecision)
- : this (format)
+ private void Init (string format, double value, int defPrecision)
{
- _defPrecision = defPrecision;
+ Init (format);
- // Double to bits
+ _defPrecision = defPrecision;
long bits = BitConverter.DoubleToInt64Bits (value);
_positive = bits >= 0;
bits &= Int64.MaxValue;
if (bits == 0) {
_decPointPos = 1;
+ _digitsLen = 0;
_positive = true;
return;
}
}
InitDecHexDigits ((ulong)res);
- _offset = (sbyte)CountTrailingZeros ();
- _digitsLen = (sbyte)(order - _offset);
+ _offset = CountTrailingZeros ();
+ _digitsLen = order - _offset;
}
- public NumberFormatter (string format, decimal value)
- : this (format)
+ private void Init (string format, decimal value)
{
- _infinity = _NaN = false;
+ Init (format);
_defPrecision = DecimalDefPrecision;
int[] bits = decimal.GetBits (value);
if (bits [0] == 0 && bits [1] == 0 && bits [2] == 0) {
_decPointPos = -scale;
_positive = true;
+ _digitsLen = 0;
return;
}
InitDecHexDigits ((uint)bits [2], ((ulong)bits [1] << 32) | (uint)bits [0]);
_digitsLen = DecHexLen ();
_decPointPos = _digitsLen - scale;
+ if (_precision != -1 || _specifier != 'G') {
+ _offset = CountTrailingZeros ();
+ _digitsLen -= _offset;
+ }
}
#endregion Constructors
private void ResetCharBuf (int size)
{
- if (_cbuf == null || _cbuf.Length < size)
- _cbuf = new char [size];
_ind = 0;
+ if (_cbuf.Length < size)
+ _cbuf = new char [size];
}
private void Resize (int len)
#region Helper properties
+ private NumberFormatInfo GetNumberFormatInstance (IFormatProvider fp)
+ {
+ if (_nfi != null && fp == null)
+ return _nfi;
+ return NumberFormatInfo.GetInstance (fp);
+ }
+
+ public CultureInfo CurrentCulture {
+ set {
+ if (value != null && value.IsReadOnly)
+ _nfi = value.NumberFormat;
+ else
+ _nfi = null;
+ }
+ }
+
private int IntegerDigits {
get { return _decPointPos > 0 ? _decPointPos : 1; }
}
get { return _digitsLen > _decPointPos ? _digitsLen - _decPointPos : 0; }
}
- private bool IsIntegerSource {
- get { return _defPrecision < 30 && _defPrecision != DoubleDefPrecision && _defPrecision != SingleDefPrecision; }
- }
-
private bool IsFloatingSource {
get { return _defPrecision == DoubleDefPrecision || _defPrecision == SingleDefPrecision; }
}
- private bool IsDecimalSource {
- get { return _defPrecision > 30; }
- }
-
private bool IsZero {
get { return _digitsLen == 0; }
}
private bool RoundBits (int shift)
{
- if (shift <= 0) {
- if (IsDecimalSource) {
- _digitsLen += _offset;
- RemoveTrailingZeros ();
- }
+ if (shift <= 0)
return false;
- }
if (shift > _digitsLen) {
_digitsLen = 0;
if (rem16 >= 0x5) {
_val1 |= 0x99999999 >> (28 - shift);
AddOneToDecHex ();
- sbyte newlen = DecHexLen ();
+ int newlen = DecHexLen ();
res = newlen != _digitsLen;
_decPointPos = _decPointPos + newlen - _digitsLen;
_digitsLen = newlen;
private void RemoveTrailingZeros ()
{
- _offset = (sbyte)CountTrailingZeros ();
+ _offset = CountTrailingZeros ();
_digitsLen -= _offset;
if (_digitsLen == 0) {
_offset = 0;
#region public number formatting methods
- public static string NumberToString (string format, sbyte value, NumberFormatInfo nfi)
+ private static NumberFormatter GetInstance()
{
- return new NumberFormatter (format, value).NumberToString (format, nfi);
+ return Thread.CurrentThread.AcquireNumberFormatter();
}
- public static string NumberToString (string format, byte value, NumberFormatInfo nfi)
+ private void Release()
{
- return new NumberFormatter (format, value).NumberToString (format, nfi);
+ _thread.ReleaseNumberFormatter (this);
}
- public static string NumberToString (string format, ushort value, NumberFormatInfo nfi)
+ public static string NumberToString (string format, sbyte value, IFormatProvider fp)
{
- return new NumberFormatter (format, value).NumberToString (format, nfi);
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value, Int8DefPrecision);
+ string res = inst.IntegerToString (format, fp);
+ inst.Release();
+ return res;
}
- public static string NumberToString (string format, short value, NumberFormatInfo nfi)
+ public static string NumberToString (string format, byte value, IFormatProvider fp)
{
- return new NumberFormatter (format, value).NumberToString (format, nfi);
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value, UInt8DefPrecision);
+ string res = inst.IntegerToString (format, fp);
+ inst.Release();
+ return res;
}
- public static string NumberToString (string format, uint value, NumberFormatInfo nfi)
+ public static string NumberToString (string format, ushort value, IFormatProvider fp)
{
- return new NumberFormatter (format, value).NumberToString (format, nfi);
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value, Int16DefPrecision);
+ string res = inst.IntegerToString (format, fp);
+ inst.Release();
+ return res;
}
- public static string NumberToString (string format, int value, NumberFormatInfo nfi)
+ public static string NumberToString (string format, short value, IFormatProvider fp)
{
- return new NumberFormatter (format, value).NumberToString (format, nfi);
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value, UInt16DefPrecision);
+ string res = inst.IntegerToString (format, fp);
+ inst.Release();
+ return res;
}
- public static string NumberToString (string format, ulong value, NumberFormatInfo nfi)
+ public static string NumberToString (string format, uint value, IFormatProvider fp)
{
- return new NumberFormatter (format, value).NumberToString (format, nfi);
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value, Int32DefPrecision);
+ string res = inst.IntegerToString (format, fp);
+ inst.Release();
+ return res;
}
- public static string NumberToString (string format, long value, NumberFormatInfo nfi)
+ public static string NumberToString (string format, int value, IFormatProvider fp)
{
- return new NumberFormatter (format, value).NumberToString (format, nfi);
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value, UInt32DefPrecision);
+ string res = inst.IntegerToString (format, fp);
+ inst.Release();
+ return res;
}
- public static string NumberToString (string format, float value, NumberFormatInfo nfi)
+ public static string NumberToString (string format, ulong value, IFormatProvider fp)
{
- NumberFormatter rep = new NumberFormatter (format, value);
- if (rep._specifier == 'R')
- return rep.FormatRoundtrip (value, nfi);
- return rep.NumberToString (format, nfi);
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value);
+ string res = inst.IntegerToString (format, fp);
+ inst.Release();
+ return res;
}
- public static string NumberToString (string format, double value, NumberFormatInfo nfi)
+ public static string NumberToString (string format, long value, IFormatProvider fp)
{
- NumberFormatter rep = new NumberFormatter (format, value);
- if (rep._specifier == 'R')
- return rep.FormatRoundtrip (value, nfi);
- return rep.NumberToString (format, nfi);
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value);
+ string res = inst.IntegerToString (format, fp);
+ inst.Release();
+ return res;
}
- public static string NumberToString (string format, decimal value, NumberFormatInfo nfi)
+ public static string NumberToString (string format, float value, IFormatProvider fp)
{
- return new NumberFormatter (format, value).NumberToString (format, nfi);
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value, SingleDefPrecision);
+ NumberFormatInfo nfi = inst.GetNumberFormatInstance (fp);
+ string res;
+ if (inst._NaN)
+ res = nfi.NaNSymbol;
+ else if (inst._infinity)
+ if (inst._positive)
+ res = nfi.PositiveInfinitySymbol;
+ else
+ res = nfi.NegativeInfinitySymbol;
+ else if (inst._specifier == 'R')
+ res = inst.FormatRoundtrip (value, nfi);
+ else
+ res = inst.NumberToString (format, nfi);
+ inst.Release();
+ return res;
}
- public string NumberToString (string format, NumberFormatInfo nfi)
+ public static string NumberToString (string format, double value, IFormatProvider fp)
{
- if (IsFloatingSource) {
- if (_NaN)
- return nfi.NaNSymbol;
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value, DoubleDefPrecision);
+ NumberFormatInfo nfi = inst.GetNumberFormatInstance (fp);
+ string res;
+ if (inst._NaN)
+ res = nfi.NaNSymbol;
+ else if (inst._infinity)
+ if (inst._positive)
+ res = nfi.PositiveInfinitySymbol;
+ else
+ res = nfi.NegativeInfinitySymbol;
+ else if (inst._specifier == 'R')
+ res = inst.FormatRoundtrip (value, nfi);
+ else
+ res = inst.NumberToString (format, nfi);
+ inst.Release();
+ return res;
+ }
- if (_infinity) {
- if (_positive)
- return nfi.PositiveInfinitySymbol;
- else
- return nfi.NegativeInfinitySymbol;
- }
+ public static string NumberToString (string format, decimal value, IFormatProvider fp)
+ {
+ NumberFormatter inst = GetInstance();
+ inst.Init (format, value);
+ string res = inst.NumberToString (format, inst.GetNumberFormatInstance (fp));
+ inst.Release();
+ return res;
+ }
+
+ public static string NumberToString (uint value, IFormatProvider fp)
+ {
+ if (value >= HundredMillion)
+ return NumberToString (null, value, fp);
+
+ NumberFormatter inst = GetInstance();
+ string res = inst.FastIntegerToString ((int)value, fp);
+ inst.Release();
+ return res;
+ }
+
+ public static string NumberToString (int value, IFormatProvider fp)
+ {
+ if (value >= HundredMillion || value <= -HundredMillion)
+ return NumberToString (null, value, fp);
+
+ NumberFormatter inst = GetInstance();
+ string res = inst.FastIntegerToString (value, fp);
+ inst.Release();
+ return res;
+ }
+
+ public static string NumberToString (ulong value, IFormatProvider fp)
+ {
+ if (value >= HundredMillion)
+ return NumberToString (null, value, fp);
+
+ NumberFormatter inst = GetInstance();
+ string res = inst.FastIntegerToString ((int)value, fp);
+ inst.Release();
+ return res;
+ }
+
+ public static string NumberToString (long value, IFormatProvider fp)
+ {
+ if (value >= HundredMillion || value <= -HundredMillion)
+ return NumberToString (null, value, fp);
+
+ NumberFormatter inst = GetInstance();
+ string res = inst.FastIntegerToString ((int)value, fp);
+ inst.Release();
+ return res;
+ }
+
+ public static string NumberToString (float value, IFormatProvider fp)
+ {
+ NumberFormatter inst = GetInstance();
+ inst.Init (null, value, SingleDefPrecision);
+ NumberFormatInfo nfi = inst.GetNumberFormatInstance (fp);
+ string res;
+ if (inst._NaN)
+ res = nfi.NaNSymbol;
+ else if (inst._infinity)
+ if (inst._positive)
+ res = nfi.PositiveInfinitySymbol;
+ else
+ res = nfi.NegativeInfinitySymbol;
+ else
+ res = inst.FormatGeneral (-1, nfi);
+ inst.Release();
+ return res;
+ }
+
+ public static string NumberToString (double value, IFormatProvider fp)
+ {
+ NumberFormatter inst = GetInstance();
+ NumberFormatInfo nfi = inst.GetNumberFormatInstance (fp);
+ inst.Init (null, value, DoubleDefPrecision);
+ string res;
+ if (inst._NaN)
+ res = nfi.NaNSymbol;
+ else if (inst._infinity)
+ if (inst._positive)
+ res = nfi.PositiveInfinitySymbol;
+ else
+ res = nfi.NegativeInfinitySymbol;
+ else
+ res = inst.FormatGeneral (-1, nfi);
+ inst.Release();
+ return res;
+ }
+
+ private string FastIntegerToString (int value, IFormatProvider fp)
+ {
+ if (value < 0) {
+ string sign = GetNumberFormatInstance(fp).NegativeSign;
+ ResetCharBuf (8 + sign.Length);
+ value = -value;
+ Append (sign);
+ }
+ else
+ ResetCharBuf (8);
+
+ if (value >= 10000) {
+ int v = value / 10000;
+ FastAppendDigits (v, false);
+ FastAppendDigits (value - v * 10000, true);
}
+ else
+ FastAppendDigits (value, false);
+ return new string (_cbuf, 0, _ind);
+ }
+
+ private string IntegerToString (string format, IFormatProvider fp)
+ {
+ NumberFormatInfo nfi = GetNumberFormatInstance (fp);
switch (_specifier) {
case 'C':
return FormatCurrency (_precision, nfi);
case 'D':
- if (IsIntegerSource)
- return FormatDecimal (_precision, nfi);
- throw new FormatException ();
+ return FormatDecimal (_precision, nfi);
case 'E':
return FormatExponential (_precision, nfi);
case 'F':
return FormatFixedPoint (_precision, nfi);
case 'G':
- if (IsIntegerSource && _precision <= 0)
+ if (_precision <= 0)
return FormatDecimal (-1, nfi);
return FormatGeneral (_precision, nfi);
case 'N':
case 'P':
return FormatPercent (_precision, nfi);
case 'X':
- if (IsIntegerSource)
- return FormatHexadecimal (_precision);
- throw new FormatException ("The specified format cannot be used in this instance");
- case 'R':
- throw new FormatException ("The specified format cannot be used in this instance");
+ return FormatHexadecimal (_precision);
+ default:
+ if (_isCustomFormat)
+ return FormatCustom (format, nfi);
+ throw new FormatException ("The specified format '" + format + "' is invalid");
+ }
+ }
+
+ private string NumberToString (string format, NumberFormatInfo nfi)
+ {
+ switch (_specifier) {
+ case 'C':
+ return FormatCurrency (_precision, nfi);
+ case 'E':
+ return FormatExponential (_precision, nfi);
+ case 'F':
+ return FormatFixedPoint (_precision, nfi);
+ case 'G':
+ return FormatGeneral (_precision, nfi);
+ case 'N':
+ return FormatNumber (_precision, nfi);
+ case 'P':
+ return FormatPercent (_precision, nfi);
+ case 'X':
default:
if (_isCustomFormat)
return FormatCustom (format, nfi);
return new string (_cbuf, 0, _ind);
}
- public string FormatDecimal (int precision, NumberFormatInfo nfi)
+ private string FormatDecimal (int precision, NumberFormatInfo nfi)
{
if (precision < _digitsLen)
precision = _digitsLen;
return "0";
ResetCharBuf (precision + 1);
- if (!_positive) {
- if (nfi == null)
- nfi = NumberFormatInfo.GetInstance (null);
-
+ if (!_positive)
Append (nfi.NegativeSign);
- }
AppendDigits (0, precision);
return new string (_cbuf, 0, _ind);
#if UNSAFE_TABLES // No unsafe code under TARGET_JVM
unsafe
#endif
- public string FormatHexadecimal (int precision)
+ private string FormatHexadecimal (int precision)
{
int size = Math.Max (precision, _decPointPos);
#if UNSAFE_TABLES
return new string (_cbuf, 0, _ind);
}
- public string FormatRoundtrip (double origval, NumberFormatInfo nfi)
+ private string FormatRoundtrip (double origval, NumberFormatInfo nfi)
{
- if (_NaN)
- return nfi.NaNSymbol;
-
- if (_infinity)
- if (_positive)
- return nfi.PositiveInfinitySymbol;
- else
- return nfi.NegativeInfinitySymbol;
-
NumberFormatter nfc = GetClone ();
if (origval >= MinRoundtripVal && origval <= MaxRoundtripVal) {
string shortRep = FormatGeneral (_defPrecision, nfi);
return nfc.FormatGeneral (_defPrecision + 2, nfi);
}
- public string FormatRoundtrip (float origval, NumberFormatInfo nfi)
+ private string FormatRoundtrip (float origval, NumberFormatInfo nfi)
{
- if (_NaN)
- return nfi.NaNSymbol;
-
- if (_infinity)
- if (_positive)
- return nfi.PositiveInfinitySymbol;
- else
- return nfi.NegativeInfinitySymbol;
-
NumberFormatter nfc = GetClone ();
string shortRep = FormatGeneral (_defPrecision, nfi);
// Check roundtrip only for "normal" double values.
return nfc.FormatGeneral (_defPrecision + 2, nfi);
}
- public string FormatGeneral (NumberFormatInfo nfi)
- {
- if (_NaN)
- return nfi.NaNSymbol;
-
- if (_infinity)
- if (_positive)
- return nfi.PositiveInfinitySymbol;
- else
- return nfi.NegativeInfinitySymbol;
-
- return FormatGeneral (-1, nfi);
- }
-
private string FormatGeneral (int precision, NumberFormatInfo nfi)
{
bool enableExp;
Append ((char)('0' | exponent));
}
else {
- int hexDigit = FastToDecHex (exponent);
+ uint hexDigit = FastToDecHex (exponent);
if (exponent >= 100 || minDigits == 3)
Append ((char)('0' | (hexDigit >> 8)));
Append ((char)('0' | ((hexDigit >> 4) & 0xf)));
_cbuf [_ind++] = (char)('0' | v & 0xf);
}
+#if UNSAFE_TABLES // No unsafe code under TARGET_JVM
+ unsafe
+#endif
+ private void FastAppendDigits (int val, bool force)
+ {
+ int i = _ind;
+ int digits;
+ if (force || val >= 100) {
+ int v = (val * 5243) >> 19;
+ digits = DecHexDigits [v];
+ if (force || val >= 1000)
+ _cbuf [i++] = (char)('0' | digits >> 4);
+ _cbuf [i++] = (char)('0' | (digits & 0xf));
+ digits = DecHexDigits [val - v * 100];
+ }
+ else
+ digits = DecHexDigits [val];
+
+ if (force || val >= 10)
+ _cbuf [i++] = (char)('0' | digits >> 4);
+ _cbuf [i++] = (char)('0' | (digits & 0xf));
+ _ind = i;
+ }
+
private void AppendDigits (int start, int end)
{
if (start >= end)
+//\r
+// System.NumberFormatter.cs\r
+//\r
+// Author:\r
+// Eyal Alaluf (eyala@mainsoft.com)\r
+//\r
+// Copyright (C) 2008 Mainsoft Co. (http://www.mainsoft.com)\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+\r
#if !TARGET_JVM\r
#define UNSAFE_TABLES\r
-#define STRUCT\r
#endif\r
\r
-namespace System2\r
+namespace System\r
{\r
#if !UNSAFE_TABLES\r
-#if STRUCT\r
- partial struct NumberFormatter\r
-#else\r
partial class NumberFormatter\r
-#endif\r
{\r
static internal readonly char[] DigitLowerTable = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };\r
static internal readonly char[] DigitUpperTable = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };\r
#endif\r
}\r
}\r
-#endif\r
+#endif // !UNSAFE_TABLES\r
public override string ToString ()
{
- return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+ return NumberFormatter.NumberToString (m_value, null);
}
public string ToString (IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return NumberFormatter.NumberToString (format, m_value, nfi);
+ return NumberFormatter.NumberToString (format, m_value, provider);
}
// =========== ICovnertible Methods =========== //
#endif
public override string ToString ()
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (null);
- return new NumberFormatter(null, m_value).FormatGeneral (nfi);
+ return NumberFormatter.NumberToString (m_value, null);
}
public string ToString (IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return new NumberFormatter(null, m_value).FormatGeneral (nfi);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return NumberFormatter.NumberToString (format, m_value, nfi);
+ return NumberFormatter.NumberToString (format, m_value, provider);
}
// ============= IConvertible Methods ============ //
sb.Append ('.');
}
- System.Globalization.NumberFormatInfo nfi = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
- sb.Append (new NumberFormatter (null, (int)Math.Abs (Hours)).FormatDecimal(2, nfi));
+ sb.Append (Math.Abs (Hours).ToString ("D2"));
sb.Append (':');
- sb.Append (new NumberFormatter (null, (int)Math.Abs (Minutes)).FormatDecimal(2, nfi));
+ sb.Append (Math.Abs (Minutes).ToString ("D2"));
sb.Append (':');
- sb.Append (new NumberFormatter (null, (int)Math.Abs (Seconds)).FormatDecimal(2, nfi));
+ sb.Append (Math.Abs (Seconds).ToString ("D2"));
int fractional = (int) Math.Abs (_ticks % TicksPerSecond);
if (fractional != 0) {
sb.Append ('.');
- sb.Append (new NumberFormatter (null, (int)Math.Abs (fractional)).FormatDecimal(7, nfi));
+ sb.Append (fractional.ToString ("D7"));
}
return sb.ToString ();
public override string ToString ()
{
- return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+ return NumberFormatter.NumberToString (m_value, null);
}
public string ToString (IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return NumberFormatter.NumberToString (format, m_value, nfi);
+ return NumberFormatter.NumberToString (format, m_value, provider);
}
// =========== IConvertible Methods =========== //
public override string ToString ()
{
- return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+ return NumberFormatter.NumberToString (m_value, null);
}
public string ToString (IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider fp)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (fp);
- return NumberFormatter.NumberToString (format, m_value, nfi);
+ return NumberFormatter.NumberToString (format, m_value, fp);
}
// =========== IConvertible Methods =========== //
public override string ToString ()
{
- return new NumberFormatter(null, m_value).FormatDecimal(-1, null);
+ return NumberFormatter.NumberToString (m_value, null);
}
public string ToString (IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return new NumberFormatter(null, m_value).FormatDecimal(-1, nfi);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (provider);
- return NumberFormatter.NumberToString (format, m_value, nfi);
+ return NumberFormatter.NumberToString (format, m_value, provider);
}
// =========== IConvertible Methods =========== //
+2008-04-01 Eyal Alaluf <eyala@mainsoft.com>
+
+ * NumberFormatterTest.cs: Test (-0.0).ToString.
+
2008-03-06 Zoltan Varga <vargaz@gmail.com>
* TypeTest.cs (PublicKeyToken): Add a test for #367670.
public void Test13000 ()\r
{\r
AssertEquals ("#01", "0", 0.0.ToString ("G", _nfi));\r
+ AssertEquals ("#01.1", "0", (-0.0).ToString ("G", _nfi));\r
AssertEquals ("#02", "0", 0.0.ToString ("g", _nfi));\r
AssertEquals ("#03", "-1.79769313486232E+308", Double.MinValue.ToString ("G", _nfi));\r
AssertEquals ("#04", "-1.79769313486232e+308", Double.MinValue.ToString ("g", _nfi));\r
\r
Microsoft Visual Studio Solution File, Format Version 10.00\r
-# Visual C# Express Codename Orcas\r
+# Visual C# Express 2008\r
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gmcs", "gmcs.csproj", "{D4A01C5B-A1B5-48F5-BB5B-D2E1BD236E56}"\r
EndProject\r
Global\r