New test.
[mono.git] / mcs / class / System / Test / System.CodeDom.Compiler / CodeGeneratorTestBase.cs
1 //
2 // Base class for CodeGenerator unit tests
3 //
4 // Authors:
5 // Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (c) Novell
8 //
9
10 using System;
11 using System.CodeDom;
12 using System.CodeDom.Compiler;
13 using System.IO;
14
15 using NUnit.Framework;
16
17 namespace MonoTests.System.CodeDom.Compiler
18 {
19         public abstract class CodeGeneratorTestBase
20         {
21                 private CodeGeneratorOptions _options;
22
23                 [SetUp]
24                 public virtual void SetUp ()
25                 {
26                         _options = new CodeGeneratorOptions ();
27                 }
28
29                 protected abstract ICodeGenerator CodeGenerator
30                 {
31                         get;
32                 }
33
34                 protected virtual string NewLine
35                 {
36                         get { return "\n"; }
37                 }
38
39                 protected CodeGeneratorOptions Options
40                 {
41                         get { return _options; }
42                 }
43
44                 protected string GenerateCodeFromType (CodeTypeDeclaration type)
45                 {
46                         return GenerateCodeFromType (type, _options);
47                 }
48
49                 protected virtual string GenerateCodeFromType (CodeTypeDeclaration type, CodeGeneratorOptions options)
50                 {
51                         using (StringWriter writer = new StringWriter ()) {
52                                 writer.NewLine = NewLine;
53                                 CodeGenerator.GenerateCodeFromType (type, writer, options);
54                                 writer.Close ();
55                                 return writer.ToString ();
56                         }
57                 }
58         }
59 }