1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using OLEDB.Test.ModuleCore;
6 using System.IO;
7 using System.Linq;
8 using System.Text;
9 using XmlCoreTest.Common;
10 using Xunit;
11 
12 namespace System.Xml.Tests
13 {
14     public partial class TCErrorConditionWriter// : XmlWriterTestCaseBase
15     {
16         public static string file = "writerErr.out";
17 
18         [Theory]
19         [XmlWriterInlineData(1)]
20         [XmlWriterInlineData(2)]
21         [XmlWriterInlineData(3)]
22         [XmlWriterInlineData(4)]
23         [XmlWriterInlineData(5)]
24         [XmlWriterInlineData(6)]
25         [XmlWriterInlineData(7)]
26         [XmlWriterInlineData(8)]
var_01(XmlWriterUtils utils, int param)27         public void var_01(XmlWriterUtils utils, int param)
28         {
29             XmlWriterSettings ws = new XmlWriterSettings();
30             try
31             {
32                 switch (param)
33                 {
34                     case 1: XmlWriter w1 = WriterHelper.Create((Stream)null, overrideAsync: true, async: utils.Async); break;
35                     case 2: XmlWriter w2 = WriterHelper.Create((TextWriter)null, overrideAsync: true, async: utils.Async); break;
36                     case 3: XmlWriter w3 = WriterHelper.Create((StringBuilder)null, overrideAsync: true, async: utils.Async); break;
37                     case 4: XmlWriter w4 = WriterHelper.Create((XmlWriter)null, overrideAsync: true, async: utils.Async); break;
38                     case 5: XmlWriter w5 = WriterHelper.Create((Stream)null, ws, overrideAsync: true, async: utils.Async); break;
39                     case 6: XmlWriter w6 = WriterHelper.Create((TextWriter)null, ws, overrideAsync: true, async: utils.Async); break;
40                     case 7: XmlWriter w7 = WriterHelper.Create((StringBuilder)null, ws, overrideAsync: true, async: utils.Async); break;
41                     case 8: XmlWriter w8 = WriterHelper.Create((XmlWriter)null, ws, overrideAsync: true, async: utils.Async); break;
42                 }
43             }
44             catch (ArgumentNullException) { return; }
45             Assert.True(false);
46         }
47 
48         [Theory]
49         [XmlWriterInlineData(true)]
50         [XmlWriterInlineData(false)]
var_02(XmlWriterUtils utils, bool param)51         public void var_02(XmlWriterUtils utils, bool param)
52         {
53             bool result = false;
54 
55             XmlWriter w = utils.CreateWriter();
56             try
57             {
58                 w.WriteAttributes(null, param);
59             }
60             catch (ArgumentNullException)
61             {
62                 try
63                 {
64                     w.WriteAttributes(null, param);
65                 }
66                 catch (ArgumentNullException) { result = true; }
67             }
68             finally
69             {
70                 w.Dispose();
71             }
72             Assert.True(result);
73         }
74 
75         [Theory]
76         [XmlWriterInlineData(true)]
77         [XmlWriterInlineData(false)]
var_03(XmlWriterUtils utils, bool param)78         public void var_03(XmlWriterUtils utils, bool param)
79         {
80             bool result = false;
81 
82             XmlWriter w = utils.CreateWriter();
83             try
84             {
85                 w.WriteNode((XmlReader)null, param);
86             }
87             catch (ArgumentNullException)
88             {
89                 try
90                 {
91                     w.WriteNode((XmlReader)null, param);
92                 }
93                 catch (ArgumentNullException) { result = true; }
94             }
95             finally
96             {
97                 w.Dispose();
98             }
99             Assert.True((result));
100         }
101 
102         [Theory]
103         [XmlWriterInlineData(1)]
104         [XmlWriterInlineData(2)]
105         [XmlWriterInlineData(3)]
106         [XmlWriterInlineData(4)]
107         [XmlWriterInlineData(5)]
108         [XmlWriterInlineData(6)]
109         [XmlWriterInlineData(7)]
110         [XmlWriterInlineData(8)]
111         [XmlWriterInlineData(9)]
112         [XmlWriterInlineData(10)]
113         [XmlWriterInlineData(11)]
114         [XmlWriterInlineData(12)]
115         [XmlWriterInlineData(13)]
116         [XmlWriterInlineData(14)]
117         [XmlWriterInlineData(15)]
118         [XmlWriterInlineData(16)]
119         [XmlWriterInlineData(17)]
120         [XmlWriterInlineData(18)]
121         [XmlWriterInlineData(19)]
122         [XmlWriterInlineData(20)]
var_04(XmlWriterUtils utils, int param)123         public void var_04(XmlWriterUtils utils, int param)
124         {
125             bool result = false;
126 
127             XmlWriter w = utils.CreateWriter();
128             try
129             {
130                 switch (param)
131                 {
132                     case 1: w.WriteAttributeString(null, null); break;
133                     case 2: w.WriteAttributeString(null, null, null); break;
134                     case 3: w.WriteAttributeString("a", null, null, null); break;
135                     case 4: w.WriteAttributeString(null, null, "a", null); break;
136                     case 5: w.WriteDocType(null, null, null, null); break;
137                     case 6: w.WriteElementString(null, null); break;
138                     case 7: w.WriteElementString(null, null, null); break;
139                     case 8: w.WriteElementString("a", null, null, null); break;
140                     case 9: w.WriteElementString("a", null, "a", null); break;
141                     case 10: w.WriteEntityRef(null); break;
142                     case 11: w.WriteName(null); break;
143                     case 12: w.WriteNmToken(null); break;
144                     case 13: w.WriteProcessingInstruction(null, null); break;
145                     case 14: w.WriteQualifiedName(null, null); break;
146                     case 15: w.WriteStartAttribute(null); break;
147                     case 16: w.WriteStartAttribute(null, null); break;
148                     case 17: w.WriteStartAttribute("a", null, null); break;
149                     case 18: w.WriteStartElement(null); break;
150                     case 19: w.WriteStartElement(null, null); break;
151                     case 20: w.WriteStartElement("a", null, null); break;
152                 }
153             }
154             catch (ArgumentException)
155             {
156                 try
157                 {
158                     switch (param)
159                     {
160                         case 1: w.WriteAttributeString(null, null); break;
161                         case 2: w.WriteAttributeString(null, null, null); break;
162                         case 3: w.WriteAttributeString("a", null, null, null); break;
163                         case 4: w.WriteAttributeString(null, null, "a", null); break;
164                         case 5: w.WriteDocType(null, null, null, null); break;
165                         case 6: w.WriteElementString(null, null); break;
166                         case 7: w.WriteElementString(null, null, null); break;
167                         case 8: w.WriteElementString("a", null, null, null); break;
168                         case 9: w.WriteElementString("a", null, "a", null); break;
169                         case 10: w.WriteEntityRef(null); break;
170                         case 11: w.WriteName(null); break;
171                         case 12: w.WriteNmToken(null); break;
172                         case 13: w.WriteProcessingInstruction(null, null); break;
173                         case 14: w.WriteQualifiedName(null, null); break;
174                         case 15: w.WriteStartAttribute(null); break;
175                         case 16: w.WriteStartAttribute(null, null); break;
176                         case 17: w.WriteStartAttribute("a", null, null); break;
177                         case 18: w.WriteStartElement(null); break;
178                         case 19: w.WriteStartElement(null, null); break;
179                         case 20: w.WriteStartElement("a", null, null); break;
180                     }
181                 }
182                 catch (ArgumentException) { result = true; }
183             }
184             catch (NullReferenceException)
185             {
186                 try
187                 {
188                     switch (param)
189                     {
190                         case 5: w.WriteDocType(null, null, null, null); break;
191                         case 10: w.WriteEntityRef(null); break;
192                         case 13: w.WriteProcessingInstruction(null, null); break;
193                         case 14: w.WriteQualifiedName(null, null); break;
194                     }
195                 }
196                 catch (NullReferenceException)
197                 {
198                     result = (utils.WriterType == WriterType.CharCheckingWriter);
199                 }
200             }
201             finally
202             {
203                 w.Dispose();
204             }
205             Assert.True((result || param == 14 && utils.WriterType == WriterType.CustomWriter));
206         }
207 
208         [Theory]
209         [XmlWriterInlineData(1)]
210         [XmlWriterInlineData(2)]
211         [XmlWriterInlineData(3)]
212         [XmlWriterInlineData(4)]
213         [XmlWriterInlineData(5)]
214         [XmlWriterInlineData(6)]
var_05(XmlWriterUtils utils, int param)215         public void var_05(XmlWriterUtils utils, int param)
216         {
217             bool result = false;
218 
219             XmlWriter w = utils.CreateWriter();
220             w.WriteStartElement("Root");
221             try
222             {
223                 switch (param)
224                 {
225                     case 1: w.WriteBinHex(null, 0, 0); break;
226                     case 2: w.WriteBase64(null, 0, 0); break;
227                     case 3: w.WriteChars(null, 0, 0); break;
228                     case 4: w.LookupPrefix(null); break;
229                     case 5: w.WriteRaw(null, 0, 0); break;
230                     case 6: w.WriteValue((object)null); break;
231                 }
232             }
233             catch (ArgumentNullException)
234             {
235                 try
236                 {
237                     switch (param)
238                     {
239                         case 1: w.WriteBinHex(null, 0, 0); break;
240                         case 2: w.WriteBase64(null, 0, 0); break;
241                         case 3: w.WriteChars(null, 0, 0); break;
242                         case 4: w.LookupPrefix(null); break;
243                         case 5: w.WriteRaw(null, 0, 0); break;
244                         case 6: w.WriteValue((object)null); break;
245                     }
246                 }
247                 catch (ArgumentNullException) { result = true; }
248                 catch (InvalidOperationException) { result = true; }
249             }
250             finally
251             {
252                 w.Dispose();
253             }
254             Assert.True((result));
255         }
256 
257         [Theory]
258         [XmlWriterInlineData(1)]
259         [XmlWriterInlineData(2)]
260         [XmlWriterInlineData(3)]
261         [XmlWriterInlineData(4)]
262         [XmlWriterInlineData(5)]
263         [XmlWriterInlineData(6)]
264         [XmlWriterInlineData(7)]
265         [XmlWriterInlineData(8)]
266         [XmlWriterInlineData(9)]
267         [XmlWriterInlineData(10)]
268         [XmlWriterInlineData(11)]
269         [XmlWriterInlineData(12)]
270         [XmlWriterInlineData(13)]
271         [XmlWriterInlineData(14)]
272         [XmlWriterInlineData(15)]
273         [XmlWriterInlineData(16)]
274         [XmlWriterInlineData(17)]
275         [XmlWriterInlineData(18)]
276         [XmlWriterInlineData(19)]
277         [XmlWriterInlineData(20)]
278         [XmlWriterInlineData(21)]
279         [XmlWriterInlineData(22)]
280         [XmlWriterInlineData(23)]
281         [XmlWriterInlineData(24)]
282         [XmlWriterInlineData(25)]
283         [XmlWriterInlineData(26)]
284         [XmlWriterInlineData(27)]
285         [XmlWriterInlineData(28)]
286         [XmlWriterInlineData(29)]
287         [XmlWriterInlineData(30)]
288         [XmlWriterInlineData(31)]
289         [XmlWriterInlineData(32)]
290         [XmlWriterInlineData(33)]
291         [XmlWriterInlineData(34)]
292         [XmlWriterInlineData(35)]
293         [XmlWriterInlineData(36)]
var_07(XmlWriterUtils utils, int param)294         public void var_07(XmlWriterUtils utils, int param)
295         {
296             bool result = false;
297             int[] skipParams = new int[] { 14, 20, 21 };
298 
299             XmlWriter w = utils.CreateWriter();
300             if (param != 30 && param != 31 && param != 32)
301                 w.WriteStartElement("Root");
302             switch (param)
303             {
304                 case 1: w.WriteComment(null); break;
305                 case 3: w.WriteCData(null); break;
306                 case 5: w.WriteRaw(null); break;
307                 case 6: w.WriteString(null); break;
308                 case 8: w.WriteValue((string)null); break;
309                 case 9: w.WriteWhitespace(null); break;
310             }
311             try
312             {
313                 switch (param)
314                 {
315                     case 1: w.WriteComment("\ud800\ud800"); break;
316                     case 2: w.WriteCharEntity('\ud800'); break;
317                     case 3: w.WriteCData("\ud800\ud800"); break;
318                     case 4: w.WriteEntityRef("\ud800\ud800"); break;
319                     case 5: w.WriteRaw("\ud800\ud800"); break;
320                     case 6: w.WriteString("\ud800\ud800"); break;
321                     case 7: w.WriteSurrogateCharEntity('\ud800', '\ud800'); break;
322                     case 8: w.WriteValue("\ud800\ud800"); break;
323                     case 9: w.WriteWhitespace("\ud800\ud800"); break;
324                     case 10: w.WriteAttributeString("\ud800\ud800", "\ud800\ud800"); break;
325                     case 11: w.WriteAttributeString("a0", "\ud800\ud800", "\ud800\ud800"); break;
326                     case 12: w.WriteAttributeString("a1", "b1", "\ud800\ud800", "\ud800\ud800"); break;
327                     case 13: w.WriteAttributeString("a2", "b2", "c2", "\ud800\ud800"); break;
328                     case 14: w.WriteDocType("\ud800\ud800", "\ud800\ud800", "\ud800\ud800", "\ud800\ud800"); break;
329                     case 15: w.WriteElementString("\ud800\ud800", "\ud800\ud800"); break;
330                     case 16: w.WriteElementString("a", "\ud800\ud800", "\ud800\ud800"); break;
331                     case 17: w.WriteElementString("a", "a", "\ud800\ud800", "\ud800\ud800"); break;
332                     case 18: w.WriteElementString("a", "a", "a", "\ud800\ud800"); break;
333                     case 19: w.WriteEntityRef("\ud800\ud800"); break;
334                     case 20: w.WriteName("\ud800\ud800"); break;
335                     case 21: w.WriteNmToken("\ud800\ud800"); break;
336                     case 22: w.WriteProcessingInstruction("\ud800\ud800", "\ud800\ud800"); break;
337                     case 23: w.WriteQualifiedName("\ud800\ud800", "\ud800\ud800"); break;
338                     case 24: w.WriteStartAttribute("\ud800\ud800"); break;
339                     case 25: w.WriteStartAttribute("\ud800\ud800", "\ud800\ud800"); break;
340                     case 26: w.WriteStartAttribute("a3", "\ud800\ud800", "\ud800\ud800"); break;
341                     case 27: w.WriteStartElement("\ud800\ud800"); break;
342                     case 28: w.WriteStartElement("\ud800\ud800", "\ud800\ud800"); break;
343                     case 29: w.WriteStartElement("a", "\ud800\ud800", "\ud800\ud800"); break;
344                     case 30: w.WriteDocType("a", "\ud800\ud800", "\ud800\ud800", "\ud800\ud800"); break;
345                     case 31: w.WriteDocType("a", "b", "\ud800\ud800", "\ud800\ud800"); break;
346                     case 32: w.WriteDocType("a", "b", "c", "\ud800\ud800"); break;
347                     case 33: w.WriteAttributeString("a4", "\ud800\ud800"); break;
348                     case 34: w.WriteElementString("a", "\ud800\ud800"); break;
349                     case 35: w.WriteProcessingInstruction("a", "\ud800\ud800"); break;
350                     case 36: w.WriteQualifiedName("a", "\ud800\ud800"); break;
351                 }
352             }
353             catch (ArgumentException)
354             {
355                 try
356                 {
357                     switch (param)
358                     {
359                         case 1: w.WriteComment("\ud800\ud800"); break;
360                         case 2: w.WriteCharEntity('\ud800'); break;
361                         case 3: w.WriteCData("\ud800\ud800"); break;
362                         case 4: w.WriteEntityRef("\ud800\ud800"); break;
363                         case 5: w.WriteRaw("\ud800\ud800"); break;
364                         case 6: w.WriteString("\ud800\ud800"); break;
365                         case 7: w.WriteSurrogateCharEntity('\ud800', '\ud800'); break;
366                         case 8: w.WriteValue("\ud800\ud800"); break;
367                         case 9: w.WriteWhitespace("\ud800\ud800"); break;
368                         case 10: w.WriteAttributeString("\ud800\ud800", "\ud800\ud800"); break;
369                         case 11: w.WriteAttributeString("a", "\ud800\ud800", "\ud800\ud800"); break;
370                         case 12: w.WriteAttributeString("a", "b", "\ud800\ud800", "\ud800\ud800"); break;
371                         case 13: w.WriteAttributeString("a", "b", "c", "\ud800\ud800"); break;
372                         case 15: w.WriteElementString("\ud800\ud800", "\ud800\ud800"); break;
373                         case 16: w.WriteElementString("a", "\ud800\ud800", "\ud800\ud800"); break;
374                         case 17: w.WriteElementString("a", "a", "\ud800\ud800", "\ud800\ud800"); break;
375                         case 18: w.WriteElementString("a", "a", "a", "\ud800\ud800"); break;
376                         case 19: w.WriteEntityRef("\ud800\ud800"); break;
377                         case 20: w.WriteName("\ud800\ud800"); break;
378                         case 21: w.WriteNmToken("\ud800\ud800"); break;
379                         case 22: w.WriteProcessingInstruction("\ud800\ud800", "\ud800\ud800"); break;
380                         case 23: w.WriteQualifiedName("\ud800\ud800", "\ud800\ud800"); break;
381                         case 24: w.WriteStartAttribute("\ud800\ud800"); break;
382                         case 25: w.WriteStartAttribute("a", "\ud800\ud800"); break;
383                         case 26: w.WriteStartAttribute("a", "b", "\ud800\ud800"); break;
384                         case 27: w.WriteStartElement("\ud800\ud800"); break;
385                         case 28: w.WriteStartElement("\ud800\ud800", "\ud800\ud800"); break;
386                         case 29: w.WriteStartElement("a", "\ud800\ud800", "\ud800\ud800"); break;
387                         case 30: w.WriteDocType("a", "\ud800\ud800", "\ud800\ud800", "\ud800\ud800"); break;
388                         case 31: w.WriteDocType("a", "b", "\ud800\ud800", "\ud800\ud800"); break;
389                         case 32: w.WriteDocType("a", "b", "c", "\ud800\ud800"); break;
390                         case 33: w.WriteAttributeString("a", "\ud800\ud800"); break;
391                         case 34: w.WriteElementString("a", "\ud800\ud800"); break;
392                         case 35: w.WriteProcessingInstruction("a", "\ud800\ud800"); break;
393                         case 36: w.WriteQualifiedName("a", "\ud800\ud800"); break;
394                     }
395                 }
396                 catch (InvalidOperationException) { return; }
397                 catch (ArgumentException) { return; }
398             }
399             catch (XmlException)
400             {
401                 try
402                 {
403                     switch (param)
404                     {
405                         case 14: w.WriteDocType("\ud800\ud800", "\ud800\ud800", "\ud800\ud800", "\ud800\ud800"); break;
406                         case 30: w.WriteDocType("a", "\ud800\ud800", "\ud800\ud800", "\ud800\ud800"); break;
407                         case 31: w.WriteDocType("a", "b", "\ud800\ud800", "\ud800\ud800"); break;
408                         case 32: w.WriteDocType("a", "b", "c", "\ud800\ud800"); break;
409                     }
410                 }
411                 catch (XmlException)
412                 {
413                     Assert.True((param == 14), "exception expected only for doctype");
414                     return;
415                 }
416                 catch (InvalidOperationException) { Assert.True(false, "InvalidOperationException not expected here"); }
417             }
418             finally
419             {
420                 try
421                 {
422                     w.Dispose();
423                 }
424                 catch (ArgumentException)
425                 {
426                     result = true;
427                 }
428             }
429             Assert.True(result || (utils.WriterType == WriterType.CharCheckingWriter && skipParams.Contains(param)));
430         }
431 
432         [Theory]
433         [XmlWriterInlineData(1)]
434         [XmlWriterInlineData(2)]
435         [XmlWriterInlineData(3)]
436         [XmlWriterInlineData(4)]
var_10(XmlWriterUtils utils, int param)437         public void var_10(XmlWriterUtils utils, int param)
438         {
439             int iBufferSize = 5;
440             int iIndex = 0;
441             int iCount = 6;
442             byte[] byteBuffer = new byte[iBufferSize];
443             for (int i = 0; i < iBufferSize; i++)
444                 byteBuffer[i] = (byte)(i + '0');
445 
446             char[] charBuffer = new char[iBufferSize];
447             for (int i = 0; i < iBufferSize; i++)
448                 charBuffer[i] = (char)(i + '0');
449 
450             XmlWriterSettings ws = new XmlWriterSettings();
451             ws.ConformanceLevel = ConformanceLevel.Auto;
452             using (XmlWriter w = utils.CreateWriter(ws))
453             {
454                 try
455                 {
456                     switch (param)
457                     {
458                         case 1: w.WriteChars(charBuffer, iIndex, iCount); break;
459                         case 2: w.WriteRaw(charBuffer, iIndex, iCount); break;
460                         case 3: w.WriteStartElement("a"); w.WriteBinHex(byteBuffer, iIndex, iCount); break;
461                         case 4: w.WriteBase64(byteBuffer, iIndex, iCount); break;
462                     }
463                 }
464                 catch (ArgumentOutOfRangeException)
465                 {
466                     try
467                     {
468                         switch (param)
469                         {
470                             case 1: w.WriteChars(charBuffer, iIndex, iCount); break;
471                             case 2: w.WriteRaw(charBuffer, iIndex, iCount); break;
472                             case 3: w.WriteBinHex(byteBuffer, iIndex, iCount); break;
473                             case 4: w.WriteBase64(byteBuffer, iIndex, iCount); break;
474                         }
475                     }
476                     catch (ArgumentOutOfRangeException) { return; }
477                     catch (InvalidOperationException) { return; }
478                 }
479                 catch (IndexOutOfRangeException)
480                 {
481                     try
482                     {
483                         switch (param)
484                         {
485                             case 1: w.WriteChars(charBuffer, iIndex, iCount); break;
486                         }
487                     }
488                     catch (IndexOutOfRangeException) { Assert.True((utils.WriterType == WriterType.CharCheckingWriter)); }
489                 }
490             }
491             Assert.True(false);
492         }
493 
494         [Theory]
495         [XmlWriterInlineData(1)]
496         [XmlWriterInlineData(2)]
497         [XmlWriterInlineData(3)]
498         [XmlWriterInlineData(4)]
var_11(XmlWriterUtils utils, int param)499         public void var_11(XmlWriterUtils utils, int param)
500         {
501             XmlWriterSettings ws = new XmlWriterSettings();
502             try
503             {
504                 switch (param)
505                 {
506                     case 1: ws.ConformanceLevel = (ConformanceLevel)777; break;
507                     case 2: ws.NewLineHandling = (NewLineHandling)777; break;
508                     case 3: ws.ConformanceLevel = (ConformanceLevel)(-1); break;
509                     case 4: ws.NewLineHandling = (NewLineHandling)(-1); break;
510                 }
511             }
512             catch (ArgumentOutOfRangeException)
513             {
514                 try
515                 {
516                     switch (param)
517                     {
518                         case 1: ws.ConformanceLevel = (ConformanceLevel)555; break;
519                         case 2: ws.NewLineHandling = (NewLineHandling)555; break;
520                         case 3: ws.ConformanceLevel = (ConformanceLevel)(-1); break;
521                         case 4: ws.NewLineHandling = (NewLineHandling)(-1); break;
522                     }
523                 }
524                 catch (ArgumentOutOfRangeException) { return; }
525             }
526             Assert.True(false);
527         }
528 
529         [Theory]
530         [XmlWriterInlineData(1)]
531         [XmlWriterInlineData(2)]
532         [XmlWriterInlineData(3)]
533         [XmlWriterInlineData(4)]
534         [XmlWriterInlineData(5)]
535         [XmlWriterInlineData(6)]
536         [XmlWriterInlineData(7)]
537         [XmlWriterInlineData(8)]
var_12(XmlWriterUtils utils, int param)538         public void var_12(XmlWriterUtils utils, int param)
539         {
540             XmlWriterSettings ws = new XmlWriterSettings();
541             TextWriter stringWriter = new StringWriter();
542 
543             switch (param)
544             {
545                 case 1: XmlWriter w1 = WriterHelper.Create(stringWriter, overrideAsync: true, async: utils.Async); break;
546                 case 2: XmlWriter w2 = WriterHelper.Create(stringWriter, overrideAsync: true, async: utils.Async); break;
547                 case 3: XmlWriter w3 = WriterHelper.Create(new StringBuilder(), overrideAsync: true, async: utils.Async); break;
548                 case 4: XmlWriter w4 = WriterHelper.Create(WriterHelper.Create(stringWriter, overrideAsync: true, async: utils.Async), overrideAsync: true, async: utils.Async); break;
549                 case 5: XmlWriter w5 = WriterHelper.Create(stringWriter, ws, overrideAsync: true, async: utils.Async); break;
550                 case 6: XmlWriter w6 = WriterHelper.Create(stringWriter, ws, overrideAsync: true, async: utils.Async); break;
551                 case 7: XmlWriter w7 = WriterHelper.Create(new StringBuilder(), ws, overrideAsync: true, async: utils.Async); break;
552                 case 8: XmlWriter w8 = WriterHelper.Create(WriterHelper.Create(stringWriter, overrideAsync: true, async: utils.Async), ws, overrideAsync: true, async: utils.Async); break;
553             }
554             return;
555         }
556 
557         [Theory]
558         [XmlWriterInlineData(1)]
559         [XmlWriterInlineData(2)]
560         [XmlWriterInlineData(3)]
561         [XmlWriterInlineData(4)]
562         [XmlWriterInlineData(5)]
563         [XmlWriterInlineData(6)]
564         [XmlWriterInlineData(7)]
565         [XmlWriterInlineData(8)]
566         [XmlWriterInlineData(9)]
567         [XmlWriterInlineData(10)]
568         [XmlWriterInlineData(11)]
569         [XmlWriterInlineData(12)]
570         [XmlWriterInlineData(13)]
571         [XmlWriterInlineData(14)]
572         [XmlWriterInlineData(15)]
573         [XmlWriterInlineData(16)]
574         [XmlWriterInlineData(17)]
575         [XmlWriterInlineData(18)]
576         [XmlWriterInlineData(19)]
577         [XmlWriterInlineData(20)]
578         [XmlWriterInlineData(21)]
579         [XmlWriterInlineData(22)]
580         [XmlWriterInlineData(23)]
581         [XmlWriterInlineData(24)]
582         [XmlWriterInlineData(25)]
583         [XmlWriterInlineData(26)]
584         [XmlWriterInlineData(27)]
var_13(XmlWriterUtils utils, int param)585         public void var_13(XmlWriterUtils utils, int param)
586         {
587             XmlWriterSettings ws = new XmlWriterSettings();
588             ws.ConformanceLevel = ConformanceLevel.Document;
589             XmlWriter w = utils.CreateWriter(ws);
590             bool result = false;
591             if (param != 30 && param != 31 && param != 32)
592                 w.WriteStartElement("Root");
593             switch (param)
594             {
595                 case 1: w.WriteComment(String.Empty); result = true; break;
596                 case 2: w.WriteCData(String.Empty); result = true; break;
597                 case 4: w.WriteRaw(String.Empty); result = true; break;
598                 case 5: w.WriteString(String.Empty); result = true; break;
599                 case 6: w.WriteValue(String.Empty); result = true; break;
600                 case 7: w.WriteWhitespace(String.Empty); result = true; break;
601             }
602             try
603             {
604                 switch (param)
605                 {
606                     case 3: w.WriteEntityRef(String.Empty); break;
607                     case 8: w.WriteAttributeString(String.Empty, String.Empty); break;
608                     case 9: w.WriteAttributeString(String.Empty, String.Empty, String.Empty); break;
609                     case 10: w.WriteAttributeString(String.Empty, String.Empty, String.Empty, String.Empty); break;
610                     case 11: w.WriteDocType(String.Empty, String.Empty, String.Empty, String.Empty); break;
611                     case 12: w.WriteElementString(String.Empty, String.Empty); break;
612                     case 13: w.WriteElementString(String.Empty, String.Empty, String.Empty); break;
613                     case 14: w.WriteElementString(String.Empty, String.Empty, String.Empty, String.Empty); break;
614                     case 15: w.WriteEntityRef(String.Empty); break;
615                     case 16: w.WriteName(String.Empty); break;
616                     case 17: w.WriteNmToken(String.Empty); break;
617                     case 18: w.WriteProcessingInstruction(String.Empty, String.Empty); break;
618                     case 19: w.WriteQualifiedName(String.Empty, String.Empty); break;
619                     case 20: w.WriteStartAttribute(String.Empty); break;
620                     case 21: w.WriteStartAttribute(String.Empty, String.Empty); break;
621                     case 22: w.WriteStartAttribute(String.Empty, String.Empty, String.Empty); break;
622                     case 23: w.WriteStartElement(String.Empty); break;
623                     case 24: w.WriteStartElement(String.Empty, String.Empty); break;
624                     case 25: w.WriteStartElement(String.Empty, String.Empty, String.Empty); break;
625                     case 26: w.WriteDocType(String.Empty, String.Empty, String.Empty, String.Empty); break;
626                     case 27: w.WriteProcessingInstruction(String.Empty, String.Empty); break;
627                 }
628             }
629             catch (ArgumentException)
630             {
631                 try
632                 {
633                     switch (param)
634                     {
635                         case 3: w.WriteEntityRef(String.Empty); break;
636                         case 8: w.WriteAttributeString(String.Empty, String.Empty); break;
637                         case 9: w.WriteAttributeString(String.Empty, String.Empty, String.Empty); break;
638                         case 10: w.WriteAttributeString(String.Empty, String.Empty, String.Empty, String.Empty); break;
639                         case 11: w.WriteDocType(String.Empty, String.Empty, String.Empty, String.Empty); break;
640                         case 12: w.WriteElementString(String.Empty, String.Empty); break;
641                         case 13: w.WriteElementString(String.Empty, String.Empty, String.Empty); break;
642                         case 14: w.WriteElementString(String.Empty, String.Empty, String.Empty, String.Empty); break;
643                         case 15: w.WriteEntityRef(String.Empty); break;
644                         case 16: w.WriteName(String.Empty); break;
645                         case 17: w.WriteNmToken(String.Empty); break;
646                         case 18: w.WriteProcessingInstruction(String.Empty, String.Empty); break;
647                         case 19: w.WriteQualifiedName(String.Empty, String.Empty); break;
648                         case 20: w.WriteStartAttribute(String.Empty); break;
649                         case 21: w.WriteStartAttribute(String.Empty, String.Empty); break;
650                         case 22: w.WriteStartAttribute(String.Empty, String.Empty, String.Empty); break;
651                         case 23: w.WriteStartElement(String.Empty); break;
652                         case 24: w.WriteStartElement(String.Empty, String.Empty); break;
653                         case 25: w.WriteStartElement(String.Empty, String.Empty, String.Empty); break;
654                         case 26: w.WriteDocType(String.Empty, String.Empty, String.Empty, String.Empty); break;
655                         case 27: w.WriteProcessingInstruction(String.Empty, String.Empty); break;
656                     }
657                 }
658                 catch (ArgumentException) { result = true; }
659             }
660             finally
661             {
662                 w.Dispose();
663             }
664             Assert.True((result || param == 19 && utils.WriterType == WriterType.CustomWriter));
665         }
666 
667         [Theory]
668         [XmlWriterInlineData(1)]
669         [XmlWriterInlineData(2)]
var_14(XmlWriterUtils utils, int param)670         public void var_14(XmlWriterUtils utils, int param)
671         {
672             XmlWriterSettings ws = new XmlWriterSettings();
673             try
674             {
675                 switch (param)
676                 {
677                     case 1: ws.IndentChars = null; break;
678                     case 2: ws.NewLineChars = null; break;
679                 }
680             }
681             catch (ArgumentNullException)
682             {
683                 try
684                 {
685                     switch (param)
686                     {
687                         case 1: ws.IndentChars = null; break;
688                         case 2: ws.NewLineChars = null; break;
689                     }
690                 }
691                 catch (ArgumentNullException) { return; }
692             }
693             Assert.True(false);
694         }
695 
696         [Theory]
697         [XmlWriterInlineData]
var_15(XmlWriterUtils utils)698         public void var_15(XmlWriterUtils utils)
699         {
700             XmlWriter w = utils.CreateWriter();
701             bool isUnicode = (utils.WriterType == WriterType.UnicodeWriter || utils.WriterType == WriterType.UnicodeWriterIndent) ? true : false;
702             bool isIndent = (utils.WriterType == WriterType.UTF8WriterIndent || utils.WriterType == WriterType.UnicodeWriterIndent) ? true : false;
703 
704             w.WriteElementString("a", "b");
705             ((IDisposable)w).Dispose();
706             ((IDisposable)w).Dispose();
707             ((IDisposable)w).Dispose();
708             CError.Compare(w.LookupPrefix(""), String.Empty, "LookupPrefix");
709             CError.Compare(w.WriteState, WriteState.Closed, "WriteState");
710             CError.Compare(w.XmlLang, null, "XmlLang");
711             CError.Compare(w.XmlSpace, XmlSpace.None, "XmlSpace");
712             if (utils.WriterType != WriterType.CustomWriter)
713             {
714                 CError.Compare(w.Settings.CheckCharacters, true, "CheckCharacters");
715                 CError.Compare(w.Settings.CloseOutput, false, "CloseOutput");
716                 CError.Compare(w.Settings.ConformanceLevel, ConformanceLevel.Document, "ConformanceLevel");
717                 CError.Compare(w.Settings.Indent, (isIndent) ? true : false, "Indent");
718                 CError.Compare(w.Settings.IndentChars, "  ", "IndentChars");
719                 CError.Compare(w.Settings.NewLineChars, Environment.NewLine, "NewLineChars");
720                 CError.Compare(w.Settings.NewLineHandling, NewLineHandling.Replace, "NewLineHandling");
721                 CError.Compare(w.Settings.NewLineOnAttributes, false, "NewLineOnAttributes");
722                 CError.Compare(w.Settings.OmitXmlDeclaration, true, "OmitXmlDeclaration");
723                 CError.Compare(w.Settings.Encoding.WebName, (isUnicode) ? "utf-16" : "utf-8", "Encoding");
724             }
725             return;
726         }
727 
728         [Theory]
729         [XmlWriterInlineData]
var_16(XmlWriterUtils utils)730         public void var_16(XmlWriterUtils utils)
731         {
732             XmlWriter w = utils.CreateWriter();
733             bool isUnicode = (utils.WriterType == WriterType.UnicodeWriter || utils.WriterType == WriterType.UnicodeWriterIndent) ? true : false;
734             bool isIndent = (utils.WriterType == WriterType.UTF8WriterIndent || utils.WriterType == WriterType.UnicodeWriterIndent) ? true : false;
735 
736             w.WriteElementString("a", "b");
737             try
738             {
739                 w.WriteDocType("a", "b", "c", "d");
740             }
741             catch (InvalidOperationException)
742             {
743                 CError.Compare(w.LookupPrefix(""), String.Empty, "LookupPrefix");
744                 CError.Compare(w.WriteState, WriteState.Error, "WriteState");
745                 CError.Compare(w.XmlLang, null, "XmlLang");
746                 CError.Compare(w.XmlSpace, XmlSpace.None, "XmlSpace");
747                 if (utils.WriterType != WriterType.CustomWriter)
748                 {
749                     CError.Compare(w.Settings.CheckCharacters, true, "CheckCharacters");
750                     CError.Compare(w.Settings.CloseOutput, false, "CloseOutput");
751                     CError.Compare(w.Settings.ConformanceLevel, ConformanceLevel.Document, "ConformanceLevel");
752                     CError.Compare(w.Settings.Indent, (isIndent) ? true : false, "Indent");
753                     CError.Compare(w.Settings.IndentChars, "  ", "IndentChars");
754                     CError.Compare(w.Settings.NewLineChars, Environment.NewLine, "NewLineChars");
755                     CError.Compare(w.Settings.NewLineHandling, NewLineHandling.Replace, "NewLineHandling");
756                     CError.Compare(w.Settings.NewLineOnAttributes, false, "NewLineOnAttributes");
757                     CError.Compare(w.Settings.OmitXmlDeclaration, true, "OmitXmlDeclaration");
758                     CError.Compare(w.Settings.Encoding.WebName, (isUnicode) ? "utf-16" : "utf-8", "Encoding");
759                 }
760                 return;
761             }
762             Assert.True(false);
763         }
764 
765         [Theory]
766         [XmlWriterInlineData(WriterType.All & ~WriterType.Async)]
bug601305(XmlWriterUtils utils)767         public void bug601305(XmlWriterUtils utils)
768         {
769             CError.WriteLine("expected:");
770             CError.WriteLine("<p:root xmlns:p='uri' />");
771             CError.WriteLine("actual:");
772             XmlWriterSettings ws = new XmlWriterSettings();
773             ws.OmitXmlDeclaration = true;
774             StringWriter sw = new StringWriter();
775             using (XmlWriter w = WriterHelper.Create(sw, ws, overrideAsync: true, async: utils.Async))
776             {
777                 w.WriteStartElement("root", "uri");
778                 w.WriteStartAttribute("xmlns", "p", "http://www.w3.org/2000/xmlns/");
779                 w.WriteString("uri");
780             }
781             CError.Compare(sw.ToString(), "<root xmlns:p=\"uri\" xmlns=\"uri\" />", "writer output");
782             return;
783         }
784 
785         [Theory]
786         [XmlWriterInlineData(1)]
787         [XmlWriterInlineData(2)]
788         [XmlWriterInlineData(3)]
789         [XmlWriterInlineData(4)]
790         [XmlWriterInlineData(5)]
791         [XmlWriterInlineData(6)]
792         [XmlWriterInlineData(7)]
793         [XmlWriterInlineData(8)]
794         [XmlWriterInlineData(9)]
795         [XmlWriterInlineData(10)]
var17(XmlWriterUtils utils, int param)796         public void var17(XmlWriterUtils utils, int param)
797         {
798             if (utils.WriterType == WriterType.CustomWriter) return;
799             XmlWriter writer = utils.CreateWriter();
800             try
801             {
802                 switch (param)
803                 {
804                     case 1: writer.Settings.CheckCharacters = false; break;
805                     case 2: writer.Settings.CloseOutput = false; break;
806                     case 3: writer.Settings.ConformanceLevel = ConformanceLevel.Fragment; break;
807                     case 4: writer.Settings.Encoding = Encoding.UTF8; break;
808                     case 5: writer.Settings.Indent = false; break;
809                     case 6: writer.Settings.IndentChars = "#"; break;
810                     case 7: writer.Settings.NewLineChars = "%"; break;
811                     case 8: writer.Settings.NewLineHandling = NewLineHandling.None; break;
812                     case 9: writer.Settings.NewLineOnAttributes = false; break;
813                     case 10: writer.Settings.OmitXmlDeclaration = true; break;
814                 }
815             }
816             catch (XmlException)
817             {
818                 try
819                 {
820                     switch (param)
821                     {
822                         case 1: writer.Settings.CheckCharacters = false; break;
823                         case 2: writer.Settings.CloseOutput = false; break;
824                         case 3: writer.Settings.ConformanceLevel = ConformanceLevel.Fragment; break;
825                         case 4: writer.Settings.Encoding = Encoding.UTF8; break;
826                         case 5: writer.Settings.Indent = false; break;
827                         case 6: writer.Settings.IndentChars = "#"; break;
828                         case 7: writer.Settings.NewLineChars = "%"; break;
829                         case 8: writer.Settings.NewLineHandling = NewLineHandling.None; break;
830                         case 9: writer.Settings.NewLineOnAttributes = false; break;
831                         case 10: writer.Settings.OmitXmlDeclaration = true; break;
832                     }
833                 }
834                 catch (XmlException) { return; }
835             }
836             Assert.True(false);
837         }
838 
839         [Theory]
840         [XmlWriterInlineData(1)]
841         [XmlWriterInlineData(2)]
842         [XmlWriterInlineData(3)]
843         [XmlWriterInlineData(4)]
844         [XmlWriterInlineData(5)]
845         [XmlWriterInlineData(6)]
846         [XmlWriterInlineData(7)]
847         [XmlWriterInlineData(8)]
848         [XmlWriterInlineData(9)]
849         [XmlWriterInlineData(10)]
850         [XmlWriterInlineData(11)]
851         [XmlWriterInlineData(12)]
852         [XmlWriterInlineData(13)]
853         [XmlWriterInlineData(14)]
854         [XmlWriterInlineData(15)]
855         [XmlWriterInlineData(16)]
856         [XmlWriterInlineData(17)]
857         [XmlWriterInlineData(18)]
858         [XmlWriterInlineData(19)]
859         [XmlWriterInlineData(20)]
860         [XmlWriterInlineData(21)]
861         [XmlWriterInlineData(22)]
862         [XmlWriterInlineData(23)]
863         [XmlWriterInlineData(24)]
864         [XmlWriterInlineData(25)]
865         [XmlWriterInlineData(26)]
866         [XmlWriterInlineData(27)]
867         [XmlWriterInlineData(28)]
868         [XmlWriterInlineData(29)]
var_18(XmlWriterUtils utils, int param)869         public void var_18(XmlWriterUtils utils, int param)
870         {
871             XmlReader r = ReaderHelper.Create(new StringReader("<xmlns/>"));
872             byte[] buffer = new byte[10];
873             char[] chbuffer = new char[10];
874             XmlWriter w = utils.CreateWriter();
875             w.WriteElementString("a", "b");
876             w.Dispose();
877             CError.Compare(w.WriteState, WriteState.Closed, "WriteState should be Error");
878             try
879             {
880                 switch (param)
881                 {
882                     case 1: w.WriteQualifiedName("foo", ""); break;
883                     case 2: w.WriteAttributes(r, true); break;
884                     case 3: w.WriteAttributeString("a", "b", "c", "d"); break;
885                     case 4: w.WriteBase64(buffer, 0, 3); break;
886                     case 5: w.WriteBinHex(buffer, 0, 3); break;
887                     case 6: w.WriteCData("a"); break;
888                     case 7: w.WriteCharEntity(Char.MaxValue); break;
889                     case 8: w.WriteChars(chbuffer, 1, 3); break;
890                     case 9: w.WriteComment("a"); break;
891                     case 10: w.WriteDocType("a", "b", "c", "d"); break;
892                     case 11: w.WriteElementString("a", "b", "c", "d"); break;
893                     case 12: w.WriteEndAttribute(); break;
894                     case 13: w.WriteEndDocument(); break;
895                     case 14: w.WriteEndElement(); break;
896                     case 15: w.WriteEntityRef("a"); break;
897                     case 16: w.WriteFullEndElement(); break;
898                     case 17: w.WriteName("b"); break;
899                     case 18: w.WriteNmToken("b"); break;
900                     case 19: w.WriteNode(r, true); break;
901                     case 20: w.WriteProcessingInstruction("a", "b"); break;
902                     case 21: w.WriteRaw("a"); break;
903                     case 22: w.WriteRaw(chbuffer, 1, 3); break;
904                     case 23: w.WriteStartAttribute("a", "b", "c"); break;
905                     case 24: w.WriteStartDocument(true); break;
906                     case 25: w.WriteStartElement("a", "b", "c"); break;
907                     case 26: w.WriteString("a"); break;
908                     case 27: w.WriteSurrogateCharEntity('\uD812', '\uDD12'); break;
909                     case 28: w.WriteValue(true); break;
910                     case 29: w.WriteWhitespace(""); break;
911                 }
912             }
913             catch (InvalidOperationException)
914             {
915                 try
916                 {
917                     switch (param)
918                     {
919                         case 1: w.WriteQualifiedName("foo", ""); break;
920                         case 3: w.WriteAttributeString("a", "b", "c", "d"); break;
921                         case 4: w.WriteBase64(buffer, 0, 3); break;
922                         case 5: w.WriteBinHex(buffer, 0, 3); break;
923                         case 6: w.WriteCData("a"); break;
924                         case 7: w.WriteCharEntity(Char.MaxValue); break;
925                         case 8: w.WriteChars(chbuffer, 1, 3); break;
926                         case 9: w.WriteComment("a"); break;
927                         case 10: w.WriteDocType("a", "b", "c", "d"); break;
928                         case 11: w.WriteElementString("a", "b", "c", "d"); break;
929                         case 12: w.WriteEndAttribute(); break;
930                         case 13: w.WriteEndDocument(); break;
931                         case 14: w.WriteEndElement(); break;
932                         case 15: w.WriteEntityRef("a"); break;
933                         case 16: w.WriteFullEndElement(); break;
934                         case 17: w.WriteName("b"); break;
935                         case 18: w.WriteNmToken("b"); break;
936                         case 19: w.WriteNode(r, true); break;
937                         case 20: w.WriteProcessingInstruction("a", "b"); break;
938                         case 21: w.WriteRaw("a"); break;
939                         case 22: w.WriteRaw(chbuffer, 1, 3); break;
940                         case 23: w.WriteStartAttribute("a", "b", "c"); break;
941                         case 24: w.WriteStartDocument(true); break;
942                         case 25: w.WriteStartElement("a", "b", "c"); break;
943                         case 26: w.WriteString("a"); break;
944                         case 28: w.WriteValue(true); break;
945                         case 29: w.WriteWhitespace(""); break;
946                     }
947                 }
948                 catch (InvalidOperationException) { return; }
949             }
950             catch (ArgumentException)
951             {
952                 try
953                 {
954                     switch (param)
955                     {
956                         case 8: w.WriteChars(chbuffer, 1, 3); break;
957                         case 27: w.WriteSurrogateCharEntity('\uD812', '\uDD12'); break;
958                     }
959                 }
960                 catch (ArgumentException) { return; }
961             }
962             catch (XmlException)
963             {
964                 try
965                 {
966                     switch (param)
967                     {
968                         case 2: w.WriteAttributes(r, true); break;
969                     }
970                 }
971                 catch (XmlException) { return; }
972             }
973             Assert.True(false);
974         }
975 
976         [Theory]
977         [XmlWriterInlineData(1)]
978         [XmlWriterInlineData(2)]
979         [XmlWriterInlineData(3)]
980         [XmlWriterInlineData(4)]
981         [XmlWriterInlineData(5)]
982         [XmlWriterInlineData(6)]
983         [XmlWriterInlineData(7)]
984         [XmlWriterInlineData(8)]
985         [XmlWriterInlineData(9)]
986         [XmlWriterInlineData(10)]
987         [XmlWriterInlineData(11)]
988         [XmlWriterInlineData(12)]
989         [XmlWriterInlineData(13)]
990         [XmlWriterInlineData(14)]
991         [XmlWriterInlineData(15)]
992         [XmlWriterInlineData(16)]
993         [XmlWriterInlineData(17)]
994         [XmlWriterInlineData(18)]
995         [XmlWriterInlineData(19)]
996         [XmlWriterInlineData(20)]
997         [XmlWriterInlineData(21)]
998         [XmlWriterInlineData(22)]
999         [XmlWriterInlineData(23)]
1000         [XmlWriterInlineData(24)]
1001         [XmlWriterInlineData(25)]
1002         [XmlWriterInlineData(26)]
1003         [XmlWriterInlineData(27)]
1004         [XmlWriterInlineData(28)]
1005         [XmlWriterInlineData(29)]
var_19(XmlWriterUtils utils, int param)1006         public void var_19(XmlWriterUtils utils, int param)
1007         {
1008             XmlReader r = ReaderHelper.Create(new StringReader("<xmlns/>"));
1009             byte[] buffer = new byte[10];
1010             char[] chbuffer = new char[10];
1011             XmlWriter w = utils.CreateWriter();
1012             try
1013             {
1014                 w.WriteStartDocument();
1015                 w.WriteEntityRef("ent");
1016             }
1017             catch (InvalidOperationException)
1018             {
1019                 CError.Compare(w.WriteState, WriteState.Error, "WriteState should be Error");
1020                 try
1021                 {
1022                     switch (param)
1023                     {
1024                         case 1: w.WriteQualifiedName("foo", ""); break;
1025                         case 2: w.WriteAttributes(r, true); break;
1026                         case 3: w.WriteAttributeString("a", "b", "c", "d"); break;
1027                         case 4: w.WriteBase64(buffer, 0, 3); break;
1028                         case 5: w.WriteBinHex(buffer, 0, 3); break;
1029                         case 6: w.WriteCData("a"); break;
1030                         case 7: w.WriteCharEntity(Char.MaxValue); break;
1031                         case 8: w.WriteChars(chbuffer, 1, 3); break;
1032                         case 9: w.WriteComment("a"); break;
1033                         case 10: w.WriteDocType("a", "b", "c", "d"); break;
1034                         case 11: w.WriteElementString("a", "b", "c", "d"); break;
1035                         case 12: w.WriteEndAttribute(); break;
1036                         case 13: w.WriteEndDocument(); break;
1037                         case 14: w.WriteEndElement(); break;
1038                         case 15: w.WriteEntityRef("a"); break;
1039                         case 16: w.WriteFullEndElement(); break;
1040                         case 17: w.WriteName("b"); break;
1041                         case 18: w.WriteNmToken("b"); break;
1042                         case 19: w.WriteNode(r, true); break;
1043                         case 20: w.WriteProcessingInstruction("a", "b"); break;
1044                         case 21: w.WriteRaw("a"); break;
1045                         case 22: w.WriteRaw(chbuffer, 1, 3); break;
1046                         case 23: w.WriteStartAttribute("a", "b", "c"); break;
1047                         case 24: w.WriteStartDocument(true); break;
1048                         case 25: w.WriteStartElement("a", "b", "c"); break;
1049                         case 26: w.WriteString("a"); break;
1050                         case 27: w.WriteSurrogateCharEntity('\uD812', '\uDD12'); break;
1051                         case 28: w.WriteValue(true); break;
1052                         case 29: w.WriteWhitespace(""); break;
1053                     }
1054                 }
1055                 catch (InvalidOperationException)
1056                 {
1057                     try
1058                     {
1059                         switch (param)
1060                         {
1061                             case 1: w.WriteQualifiedName("foo", ""); break;
1062                             case 3: w.WriteAttributeString("a", "b", "c", "d"); break;
1063                             case 4: w.WriteBase64(buffer, 0, 3); break;
1064                             case 5: w.WriteBinHex(buffer, 0, 3); break;
1065                             case 6: w.WriteCData("a"); break;
1066                             case 7: w.WriteCharEntity(Char.MaxValue); break;
1067                             case 8: w.WriteChars(chbuffer, 1, 3); break;
1068                             case 9: w.WriteComment("a"); break;
1069                             case 10: w.WriteDocType("a", "b", "c", "d"); break;
1070                             case 11: w.WriteElementString("a", "b", "c", "d"); break;
1071                             case 12: w.WriteEndAttribute(); break;
1072                             case 13: w.WriteEndDocument(); break;
1073                             case 14: w.WriteEndElement(); break;
1074                             case 15: w.WriteEntityRef("a"); break;
1075                             case 16: w.WriteFullEndElement(); break;
1076                             case 17: w.WriteName("b"); break;
1077                             case 18: w.WriteNmToken("b"); break;
1078                             case 19: w.WriteNode(r, true); break;
1079                             case 20: w.WriteProcessingInstruction("a", "b"); break;
1080                             case 21: w.WriteRaw("a"); break;
1081                             case 22: w.WriteRaw(chbuffer, 1, 3); break;
1082                             case 23: w.WriteStartAttribute("a", "b", "c"); break;
1083                             case 24: w.WriteStartDocument(true); break;
1084                             case 25: w.WriteStartElement("a", "b", "c"); break;
1085                             case 26: w.WriteString("a"); break;
1086                             case 28: w.WriteValue(true); break;
1087                             case 29: w.WriteWhitespace(""); break;
1088                         }
1089                     }
1090                     catch (InvalidOperationException) { return; }
1091                 }
1092                 catch (ArgumentException)
1093                 {
1094                     try
1095                     {
1096                         switch (param)
1097                         {
1098                             case 8: w.WriteChars(chbuffer, 1, 3); break;
1099                             case 27: w.WriteSurrogateCharEntity('\uD812', '\uDD12'); break;
1100                         }
1101                     }
1102                     catch (ArgumentException) { return; }
1103                 }
1104                 catch (XmlException)
1105                 {
1106                     try
1107                     {
1108                         switch (param)
1109                         {
1110                             case 2: w.WriteAttributes(r, true); break;
1111                         }
1112                     }
1113                     catch (XmlException) { return; }
1114                 }
1115             }
1116             Assert.True(false);
1117         }
1118 
1119         [Theory]
1120         [XmlWriterInlineData]
var_20(XmlWriterUtils utils)1121         public void var_20(XmlWriterUtils utils)
1122         {
1123             XmlWriter w = utils.CreateWriter();
1124             w.WriteStartElement("root");
1125             try
1126             {
1127                 w.WriteAttributeString("attr1", "\uD812\uD812");
1128                 w.WriteEndElement();
1129             }
1130             catch (ArgumentException e)
1131             {
1132                 CError.WriteLine(e);
1133                 try
1134                 {
1135                     w.WriteAttributeString("attr2", "\uD812\uD812");
1136                     w.WriteEndElement();
1137                 }
1138                 catch (InvalidOperationException ioe) { CError.WriteLine(ioe); return; }
1139                 catch (ArgumentException ae) { CError.WriteLine(ae); return; }
1140             }
1141             finally
1142             {
1143                 w.Dispose();
1144             }
1145             Assert.True(false);
1146         }
1147 
1148         [Theory]
1149         [XmlWriterInlineData(1)]
1150         [XmlWriterInlineData(2)]
1151         [XmlWriterInlineData(3)]
1152         [XmlWriterInlineData(4)]
1153         [XmlWriterInlineData(5)]
1154         [XmlWriterInlineData(6)]
1155         [XmlWriterInlineData(7)]
1156         [XmlWriterInlineData(8)]
1157         [XmlWriterInlineData(9)]
1158         [XmlWriterInlineData(10)]
1159         [XmlWriterInlineData(11)]
1160         [XmlWriterInlineData(12)]
1161         [XmlWriterInlineData(13)]
1162         [XmlWriterInlineData(14)]
1163         [XmlWriterInlineData(15)]
1164         [XmlWriterInlineData(16)]
1165         [XmlWriterInlineData(17)]
1166         [XmlWriterInlineData(18)]
1167         [XmlWriterInlineData(19)]
1168         [XmlWriterInlineData(20)]
1169         [XmlWriterInlineData(21)]
1170         [XmlWriterInlineData(22)]
1171         [XmlWriterInlineData(23)]
1172         [XmlWriterInlineData(24)]
1173         [XmlWriterInlineData(25)]
1174         [XmlWriterInlineData(26)]
1175         [XmlWriterInlineData(27)]
1176         [XmlWriterInlineData(28)]
1177         [XmlWriterInlineData(29)]
1178         [XmlWriterInlineData(30)]
1179         [XmlWriterInlineData(31)]
1180         [XmlWriterInlineData(32)]
1181         [XmlWriterInlineData(33)]
1182         [XmlWriterInlineData(34)]
var_21(XmlWriterUtils utils, int param)1183         public void var_21(XmlWriterUtils utils, int param)
1184         {
1185             bool result = false;
1186             string val = "\uDE34\uD9A2";
1187             XmlWriter w = utils.CreateWriter();
1188             if (param != 13 && param != 14 && param != 15) w.WriteStartElement("a", "b");
1189             try
1190             {
1191                 switch (param)
1192                 {
1193                     case 1: w.WriteStartAttribute("c"); w.WriteValue(val); break;
1194                     case 2: w.WriteStartAttribute("c"); w.WriteComment(val); break;
1195                     case 3: w.WriteStartAttribute("c"); w.WriteCData(val); break;
1196                     case 4: w.WriteStartAttribute("c"); w.WriteProcessingInstruction("a", val); break;
1197                     case 5: w.WriteStartAttribute("c"); w.WriteRaw(val); break;
1198                     case 6: w.WriteValue(val); break;
1199                     case 7: w.WriteComment(val); break;
1200                     case 8: w.WriteCData(val); break;
1201                     case 9: w.WriteProcessingInstruction("a", val); break;
1202                     case 10: w.WriteRaw(val); break;
1203                     case 11: w.WriteAttributeString("a", val); break;
1204                     case 12: w.WriteCharEntity('\uDE34'); break;
1205                     case 13: w.WriteDocType("a", val, val, val); break;
1206                     case 14: w.WriteDocType("a", "b", val, val); break;
1207                     case 15: w.WriteDocType("a", "b", "c", val); break;
1208                     case 16: w.WriteElementString(val, val, val, val); break;
1209                     case 17: w.WriteElementString("a", val, val, val); break;
1210                     case 18: w.WriteElementString("a", "b", val, val); break;
1211                     case 19: w.WriteElementString("a", "b", "c", val); break;
1212                     case 20: w.WriteEntityRef(val); break;
1213                     case 21: w.WriteName(val); break;
1214                     case 22: w.WriteNmToken(val); break;
1215                     case 23: w.WriteQualifiedName(val, val); break;
1216                     case 24: w.WriteQualifiedName("a", val); break;
1217                     case 25: w.WriteStartAttribute(val); break;
1218                     case 26: w.WriteStartAttribute("a", val); break;
1219                     case 27: w.WriteStartAttribute("a", val, val); break;
1220                     case 28: w.WriteStartElement(val); break;
1221                     case 29: w.WriteStartElement("a", val); break;
1222                     case 30: w.WriteStartElement("a", val, val); break;
1223                     case 31: w.WriteString(val); break;
1224                     case 32: w.WriteWhitespace(val); break;
1225                     case 33: w.WriteStartAttribute("c"); w.WriteString(val); break;
1226                     case 34: w.WriteSurrogateCharEntity('\uD9A2', '\uDE34'); break;
1227                 }
1228             }
1229             catch (ArgumentException e)
1230             {
1231                 CError.WriteLine(e.Message);
1232                 try
1233                 {
1234                     switch (param)
1235                     {
1236                         case 1: w.WriteStartAttribute("b"); w.WriteValue(val); break;
1237                         case 2: w.WriteStartAttribute("b"); w.WriteComment(val); break;
1238                         case 3: w.WriteStartAttribute("b"); w.WriteCData(val); break;
1239                         case 4: w.WriteStartAttribute("b"); w.WriteProcessingInstruction("a", val); break;
1240                         case 5: w.WriteStartAttribute("b"); w.WriteRaw(val); break;
1241                         case 6: w.WriteValue(val); break;
1242                         case 7: w.WriteComment(val); break;
1243                         case 8: w.WriteCData(val); break;
1244                         case 9: w.WriteProcessingInstruction("a", val); break;
1245                         case 10: w.WriteRaw(val); break;
1246                         case 11: w.WriteAttributeString("a2", val); break;
1247                         case 12: w.WriteCharEntity('\uDE34'); break;
1248                         case 13: w.WriteDocType("a", val, val, val); break;
1249                         case 14: w.WriteDocType("a", "b", val, val); break;
1250                         case 15: w.WriteDocType("a", "b", "c", val); break;
1251                         case 16: w.WriteElementString(val, val, val, val); break;
1252                         case 17: w.WriteElementString("a", val, val, val); break;
1253                         case 18: w.WriteElementString("a", "b", val, val); break;
1254                         case 19: w.WriteElementString("a", "b", "c", val); break;
1255                         case 20: w.WriteEntityRef(val); break;
1256                         case 21: w.WriteName(val); break;
1257                         case 22: w.WriteNmToken(val); break;
1258                         case 23: w.WriteQualifiedName(val, val); break;
1259                         case 24: w.WriteQualifiedName("a", val); break;
1260                         case 25: w.WriteStartAttribute(val); break;
1261                         case 26: w.WriteStartAttribute("a", val); break;
1262                         case 27: w.WriteStartAttribute("a", val, val); break;
1263                         case 28: w.WriteStartElement(val); break;
1264                         case 29: w.WriteStartElement("a", val); break;
1265                         case 30: w.WriteStartElement("a", val, val); break;
1266                         case 31: w.WriteString(val); break;
1267                         case 32: w.WriteWhitespace(val); break;
1268                         case 33: w.WriteStartAttribute("b"); w.WriteString(val); break;
1269                         case 34: w.WriteSurrogateCharEntity('\uD9A2', '\uDE34'); break;
1270                     }
1271                 }
1272                 catch (InvalidOperationException) { CError.WriteLine(e.Message); result = true; }
1273                 catch (ArgumentException) { CError.WriteLine(e.Message); result = true; }
1274             }
1275             catch (XmlException e)
1276             {
1277                 CError.WriteLine(e.Message);
1278                 try
1279                 {
1280                     switch (param)
1281                     {
1282                         case 13: w.WriteDocType("a", val, val, val); break;
1283                         case 14: w.WriteDocType("a", "b", val, val); break;
1284                         case 15: w.WriteDocType("a", "b", "c", val); break;
1285                         case 21: w.WriteName(val); break;
1286                         case 22: w.WriteNmToken(val); break;
1287                     }
1288                 }
1289                 catch (XmlException)
1290                 {
1291                     result = (utils.WriterType == WriterType.CharCheckingWriter && (param == 21 || param == 22));
1292                 }
1293                 catch (InvalidOperationException) { result = false; }
1294             }
1295             finally
1296             {
1297                 try
1298                 {
1299                     w.Dispose();
1300                 }
1301                 catch (ArgumentException) { result = true; }
1302             }
1303             Assert.True(result);
1304         }
1305 
1306         [Theory]
1307         [XmlWriterInlineData(1)]
1308         [XmlWriterInlineData(2)]
1309         [XmlWriterInlineData(3)]
1310         [XmlWriterInlineData(4)]
bug600541(XmlWriterUtils utils, int param)1311         public void bug600541(XmlWriterUtils utils, int param)
1312         {
1313             string xml = "<root a=\"a\" b=\"b\" c=\"c\" d=\"d\" />";
1314             switch (param)
1315             {
1316                 case 1: break;
1317                 case 2: xml = "<root b=\"b\" c=\"c\" d=\"d\" />"; break;
1318                 case 3: xml = "<root c=\"c\" d=\"d\" />"; break;
1319                 case 4: xml = "<root d=\"d\" />"; break;
1320             }
1321             using (XmlReader r = ReaderHelper.Create(new StringReader(xml)))
1322             {
1323                 r.Read();
1324                 CError.Compare(r.NodeType, XmlNodeType.Element, "XNT");
1325                 CError.Compare(r.MoveToFirstAttribute(), true, "MFA");
1326                 using (XmlWriter w = utils.CreateWriter())
1327                 {
1328                     w.WriteStartElement("root");
1329                     switch (param)
1330                     {
1331                         case 1: break;
1332                         case 2: r.MoveToAttribute("b"); break;
1333                         case 3: r.MoveToAttribute("c"); break;
1334                         case 4: r.MoveToAttribute("d"); break;
1335                     }
1336                     w.WriteAttributes(r, true);
1337                     w.Dispose();
1338                     Assert.True((utils.CompareString(xml)));
1339                 }
1340             }
1341         }
1342 
1343         [Theory]
1344         [XmlWriterInlineData]
bug630890(XmlWriterUtils utils)1345         public void bug630890(XmlWriterUtils utils)
1346         {
1347             object obj = (object)1;
1348             for (int i = 0; i < 100000; i++)
1349             {
1350                 obj = new object[1] { obj };
1351             }
1352 
1353             using (XmlWriter w = utils.CreateWriter())
1354             {
1355                 w.WriteStartElement("Root");
1356                 try
1357                 {
1358                     w.WriteValue(obj);
1359                     CError.Compare(false, "Failed1");
1360                 }
1361                 catch (InvalidCastException e)
1362                 {
1363                     CError.WriteLine(e);
1364                     try
1365                     {
1366                         w.WriteValue(obj);
1367                         CError.Compare(false, "Failed1");
1368                     }
1369                     catch (InvalidOperationException) { CError.WriteLine(e.Message); return; }
1370                     catch (InvalidCastException) { CError.WriteLine(e.Message); return; }
1371                 }
1372             }
1373             Assert.True(false);
1374         }
1375 
1376         [Theory]
1377         [XmlWriterInlineData]
PassingArrayWithNullOrEmptyItemsCausesWriteValueToFail(XmlWriterUtils utils)1378         public void PassingArrayWithNullOrEmptyItemsCausesWriteValueToFail(XmlWriterUtils utils)
1379         {
1380             string[] a = new string[5];
1381             string exp = "<b>a a1 </b>";
1382             a[0] = "a";
1383             a[1] = "a1";
1384             a[3] = null;
1385             a[4] = "";
1386 
1387             using (XmlWriter w = utils.CreateWriter())
1388             {
1389                 w.WriteStartElement("b");
1390                 w.WriteValue(a);
1391             }
1392             Assert.True((utils.CompareString(exp)));
1393         }
1394     }
1395 }
1396 
1397