Author: atsushi
Date: 2007-03-14 10:11:21 -0500 (Wed, 14 Mar 2007)
New Revision: 74260

Added:
   
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryWriterSessionTest.cs
Modified:
   
trunk/olive/class/System.Runtime.Serialization/System.Runtime.Serialization_test.dll.sources
   trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog
   
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryWriter.cs
   
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryWriterSession.cs
   trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/ChangeLog
   
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryDictionaryWriterTest.cs
   
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlDictionaryReaderQuotasTest.cs
Log:
2007-03-14  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * XmlBinaryWriterSession.cs : implemented.
        * XmlBinaryDictionaryWriter.cs : a bunch of updates.

        * XmlDictionaryReaderQuotasTest.cs : fixed test class name.
        * XmlBinaryDictionaryWriterTest.cs : added a bunch of tests. Many
          tests still fail. They are going to be fixed.
        * XmlBinaryWriterSessionTest.cs : new test.



Modified: 
trunk/olive/class/System.Runtime.Serialization/System.Runtime.Serialization_test.dll.sources
===================================================================
--- 
trunk/olive/class/System.Runtime.Serialization/System.Runtime.Serialization_test.dll.sources
        2007-03-14 15:08:09 UTC (rev 74259)
+++ 
trunk/olive/class/System.Runtime.Serialization/System.Runtime.Serialization_test.dll.sources
        2007-03-14 15:11:21 UTC (rev 74260)
@@ -3,6 +3,7 @@
 System.Runtime.Serialization/XsdDataContractImporterTest.cs
 System.Xml/UniqueIdTest.cs
 System.Xml/XmlBinaryDictionaryWriterTest.cs
+System.Xml/XmlBinaryWriterSessionTest.cs
 System.Xml/XmlDictionaryReaderAbstractTest.cs
 System.Xml/XmlDictionaryReaderQuotasTest.cs
 System.Xml/XmlDictionaryTest.cs

Modified: trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog
===================================================================
--- trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog 
2007-03-14 15:08:09 UTC (rev 74259)
+++ trunk/olive/class/System.Runtime.Serialization/System.Xml/ChangeLog 
2007-03-14 15:11:21 UTC (rev 74260)
@@ -1,5 +1,10 @@
 2007-03-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * XmlBinaryWriterSession.cs : implemented.
+       * XmlBinaryDictionaryWriter.cs : a bunch of updates.
+
+2007-03-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * UniqueId.cs : hacky Equals() implementation.
        * XmlDictionaryReaderQuotas.cs : removed Default and fixed Max.
        * XmlSimpleDictionaryWriter.cs : in .NET 3.0 RTM, it is supported.

Modified: 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryWriter.cs
===================================================================
--- 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryWriter.cs
      2007-03-14 15:08:09 UTC (rev 74259)
+++ 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryWriter.cs
      2007-03-14 15:11:21 UTC (rev 74260)
@@ -4,7 +4,7 @@
 // Author:
 //     Atsushi Enomoto  <[EMAIL PROTECTED]>
 //
-// Copyright (C) 2005 Novell, Inc.  http://www.novell.com
+// Copyright (C) 2005, 2007 Novell, Inc.  http://www.novell.com
 //
 
 //
