1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
//
// AppDomainSetupTest.cs - NUnit Test Cases for the System.AppDomainSetup class
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Ximian, Inc. http://www.ximian.com
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.IO;
namespace MonoTests.System
{
[TestFixture]
public class AppDomainSetupTest {
static readonly string tmpPath = Path.GetTempPath ();
static readonly string curDir = Directory.GetCurrentDirectory ();
private bool RunningOnWindows {
get {
int os = (int)Environment.OSVersion.Platform;
#if NET_2_0
return (os != 4);
#else
return (os != 128);
#endif
}
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ConfigurationFile_Relative_ApplicationBase ()
{
string fileName = "blar.config";
AppDomainSetup setup = new AppDomainSetup();
string dir = "app_base";
setup.ApplicationBase = dir;
setup.ConfigurationFile = fileName;
string baseDir = Path.GetFullPath(dir);
string configFile = Path.Combine(baseDir, fileName);
Assert.AreEqual(configFile, setup.ConfigurationFile, "Check relative to ApplicationBase");
}
[Test]
public void ConfigurationFile_Null ()
{
AppDomainSetup setup = new AppDomainSetup();
Assert.IsNull(setup.ConfigurationFile);
}
[Test]
[ExpectedException (typeof (MemberAccessException))] // The ApplicationBase must be set before retrieving this property
[Category ("TargetJvmNotWorking")]
public void ConfigurationFile_Relative_NoApplicationBase ()
{
AppDomainSetup setup = new AppDomainSetup();
setup.ConfigurationFile = "blar.config";
string configFile = setup.ConfigurationFile;
if (configFile == null) {
// avoid compiler warning
}
}
[Test]
public void ConfigurationFile_Absolute_NoApplicationBase ()
{
AppDomainSetup setup = new AppDomainSetup();
string configFile = Path.GetFullPath("blar.config");
setup.ConfigurationFile = configFile;
Assert.AreEqual(configFile, setup.ConfigurationFile);
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase1 ()
{
string expected_path = tmpPath.Replace(@"\", @"/");
AppDomainSetup setup = new AppDomainSetup ();
string fileUri = "file://" + expected_path;
setup.ApplicationBase = fileUri;
// with MS 1.1 SP1 the expected_path starts with "//" but this make
// sense only under Windows (i.e. reversed \\ for local files)
if (RunningOnWindows)
expected_path = "//" + expected_path;
#if NET_2_0
try {
// under 2.0 the NotSupportedException is throw when getting
// (and not setting) the ApplicationBase property
Assert.AreEqual (expected_path, setup.ApplicationBase);
}
catch (NotSupportedException) {
// however the path is invalid only on Windows
if (!RunningOnWindows)
throw;
}
#else
Assert.AreEqual (expected_path, setup.ApplicationBase);
#endif
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase2 ()
{
AppDomainSetup setup = new AppDomainSetup ();
setup.ApplicationBase = curDir;
Assert.AreEqual (curDir, setup.ApplicationBase);
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase3 ()
{
AppDomainSetup setup = new AppDomainSetup ();
string expected = Path.Combine (Environment.CurrentDirectory, "lalala");
setup.ApplicationBase = "lalala";
Assert.AreEqual (expected, setup.ApplicationBase);
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase4 ()
{
AppDomainSetup setup = new AppDomainSetup ();
setup.ApplicationBase = "lala:la";
#if NET_2_0
try {
// under 2.0 the NotSupportedException is throw when getting
// (and not setting) the ApplicationBase property
Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
}
catch (NotSupportedException) {
// however the path is invalid only on Windows
// (same exceptions as Path.GetFullPath)
if (!RunningOnWindows)
throw;
}
#else
// under 1.x a "bad" path containing ":" will be returned "as-is"
// but the name is legal for linux so we return a full path
if (RunningOnWindows)
Assert.AreEqual ("lala:la", setup.ApplicationBase);
else
Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
#endif
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase5 ()
{
// This is failing because of (probably) a windows-ism, so don't worry
AppDomainSetup setup = new AppDomainSetup ();
setup.ApplicationBase = "file:///lala:la";
#if NET_2_0
try {
// under 2.0 the NotSupportedException is throw when getting
// (and not setting) the ApplicationBase property
Assert.AreEqual ("/lala:la", setup.ApplicationBase);
}
catch (NotSupportedException) {
// however the path is invalid only on Windows
// (same exceptions as Path.GetFullPath)
if (!RunningOnWindows)
throw;
}
#else
// under 1.x a "bad" path containing ":" will be returned "as-is"
// but the name is legal for linux so we return a full path
if (RunningOnWindows)
Assert.AreEqual ("lala:la", setup.ApplicationBase);
else
Assert.AreEqual ("/lala:la", setup.ApplicationBase);
#endif
}
[Test]
[Category ("TargetJvmNotWorking")]
public void ApplicationBase6 ()
{
AppDomainSetup setup = new AppDomainSetup ();
setup.ApplicationBase = "la?lala";
// paths containing "?" are *always* bad on Windows
// but are legal for linux so we return a full path
if (RunningOnWindows) {
try {
// ArgumentException is throw when getting
// (and not setting) the ApplicationBase property
Assert.Fail ("setup.ApplicationBase returned :" + setup.ApplicationBase);
}
catch (ArgumentException) {
}
catch (Exception e) {
Assert.Fail ("Unexpected exception: " + e.ToString ());
}
} else {
Assert.AreEqual (Path.GetFullPath ("la?lala"), setup.ApplicationBase);
}
}
#if NET_2_0
[Test]
public void AppDomainInitializer1 ()
{
AppDomainSetup s = new AppDomainSetup ();
s.AppDomainInitializer = AppDomainInitialized1;
s.AppDomainInitializerArguments = new string [] {"A", "B"};
AppDomain domain = AppDomain.CreateDomain ("MyDomain", null, s);
object data = domain.GetData ("Initialized");
Assert.IsNotNull (data);
Assert.IsTrue ((bool) data);
}
static void AppDomainInitialized1 (string [] args)
{
bool initialized = true;
initialized &= args [0] == "A";
initialized &= args [1] == "B";
initialized &= AppDomain.CurrentDomain.FriendlyName == "MyDomain";
AppDomain.CurrentDomain.SetData ("Initialized", initialized);
}
public void InstanceInitializer (string [] args)
{
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void AppDomainInitializerNonStaticMethod ()
{
AppDomainSetup s = new AppDomainSetup ();
s.AppDomainInitializer = InstanceInitializer;
AppDomain.CreateDomain ("MyDomain", null, s);
}
#endif
}
}
|