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 public void ApplicationBase1 ()
38 string expected_path = tmpPath.Replace(@"\", @"/");
39 AppDomainSetup setup = new AppDomainSetup ();
40 string fileUri = "file://" + expected_path;
41 setup.ApplicationBase = fileUri;
42 // with MS 1.1 SP1 the expected_path starts with "//" but this make
43 // sense only under Windows (i.e. reversed \\ for local files)
45 expected_path = "//" + expected_path;
48 // under 2.0 the NotSupportedException is throw when getting
49 // (and not setting) the ApplicationBase property
50 Assert.AreEqual (expected_path, setup.ApplicationBase);
52 catch (NotSupportedException) {
53 // however the path is invalid only on Windows
54 if (!RunningOnWindows)
58 Assert.AreEqual (expected_path, setup.ApplicationBase);
63 public void ApplicationBase2 ()
65 AppDomainSetup setup = new AppDomainSetup ();
66 setup.ApplicationBase = curDir;
67 Assert.AreEqual (curDir, setup.ApplicationBase);
71 public void ApplicationBase3 ()
73 AppDomainSetup setup = new AppDomainSetup ();
74 string expected = Path.Combine (Environment.CurrentDirectory, "lalala");
75 setup.ApplicationBase = "lalala";
76 Assert.AreEqual (expected, setup.ApplicationBase);
80 public void ApplicationBase4 ()
82 AppDomainSetup setup = new AppDomainSetup ();
83 setup.ApplicationBase = "lala:la";
86 // under 2.0 the NotSupportedException is throw when getting
87 // (and not setting) the ApplicationBase property
88 Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
90 catch (NotSupportedException) {
91 // however the path is invalid only on Windows
92 // (same exceptions as Path.GetFullPath)
93 if (!RunningOnWindows)
97 // under 1.x a "bad" path containing ":" will be returned "as-is"
98 // but the name is legal for linux so we return a full path
100 Assert.AreEqual ("lala:la", setup.ApplicationBase);
102 Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
107 public void ApplicationBase5 ()
109 // This is failing because of (probably) a windows-ism, so don't worry
110 AppDomainSetup setup = new AppDomainSetup ();
111 setup.ApplicationBase = "file:///lala:la";
114 // under 2.0 the NotSupportedException is throw when getting
115 // (and not setting) the ApplicationBase property
116 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
118 catch (NotSupportedException) {
119 // however the path is invalid only on Windows
120 // (same exceptions as Path.GetFullPath)
121 if (!RunningOnWindows)
125 // under 1.x a "bad" path containing ":" will be returned "as-is"
126 // but the name is legal for linux so we return a full path
127 if (RunningOnWindows)
128 Assert.AreEqual ("lala:la", setup.ApplicationBase);
130 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
135 public void ApplicationBase6 ()
137 AppDomainSetup setup = new AppDomainSetup ();
138 setup.ApplicationBase = "la?lala";
139 // paths containing "?" are *always* bad on Windows
140 // but are legal for linux so we return a full path
141 if (RunningOnWindows) {
143 // ArgumentException is throw when getting
144 // (and not setting) the ApplicationBase property
145 Assert.Fail ("setup.ApplicationBase returned :" + setup.ApplicationBase);
147 catch (ArgumentException) {
149 catch (Exception e) {
150 Assert.Fail ("Unexpected exception: " + e.ToString ());
153 Assert.AreEqual (Path.GetFullPath ("la?lala"), setup.ApplicationBase);