~ubuntu-branches/ubuntu/oneiric/cecil/oneiric

« back to all changes in this revision

Viewing changes to Test/Mono.Cecil.Tests/BaseTestFixture.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane, Iain Lane, Jo Shields
  • Date: 2011-08-07 22:38:20 UTC
  • mfrom: (1.1.7 upstream) (6.1.6 experimental)
  • Revision ID: james.westby@ubuntu.com-20110807223820-nfdm4q0pk2smjm11
Tags: 0.9.5+dfsg-1
[ Iain Lane ]
* [411dc78] Update to use my d.o email address
* [74bedaf] Disable clilibs; this is an unstable library
  apps grow unnecessary depends otherwise
* [5288c1f] Mangle debian version in watch file to take care of repacking.
  Also update watch file to look at new github location for tarballs
* [8f7110f] Relax version restriction on cli-common-dev; anything from 0.8
  will do

[ Jo Shields ]
* [e846eb8] Imported Upstream version 0.9.5+dfsg
* [3017d96] Bump build dependencies, as we're building for Mono 2.10 now.
* [27c2cff] Set to DebSrc 3.0, so we can apply patches via Quilt.
* [d0447b3] Update build to use XBuild, not manual compiler invocation.
* [08d2b92] Patch to avoid building tests (which rely on NUnit 2.4)
* [fa5a033] Update install file to include all new assemblies and locations.
* [43bd1e2] Since upstream no longer ships a pcfile, add our own.
* [942ead4] Don't try to ship a Changelog when none exists.
* [ba8232d] Erase obj/ folders in clean rule.
* [090af34] Exclude modulerefs on Windowsy libraries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.IO;
 
3
using System.Reflection;
 
4
 
 
5
using NUnit.Framework;
 
6
 
 
7
using Mono.Cecil.PE;
 
8
 
 
9
namespace Mono.Cecil.Tests {
 
10
 
 
11
        public abstract class BaseTestFixture {
 
12
 
 
13
                public static string GetResourcePath (string name, Assembly assembly)
 
14
                {
 
15
                        return Path.Combine (FindResourcesDirectory (assembly), name);
 
16
                }
 
17
 
 
18
                public static string GetAssemblyResourcePath (string name, Assembly assembly)
 
19
                {
 
20
                        return GetResourcePath (Path.Combine ("assemblies", name), assembly);
 
21
                }
 
22
 
 
23
                public static string GetCSharpResourcePath (string name, Assembly assembly)
 
24
                {
 
25
                        return GetResourcePath (Path.Combine ("cs", name), assembly);
 
26
                }
 
27
 
 
28
                public static string GetILResourcePath (string name, Assembly assembly)
 
29
                {
 
30
                        return GetResourcePath (Path.Combine ("il", name), assembly);
 
31
                }
 
32
 
 
33
                public static ModuleDefinition GetResourceModule (string name)
 
34
                {
 
35
                        return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly));
 
36
                }
 
37
 
 
38
                public static ModuleDefinition GetResourceModule (string name, ReaderParameters parameters)
 
39
                {
 
40
                        return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly), parameters);
 
41
                }
 
42
 
 
43
                public static ModuleDefinition GetResourceModule (string name, ReadingMode mode)
 
44
                {
 
45
                        return ModuleDefinition.ReadModule (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly), new ReaderParameters (mode));
 
46
                }
 
47
 
 
48
                internal static Image GetResourceImage (string name)
 
49
                {
 
50
                        using (var fs = new FileStream (GetAssemblyResourcePath (name, typeof (BaseTestFixture).Assembly), FileMode.Open, FileAccess.Read))
 
51
                                return ImageReader.ReadImageFrom (fs);
 
52
                }
 
53
 
 
54
                public static ModuleDefinition GetCurrentModule ()
 
55
                {
 
56
                        return ModuleDefinition.ReadModule (typeof (BaseTestFixture).Module.FullyQualifiedName);
 
57
                }
 
58
 
 
59
                public static ModuleDefinition GetCurrentModule (ReaderParameters parameters)
 
60
                {
 
61
                        return ModuleDefinition.ReadModule (typeof (BaseTestFixture).Module.FullyQualifiedName, parameters);
 
62
                }
 
63
 
 
64
                public static string FindResourcesDirectory (Assembly assembly)
 
65
                {
 
66
                        var path = Path.GetDirectoryName (new Uri (assembly.CodeBase).LocalPath);
 
67
                        while (!Directory.Exists (Path.Combine (path, "Resources"))) {
 
68
                                var old = path;
 
69
                                path = Path.GetDirectoryName (path);
 
70
                                Assert.AreNotEqual (old, path);
 
71
                        }
 
72
 
 
73
                        return Path.Combine (path, "Resources");
 
74
                }
 
75
        }
 
76
}