Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Xml / XmlDsigExcC14NTransformTest.cs
1 //
2 // XmlDsigExcC14NTransformTest.cs - NUnit Test Cases for XmlDsigExcC14NTransform
3 //
4 // Author:
5 //  original:
6 //      Sebastien Pouliot <sebastien@ximian.com>
7 //      Aleksey Sanin (aleksey@aleksey.com)
8 //  this file:
9 //      Atsushi Enomoto <atsushi@ximian.com>
10 //
11 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
12 // (C) 2003 Aleksey Sanin (aleksey@aleksey.com)
13 // (C) 2004 Novell (http://www.novell.com)
14 //
15
16 //
17 // WARNING!!
18 //      This file is simply replaced C14N->ExcC14N, and then replaced expected
19 //      output XML. So, they are *not* from c14n specification.
20 //
21
22 #if NET_2_0
23
24 using System;
25 using System.IO;
26 using System.Security.Cryptography.Xml;
27 using System.Text;
28 using System.Xml;
29
30 using NUnit.Framework;
31
32 namespace MonoTests.System.Security.Cryptography.Xml {
33
34         // Note: GetInnerXml is protected in XmlDsigExcC14NTransform making it
35         // difficult to test properly. This class "open it up" :-)
36         public class UnprotectedXmlDsigExcC14NTransform : XmlDsigExcC14NTransform {
37                 public UnprotectedXmlDsigExcC14NTransform ()
38                 {
39                 }
40
41                 public UnprotectedXmlDsigExcC14NTransform (bool includeComments)
42                         : base (includeComments)
43                 {
44                 }
45
46                 public UnprotectedXmlDsigExcC14NTransform (string inclusiveNamespacesPrefixList)
47                         : base (inclusiveNamespacesPrefixList)
48                 {
49                 }
50
51                 public UnprotectedXmlDsigExcC14NTransform (bool includeComments, string inclusiveNamespacesPrefixList)
52                         : base (includeComments, inclusiveNamespacesPrefixList)
53                 {
54                 }
55
56                 public XmlNodeList UnprotectedGetInnerXml () {
57                         return base.GetInnerXml ();
58                 }
59         }
60
61         [TestFixture]
62         public class XmlDsigExcC14NTransformTest {
63
64                 protected UnprotectedXmlDsigExcC14NTransform transform;
65
66                 [SetUp]
67                 protected void SetUp () 
68                 {
69                         transform = new UnprotectedXmlDsigExcC14NTransform ();
70                 }
71
72                 [TearDown]
73                 protected void CleanUp () 
74                 {
75                         try {
76                                 if (File.Exists ("doc.dtd"))
77                                         File.Delete ("doc.dtd");
78                                 if (File.Exists ("world.txt"))
79                                         File.Delete ("world.txt");
80                         }
81                         catch {}
82                 }
83
84                 [Test] // ctor ()
85                 public void Constructor1 ()
86                 {
87                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
88                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
89                         CheckProperties (transform);
90                 }
91
92                 [Test] // ctor (Boolean)
93                 public void Constructor2 ()
94                 {
95                         transform = new UnprotectedXmlDsigExcC14NTransform (true);
96                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
97                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
98                         CheckProperties (transform);
99
100                         transform = new UnprotectedXmlDsigExcC14NTransform (false);
101                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
102                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
103                         CheckProperties (transform);
104                 }
105
106                 [Test] // ctor (String)
107                 public void Constructor3 ()
108                 {
109                         transform = new UnprotectedXmlDsigExcC14NTransform (null);
110                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
111                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
112                         CheckProperties (transform);
113
114                         transform = new UnprotectedXmlDsigExcC14NTransform (string.Empty);
115                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
116                         Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
117                         CheckProperties (transform);
118
119                         transform = new UnprotectedXmlDsigExcC14NTransform ("#default xsd");
120                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
121                         Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
122                         CheckProperties (transform);
123                 }
124
125                 [Test] // ctor (Boolean, String)
126                 public void Constructor4 ()
127                 {
128                         transform = new UnprotectedXmlDsigExcC14NTransform (true, null);
129                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
130                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
131                         CheckProperties (transform);
132
133                         transform = new UnprotectedXmlDsigExcC14NTransform (true, string.Empty);
134                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
135                         Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
136                         CheckProperties (transform);
137
138                         transform = new UnprotectedXmlDsigExcC14NTransform (true, "#default xsd");
139                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
140                         Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
141                         CheckProperties (transform);
142
143                         transform = new UnprotectedXmlDsigExcC14NTransform (false, null);
144                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
145                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
146                         CheckProperties (transform);
147
148                         transform = new UnprotectedXmlDsigExcC14NTransform (false, string.Empty);
149                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
150                         Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
151                         CheckProperties (transform);
152
153                         transform = new UnprotectedXmlDsigExcC14NTransform (false, "#default xsd");
154                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
155                         Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
156                         CheckProperties (transform);
157                 }
158
159                 void CheckProperties (XmlDsigExcC14NTransform transform)
160                 {
161                         Type[] input = transform.InputTypes;
162                         Assert.IsTrue ((input.Length == 3), "Input #");
163                         // check presence of every supported input types
164                         bool istream = false;
165                         bool ixmldoc = false;
166                         bool ixmlnl = false;
167                         foreach (Type t in input) {
168                                 if (t.ToString () == "System.IO.Stream")
169                                         istream = true;
170                                 if (t.ToString () == "System.Xml.XmlDocument")
171                                         ixmldoc = true;
172                                 if (t.ToString () == "System.Xml.XmlNodeList")
173                                         ixmlnl = true;
174                         }
175                         Assert.IsTrue (istream, "Input Stream");
176                         Assert.IsTrue (ixmldoc, "Input XmlDocument");
177                         Assert.IsTrue (ixmlnl, "Input XmlNodeList");
178
179                         Type[] output = transform.OutputTypes;
180                         Assert.IsTrue ((output.Length == 1), "Output #");
181                         // check presence of every supported output types
182                         bool ostream = false;
183                         foreach (Type t in output) {
184                                 if (t.ToString () == "System.IO.Stream")
185                                         ostream = true;
186                         }
187                         Assert.IsTrue (ostream, "Output Stream");
188                 }
189
190                 [Test]
191                 public void Types ()
192                 {
193                         Type [] input = transform.InputTypes;
194                         input [0] = null;
195                         input [1] = null;
196                         input [2] = null;
197                         // property does not return a clone
198                         foreach (Type t in transform.InputTypes) {
199                                 Assert.IsNull (t);
200                         }
201                         // it's not a static array
202                         XmlDsigExcC14NTransform t2 = new XmlDsigExcC14NTransform ();
203                         foreach (Type t in t2.InputTypes) {
204                                 Assert.IsNotNull (t);
205                         }
206                 }
207
208                 [Test]
209                 public void GetInnerXml () 
210                 {
211                         XmlNodeList xnl = transform.UnprotectedGetInnerXml ();
212                         Assert.IsNull (xnl, "Default InnerXml");
213                 }
214
215                 private string Stream2String (Stream s) 
216                 {
217                         StringBuilder sb = new StringBuilder ();
218                         int b = s.ReadByte ();
219                         while (b != -1) {
220                                 sb.Append (Convert.ToChar (b));
221                                 b = s.ReadByte ();
222                         }
223                         return sb.ToString ();
224                 }
225
226                 static string xml = "<Test  attrib='at ' xmlns=\"http://www.go-mono.com/\" > \r\n &#xD; <Toto/> text &amp; </Test   >";
227                 // BAD for XmlDocument input (framework 1.0 result)
228                 static string c14xml1 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \r\n \r <Toto></Toto> text &amp; </Test>";
229                 // GOOD for Stream input
230                 static string c14xml2 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \n &#xD; <Toto></Toto> text &amp; </Test>";
231                 // GOOD for XmlDocument input. The difference is because once
232                 // xml string is loaded to XmlDocument, there is no difference
233                 // between \r and &#xD;, so every \r must be handled as &#xD;.
234                 static string c14xml3 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> &#xD;\n &#xD; <Toto></Toto> text &amp; </Test>";
235
236                 private XmlDocument GetDoc () 
237                 {
238                         XmlDocument doc = new XmlDocument ();
239                         doc.PreserveWhitespace = true;
240                         doc.LoadXml (xml);
241                         return doc;
242                 }
243
244                 [Test]
245                 public void LoadInputAsXmlDocument () 
246                 {
247                         XmlDocument doc = GetDoc ();
248                         transform.LoadInput (doc);
249                         Stream s = (Stream) transform.GetOutput ();
250                         string output = Stream2String (s);
251                         Assert.AreEqual (c14xml3, output, "XmlDocument");
252                 }
253
254                 [Test]
255                 [Category ("NotDotNet")]
256                 // see LoadInputAsXmlNodeList2 description
257                 public void LoadInputAsXmlNodeList () 
258                 {
259                         XmlDocument doc = GetDoc ();
260                         // Argument list just contains element Test.
261                         transform.LoadInput (doc.ChildNodes);
262                         Stream s = (Stream) transform.GetOutput ();
263                         string output = Stream2String (s);
264                         Assert.AreEqual ("<Test></Test>", output, "XmlChildNodes");
265                 }
266
267                 [Test]
268                 [Category ("NotDotNet")]
269                 // MS has a bug that those namespace declaration nodes in
270                 // the node-set are written to output. Related spec section is:
271                 // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel
272                 public void LoadInputAsXmlNodeList2 () 
273                 {
274                         XmlDocument doc = GetDoc ();
275                         transform.LoadInput (doc.SelectNodes ("//*"));
276                         Stream s = (Stream) transform.GetOutput ();
277                         string output = Stream2String (s);
278                         string expected = @"<Test><Toto></Toto></Test>";
279                         Assert.AreEqual (expected, output, "XmlChildNodes");
280                 }
281
282                 [Test]
283                 public void LoadInputAsStream () 
284                 {
285                         MemoryStream ms = new MemoryStream ();
286                         byte[] x = Encoding.ASCII.GetBytes (xml);
287                         ms.Write (x, 0, x.Length);
288                         ms.Position = 0;
289                         transform.LoadInput (ms);
290                         Stream s = (Stream) transform.GetOutput ();
291                         string output = Stream2String (s);
292                         Assert.AreEqual (c14xml2, output, "MemoryStream");
293                 }
294
295                 [Test]
296                 [Ignore ("LAMESPEC: input MUST be one of InputType - but no exception is thrown (not documented)")]
297                 public void LoadInputWithUnsupportedType () 
298                 {
299                         byte[] bad = { 0xBA, 0xD };
300                         transform.LoadInput (bad);
301                 }
302
303                 [Test]
304                 [ExpectedException (typeof (ArgumentException))]
305                 public void UnsupportedOutput () 
306                 {
307                         XmlDocument doc = new XmlDocument();
308                         object o = transform.GetOutput (doc.GetType ());
309                 }
310
311                 [Test]
312                 public void ExcC14NSpecExample1 ()
313                 {
314                         using (StreamWriter sw = new StreamWriter ("doc.dtd", false, Encoding.ASCII)) {
315                                 sw.Write ("<!-- presence, not content, required -->");
316                                 sw.Close ();
317                         }
318                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample1Input);
319                         Assert.AreEqual (ExcC14NSpecExample1Output, res, "Example 1 from c14n spec - PIs, Comments, and Outside of Document Element (without comments)");
320                 }
321
322                 [Test]
323                 public void ExcC14NSpecExample2 ()
324                 {
325                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample2Input);
326                         Assert.AreEqual (ExcC14NSpecExample2Output, res, "Example 2 from c14n spec - Whitespace in Document Content (without comments)");
327                 }
328
329                 [Test]
330                 public void ExcC14NSpecExample3 ()
331                 {
332                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample3Input);
333                         Assert.AreEqual (ExcC14NSpecExample3Output, res, "Example 3 from c14n spec - Start and End Tags (without comments)");
334                 }
335             
336                 [Test]
337 //              [Ignore ("This test should be fine, but it does not pass under MS.NET")]
338                 public void ExcC14NSpecExample4 ()
339                 {
340                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample4Input);
341                         Assert.AreEqual (ExcC14NSpecExample4Output, res, "Example 4 from c14n spec - Character Modifications and Character References (without comments)");
342                 }
343             
344                 [Test]
345                 public void ExcC14NSpecExample5 ()
346                 {
347                         using (StreamWriter sw = new StreamWriter ("world.txt", false, Encoding.ASCII)) {
348                                 sw.Write ("world");
349                                 sw.Close ();
350                         }
351                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample5Input);
352                         Assert.AreEqual (ExcC14NSpecExample5Output, res, "Example 5 from c14n spec - Entity References (without comments)");
353                 }
354     
355                 [Test]
356                 public void ExcC14NSpecExample6 ()
357                 {
358                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample6Input);
359                         Assert.AreEqual (ExcC14NSpecExample6Output, res, "Example 6 from c14n spec - UTF-8 Encoding (without comments)");
360                 }
361
362                 private string ExecuteXmlDSigExcC14NTransform (string InputXml)
363                 {
364                         XmlDocument doc = new XmlDocument ();
365                         doc.PreserveWhitespace = true;
366                         doc.LoadXml (InputXml);
367                 
368                         // Testing default attribute support with
369                         // vreader.ValidationType = ValidationType.None.
370                         //
371                         UTF8Encoding utf8 = new UTF8Encoding ();
372                         byte[] data = utf8.GetBytes (InputXml.ToString ());
373                         Stream stream = new MemoryStream (data);
374                         XmlTextReader reader = new XmlTextReader (stream);
375                         XmlValidatingReader vreader = new XmlValidatingReader (reader);
376                         vreader.ValidationType = ValidationType.None;
377                         vreader.EntityHandling = EntityHandling.ExpandCharEntities;
378                         doc.Load (vreader);
379
380                         transform.LoadInput (doc);
381                         return Stream2String ((Stream)transform.GetOutput ());
382                 }
383
384                 //
385                 // Example 1 from ExcC14N spec - PIs, Comments, and Outside of Document Element: 
386                 // http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
387                 // 
388                 // Aleksey: 
389                 // removed reference to an empty external DTD
390                 //
391                 static string ExcC14NSpecExample1Input =  
392                         "<?xml version=\"1.0\"?>\n" +
393                         "\n" +
394                         "<?xml-stylesheet   href=\"doc.xsl\"\n" +
395                         "   type=\"text/xsl\"   ?>\n" +
396                         "\n" +
397                         // "<!DOCTYPE doc SYSTEM \"doc.dtd\">\n" +
398                         "\n" +
399                         "<doc>Hello, world!<!-- Comment 1 --></doc>\n" +
400                         "\n" +
401                         "<?pi-without-data     ?>\n\n" +
402                         "<!-- Comment 2 -->\n\n" +
403                         "<!-- Comment 3 -->\n";
404                 static string ExcC14NSpecExample1Output =   
405                         "<?xml-stylesheet href=\"doc.xsl\"\n" +
406                         "   type=\"text/xsl\"   ?>\n" +
407                         "<doc>Hello, world!</doc>\n" +
408                         "<?pi-without-data?>";
409                 
410                 //
411                 // Example 2 from ExcC14N spec - Whitespace in Document Content: 
412                 // http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
413                 // 
414                 static string ExcC14NSpecExample2Input =  
415                         "<doc>\n" +
416                         "  <clean>   </clean>\n" +
417                         "   <dirty>   A   B   </dirty>\n" +
418                         "   <mixed>\n" +
419                         "      A\n" +
420                         "      <clean>   </clean>\n" +
421                         "      B\n" +
422                         "      <dirty>   A   B   </dirty>\n" +
423                         "      C\n" +
424                         "   </mixed>\n" +
425                         "</doc>\n";
426                 static string ExcC14NSpecExample2Output =   
427                         "<doc>\n" +
428                         "  <clean>   </clean>\n" +
429                         "   <dirty>   A   B   </dirty>\n" +
430                         "   <mixed>\n" +
431                         "      A\n" +
432                         "      <clean>   </clean>\n" +
433                         "      B\n" +
434                         "      <dirty>   A   B   </dirty>\n" +
435                         "      C\n" +
436                         "   </mixed>\n" +
437                         "</doc>";
438             
439                 //
440                 // Example 3 from ExcC14N spec - Start and End Tags: 
441                 // http://www.w3.org/TR/xml-c14n#Example-SETags
442                 //
443                 static string ExcC14NSpecExample3Input =  
444                         "<!DOCTYPE doc [<!ATTLIST e9 attr CDATA \"default\">]>\n" +
445                         "<doc>\n" +
446                         "   <e1   />\n" +
447                         "   <e2   ></e2>\n" +
448                         "   <e3    name = \"elem3\"   id=\"elem3\"    />\n" +
449                         "   <e4    name=\"elem4\"   id=\"elem4\"    ></e4>\n" +
450                         "   <e5 a:attr=\"out\" b:attr=\"sorted\" attr2=\"all\" attr=\"I\'m\"\n" +
451                         "       xmlns:b=\"http://www.ietf.org\" \n" +
452                         "       xmlns:a=\"http://www.w3.org\"\n" +
453                         "       xmlns=\"http://www.uvic.ca\"/>\n" +
454                         "   <e6 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" +
455                         "       <e7 xmlns=\"http://www.ietf.org\">\n" +
456                         "           <e8 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" +
457                         "               <e9 xmlns=\"\" xmlns:a=\"http://www.ietf.org\"/>\n" +
458                         "           </e8>\n" +
459                         "       </e7>\n" +
460                         "   </e6>\n" +
461                         "</doc>\n";
462                 static string ExcC14NSpecExample3Output =   
463                         "<doc>\n" +
464                         "   <e1></e1>\n" +
465                         "   <e2></e2>\n" +
466                         "   <e3 id=\"elem3\" name=\"elem3\"></e3>\n" +
467                         "   <e4 id=\"elem4\" name=\"elem4\"></e4>\n" +
468                         "   <e5 xmlns=\"http://www.uvic.ca\" xmlns:a=\"http://www.w3.org\" xmlns:b=\"http://www.ietf.org\" attr=\"I\'m\" attr2=\"all\" b:attr=\"sorted\" a:attr=\"out\"></e5>\n" +
469                         "   <e6>\n" +
470                         "       <e7 xmlns=\"http://www.ietf.org\">\n" +
471                         "           <e8 xmlns=\"\">\n" +
472                         "               <e9 attr=\"default\"></e9>\n" +
473 //                      "               <e9 xmlns:a=\"http://www.ietf.org\"></e9>\n" +
474                         "           </e8>\n" +
475                         "       </e7>\n" +
476                         "   </e6>\n" +
477                         "</doc>";
478             
479             
480                 //
481                 // Example 4 from ExcC14N spec - Character Modifications and Character References: 
482                 // http://www.w3.org/TR/xml-c14n#Example-Chars
483                 //
484                 // Aleksey: 
485                 // This test does not include "normId" element
486                 // because it has an invalid ID attribute "id" which
487                 // should be normalized by XML parser. Currently Mono
488                 // does not support this (see comment after this example
489                 // in the spec).
490                 static string ExcC14NSpecExample4Input =  
491                         "<!DOCTYPE doc [<!ATTLIST normId id ID #IMPLIED>]>\n" +
492                         "<doc>\n" +
493                         "   <text>First line&#x0d;&#10;Second line</text>\n" +
494                         "   <value>&#x32;</value>\n" +
495                         "   <compute><![CDATA[value>\"0\" && value<\"10\" ?\"valid\":\"error\"]]></compute>\n" +
496                         "   <compute expr=\'value>\"0\" &amp;&amp; value&lt;\"10\" ?\"valid\":\"error\"\'>valid</compute>\n" +
497                         "   <norm attr=\' &apos;   &#x20;&#13;&#xa;&#9;   &apos; \'/>\n" +
498                         // "   <normId id=\' &apos;   &#x20;&#13;&#xa;&#9;   &apos; \'/>\n" +
499                         "</doc>\n";
500                 static string ExcC14NSpecExample4Output =   
501                         "<doc>\n" +
502                         "   <text>First line&#xD;\n" +
503                         "Second line</text>\n" +
504                         "   <value>2</value>\n" +
505                         "   <compute>value&gt;\"0\" &amp;&amp; value&lt;\"10\" ?\"valid\":\"error\"</compute>\n" +
506                         "   <compute expr=\"value>&quot;0&quot; &amp;&amp; value&lt;&quot;10&quot; ?&quot;valid&quot;:&quot;error&quot;\">valid</compute>\n" +
507                         "   <norm attr=\" \'    &#xD;&#xA;&#x9;   \' \"></norm>\n" +
508                         // "   <normId id=\"\' &#xD;&#xA;&#x9; \'\"></normId>\n" +
509                         "</doc>";
510             
511                 //
512                 // Example 5 from ExcC14N spec - Entity References: 
513                 // http://www.w3.org/TR/xml-c14n#Example-Entities
514                 //
515                 static string ExcC14NSpecExample5Input =  
516                         "<!DOCTYPE doc [\n" +
517                         "<!ATTLIST doc attrExtEnt ENTITY #IMPLIED>\n" +
518                         "<!ENTITY ent1 \"Hello\">\n" +
519                         "<!ENTITY ent2 SYSTEM \"world.txt\">\n" +
520                         "<!ENTITY entExt SYSTEM \"earth.gif\" NDATA gif>\n" +
521                         "<!NOTATION gif SYSTEM \"viewgif.exe\">\n" +
522                         "]>\n" +
523                         "<doc attrExtEnt=\"entExt\">\n" +
524                         "   &ent1;, &ent2;!\n" +
525                         "</doc>\n" +
526                         "\n" +
527                         "<!-- Let world.txt contain \"world\" (excluding the quotes) -->\n";
528                 static string ExcC14NSpecExample5Output =  
529                         "<doc attrExtEnt=\"entExt\">\n" +
530                         "   Hello, world!\n" +
531                         "</doc>";           
532     
533                 //
534                 // Example 6 from ExcC14N spec - UTF-8 Encoding: 
535                 // http://www.w3.org/TR/xml-c14n#Example-UTF8
536                 // 
537                 static string ExcC14NSpecExample6Input =  
538                         "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
539                         "<doc>&#169;</doc>\n";
540                 static string ExcC14NSpecExample6Output =  
541                         "<doc>\xC2\xA9</doc>";
542             
543
544                 //
545                 // Example 7 from ExcC14N spec - Document Subsets: 
546                 // http://www.w3.org/TR/xml-c14n#Example-DocSubsets
547                 // 
548                 // Aleksey:
549                 // Well, XPath support in Mono is far from complete....
550                 // I was not able to simplify the xpath expression from this test
551                 // so it runs on Mono and still makes sense for testing this feature.
552                 // Thus this test is not included in the suite now.
553                 static string ExcC14NSpecExample7Input =  
554                         "<!DOCTYPE doc [\n" +
555                         "<!ATTLIST e2 xml:space (default|preserve) \'preserve\'>\n" +
556                         "<!ATTLIST e3 id ID #IMPLIED>\n" +
557                         "]>\n" +
558                         "<doc xmlns=\"http://www.ietf.org\" xmlns:w3c=\"http://www.w3.org\">\n" +
559                         "   <e1>\n" +
560                         "      <e2 xmlns=\"\">\n" +
561                         "         <e3 id=\"E3\"/>\n" +
562                         "      </e2>\n" +
563                         "   </e1>\n" +
564                         "</doc>\n";
565
566                 static string ExcC14NSpecExample7Xpath =  
567                         "(//.|//@*|//namespace::*)\n" +
568                         "[\n" +
569                         "self::ietf:e1\n" +
570                         "    or\n" +
571                         "(parent::ietf:e1 and not(self::text() or self::e2))\n" +
572                         "    or\n" +
573                         "count(id(\"E3\")|ancestor-or-self::node()) = count(ancestor-or-self::node())\n" +
574                         "]";
575                 static string ExcC14NSpecExample7Output =  
576                         "<e1 xmlns=\"http://www.ietf.org\" xmlns:w3c=\"http://www.w3.org\"><e3 xmlns=\"\" id=\"E3\" xml:space=\"preserve\"></e3></e1>";
577
578                 [Test]
579                 public void SimpleNamespacePrefixes ()
580                 {
581                         string input = "<a:Action xmlns:a='urn:foo'>http://tempuri.org/IFoo/Echo</a:Action>";
582                         string expected = @"<a:Action xmlns:a=""urn:foo"">http://tempuri.org/IFoo/Echo</a:Action>";
583
584                         XmlDocument doc = new XmlDocument ();
585                         doc.LoadXml (input);
586                         XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform ();
587                         t.LoadInput (doc);
588                         Stream s = t.GetOutput () as Stream;
589                         Assert.AreEqual (new StreamReader (s, Encoding.UTF8).ReadToEnd (), expected);
590                 }
591
592                 [Test]
593                 [ExpectedException (typeof (NullReferenceException))]
594                 public void GetDigestedOutput_Null ()
595                 {
596                         new XmlDsigExcC14NTransform ().GetDigestedOutput (null);
597                 }
598         }    
599 }
600
601 #endif