// NAnt - A .NET build tool // Copyright (C) 2001-2002 Gerry Shaw // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // Clayton Harbour (claytonharbour@sporadicism.com) using System; using System.Collections; using System.Globalization; using System.IO; using NUnit.Framework; using NAnt.Core; using NAnt.Core.Tasks; using Tests.NAnt.Core; using Tests.NAnt.VSNet; namespace Tests.NAnt.VSNet.Tasks { /// /// Summary description for LanguageType. /// public enum LanguageType { cpp, cs, vb, vjs } /// /// Available configurations. /// public enum ConfigurationType { Release, Debug } /// /// Type of binary that was built. /// public enum OutputType { exe, dll } /// /// Test that c# projects are built successfully. /// [TestFixture] public abstract class SolutionTestBase : BuildTestBase { private readonly string _checkoutXML = @" "; private DirectoryInfo _currentBaseDir; private DirectoryInfo CurrentBaseDir { get { if (null == this._currentBaseDir) { string examplesDir = this.GetExampleBaseDir().FullName; string currentLanguage = this.CurrentLanguage.ToString(); string fullPath = Path.Combine(examplesDir, currentLanguage); this._currentBaseDir = new DirectoryInfo(fullPath); } return this._currentBaseDir; } } /// /// Get a string that represents the NAnt build file used to build a solution. /// protected string SolutionProject = @" "; /// /// Simple nant build file, builds all solutions by kicking off a default.build file /// located in each language sub-folder. /// protected string SimpleBuild = @" "; /// /// Constructor. /// public SolutionTestBase () { } /// /// The that the test is targetting. /// protected abstract LanguageType CurrentLanguage {get;} /// /// Constructs the path to the solution file using the following substitutions: /// ${examples.dir}/${CurrentLanguage}/${name}/${name}.sln /// /// /// protected FileInfo GetCurrentSolutionFile (string name) { string solutionDir = name; string solutionFile = name + ".sln"; string fullPath; fullPath = Path.Combine(CurrentBaseDir.FullName, solutionDir); fullPath = Path.Combine(fullPath, solutionFile); return new FileInfo(fullPath); } /// /// Execute any default setup. /// [SetUp] protected override void SetUp () { base.SetUp (); } /// /// Execute any default tear down. /// [TearDown] protected override void TearDown () { base.TearDown(); } #region Protected Instance Methods /// /// Checkout the project to a temporary path. /// /// Cvsroot used to checkout the project. /// Module to checkout. /// Place to put the files checkout out. /// Password, or String.Empty if no passord. /// The date tag to use when checking out the project (used to seperate /// a failing test from a failing build, and most times this is the current date /// unless a project has been failing consistently. protected void CheckoutFiles (string cvsroot, string module, string destination, string password, DateTime date) { object[] args = { module, cvsroot, destination, string.Empty, DateTime.Now}; string build = FormatBuildFile(_checkoutXML, args); RunBuild(build, Level.Info); } /// /// Get the solution example base directory. /// /// protected DirectoryInfo GetExampleBaseDir () { string path = Path.Combine(System.Environment.CurrentDirectory, ".."); path = Path.Combine(path, "examples"); path = Path.Combine(path, "Solution"); return new DirectoryInfo(path); } protected string FormatBuildFile(string baseFile, object[] args) { return string.Format(CultureInfo.InvariantCulture, baseFile, args); } /// /// Assert that the output directory and output file exist. If they do not exist then /// an assertion exception is thrown. /// /// /// /// protected void AssertOutputExists (ConfigurationType configType, OutputType outputType, string solutionName) { string baseDir = Path.Combine(this.CurrentBaseDir.FullName, solutionName); string binDir = Path.Combine(baseDir, "bin"); string outputDir = Path.Combine(binDir, configType.ToString()); string outputFile = Path.Combine(outputDir, String.Format("{0}.{1}", solutionName, outputType.ToString())); DirectoryInfo od = new DirectoryInfo(outputDir); FileInfo of = new FileInfo(outputFile); Assert.IsTrue(od.Exists, String.Format("Output directory does not exist: {0}.", od.FullName)); Assert.IsTrue(of.Exists, String.Format("Output file does not exist: {0}.", of.FullName)); } /// /// Run a plain build using the given solution file and output type. /// /// /// protected void RunTestPlain() { try { this.RunSimpleBuild("rebuild"); } finally { this.RunSimpleBuild("clean"); } } #endregion Protected Instance Methods #region "Private Instance Methods" private void RunSimpleBuild(string target) { // run Release build object[] args = {target, "{target::get-current-target()}", this.CurrentBaseDir.FullName}; string build = FormatBuildFile(this.SimpleBuild, args); RunBuild(build, Level.Info); } #endregion "Private Instance Methods" } }