[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
[mono.git] / mcs / class / System.Runtime.Serialization / Test / System.Xml / XmlMtomDictionaryWriterTest.cs
1 //
2 // XmlMtomDictionaryWriterTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2009 Novell, Inc.  http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 #if !MOBILE
30
31 using System;
32 using System.IO;
33 using System.Text;
34 using System.Xml;
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Xml
38 {
39         [TestFixture]
40         public class XmlMtomDictionaryWriterTest
41         {
42                 // Nothing gave me either multi-parted MTOM message or
43                 // xop-included xml so far ...
44
45                 [Test]
46                 public void UseCase1 ()
47                 {
48                         MemoryStream ms = new MemoryStream ();
49                         var w = XmlDictionaryWriter.CreateMtomWriter (ms, Encoding.UTF8, 10000, "sTaRt", "myboundary", "urn:foo", false, false);
50                         w.WriteStartDocument ();
51                         w.WriteStartElement ("root");
52                         w.WriteRaw ("RAW");
53                         w.WriteStartElement ("foo");
54                         w.WriteChars (new char [] {'b', 'c', 'd'}, 0, 3);
55                         w.WriteBase64 (new byte [] {50, 60, 70}, 0, 3);
56                         w.WriteArray ("", "arr", "", new bool [] {true,false,true},0,3);
57                         w.WriteValue (new MyStreamProvider ());
58                         w.WriteString ("999\r\n\r\n666");
59                         w.WriteEndElement ();
60                         //w.WriteProcessingInstruction ("pi", "data");
61                         w.WriteEndElement (); // it outputs end of mime data.
62                         w.WriteStartElement ("root"); // it is in the next part).
63                         w.WriteEndElement (); // it does not close current part.
64                         w.WriteEndDocument (); // no effect.
65                         w.WriteStartElement ("root");
66                         w.WriteEndElement ();
67                         w.WriteStartElement ("root");
68                         w.WriteEndElement ();
69                         w.WriteEndDocument ();
70                         w.Flush ();
71                         ms.Position = 0;
72                         // there are some insiginificant output differences
73                         Assert.AreEqual (usecase1, new StreamReader (ms).ReadToEnd ().Replace ("<root />", "<root/>"));
74                 }
75
76                 string usecase1 = @"
77 --myboundary
78 Content-ID: <urn:foo>
79 Content-Transfer-Encoding: 8bit
80 Content-Type: application/xop+xml;charset=utf-8;type=""sTaRt""
81
82 <root>RAW<foo>bcdMjxG<arr>true</arr><arr>false</arr><arr>true</arr>AQIDBAU=999&#xD;
83 &#xD;
84 666</foo></root>
85 --myboundary--
86 <root/><root/><root/>".Replace ("\n", "\r\n");
87         }
88
89         class MyStreamProvider : IStreamProvider
90         {
91                 public Stream GetStream ()
92                 {
93                         return new MemoryStream (new byte [] {1, 2, 3, 4, 5});
94                 }
95
96                 public void ReleaseStream (Stream s)
97                 {
98                 }
99         }
100 }
101
102 #endif