@@ -37,25 +37,44 @@
 
 namespace System.Xml
 {
-       /* Binary Format (maybe incomplete):
+       /* Binary Format (incomplete):
 
-               StartAttribute without Prefix: 00 name
-               StartAttribute with Prefix without nsIndex: 01 prefix name
-               StartAttribute dict. without Prefix: 02 nameIdx
-               StartAttribute dict. with Prefix: 03 prefix nameIdx
-               StartAttribute with Prefix with nsIndex: [22-3B] name
-               Missing default namespace: 04 ns (before 3C)
-               Missing non-default namespace: 05 prefix ns (before 3C)
-               EndElement: 3C
-               Comment: 3D fixed_len utf8bin
-               StartElement with no Prefix: 3F name
-               StartElement with Prefix: 40 prefix name
-               StartElement dict. with no Prefix: 41 name
-               StartElement dict. with Prefix: 42 prefix nameIdx
-               Empty string: 82
-               Text, CDATA, Whitespace: 83 len utf8bin
-               Text, CDATA, Whitespace + EndElement?: 9D len utf8bin
+               Literal strings are represented as UTF-8 string, with a length
+               prefixed to the string itself.
 
+               Key indices are based on the rules below:
+               - dictionary strings which can be found in IXmlDictionary are 
+                 doubled its Key. e.g. if the string.Key is 4, then the
+                 output is 8.
+               - dictionary strings which cannot be found in IXmlDictionary
+                 are stored in the XmlBinaryWriterSession, and its output
+                 number is doubled + 1 e.g. if the string is the first
+                 non-dictionary entry, then the output is 1, and 7 for the
+                 fourth one.
+               - When the index goes beyond 128, then it becomes 2 bytes,
+                 where the first byte becomes 0x80 + idx % 0x80 and
+                 the second byte becomes idx / 0x80.
+
+               Below are operations. Prefixes are always raw strings.
+               $string is length-prefixed string. @index is index as
+               described above. [value] is length-prefixed raw array.
+
+               01                      : EndElement
+               02 $value               : Comment
+               04 $name                : local attribute by string
+               05 $prefix $name        : global attribute by string
+               06 @name                : local attribute by index
+               07 $prefix @name        : global attribute by index
+               0A @name                : default namespace
+               0B $prefix @name        : prefixed namespace
+               40 $name                : element w/o namespace by string
+               41 $prefix $name        : element with namespace by string
+               42 @name                : element w/o namespace by index
+               42 $prefix @name        : element with namespace by index
+               98 $value               : text/cdata/chars
+               99 $value               : text/cdata/chars + EndElement
+               9F [value]              : base64
+
                FIXME: Below are not implemented:
                byte : 7B
                short : 7C
@@ -65,21 +84,20 @@
                double: 80
                decimal: 81
                DateTime: 82
+               bool-false: 85
+               bool-true: 86
                UniqueId: 8D
                TimeSpan: 8E
-               Guid: 8F
-               base64Binary: A0
-               (Uri is simply 83, QName is 83 '{' ns '}' 83 name)
+               Guid: B0
+               Guid + EndElement: B1
+               base64Binary: 9F
+               (Uri is simply 98, QName is 98 '{' ns '}' 98 name)
 
                Error: PIs, doctype
                Ignored: XMLdecl
-
-               prefix, name and ns are name strings: length utf8bin
-
        */
 
        // FIXME:
-       //      - Support XmlBinaryWriterSession (esp. EmitStrings).
        //      - Support XmlDictionaryString.
        //      - Namespace node processing seems still incomplete.
        //      - Find out how it can write 0x9D (text + EndElement).
@@ -162,15 +180,28 @@
                        if (new_namespaces.Count > 0) {
                                foreach (DictionaryEntry ent in new_namespaces) 
{
                                        string prefix = (string) ent.Key;
-                                       string ns = (string) ent.Value;
-                                       if (prefix.Length > 0) {
-                                               stream.WriteByte (0x05);
-                                               WriteNamePart (prefix);
+                                       string ns = ent.Value as string;
+                                       XmlDictionaryString dns = ent.Value as 
XmlDictionaryString;
+                                       if (ns != null) {
+                                               if (prefix.Length > 0) {
+                                                       stream.WriteByte (0x09);
+                                                       WriteNamePart (prefix);
+                                               }
+                                               else
+                                                       stream.WriteByte (0x08);
+                                               WriteNamePart (ns);
+                                               nsmgr.AddNamespace (prefix, ns);
+                                       } else {
+                                               if (prefix.Length > 0) {
+                                                       stream.WriteByte (0x0B);
+                                                       WriteNamePart (prefix);
+                                               }
+                                               else
+                                                       stream.WriteByte (0x0A);
+                                               // FIXME: index could be > 256
+                                               stream.WriteByte ((byte) 
(dns.Key != 0 ? dns.Key << 1 : 0));
+                                               nsmgr.AddNamespace (prefix, 
dns.Value);
                                        }
-                                       else
-                                               stream.WriteByte (0x04);
-                                       WriteNamePart (ns);
-                                       nsmgr.AddNamespace (prefix, ns);
                                }
                                new_namespaces.Clear ();
                        }
@@ -204,11 +235,8 @@
                        if (open_attribute)
                                WriteEndAttribute ();
 
-                       // FIXME: I think this should be done, but WinFX beta1 
-                       // does not output missing ones.
-                       // while (open_element_count > 0) {
-                       //      WriteEndElement ();
-                       //}
+                        while (open_element_count > 0)
+                               WriteEndElement ();
                }
 
                private void CloseStartElement ()
@@ -231,9 +259,12 @@
                {
                        if (ns == null || ns == String.Empty)
                                throw new ArgumentException ("The Namespace 
cannot be empty.");
-                       foreach (DictionaryEntry de in new_namespaces)
-                               if (ns == de.Value as string)
+                       foreach (DictionaryEntry de in new_namespaces) {
+                               XmlDictionaryString dns = de.Value as 
XmlDictionaryString;
+                               string cns = dns != null ? dns.Value : de.Value 
as string;
+                               if (ns == cns)
                                        return (string) de.Key;
+                       }
 
                        string prefix = nsmgr.LookupPrefix (nsmgr.NameTable.Get 
(ns));
                        // XmlNamespaceManager might return such prefix that
@@ -251,7 +282,7 @@
                                CloseStartElement ();
                        }
 
-                       WriteToStream (0xA0, buffer, index, count);
+                       WriteToStream (0x9F, buffer, index, count);
                }
 
                public override void WriteCData (string text)
@@ -282,7 +313,7 @@
                                stream.WriteByte (0x8B);
                        else {
                                byte [] data = utf8Enc.GetBytes (buffer, index, 
count);
-                               WriteToStream (0x83, data, 0, data.Length);
+                               WriteToStream (0x98, data, 0, data.Length);
                        }
                }
 
@@ -296,7 +327,10 @@
                        CheckState ();
                        CloseStartElement ();
 
-                       WriteToStream (0x3D, text);
+                       // FIXME: this 0xA8 might be wrong
+                       if (text.Length == 0)
+                               stream.WriteByte (0xA8);
+                       WriteToStream (0x02, text);
                }
 
                public override void WriteDocType (string name, string pubid, 
string sysid, string subset)
@@ -368,7 +402,7 @@
                        CheckState ();
                        AddMissingElementXmlns ();
 
-                       stream.WriteByte (0x3C);
+                       stream.WriteByte (0x01);
 
                        open_element_count--;
                        xml_lang = xml_lang_stack.Pop ();
