2 // AppDomainSetupTest.cs - NUnit Test Cases for the System.AppDomainSetup class
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // (C) 2003 Ximian, Inc. http://www.ximian.com
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
12 using NUnit.Framework;
16 namespace MonoTests.System
19 public class AppDomainSetupTest {
21 static readonly string tmpPath = Path.GetTempPath ();
22 static readonly string curDir = Directory.GetCurrentDirectory ();
24 private bool RunningOnWindows {
26 int os = (int)Environment.OSVersion.Platform;
36 [Category ("TargetJvmNotWorking")]
37 public void ConfigurationFile_Relative_ApplicationBase ()
39 string fileName = "blar.config";
40 AppDomainSetup setup = new AppDomainSetup();
41 string dir = "app_base";
42 setup.ApplicationBase = dir;
43 setup.ConfigurationFile = fileName;
44 string baseDir = Path.GetFullPath(dir);
45 string configFile = Path.Combine(baseDir, fileName);
46 Assert.AreEqual(configFile, setup.ConfigurationFile, "Check relative to ApplicationBase");
50 public void ConfigurationFile_Null ()
52 AppDomainSetup setup = new AppDomainSetup();
53 Assert.IsNull(setup.ConfigurationFile);
57 [ExpectedException (typeof (MemberAccessException))] // The ApplicationBase must be set before retrieving this property
58 [Category ("TargetJvmNotWorking")]
59 public void ConfigurationFile_Relative_NoApplicationBase ()
61 AppDomainSetup setup = new AppDomainSetup();
62 setup.ConfigurationFile = "blar.config";
63 string configFile = setup.ConfigurationFile;
64 if (configFile == null) {
65 // avoid compiler warning
70 public void ConfigurationFile_Absolute_NoApplicationBase ()
72 AppDomainSetup setup = new AppDomainSetup();
73 string configFile = Path.GetFullPath("blar.config");
74 setup.ConfigurationFile = configFile;
75 Assert.AreEqual(configFile, setup.ConfigurationFile);
79 [Category ("TargetJvmNotWorking")]
80 public void ApplicationBase1 ()
82 string expected_path = tmpPath.Replace(@"\", @"/");
83 AppDomainSetup setup = new AppDomainSetup ();
84 string fileUri = "file://" + expected_path;
85 setup.ApplicationBase = fileUri;
86 // with MS 1.1 SP1 the expected_path starts with "//" but this make
87 // sense only under Windows (i.e. reversed \\ for local files)
89 expected_path = "//" + expected_path;
92 // under 2.0 the NotSupportedException is throw when getting
93 // (and not setting) the ApplicationBase property
94 Assert.AreEqual (expected_path, setup.ApplicationBase);
96 catch (NotSupportedException) {
97 // however the path is invalid only on Windows
98 if (!RunningOnWindows)
102 Assert.AreEqual (expected_path, setup.ApplicationBase);
107 [Category ("TargetJvmNotWorking")]
108 public void ApplicationBase2 ()
110 AppDomainSetup setup = new AppDomainSetup ();
111 setup.ApplicationBase = curDir;
112 Assert.AreEqual (curDir, setup.ApplicationBase);
116 [Category ("TargetJvmNotWorking")]
117 public void ApplicationBase3 ()
119 AppDomainSetup setup = new AppDomainSetup ();
120 string expected = Path.Combine (Environment.CurrentDirectory, "lalala");
121 setup.ApplicationBase = "lalala";
122 Assert.AreEqual (expected, setup.ApplicationBase);
126 [Category ("TargetJvmNotWorking")]
127 public void ApplicationBase4 ()
129 AppDomainSetup setup = new AppDomainSetup ();
130 setup.ApplicationBase = "lala:la";
133 // under 2.0 the NotSupportedException is throw when getting
134 // (and not setting) the ApplicationBase property
135 Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
137 catch (NotSupportedException) {
138 // however the path is invalid only on Windows
139 // (same exceptions as Path.GetFullPath)
140 if (!RunningOnWindows)
144 // under 1.x a "bad" path containing ":" will be returned "as-is"
145 // but the name is legal for linux so we return a full path
146 if (RunningOnWindows)
147 Assert.AreEqual ("lala:la", setup.ApplicationBase);
149 Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
154 [Category ("TargetJvmNotWorking")]
155 public void ApplicationBase5 ()
157 // This is failing because of (probably) a windows-ism, so don't worry
158 AppDomainSetup setup = new AppDomainSetup ();
159 setup.ApplicationBase = "file:///lala:la";
162 // under 2.0 the NotSupportedException is throw when getting
163 // (and not setting) the ApplicationBase property
164 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
166 catch (NotSupportedException) {
167 // however the path is invalid only on Windows
168 // (same exceptions as Path.GetFullPath)
169 if (!RunningOnWindows)
173 // under 1.x a "bad" path containing ":" will be returned "as-is"
174 // but the name is legal for linux so we return a full path
175 if (RunningOnWindows)
176 Assert.AreEqual ("lala:la", setup.ApplicationBase);
178 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
183 [Category ("TargetJvmNotWorking")]
184 public void ApplicationBase6 ()
186 AppDomainSetup setup = new AppDomainSetup ();
187 setup.ApplicationBase = "la?lala";
188 // paths containing "?" are *always* bad on Windows
189 // but are legal for linux so we return a full path
190 if (RunningOnWindows) {
192 // ArgumentException is throw when getting
193 // (and not setting) the ApplicationBase property
194 Assert.Fail ("setup.ApplicationBase returned :" + setup.ApplicationBase);
196 catch (ArgumentException) {
198 catch (Exception e) {
199 Assert.Fail ("Unexpected exception: " + e.ToString ());
202 Assert.AreEqual (Path.GetFullPath ("la?lala"), setup.ApplicationBase);