From 1a17abff275c7916a0c963e45446ed7b10980eb7 Mon Sep 17 00:00:00 2001 From: dotneteer Date: Thu, 14 Apr 2011 23:27:40 -0700 Subject: [PATCH] Added unmanaged VBScrip Test. --HG-- rename : aspclassiccompiler/VBScriptTest/TestRunner.cs => aspclassiccompiler/VBScriptTest/VBscriptDotNetTest.cs --- aspclassiccompiler/AspWebApp/AspWebApp.csproj | 16 ++++++ .../NerdDinnerAsp/NerdDinnerAsp.csproj | 16 ++++++ aspclassiccompiler/Parser/Parser.vbproj | 21 ++++++++ .../VBScript/Runtime/IAssert.cs | 6 +-- aspclassiccompiler/VBScript/VBScript.csproj | 16 ++++++ .../VBScriptTest/DirectoryWalker.cs | 53 +++++++++++++++++++ .../VBScriptTest/NunitAssert.cs | 27 +--------- .../VBScriptTest/UnmanagedVBScriptTest.cs | 34 ++++++++++++ .../VBScriptTest/UnmangedVBScriptHost.cs | 38 +++++++++++++ .../VBScriptTest/VBScriptTest.csproj | 15 +++++- .../VBScriptTest/VBScriptTestHelper.cs | 45 ---------------- .../VBScriptTest/VBScripts/DataTypes.vbs | 2 +- .../{TestRunner.cs => VBscriptDotNetTest.cs} | 17 ++++-- aspclassiccompiler/asp/Asp.csproj | 16 ++++++ 14 files changed, 240 insertions(+), 82 deletions(-) create mode 100644 aspclassiccompiler/VBScriptTest/DirectoryWalker.cs create mode 100644 aspclassiccompiler/VBScriptTest/UnmanagedVBScriptTest.cs create mode 100644 aspclassiccompiler/VBScriptTest/UnmangedVBScriptHost.cs rename aspclassiccompiler/VBScriptTest/{TestRunner.cs => VBscriptDotNetTest.cs} (77%) diff --git a/aspclassiccompiler/AspWebApp/AspWebApp.csproj b/aspclassiccompiler/AspWebApp/AspWebApp.csproj index 8c9e002..1254e82 100644 --- a/aspclassiccompiler/AspWebApp/AspWebApp.csproj +++ b/aspclassiccompiler/AspWebApp/AspWebApp.csproj @@ -29,6 +29,22 @@ prompt 4 + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + False diff --git a/aspclassiccompiler/NerdDinnerAsp/NerdDinnerAsp.csproj b/aspclassiccompiler/NerdDinnerAsp/NerdDinnerAsp.csproj index b0c38f1..a1e029c 100644 --- a/aspclassiccompiler/NerdDinnerAsp/NerdDinnerAsp.csproj +++ b/aspclassiccompiler/NerdDinnerAsp/NerdDinnerAsp.csproj @@ -30,6 +30,22 @@ prompt 4 + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + False diff --git a/aspclassiccompiler/Parser/Parser.vbproj b/aspclassiccompiler/Parser/Parser.vbproj index 65c5c4e..9dc3e09 100644 --- a/aspclassiccompiler/Parser/Parser.vbproj +++ b/aspclassiccompiler/Parser/Parser.vbproj @@ -84,6 +84,27 @@ 1 42016,42017,42018,42019,42032 + + true + true + true + bin\x86\Debug\ + 285212672 + Dlrsoft.VBParser.xml + 1 + 42016,42017,42018,42019,42032 + x86 + + + true + bin\x86\Release\ + 285212672 + Dlrsoft.VBParser.xml + true + 1 + 42016,42017,42018,42019,42032 + x86 + System diff --git a/aspclassiccompiler/VBScript/Runtime/IAssert.cs b/aspclassiccompiler/VBScript/Runtime/IAssert.cs index 8976849..ad7063a 100644 --- a/aspclassiccompiler/VBScript/Runtime/IAssert.cs +++ b/aspclassiccompiler/VBScript/Runtime/IAssert.cs @@ -1,20 +1,16 @@ using System; using System.Collections.Generic; using System.Text; +using System.Runtime.InteropServices; namespace Dlrsoft.VBScript.Runtime { public interface IAssert { - void AreEqual(object expected, object actual); void AreEqual(object expected, object actual, string message); - void AreNotEqual(object notExpected, object actual); void AreNotEqual(object notExpected, object actual, string message); - void Fail(); void Fail(string message); - void IsFalse(bool condition); void IsFalse(bool condition, string message); - void IsTrue(bool condition); void IsTrue(bool condition, string message); } } diff --git a/aspclassiccompiler/VBScript/VBScript.csproj b/aspclassiccompiler/VBScript/VBScript.csproj index f388d58..0f4673b 100644 --- a/aspclassiccompiler/VBScript/VBScript.csproj +++ b/aspclassiccompiler/VBScript/VBScript.csproj @@ -32,6 +32,22 @@ prompt 4 + + true + bin\x86\Debug\ + TRACE;DEBUG;USE35 + full + x86 + prompt + + + bin\x86\Release\ + TRACE;USE35 + true + pdbonly + x86 + prompt + False diff --git a/aspclassiccompiler/VBScriptTest/DirectoryWalker.cs b/aspclassiccompiler/VBScriptTest/DirectoryWalker.cs new file mode 100644 index 0000000..1540e0e --- /dev/null +++ b/aspclassiccompiler/VBScriptTest/DirectoryWalker.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Reflection; + +namespace Dlrsoft.VBScriptTest +{ + public class DirectoryWalker + { + static public string AssemblyDirectory + { + get + { + string codeBase = Assembly.GetExecutingAssembly().CodeBase; + UriBuilder uri = new UriBuilder(codeBase); + string path = Uri.UnescapeDataString(uri.Path); + return Path.GetDirectoryName(path); + } + } + + static public void Walk(string path, Action fileHandler) + { + FileAttributes fa = File.GetAttributes(path); + if ((fa & FileAttributes.Directory) == FileAttributes.Directory) + { + Walk(new DirectoryInfo(path), fileHandler); + } + else + { + Walk(new FileInfo(path), fileHandler); + } + } + + static private void Walk(DirectoryInfo di, Action fileHandler) + { + foreach (FileInfo fi in di.GetFiles()) + { + Walk(fi, fileHandler); + } + + foreach (DirectoryInfo cdi in di.GetDirectories()) + { + Walk(cdi, fileHandler); + } + } + + static private void Walk(FileInfo fi, Action fileHandler) + { + fileHandler(fi.FullName); + } + } +} diff --git a/aspclassiccompiler/VBScriptTest/NunitAssert.cs b/aspclassiccompiler/VBScriptTest/NunitAssert.cs index f0b5187..f2cbb64 100644 --- a/aspclassiccompiler/VBScriptTest/NunitAssert.cs +++ b/aspclassiccompiler/VBScriptTest/NunitAssert.cs @@ -3,58 +3,35 @@ using System.Collections.Generic; using System.Text; using Dlrsoft.VBScript.Runtime; using NUnit.Framework; +using System.Runtime.InteropServices; namespace Dlrsoft.VBScriptTest { + [ComVisible(true)] public class NunitAssert : IAssert { #region IAssert Members - public void AreEqual(object expected, object actual) - { - Assert.AreEqual(expected, actual); - } - public void AreEqual(object expected, object actual, string message) { Assert.AreEqual(expected, actual, message); } - public void AreNotEqual(object notExpected, object actual) - { - Assert.AreNotEqual(notExpected, actual); - } - public void AreNotEqual(object notExpected, object actual, string message) { Assert.AreNotEqual(notExpected, actual, message); } - public void Fail() - { - Assert.Fail(); - } - public void Fail(string message) { Assert.Fail(message); } - public void IsFalse(bool condition) - { - Assert.IsFalse(condition); - } - public void IsFalse(bool condition, string message) { Assert.IsFalse(condition, message); } - public void IsTrue(bool condition) - { - Assert.IsTrue(condition); - } - public void IsTrue(bool condition, string message) { Assert.IsTrue(condition, message); diff --git a/aspclassiccompiler/VBScriptTest/UnmanagedVBScriptTest.cs b/aspclassiccompiler/VBScriptTest/UnmanagedVBScriptTest.cs new file mode 100644 index 0000000..d01133e --- /dev/null +++ b/aspclassiccompiler/VBScriptTest/UnmanagedVBScriptTest.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using System.IO; + +namespace Dlrsoft.VBScriptTest +{ + [TestFixture] + public class UnmanagedVBScriptTest + { + [Test] + public void RunTest() + { + DirectoryWalker.Walk( + Path.Combine(DirectoryWalker.AssemblyDirectory, "../../VBScripts"), + f => + { + if (f.EndsWith(".vbs", StringComparison.InvariantCultureIgnoreCase)) + { + try + { + UnmangedVBScriptHost.Run(f); + } + catch (Exception ex) + { + Assert.Fail(f + ":" + ex.Message); + } + } + } + ); + } + } +} diff --git a/aspclassiccompiler/VBScriptTest/UnmangedVBScriptHost.cs b/aspclassiccompiler/VBScriptTest/UnmangedVBScriptHost.cs new file mode 100644 index 0000000..473501e --- /dev/null +++ b/aspclassiccompiler/VBScriptTest/UnmangedVBScriptHost.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; +using MSScriptControl; +using System.IO; +using Dlrsoft.VBScript.Runtime; + +namespace Dlrsoft.VBScriptTest +{ + public class UnmangedVBScriptHost + { + public static void Run(string filePath) + { + ScriptControlClass scripter = new ScriptControlClass(); + + try { + scripter.Language = "VBScript"; + scripter.AllowUI = false; + scripter.UseSafeSubset = true; + IAssert assert = new NunitAssert(); + scripter.AddObject("Assert", assert, false); + + string code = File.ReadAllText(filePath); + scripter.AddCode(code); + } + catch(Exception ex) + { + throw; + } + finally + { + System.Runtime.InteropServices.Marshal.ReleaseComObject(scripter); + scripter = null; + } + + } + } +} diff --git a/aspclassiccompiler/VBScriptTest/VBScriptTest.csproj b/aspclassiccompiler/VBScriptTest/VBScriptTest.csproj index c8b2a72..fe1be3d 100644 --- a/aspclassiccompiler/VBScriptTest/VBScriptTest.csproj +++ b/aspclassiccompiler/VBScriptTest/VBScriptTest.csproj @@ -55,10 +55,13 @@ + + + - + @@ -69,6 +72,16 @@ + + + {0E59F1D2-1FBE-11D0-8FF2-00A0D10038BC} + 1 + 0 + 0 + tlbimp + False + +