@@ -391,7 +425,7 @@
                public override void WriteProcessingInstruction (string name, 
string text)
                {
                        if (name != "xml")
-                               throw new InvalidOperationException 
("Processing instructions are not supported. ('xml' is allowed for 
XmlDeclaration; this is because of design problem of ECMA XmlWriter)");
+                               throw new ArgumentException ("Processing 
instructions are not supported. ('xml' is allowed for XmlDeclaration; this is 
because of design problem of ECMA XmlWriter)");
                        // Otherwise, silently ignored. WriteStartDocument()
                        // is still callable after this method(!)
                }
@@ -450,11 +484,12 @@
                        if (ns == null)
                                ns = String.Empty;
 
-                       int nsIdentifier = prefix.Length > 0 ? 1 : 0;
+                       int nsIdentifier = prefix.Length > 0 ? 0x05 : 0x04;
 
                        if (ns != String.Empty && prefix != "xmlns") {
                                if (prefix.Length > 0) {
-                                       string existingNS = new_namespaces 
[prefix] as string;
+                                       XmlDictionaryString dns = 
new_namespaces [prefix] as XmlDictionaryString;
+                                       string existingNS = dns != null ? 
dns.Value : new_namespaces [prefix] as string;
                                        if (existingNS != null && existingNS != 
ns)
                                                throw new ArgumentException 
(String.Format ("The prefix '{0}' is already bound to the namespace '{1}' and 
cannot be reassigned to '{2}'", prefix, existingNS, ns));
                                }
@@ -469,7 +504,7 @@
 
                        // Write to Stream
                        stream.WriteByte ((byte) nsIdentifier);
-                       WriteNames (nsIdentifier > 1 ? String.Empty : prefix, 
localName);
+                       WriteNames (/*nsIdentifier > 1 ? String.Empty : 
*/prefix, localName);
 
                        open_attribute = true;
                        state = WriteState.Attribute;
@@ -532,7 +567,7 @@
                        state = WriteState.Prolog;
                }
 
-               public override void WriteStartElement (string prefix, string 
localName, string ns)
+               void PrepareStartElement ()
                {
                        CheckState ();
                        CloseStartElement ();
@@ -540,7 +575,12 @@
                        xml_lang_stack.Push (xml_lang);
                        xml_space_stack.Push (xml_space);
                        nsmgr.PushScope ();
+               }
 
+               public override void WriteStartElement (string prefix, string 
localName, string ns)
+               {
+                       PrepareStartElement ();
+
                        if ((prefix != null && prefix != String.Empty) && ((ns 
== null) || (ns == String.Empty)))
                                throw new ArgumentException ("Cannot use a 
prefix with an empty namespace.");
 
@@ -554,23 +594,26 @@
                        if (prefix == null)
                                prefix = String.Empty;
 
-                       stream.WriteByte ((byte) (prefix.Length > 0 ? 0x40 : 
0x3F));
+                       stream.WriteByte ((byte) (prefix.Length > 0 ? 0x41 : 
0x40));
                        WriteNames (prefix, localName);
 
+                       PushElement (prefix, ns, ns);
+               }
+
+               void PushElement (string prefix, string ns, object nsobj)
+               {
                        open_element_count++;
                        state = WriteState.Element;
                        open_start_element = true;
 
-                       if (ns.Length > 0) {
-                               string existing = LookupPrefix (ns);
-                               if (existing != prefix) {
-                                       new_namespaces.Add (prefix, ns);
-                               }
-                       } else {
-                               if (ns != nsmgr.DefaultNamespace) {
-                                       new_namespaces.Add ("", ns);
-                               }
-                       }
+                       if (ns.Length == 0)
+                               return;
+
+                       string existing = LookupPrefix (ns);
+                       if (existing == prefix)
+                               return;
+
+                       new_namespaces.Add (prefix, nsobj);
                }
 
                public override void WriteString (string text)
@@ -622,12 +665,65 @@
                        WriteTextBinary (ws);
                }
 
+               #region DictionaryString
+               public override void WriteStartElement (string prefix, 
XmlDictionaryString localName, XmlDictionaryString namespaceUri)
+               {
+                       PrepareStartElement ();
+
+                       if (prefix == null && namespaceUri.Value.Length > 0)
+                               prefix = nsmgr.LookupPrefix 
(nsmgr.NameTable.Get (namespaceUri.Value));
+                       if (prefix == null)
+                               prefix = String.Empty;
+
+                       if (prefix.Length == 0)
+                               stream.WriteByte (0x42);
+                       else
+                               WriteToStream (0x43, prefix);
+                       stream.WriteByte ((byte) (localName.Key != 0 ? 
localName.Key << 1 : 0));
+
+                       PushElement (prefix, namespaceUri.Value, namespaceUri);
+               }
+               #endregion
+
+               #region WriteValue
+               public override void WriteValue (Guid value)
+               {
+                       stream.WriteByte (0xB0);
+                       byte [] bytes = value.ToByteArray ();
+                       stream.Write (bytes, 0, bytes.Length);
+               }
+
+               public override void WriteValue (UniqueId value)
+               {
+                       WriteToStream (0x8D, value.ToString ());
+               }
+
+               public override void WriteValue (TimeSpan value)
+               {
+                       stream.WriteByte (0x8E);
+                       WriteLong (value.Ticks);
+               }
+               #endregion
+
+               private void WriteLong (long value)
+               {
+                       long v = 0;
+                       for (int i = 0; i < 4; i++) {
+                               v = (v << 4) + value & 0xFF;
+                               value >>= 4;
+                       }
+                       for (int i = 0; i < 4; i++) {
+                               stream.WriteByte ((byte) (v & 0xFF));
+                               v >>= 4;
+                       }
+               }
+
                private void WriteTextBinary (string text)
                {
                        if (text.Length == 0)
-                               stream.WriteByte (0x8B);
+                               stream.WriteByte (0xA8);
                        else
-                               WriteToStream (0x83, text);
+                               WriteToStream (0x98, text);
                }
 
                private void WriteNames (string prefix, string localName)

Modified: 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryWriterSession.cs
===================================================================
--- 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryWriterSession.cs
 2007-03-14 15:08:09 UTC (rev 74259)
+++ 
trunk/olive/class/System.Runtime.Serialization/System.Xml/XmlBinaryWriterSession.cs
 2007-03-14 15:11:21 UTC (rev 74260)
@@ -4,7 +4,7 @@
 // Author:
 //     Atsushi Enomoto <[EMAIL PROTECTED]>
 //
-// Copyright (C) 2005 Novell, Inc.  http://www.novell.com
+// Copyright (C) 2005, 2007 Novell, Inc.  http://www.novell.com
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -26,27 +26,36 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 #if NET_2_0
+using System.Collections.Generic;
+
 namespace System.Xml
 {
        public class XmlBinaryWriterSession
        {
+               Dictionary<int,XmlDictionaryString> dic =
+                       new Dictionary<int,XmlDictionaryString> ();
+
                public XmlBinaryWriterSession ()
                {
                }
 
-               [MonoTODO]
                public void Reset ()
                {
-                       throw new NotImplementedException ();
+                       dic.Clear ();
                }
 
-               [MonoTODO]
                // Unlike XmlDictionary, it throws an InvalidOperationException
                // if the same string already exists.
                public virtual bool TryAdd (XmlDictionaryString value,
                        out int key)
                {
-                       throw new NotImplementedException ();
+                       if (value == null)
+                               throw new ArgumentNullException ("value");
+                       if (dic.ContainsValue (value))
+                               throw new InvalidOperationException ("Argument 
XmlDictionaryString was already added to the writer session");
+                       key = dic.Count;
+                       dic.Add (dic.Count, value);
+                       return true;
                }
        }
 }

Modified: 
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/ChangeLog
===================================================================
--- trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/ChangeLog    
2007-03-14 15:08:09 UTC (rev 74259)
+++ trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/ChangeLog    
2007-03-14 15:11:21 UTC (rev 74260)
@@ -1,5 +1,12 @@
 2007-03-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * XmlDictionaryReaderQuotasTest.cs : fixed test class name.
+       * XmlBinaryDictionaryWriterTest.cs : added a bunch of tests. Many
+         tests still fail. They are going to be fixed.
+       * XmlBinaryWriterSessionTest.cs : new test.
+
+2007-03-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * XmlDictionaryTest.cs : removed pointless test-breaking return.
          Added test for Add() and key index. Added test for Empty.
        * XmlSimpleDictionaryWriterTest.cs : in .NET 3.0 RTM processing

Modified: 
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryDictionaryWriterTest.cs
===================================================================
--- 
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryDictionaryWriterTest.cs
     2007-03-14 15:08:09 UTC (rev 74259)
+++ 
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryDictionaryWriterTest.cs
     2007-03-14 15:11:21 UTC (rev 74260)
@@ -4,7 +4,7 @@
 // Author:
 //     Atsushi Enomoto <[EMAIL PROTECTED]>
 //
-// Copyright (C) 2005 Novell, Inc.  http://www.novell.com
+// Copyright (C) 2005, 2007 Novell, Inc.  http://www.novell.com
 
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -87,9 +87,9 @@
                        w.WriteString ("CCC");
                        w.WriteBase64 (new byte [] {0x20, 0x20, 0x20, 0xFF, 
0x80, 0x30}, 0, 6);
                        w.WriteEndElement ();
-                       // FIXME: this WriteEndElement() should result in
-                       // one more 0x3C, but WinFX beta1 does not output it.
-                       //w.WriteEndElement ();
+                       // this WriteEndElement() should result in one more
+                       // 0x3C, but .net does not output it.
+                       w.WriteEndElement ();
                        w.WriteEndDocument ();
 
                        w.Close ();
@@ -102,39 +102,406 @@
                // FIXME: see fixmes in the test itself.
                static readonly byte [] usecase1_result = new byte [] {
                        // $!root$!  a....!__  ___.!AAA  $!urn:AA  A$$!ePfi
-                       0x3F, 0x04, 0x72, 0x6F, 0x6F, 0x74, 0x00, 0x01,
-                       0x61, 0x8B, 0x3D, 0x00, 0x83, 0x05, 0x20, 0x20,
-                       0x20, 0x20, 0x20, 0x3F, 0x03, 0x41, 0x41, 0x41,
-                       0x04, 0x07, 0x75, 0x72, 0x6E, 0x3A, 0x41, 0x41,
-                       0x41, 0x3C, 0x40, 0x05, 0x65, 0x50, 0x66, 0x69,// 40
+                       0x40, 0x04, 0x72, 0x6F, 0x6F, 0x74, 0x04, 0x01,
+                       0x61, 0xA8, 0x02, 0x00, 0x98, 0x05, 0x20, 0x20,
+                       0x20, 0x20, 0x20, 0x40, 0x03, 0x41, 0x41, 0x41,
+                       0x08, 0x07, 0x75, 0x72, 0x6E, 0x3A, 0x41, 0x41,
+                       0x41, 0x01, 0x41, 0x05, 0x65, 0x50, 0x66, 0x69,// 40
                        // x!AAA$!e  Pfix!urn  :AAABBB$  $!AAA$!C  CC......
-                       0x78, 0x03, 0x41, 0x41, 0x41, 0x05, 0x05, 0x65,
+                       0x78, 0x03, 0x41, 0x41, 0x41, 0x09, 0x05, 0x65,
                        0x50, 0x66, 0x69, 0x78, 0x0A, 0x75, 0x72, 0x6E,
-                       0x3A, 0x41, 0x41, 0x41, 0x42, 0x42, 0x42, 0x3C,
-                       0x3F, 0x03, 0x41, 0x41, 0x41, 0x83, 0x0C, 0x43,
+                       0x3A, 0x41, 0x41, 0x41, 0x42, 0x42, 0x42, 0x01,
+                       0x40, 0x03, 0x41, 0x41, 0x41, 0x98, 0x0C, 0x43,
                        0x43, 0x43, 0xE3, 0x80, 0x85, 0xE4, 0xB8, 0x80,// 80
                        // AAA$!DDD  $AAA$!DD  D$DDD...  ..$!COMM  ENT$$!AA
-                       0x43, 0x43, 0x43, 0x83, 0x07, 0x41, 0x41, 0x41,
-                       0x26, 0x41, 0x41, 0x41, 0x83, 0x07, 0x44, 0x44,
-                       0x44, 0x26, 0x44, 0x44, 0x44, 0x83, 0x03, 0xE4,
-                       0xB8, 0x81, 0x3D, 0x07, 0x43, 0x4F, 0x4D, 0x4D,
-                       0x45, 0x4E, 0x54, 0x3C, 0x3F, 0x03, 0x41, 0x41,// 120
-                       // A$!BBB$!  bbb$!pfi  x!BBB$!B  BBBB$!CC  C$!CCCCC
-                       0x41, 0x00, 0x03, 0x42, 0x42, 0x42, 0x83, 0x03,
-                       0x62, 0x62, 0x62, 0x01, 0x04, 0x70, 0x66, 0x69,
-                       0x78, 0x03, 0x42, 0x42, 0x42, 0x83, 0x05, 0x62,
-                       0x62, 0x62, 0x62, 0x62, 0x01, 0x03, 0x78, 0x6D,
-                       0x6C, 0x04, 0x6C, 0x61, 0x6E, 0x67, 0x83, 0x02,// 160
-                       0x6A, 0x61, 0x01, 0x03, 0x78, 0x6D, 0x6C, 0x05,
-                       0x73, 0x70, 0x61, 0x63, 0x65, 0x83, 0x08, 0x70,
-                       0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x01,
+                       0x43, 0x43, 0x43, 0x98, 0x07, 0x41, 0x41, 0x41,
+                       0x26, 0x41, 0x41, 0x41, 0x98, 0x07, 0x44, 0x44,
+                       0x44, 0x26, 0x44, 0x44, 0x44, 0x98, 0x03, 0xE4,
+                       0xB8, 0x81, 0x02, 0x07, 0x43, 0x4F, 0x4D, 0x4D,
+                       0x45, 0x4E, 0x54, 0x01, 0x40, 0x03, 0x41, 0x41,// 120
+                       // A$!BBB$!  bbb$!pfi  x!BBB$!b  bbbb$!xm  l!lang$!
+                       0x41, 0x04, 0x03, 0x42, 0x42, 0x42, 0x98, 0x03,
+                       0x62, 0x62, 0x62, 0x05, 0x04, 0x70, 0x66, 0x69,
+                       0x78, 0x03, 0x42, 0x42, 0x42, 0x98, 0x05, 0x62,
+                       0x62, 0x62, 0x62, 0x62, 0x05, 0x03, 0x78, 0x6D,
+                       0x6C, 0x04, 0x6C, 0x61, 0x6E, 0x67, 0x98, 0x02,// 160
+                       // ja$!xml!  space$!p  reserve
+                       0x6A, 0x61, 0x05, 0x03, 0x78, 0x6D, 0x6C, 0x05,
+                       0x73, 0x70, 0x61, 0x63, 0x65, 0x98, 0x08, 0x70,
+                       0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x05,
                        0x03, 0x78, 0x6D, 0x6C, 0x04, 0x62, 0x61, 0x73,
-                       0x65, 0x83, 0x0E, 0x6C, 0x6F, 0x63, 0x61, 0x6C,// 200
+                       0x65, 0x98, 0x0E, 0x6C, 0x6F, 0x63, 0x61, 0x6C,// 200
                        0x3A, 0x68, 0x6F, 0x67, 0x65, 0x68, 0x6F, 0x67,
-                       0x65, 0x05, 0x04, 0x70, 0x66, 0x69, 0x78, 0x07,
-                       0x75, 0x72, 0x6E, 0x3A, 0x62, 0x62, 0x62, 0x83,
-                       0x03, 0x43, 0x43, 0x43, 0xA4, 0x06, 0x20, 0x20,
-                       0x20, 0xFF, 0x80, 0x30, 0x3C, /*0x3C*/
+                       0x65, 0x09, 0x04, 0x70, 0x66, 0x69, 0x78, 0x07,
+                       0x75, 0x72, 0x6E, 0x3A, 0x62, 0x62, 0x62, 0x98,
+                       // CCC, base64
+                       0x03, 0x43, 0x43, 0x43, 0x9F, 0x06, 0x20, 0x20,
+                       0x20, 0xFF, 0x80, 0x30, 0x01, /*0x01*/
                        };
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ProcessingInstructions ()
+               {
+                       MemoryStream ms = new MemoryStream ();
+                       XmlBinaryWriterSession session = new 
XmlBinaryWriterSession ();
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, null, session);
+                       w.WriteStartDocument ();
+                       w.WriteProcessingInstruction ("myPI", "myValue");
+               }
+
+               [Test]
+               public void UseCase2 ()
+               {
+                       XmlDictionary dic = new XmlDictionary ();
+                       MemoryStream ms = new MemoryStream ();
+                       XmlBinaryWriterSession session = new 
XmlBinaryWriterSession ();
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
+                       XmlDictionaryString empty = dic.Add (String.Empty);
+                       // empty ns
+                       w.WriteStartElement (dic.Add ("FOO"), empty);
+                       // non-dic string
+                       w.WriteStartElement ("BAR");
+                       // second time ns
+                       w.WriteStartElement (dic.Add ("FOO"), empty);
+                       // first time dic string but prior non-dic name existed
+                       w.WriteStartElement (dic.Add ("BAR"), empty);
+                       w.WriteEndElement ();
+                       w.WriteEndElement ();
+                       w.WriteEndElement ();
+                       // dicstr w/ ns with empty prefix
+                       w.WriteStartElement (dic.Add ("BAR"), dic.Add 
("urn:bar"));
+                       // with prefix
+                       w.WriteStartElement ("ppp", dic.Add ("BAR"), dic.Add 
("urn:bar"));
+                       w.WriteChars (new char [] {'x', 'y', 'z'}, 0, 3);
+//                     w.WriteString ("xyz"); // the same as WriteChars()
+                       w.WriteEndElement ();
+                       w.WriteString ("bbbb");
+                       w.WriteCData ("ccc");
+                       w.WriteValue (new Guid 
("11112222333344445555666677778888"));
+                       w.WriteEndElement ();
+                       w.WriteStartElement ("FOO");
+                       w.WriteStartAttribute ("AAA");
+                       w.WriteValue (new Guid 
("11112222333344445555666677778888"));
+                       w.WriteEndAttribute ();
+                       w.WriteStartAttribute ("BBB");
+                       w.WriteValue (TimeSpan.Zero);
+                       w.WriteEndAttribute ();
+                       w.WriteStartAttribute ("CC");
+                       w.WriteValue (new UniqueId 
("uuid-00000000-0000-0000-0000-000000000000-1"));
+                       w.WriteEndAttribute ();
+                       w.WriteStartElement ("XX");
+                       w.WriteValue (true);
+                       w.WriteValue (false);
+                       w.WriteEndElement ();
+                       w.WriteStartElement ("xx", "aaa", "urn:zzz");
+                       w.WriteEndElement ();
+                       w.WriteEndElement ();
+
+                       w.Close ();
+
+foreach (byte b in ms.ToArray ()) Console.Write ("{0:X02} ", b); 
Console.WriteLine ();
+
+                       Assert.AreEqual (usecase2_result, ms.ToArray ());
+               }
+
+               // $ : kind
+               // / : especially. EndElement
+               // ! : length
+               // @ : dictionary index
+               // ^ : missing ns decl?
+               // FIXME: see fixmes in the test itself.
+               static readonly byte [] usecase2_result = new byte [] {
+                       // [EMAIL PROTECTED]  @$@///$@  [EMAIL PROTECTED]  
[EMAIL PROTECTED]  xyz$!bbb
+                       0x42, 2, 0x40, 3, 0x42, 0x41, 0x52, 0x42,
+                       2, 0x42, 4, 1, 1, 1, 0x42, 4,
+                       10, 6, 0x43, 3, 0x70, 0x70, 0x70, 4,
+                       11, 3, 0x70, 0x70, 0x70, 6, 0x99, 3,
+                       0x78, 0x79, 0x7A, 0x98, 4, 0x62, 0x62, 0x62,
+                       // b$!ccc$G  UIDGUIDG  UIDGUID$  !FOO$!GU  IDGUIDGU
+                       0x62, 0x98, 3, 0x63, 0x63, 0x63, 0xB1, 0x22,
+                       0x22, 0x11, 0x11, 0x33, 0x33, 0x44, 0x44, 0x55,
+                       0x55, 0x66, 0x66, 0x77, 0x77, 0x88, 0x88, 0x40,
+                       3, 0x46, 0x4F, 0x4F, 0x04, 3, 0x41, 0x41,
+                       0x41, 0xB0, 0x22, 0x22, 0x11, 0x11, 0x33, 0x33,
+                       // IDGUIDGU  ID$!BBB$T  IMESPAN  $!CC$!UN  IQUEIDUN
+                       0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77,
+                       0x88, 0x88, 0x04, 3, 0x42, 0x42, 0x42, 0xAE,
+                       0, 0, 0, 0, 0, 0, 0, 0,
+                       0x04, 2, 0x43, 0x43, 0x98, 0x2B, 0x75, 0x75,
+                       0x69, 0x64, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30,
+                       // IQUEIDUN  IQUEIDUN  IQUEIDUN  IQUEID..  .$!XX$$$!
+                       0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30,
+                       0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30,
+                       0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30,
+                       0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x2D,
+                       0x31, 0x40, 2, 0x58, 0x58, 0x86, 0x85, 0x41, 2,
+                       // xx!aaa$!x  x!urn:xxx
+                       0x78, 0x78, 3, 0x61, 0x61, 0x61, 0x09, 2, 0x78,
+                       0x78, 0x07, 0x75, 0x72, 0x6E, 0x3A, 0x7A, 0x7A,
+                       0x7A, 1, 1, 1
+                       };
+
+               [Test]
+               public void WriteDictionaryStringWithNullDictionary ()
+               {
+                       MemoryStream ms = new MemoryStream ();
+                       XmlBinaryWriterSession session = new 
XmlBinaryWriterSession ();
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, null, session);
+                       XmlDictionary dic = new XmlDictionary ();
+                       w.WriteStartElement (dic.Add ("FOO"), 
XmlDictionaryString.Empty);
+               }
+
+               class MyWriterSession1 : XmlBinaryWriterSession
+               {
+                       int count;
+
+                       public override bool TryAdd (XmlDictionaryString d, out 
int idx)
+                       {
+                               base.TryAdd (d, out idx);
+                               Assert.AreEqual (count, idx, "#x1-" + count);
+                               if (count++ == 0)
+                                       Assert.AreEqual (String.Empty, d.Value, 
"#x2");
+                               else
+                                       Assert.AreEqual ("FOO", d.Value, "#x3");
+                               return true;
+                       }
+               }
+
+               [Test]
+               public void WriteDictionaryStringWithSameDictionary ()
+               {
+                       MemoryStream ms = new MemoryStream ();
+                       MyWriterSession1 session = new MyWriterSession1 ();
+                       XmlDictionary dic = new XmlDictionary ();
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
+                       w.WriteStartElement (dic.Add ("FOO"), 
XmlDictionaryString.Empty);
+                       w.Close ();
+                       Assert.AreEqual (new byte [] {0x42, 0, 1}, ms.ToArray 
());
+               }
+
+               [Test]
+               public void WriteDictionaryStringWithDifferentDictionary () // 
it actually works
+               {
+                       MemoryStream ms = new MemoryStream ();
+                       XmlBinaryWriterSession session = new 
XmlBinaryWriterSession ();
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, new XmlDictionary (), session);
+                       XmlDictionary dic = new XmlDictionary ();
+                       w.WriteStartElement (dic.Add ("FOO"), 
XmlDictionaryString.Empty);
+                       w.Close ();
+                       Assert.AreEqual (new byte [] {0x42, 1, 1}, ms.ToArray 
());
+               }
+
+               [Test]
+               public void IndicesFromDictionaryAndSession ()
+               {
+                       // So, I found out the solution for the indices puzzle.
+                       MemoryStream ms = new MemoryStream ();
+                       XmlBinaryWriterSession session = new 
XmlBinaryWriterSession ();
+                       XmlDictionary dic = new XmlDictionary ();
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
+                       XmlDictionary dic2 = new XmlDictionary ();
+                       XmlDictionary dic3 = new XmlDictionary ();
+                       w.WriteStartElement (dic.Add ("FOO"), 
XmlDictionaryString.Empty);
+                       w.WriteStartElement (dic2.Add ("FOO"), 
XmlDictionaryString.Empty);
+                       w.WriteStartElement (dic3.Add ("FOO"), 
XmlDictionaryString.Empty);
+                       w.WriteStartElement (dic2.Add ("BAR"), 
XmlDictionaryString.Empty);
+                       w.WriteStartElement (dic.Add ("BAR"), 
XmlDictionaryString.Empty);
+                       w.Close ();
+                       // ... so, looks like even indices are for dictionary, 
+                       // and odd indices are for session.
+                       byte [] bytes = new byte [] {
+                               0x42, 0, 0x42, 1, 0x42, 1,0x42, 3,
+                               0x42, 2, 1, 1, 1, 1, 1};
+                       Assert.AreEqual (bytes, ms.ToArray ());
+               }
+
+               [Test]
+               public void UseStandardSession ()
+               {
+                       MemoryStream ms = new MemoryStream ();
+                       XmlBinaryWriterSession session =
+                               new XmlBinaryWriterSession ();
+                       XmlDictionary dic = new XmlDictionary ();
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
+                       w.WriteStartElement (dic.Add ("FOO"), 
XmlDictionaryString.Empty);
+                       w.WriteStartElement (dic.Add ("blah"), 
XmlDictionaryString.Empty);
+                       w.WriteStartElement (dic.Add ("blabla"), 
XmlDictionaryString.Empty);
+                       w.Close ();
+                       Assert.AreEqual (new byte [] {0x42, 0, 0x42, 2, 0x42, 
4, 1, 1, 1}, ms.ToArray ());
+               }
+
+               [Test]
+               public void UseStandardSession2 ()
+               {
+                       MemoryStream ms = new MemoryStream ();
+                       XmlBinaryWriterSession session =
+                               new XmlBinaryWriterSession ();
+                       XmlDictionary dic = new XmlDictionary ();
+                       XmlDictionaryString x = dic.Add ("urn:foo");
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
+                       w.WriteStartElement (dic.Add ("FOO"), x);
+                       w.WriteStartElement (dic.Add ("blah"), x);
+                       w.WriteStartElement (dic.Add ("blabla"), x);
+                       w.Close ();
+                       Assert.AreEqual (new byte [] {0x42, 2, 0x0A, 0, 0x42, 
4, 0x42, 6, 1, 1, 1}, ms.ToArray (), "#1");
+
+                       XmlDictionaryString ds;
+                       Assert.IsTrue (dic.TryLookup (0, out ds), "#2-1");
+                       Assert.AreEqual ("urn:foo", ds.Value, "#2-2");
+                       Assert.AreEqual (0, ds.Key, "#2-3");
+                       Assert.IsTrue (dic.TryLookup (1, out ds), "#3-1");
+                       Assert.AreEqual ("FOO", ds.Value, "#3-2");
+                       Assert.AreEqual (1, ds.Key, "#3-3");
+                       Assert.IsTrue (dic.TryLookup (2, out ds), "#4-1");
+                       Assert.AreEqual ("blah", ds.Value, "#4-2");
+                       Assert.AreEqual (2, ds.Key, "#4-3");
+                       Assert.IsTrue (dic.TryLookup (3, out ds), "#5-1");
+                       Assert.AreEqual ("blabla", ds.Value, "#5-2");
+                       Assert.AreEqual (3, ds.Key, "#5-3");
+               }
+
+               class MyWriterSession2 : XmlBinaryWriterSession
+               {
+                       int count;
+
+                       public override bool TryAdd (XmlDictionaryString d, out 
int idx)
+                       {
+                               // do nothing
+                               idx = d.Value.Length;
+                               return true;
+                       }
+               }
+
+               [Test]
+               public void UseNOPSession ()
+               {
+                       MemoryStream ms = new MemoryStream ();
+                       MyWriterSession2 session = new MyWriterSession2 ();
+                       XmlDictionary dic = new XmlDictionary ();
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
+                       w.WriteStartElement (dic.Add ("FOO"), 
XmlDictionaryString.Empty);
+                       w.WriteStartElement (dic.Add ("blah"), 
XmlDictionaryString.Empty);
+                       w.WriteStartElement (dic.Add ("blabla"), 
XmlDictionaryString.Empty);
+                       w.Close ();
+                       Assert.AreEqual (new byte [] {0x42, 0, 0x42, 2, 0x42, 
4, 1, 1, 1}, ms.ToArray ());
+               }
+
+               [Test]
+               public void WriteElementWithNS ()
+               {
+                       byte [] bytes = new byte [] {
+                               0x42, 0, 10, 2, 0x98, 3, 0x61, 0x61,
+                               0x61, 0x42, 0, 0x42, 2, 1, 1, 1};
+                       XmlDictionaryString ds;
+                       MemoryStream ms = new MemoryStream ();
+                       XmlBinaryWriterSession session = new 
XmlBinaryWriterSession ();
+                       XmlDictionary dic = new XmlDictionary ();
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
+                       w.WriteStartElement (dic.Add ("FOO"), dic.Add ("foo"));
+                       Assert.IsTrue (dic.TryLookup ("foo", out ds), "#1");
+                       Assert.AreEqual (1, ds.Key, "#2");
+                       w.WriteString ("aaa");
+                       w.WriteStartElement (dic.Add ("FOO"), dic.Add ("foo"));
+                       w.WriteStartElement (dic.Add ("foo"), dic.Add ("foo"));
+                       w.Close ();
+                       Assert.AreEqual (bytes, ms.ToArray (), "result");
+
+                       byte [] bytes2 = new byte [] {
+                               0x42, 1, 10, 2, 0x98, 3, 0x61, 0x61,
+                               0x61, 0x42, 0, 0x42, 2, 1, 1, 1};
+                               
+                       XmlDictionaryReader dr = 
XmlDictionaryReader.CreateBinaryReader (new MemoryStream (bytes2), dic, new 
XmlDictionaryReaderQuotas ());
+                       try {
+                               dr.Read ();
+                               Assert.Fail ("dictionary index 1 should be 
regarded as invalid.");
+                       } catch (XmlException) {
+                       }
+               }
+
+               [Test]
+               public void Beyond128DictionaryEntries ()
+               {
+                       XmlDictionaryString ds;
+                       MemoryStream ms = new MemoryStream ();
+                       XmlDictionary dic = new XmlDictionary ();
+                       for (int i = 0; i < 260; i++)
+                               dic.Add ("n" + i);
+                       XmlDictionary dic2 = new XmlDictionary ();
+                       XmlBinaryWriterSession session = new 
XmlBinaryWriterSession ();
+                       int idx;
+                       for (int i = 0; i < 260; i++)
+                               session.TryAdd (dic2.Add ("n" + i), out idx);
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
+                       w.WriteStartElement (dic.Add ("n128"), dic.Add 
("n129"));
+                       w.WriteStartElement (dic2.Add ("n130"), dic2.Add 
("n131"));
+                       w.WriteStartElement (dic.Add ("n132"), dic2.Add 
("n133"));
+                       w.WriteStartElement (dic.Add ("n256"), dic2.Add 
("n256"));
+                       w.Close ();
+
+                       byte [] bytes = new byte [] {
+                               // so, when it went beyond 128, the index
+                               // becomes 2 bytes, where
+                               // - the first byte always becomes > 80, and
+                               // - the second byte becomes (n / 0x80) * 2.
+                               0x42, 0x80, 2, 0x0A, 0x82, 2,
+                               0x42, 0x85, 2, 0x0A, 0x87, 2,
+                               0x42, 0x88, 2, 0x0A, 0x8B, 2,
+                               0x42, 0x80, 4, 0x0A, 0x81, 4,
+                               1, 1, 1, 1};
+                       Assert.AreEqual (bytes, ms.ToArray (), "result");
+               }
+
+               [Test]
+               public void GlobalAttributes ()
+               {
+                       XmlDictionaryString ds;
+                       MemoryStream ms = new MemoryStream ();
+                       XmlDictionary dic = new XmlDictionary ();
+                       XmlDictionary dic2 = new XmlDictionary ();
+                       XmlBinaryWriterSession session = new 
XmlBinaryWriterSession ();
+                       int idx;
+                       XmlDictionaryWriter w = 
XmlDictionaryWriter.CreateBinaryWriter (ms, dic, session);
+                       dic.Add ("n1");
+                       dic.Add ("urn:foo");
+                       dic.Add ("n2");
+                       dic.Add ("n3");
+                       dic.Add ("n4");
+                       dic.Add ("urn:bar");
+                       dic.Add ("n7");
+                       w.WriteStartElement (dic.Add ("n1"), dic.Add 
("urn:foo"));
+                       w.WriteAttributeString (dic.Add ("n2"), dic.Add 
("urn:bar"), String.Empty);
+                       w.WriteAttributeString (dic.Add ("n3"), dic.Add 
("urn:foo"), "v");
+                       w.WriteAttributeString ("aaa", dic.Add ("n4"), dic.Add 
("urn:bar"), String.Empty);
+                       w.WriteAttributeString ("bbb", "n5", "urn:foo", 
String.Empty);
+                       w.WriteAttributeString ("n6", String.Empty);
+                       w.WriteAttributeString (dic.Add ("n7"), 
XmlDictionaryString.Empty, String.Empty);
+                       w.Close ();
+
+                       // 0x0C nameidx (value) 0x0C nameidx (value)
+                       // 0x07 (prefix) nameidx (value)
+                       // 0x05 (prefix) (name) (value)
+                       // 0x0A nsidx
+                       // 0x0B (prefix) nsidx
+                       byte [] bytes = new byte [] {
+                               // [EMAIL PROTECTED]@[EMAIL PROTECTED]  !v$!aaa@
+                               // [EMAIL PROTECTED]  [EMAIL PROTECTED]@
+                               // $!aaa!$!  bbb$urn:foo$
+                               0x42, 0,
+                               0x0C, 4, 0xA8,
+                               0x0D, 6, 0x98, 1, 0x76,
+                               0x07, 3, 0x61, 0x61, 0x61, 8, 0xA8, // 16
+                               0x05, 3, 0x62, 0x62, 0x62, 2, 0x6E, 0x35, 0xA8,
+                               0x04, 2, 0x6E, 0x36, 0xA8, // 30
+                               0x06, 12, 0xA8,
+                               0x0A, 2,
+                               0x0B, 1, 0x61, 10,
+                               0x0B, 1, 0x62, 2,
+                               0x0B, 3, 0x61, 0x61, 0x61, 10,
+                               0x09, 3, 0x62, 0x62, 0x62,
+                               0x07, 0x75, 0x72, 0x6E, 0x3A, 0x66, 0x6F, 0x6F,
+                               1};
+                       Assert.AreEqual (bytes, ms.ToArray (), "result");
+               }
        }
 }

