diff options
author | Antonius Riha <antoniusriha@gmail.com> | 2013-12-30 03:23:35 +0400 |
---|---|---|
committer | Antonius Riha <antoniusriha@gmail.com> | 2014-01-03 00:14:53 +0400 |
commit | bbd241298576279e117a0e294006bfc7be407432 (patch) | |
tree | 646be8e4ab4f1ad10784bf547e8e8418a3950afb /mcs/class/Mono.XBuild.Tasks | |
parent | 9ac4fc1b5226be7b5a59535a6201ea852d533b97 (diff) |
Setup PcFileCache stubs and ctor tests
Diffstat (limited to 'mcs/class/Mono.XBuild.Tasks')
-rw-r--r-- | mcs/class/Mono.XBuild.Tasks/Test/Mono.XBuild.Tasks/PcFileCacheTest.cs | 181 |
1 files changed, 180 insertions, 1 deletions
diff --git a/mcs/class/Mono.XBuild.Tasks/Test/Mono.XBuild.Tasks/PcFileCacheTest.cs b/mcs/class/Mono.XBuild.Tasks/Test/Mono.XBuild.Tasks/PcFileCacheTest.cs index 2c3b3ab1443..9ac9c64386f 100644 --- a/mcs/class/Mono.XBuild.Tasks/Test/Mono.XBuild.Tasks/PcFileCacheTest.cs +++ b/mcs/class/Mono.XBuild.Tasks/Test/Mono.XBuild.Tasks/PcFileCacheTest.cs @@ -23,12 +23,191 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; +using System.IO; +using Mono.PkgConfig; using NUnit.Framework; -namespace MonoTests.Microsoft.Build.Tasks +namespace MonoTests.Mono.PkgConfig { [TestFixture] public class PcFileCacheTest { + static readonly string cacheDir = "testcache"; + static readonly string pcCacheFileName = "pkgconfig-cache-2.xml"; + static readonly string pcCacheFilePath = Path.Combine (cacheDir, pcCacheFileName); + static readonly string pkgConfigDir = "testpkgconfig"; + + [SetUp] + public void Setup () + { + Directory.CreateDirectory (cacheDir); + Directory.CreateDirectory (pkgConfigDir); + } + + [TearDown] + public void Teardown () + { + if (Directory.Exists (cacheDir)) + Directory.Delete (cacheDir, true); + if (Directory.Exists (pkgConfigDir)) + Directory.Delete (pkgConfigDir, true); + } + + [Test] + public void CreatePcFileCache () + { + PcFileCacheStub.Create (cacheDir); + + // cache dir should exist + Assert.IsTrue (Directory.Exists (cacheDir), "A1"); + + // cache file should not exist + Assert.IsFalse (File.Exists (pcCacheFilePath), "A2"); + } + + [Test] + public void CreatePcFileCacheWithExistingEmptyCacheFile () + { + // Create pc cache file + WritePcCacheFileContent (""); + PcFileCache cache = PcFileCacheStub.Create (cacheDir); + + // cache should be empty + string[] pkgConfigDirs = { pkgConfigDir }; + CollectionAssert.IsEmpty (cache.GetPackages (pkgConfigDirs), "A1"); + } + + [Test] + public void CreatePcFileCacheWithCacheFileContaining1EntryForAnExistingPcFile () + { + // Create pc cache file with an entry and corresponding pc file + string pkgConfigFileName = "gtk-sharp-2.0.pc"; + string pkgConfigFullFilePath = Path.GetFullPath (Path.Combine (pkgConfigDir, pkgConfigFileName)); + string pcCacheFileContent = @"<PcFileCache> + <File path=""" + pkgConfigFullFilePath + @""" lastWriteTime=""2013-11-23T21:18:31+01:00"" /> +</PcFileCache> +"; + + string pkgConfigFileContent = @"prefix=${pcfiledir}/../.. +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +gapidir=${prefix}/share/gapi-2.0 + + +Name: Gtk# +Description: Gtk# - GNOME .NET Binding +Version: 2.12.10 +Cflags: -I:${gapidir}/pango-api.xml -I:${gapidir}/atk-api.xml -I:${gapidir}/gdk-api.xml -I:${gapidir}/gtk-api.xml +Libs: -r:${libdir}/cli/pango-sharp-2.0/pango-sharp.dll -r:${libdir}/cli/atk-sharp-2.0/atk-sharp.dll -r:${libdir}/cli/gdk-sharp-2.0/gdk-sharp.dll -r:${libdir}/cli/gtk-sharp-2.0/gtk-sharp.dll +Requires: glib-sharp-2.0 +"; + + AddPkgConfigFile (pkgConfigFileName, pkgConfigFileContent); + WritePcCacheFileContent (pcCacheFileContent); + + PcFileCache cache = PcFileCacheStub.Create (cacheDir); + + // cache should contain entry of pc file + Assert.IsNotNull (cache.GetPackageInfo (pkgConfigFullFilePath), "A1"); + } + + [Test] + public void CreatePcFileCacheWithCacheFileContainingOneOrphanedEntry () + { + string pkgConfigFileName = "gtk-sharp-2.0.pc"; + string pkgConfigFullFilePath = Path.GetFullPath (Path.Combine (pkgConfigDir, pkgConfigFileName)); + string pcCacheFileContent = @"<PcFileCache> + <File path=""" + pkgConfigFullFilePath + @""" lastWriteTime=""2013-11-23T21:18:31+01:00"" /> +</PcFileCache> +"; + WritePcCacheFileContent (pcCacheFileContent); + + PcFileCache cache = PcFileCacheStub.Create (cacheDir); + + // cache should contain orphaned entry + Assert.IsNotNull (cache.GetPackageInfo (pkgConfigFullFilePath), "A1"); + } + + [Test] + public void CreatePcFileCacheWithoutCacheFileButWithPcFile () + { + string pkgConfigFileName = "gtk-sharp-2.0.pc"; + string pkgConfigFileContent = @"prefix=${pcfiledir}/../.. +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +gapidir=${prefix}/share/gapi-2.0 + + +Name: Gtk# +Description: Gtk# - GNOME .NET Binding +Version: 2.12.10 +Cflags: -I:${gapidir}/pango-api.xml -I:${gapidir}/atk-api.xml -I:${gapidir}/gdk-api.xml -I:${gapidir}/gtk-api.xml +Libs: -r:${libdir}/cli/pango-sharp-2.0/pango-sharp.dll -r:${libdir}/cli/atk-sharp-2.0/atk-sharp.dll -r:${libdir}/cli/gdk-sharp-2.0/gdk-sharp.dll -r:${libdir}/cli/gtk-sharp-2.0/gtk-sharp.dll +Requires: glib-sharp-2.0 +"; + AddPkgConfigFile (pkgConfigFileName, pkgConfigFileContent); + + PcFileCache cache = PcFileCacheStub.Create (cacheDir); + + // cache file should exist + Assert.IsFalse (File.Exists (pcCacheFilePath), "A1"); + + // cache should be empty + string[] pkgConfigDirs = { pkgConfigDir }; + CollectionAssert.IsEmpty (cache.GetPackages (pkgConfigDirs), "A2"); + } + + static void WritePcCacheFileContent (string content) + { + File.WriteAllText (pcCacheFilePath, content); + } + + static void AddPkgConfigFile (string fileName, string content) + { + string path = Path.Combine (pkgConfigDir, fileName); + File.WriteAllText (path, content); + } + + class PcFileCacheContextStub : IPcFileCacheContext + { + public void StoreCustomData (PcFile pcfile, PackageInfo pkg) + { + } + + public bool IsCustomDataComplete (string pcfile, PackageInfo pkg) + { + return false; + } + + public void ReportError (string message, Exception ex) + { + } + } + + class PcFileCacheStub : PcFileCache + { + static string initCacheDirectory; + readonly string cacheDirectory; + + PcFileCacheStub (string cacheDirectory) : base (new PcFileCacheContextStub ()) + { + if (cacheDirectory == null) + throw new ArgumentNullException ("cacheDirectory"); + this.cacheDirectory = cacheDirectory; + } + + protected override string CacheDirectory { + get { return initCacheDirectory == null ? cacheDirectory : initCacheDirectory; } + } + + public static PcFileCache Create (string cacheDirectory) + { + initCacheDirectory = cacheDirectory; + PcFileCache cache = new PcFileCacheStub (cacheDirectory); + initCacheDirectory = null; + return cache; + } + } } } |