2006-03-16 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / corlib / Test / System / AppDomainSetupTest.cs
1 //
2 // AppDomainSetupTest.cs - NUnit Test Cases for the System.AppDomainSetup class
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // (C) 2003 Ximian, Inc.  http://www.ximian.com
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // 
11
12 using NUnit.Framework;
13 using System;
14 using System.IO;
15
16 namespace MonoTests.System
17 {
18         [TestFixture]
19         public class AppDomainSetupTest {
20
21                 static readonly string tmpPath = Path.GetTempPath ();
22                 static readonly string curDir = Directory.GetCurrentDirectory ();
23
24                 private bool RunningOnWindows {
25                         get {
26                                 int os = (int)Environment.OSVersion.Platform;
27 #if NET_2_0
28                                 return (os != 4);
29 #else
30                                 return (os != 128);
31 #endif
32                         }
33                 }
34
35                 [Test]
36                 public void ApplicationBase1 ()
37                 {
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)
44                         if (RunningOnWindows)
45                                 expected_path = "//" + expected_path;
46 #if NET_2_0
47                         try {
48                                 // under 2.0 the NotSupportedException is throw when getting 
49                                 // (and not setting) the ApplicationBase property
50                                 Assert.AreEqual (expected_path, setup.ApplicationBase);
51                         }
52                         catch (NotSupportedException) {
53                                 // however the path is invalid only on Windows
54                                 if (!RunningOnWindows)
55                                         throw;
56                         }
57 #else
58                         Assert.AreEqual (expected_path, setup.ApplicationBase);
59 #endif
60                 }
61
62                 [Test]
63                 public void ApplicationBase2 ()
64                 {
65                         AppDomainSetup setup = new AppDomainSetup ();
66                         setup.ApplicationBase = curDir;
67                         Assert.AreEqual (curDir, setup.ApplicationBase);
68                 }
69
70                 [Test]
71                 public void ApplicationBase3 ()
72                 {
73                         AppDomainSetup setup = new AppDomainSetup ();
74                         string expected = Path.Combine (Environment.CurrentDirectory, "lalala");
75                         setup.ApplicationBase = "lalala";
76                         Assert.AreEqual (expected, setup.ApplicationBase);
77                 }
78
79                 [Test]
80                 public void ApplicationBase4 ()
81                 {
82                         AppDomainSetup setup = new AppDomainSetup ();
83                         setup.ApplicationBase = "lala:la";
84 #if NET_2_0
85                         try {
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);
89                         }
90                         catch (NotSupportedException) {
91                                 // however the path is invalid only on Windows
92                                 // (same exceptions as Path.GetFullPath)
93                                 if (!RunningOnWindows)
94                                         throw;
95                         }
96 #else
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
99                         if (RunningOnWindows)
100                                 Assert.AreEqual ("lala:la", setup.ApplicationBase);
101                         else
102                                 Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
103 #endif
104                 }
105
106                 [Test]
107                 public void ApplicationBase5 ()
108                 {
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";
112 #if NET_2_0
113                         try {
114                                 // under 2.0 the NotSupportedException is throw when getting 
115                                 // (and not setting) the ApplicationBase property
116                                 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
117                         }
118                         catch (NotSupportedException) {
119                                 // however the path is invalid only on Windows
120                                 // (same exceptions as Path.GetFullPath)
121                                 if (!RunningOnWindows)
122                                         throw;
123                         }
124 #else
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);
129                         else
130                                 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
131 #endif
132                 }
133
134                 [Test]
135                 public void ApplicationBase6 ()
136                 {
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) {
142                                 try {
143                                         // ArgumentException is throw when getting 
144                                         // (and not setting) the ApplicationBase property
145                                         Assert.Fail ("setup.ApplicationBase returned :" + setup.ApplicationBase);
146                                 }
147                                 catch (ArgumentException) {
148                                 }
149                                 catch (Exception e) {
150                                         Assert.Fail ("Unexpected exception: " + e.ToString ());
151                                 }
152                         } else {
153                                 Assert.AreEqual (Path.GetFullPath ("la?lala"), setup.ApplicationBase);
154                         }
155                 }
156         }
157 }