testing commit notification
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy.Tests / BasePEVerifyTestCase.cs
blob110aae999c4cad4080a625b9b864de9945f8a07b
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.DynamicProxy.Tests
17 using System;
18 using System.Configuration;
19 using System.Diagnostics;
20 using System.IO;
21 using NUnit.Framework;
23 public abstract class BasePEVerifyTestCase
25 protected ProxyGenerator generator;
26 protected PersistentProxyBuilder builder;
28 private bool verificationDisabled;
30 [SetUp]
31 public virtual void Init()
33 ResetGeneratorAndBuilder();
34 verificationDisabled = false;
37 public void ResetGeneratorAndBuilder ()
39 builder = new PersistentProxyBuilder();
40 generator = new ProxyGenerator(builder);
43 public void DisableVerification ()
45 verificationDisabled = true;
48 public bool IsVerificationDisabled
50 get { return verificationDisabled; }
53 #if !MONO // mono doesn't have PEVerify
55 [TearDown]
56 public virtual void TearDown ()
58 if (!IsVerificationDisabled)
60 // Note: only supports one generated assembly at the moment
61 string path = builder.SaveAssembly();
62 if (path != null)
63 RunPEVerifyOnGeneratedAssembly (path);
67 public void RunPEVerifyOnGeneratedAssembly(string assemblyPath)
69 Process process = new Process();
71 string path = Path.Combine(ConfigurationManager.AppSettings["sdkDir"], "peverify.exe");
73 if (!File.Exists(path))
75 path = Path.Combine(ConfigurationManager.AppSettings["x86SdkDir"], "peverify.exe");
78 if (!File.Exists(path))
80 throw new FileNotFoundException(
81 "Please check the sdkDir configuration setting and set it to the location of peverify.exe");
84 process.StartInfo.FileName = path;
85 process.StartInfo.RedirectStandardOutput = true;
86 process.StartInfo.UseShellExecute = false;
87 process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
88 process.StartInfo.Arguments = "\"" + assemblyPath + "\" /VERBOSE";
89 process.StartInfo.CreateNoWindow = true;
90 process.Start ();
91 string processOutput = process.StandardOutput.ReadToEnd();
92 process.WaitForExit();
94 string result = process.ExitCode + " code ";
96 Console.WriteLine(GetType().FullName + ": " + result);
98 if (process.ExitCode != 0)
100 Console.WriteLine(processOutput);
101 Assert.Fail("PeVerify reported error(s): " + Environment.NewLine + processOutput, result);
105 #else
107 [TearDown]
108 public virtual void TearDown ()
112 #endif