Added: 
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryWriterSessionTest.cs
===================================================================
--- 
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryWriterSessionTest.cs
        2007-03-14 15:08:09 UTC (rev 74259)
+++ 
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryWriterSessionTest.cs
        2007-03-14 15:11:21 UTC (rev 74260)
@@ -0,0 +1,65 @@
+//
+// XmlBinaryWriterSessionTest.cs
+//
+// Author:
+//     Atsushi Enomoto <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Novell, Inc.  http://www.novell.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.
+//
+
+using System;
+using System.Xml;
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+       [TestFixture]
+       public class XmlBinaryWriterSessionTest
+       {
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void TryAddDuplicate ()
+               {
+                       XmlDictionary dic = new XmlDictionary ();
+                       XmlDictionaryString d1 = dic.Add ("foo");
+                       XmlBinaryWriterSession s = new XmlBinaryWriterSession 
();
+                       int idx;
+                       s.TryAdd (d1, out idx);
+                       s.TryAdd (d1, out idx);
+               }
+
+               [Test]
+               public void TryAddIndex ()
+               {
+                       XmlDictionary dic = new XmlDictionary ();
+                       XmlDictionaryString d1 = dic.Add ("foo");
+                       XmlDictionaryString d2 = dic.Add ("bar");
+                       XmlDictionaryString d3 = dic.Add ("baz");
+                       XmlBinaryWriterSession s = new XmlBinaryWriterSession 
();
+                       int idx;
+                       s.TryAdd (d1, out idx);
+                       Assert.AreEqual (0, idx, "#1");
+                       s.TryAdd (d3, out idx);
+                       Assert.AreEqual (1, idx, "#2"); // not 2
+               }
+       }
+}

Modified: 
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlDictionaryReaderQuotasTest.cs
===================================================================
--- 
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlDictionaryReaderQuotasTest.cs
     2007-03-14 15:08:09 UTC (rev 74259)
+++ 
trunk/olive/class/System.Runtime.Serialization/Test/System.Xml/XmlDictionaryReaderQuotasTest.cs
     2007-03-14 15:11:21 UTC (rev 74260)
@@ -35,7 +35,7 @@
 namespace MonoTests.System.Xml
 {
        [TestFixture]
-       public class XmlDictionaryReaderQuotas
+       public class XmlDictionaryReaderQuotasTest
        {
                [Test]
                public void StaticAndDefaultValues ()

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to