2003-12-11 Nick Drochak <ndrochak@ieee.org>
[mono.git] / mcs / class / System / Test / Microsoft.VisualBasic / VBCodeProviderTest.cs
1 //\r
2 // Microsoft.VisualBasic.VBCodeProvider.cs\r
3 //\r
4 // Author:\r
5 //   Jochen Wezel (jwezel@compumaster.de) //\r
6 //\r
7 // (C) 2003 Jochen Wezel (CompuMaster GmbH)\r
8 //\r
9 // Last modifications:\r
10 // 2003-12-10 JW: publishing of this file\r
11 //\r
12 \r
13 using NUnit.Framework;\r
14 using System;\r
15 using Microsoft.VisualBasic;\r
16 using System.CodeDom.Compiler;\r
17 using System.ComponentModel;\r
18 using System.Collections.Specialized;\r
19 using System.Reflection;\r
20 using System.Diagnostics;\r
21 using System.IO;\r
22 \r
23 namespace MonoTests.System.Microsoft.VisualBasic\r
24 {\r
25         [TestFixture]\r
26         public class VBCodeProviderTest : Assertion {\r
27         \r
28                 CodeDomProvider MyVBCodeProvider;\r
29 \r
30                 [SetUp]\r
31                 public void GetReady() { \r
32                         MyVBCodeProvider = new VBCodeProvider(); \r
33                 }\r
34 \r
35                 [Test]\r
36                 public void FileExtension ()\r
37                 {\r
38                         AssertEquals ("#JW10", "vb", MyVBCodeProvider.FileExtension);\r
39                 }\r
40 \r
41                 [Test]\r
42                 public void LanguageOptionsTest ()\r
43                 {\r
44                         AssertEquals ("#JW20", LanguageOptions.CaseInsensitive, MyVBCodeProvider.LanguageOptions);\r
45                 }\r
46 \r
47                 [Test]\r
48                 public void CreateCompiler()\r
49                 {\r
50                         // Prepare the compilation\r
51                         //Console.WriteLine("#J30.pre1 - CreateCompiler");\r
52                         ICodeCompiler MyVBCodeCompiler;\r
53                         MyVBCodeCompiler = MyVBCodeProvider.CreateCompiler();\r
54                         AssertNotNull ("#JW30 - CreateCompiler", MyVBCodeCompiler);\r
55                         CompilerResults MyVBCodeCompilerResults;\r
56                         //Console.WriteLine("#J30.post1 - CreateCompiler");\r
57 \r
58                         CompilerParameters options = new CompilerParameters();\r
59                         options.GenerateExecutable = true;\r
60                         options.IncludeDebugInformation = true;\r
61                         options.TreatWarningsAsErrors = true;\r
62                         \r
63                         // Process compilation\r
64                         MyVBCodeCompilerResults = MyVBCodeCompiler.CompileAssemblyFromSource(options,\r
65                                 "public class TestModule" + Environment.NewLine + "public shared sub Main()" + Environment.NewLine + "System.Console.Write(\"Hello world!\")" + Environment.NewLine + "End Sub" + Environment.NewLine + "End Class" + Environment.NewLine);\r
66 \r
67                         // Analyse the compilation success/messages\r
68                         StringCollection MyOutput;\r
69                         MyOutput = MyVBCodeCompilerResults.Output;\r
70                         string MyOutStr = "";\r
71                         foreach (string MyStr in MyOutput)\r
72                         {\r
73                                 MyOutStr += MyStr + Environment.NewLine + Environment.NewLine;\r
74                         }\r
75 \r
76                         AssertEquals ("#JW31 - Hello world compilation: " + MyOutStr, 0, MyVBCodeCompilerResults.Errors.Count);\r
77 \r
78                         try\r
79                         {\r
80                                 Assembly MyAss = MyVBCodeCompilerResults.CompiledAssembly;\r
81                         }\r
82                         catch (Exception ex)\r
83                         {\r
84                                 Assert ("#JW32 - MyVBCodeCompilerResults.CompiledAssembly hasn't been an expected object" + \r
85                                                 Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, false);\r
86                         }\r
87 \r
88                         // Execute the test app\r
89                         ProcessStartInfo NewProcInfo = new ProcessStartInfo();\r
90                         NewProcInfo.FileName = MyVBCodeCompilerResults.CompiledAssembly.Location;\r
91                         NewProcInfo.RedirectStandardOutput = true;\r
92                         NewProcInfo.UseShellExecute = false;\r
93                         NewProcInfo.CreateNoWindow = true;\r
94                         string TestAppOutput = "";\r
95                         try\r
96                         {\r
97                                 Process MyProc = Process.Start(NewProcInfo);\r
98                                 MyProc.WaitForExit();\r
99                                 TestAppOutput = MyProc.StandardOutput.ReadToEnd();\r
100                                 MyProc.Close();\r
101                                 MyProc.Dispose();\r
102                         }\r
103                         catch (Exception ex)\r
104                         {\r
105                                 Assert("#JW34 - " + ex.Message + Environment.NewLine + ex.StackTrace, false);\r
106                         }\r
107                         AssertEquals("#JW33 - Application output", "Hello world!", TestAppOutput);\r
108 \r
109                         // Clean up\r
110                         try\r
111                         {\r
112                                 File.Delete (NewProcInfo.FileName);\r
113                         }\r
114                         catch {}\r
115                 }\r
116 \r
117                 [Test]\r
118                 public void CreateGenerator()\r
119                 {\r
120                         ICodeGenerator MyVBCodeGen;\r
121                         MyVBCodeGen = MyVBCodeProvider.CreateGenerator();\r
122                         Assert ("#JW40 - CreateGenerator", (MyVBCodeGen != null));\r
123                         AssertEquals ("#JW41", true, MyVBCodeGen.Supports (GeneratorSupport.DeclareEnums));\r
124                 }\r
125 \r
126                 \r
127                 //TODO: [Test]\r
128                 public void     CreateParser()\r
129                 {\r
130                         //System.CodeDom.Compiler.ICodeParser CreateParser()\r
131                 }\r
132 \r
133                 //TODO: [Test]\r
134                 public void     CreateObjRef()\r
135                 {\r
136                         //System.Runtime.Remoting.ObjRef CreateObjRef(System.Type requestedType)\r
137                 }\r
138 \r
139         }\r
140 }\r