remove TARGET_JVM
[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 ConfigurationFile_Relative_ApplicationBase ()
37                 {
38                         string fileName = "blar.config";
39                         AppDomainSetup setup = new AppDomainSetup();
40                         string dir = "app_base";
41                         setup.ApplicationBase = dir;
42                         setup.ConfigurationFile = fileName;
43                         string baseDir = Path.GetFullPath(dir);
44                         string configFile = Path.Combine(baseDir, fileName);
45                         Assert.AreEqual(configFile, setup.ConfigurationFile, "Check relative to ApplicationBase");
46                 }
47
48                 [Test]
49                 public void ConfigurationFile_Null ()
50                 {
51                         AppDomainSetup setup = new AppDomainSetup();
52                         Assert.IsNull(setup.ConfigurationFile);
53                 }
54
55                 [Test]
56                 [ExpectedException (typeof (MemberAccessException))] // The ApplicationBase must be set before retrieving this property
57                 public void ConfigurationFile_Relative_NoApplicationBase ()
58                 {
59                         AppDomainSetup setup = new AppDomainSetup();
60                         setup.ConfigurationFile = "blar.config";
61                         string configFile = setup.ConfigurationFile;
62                         if (configFile == null) {
63                                 // avoid compiler warning
64                         }
65                 }
66
67                 [Test]
68                 public void ConfigurationFile_Absolute_NoApplicationBase ()
69                 {
70                         AppDomainSetup setup = new AppDomainSetup();
71                         string configFile = Path.GetFullPath("blar.config");
72                         setup.ConfigurationFile = configFile;
73                         Assert.AreEqual(configFile, setup.ConfigurationFile);
74                 }
75
76                 [Test]
77                 public void ApplicationBase1 ()
78                 {
79                         string expected_path = tmpPath.Replace(@"\", @"/");
80                         AppDomainSetup setup = new AppDomainSetup ();
81                         string fileUri = "file://" + expected_path;
82                         setup.ApplicationBase = fileUri;
83                         // with MS 1.1 SP1 the expected_path starts with "//" but this make
84                         // sense only under Windows (i.e. reversed \\ for local files)
85                         if (RunningOnWindows)
86                                 expected_path = "//" + expected_path;
87 #if NET_2_0
88                         try {
89                                 // under 2.0 the NotSupportedException is throw when getting 
90                                 // (and not setting) the ApplicationBase property
91                                 Assert.AreEqual (expected_path, setup.ApplicationBase);
92                         }
93                         catch (NotSupportedException) {
94                                 // however the path is invalid only on Windows
95                                 if (!RunningOnWindows)
96                                         throw;
97                         }
98 #else
99                         Assert.AreEqual (expected_path, setup.ApplicationBase);
100 #endif
101                 }
102
103                 [Test]
104                 public void ApplicationBase2 ()
105                 {
106                         AppDomainSetup setup = new AppDomainSetup ();
107                         setup.ApplicationBase = curDir;
108                         Assert.AreEqual (curDir, setup.ApplicationBase);
109                 }
110
111                 [Test]
112                 public void ApplicationBase3 ()
113                 {
114                         AppDomainSetup setup = new AppDomainSetup ();
115                         string expected = Path.Combine (Environment.CurrentDirectory, "lalala");
116                         setup.ApplicationBase = "lalala";
117                         Assert.AreEqual (expected, setup.ApplicationBase);
118                 }
119
120                 [Test]
121                 public void ApplicationBase4 ()
122                 {
123                         AppDomainSetup setup = new AppDomainSetup ();
124                         setup.ApplicationBase = "lala:la";
125 #if NET_2_0
126                         try {
127                                 // under 2.0 the NotSupportedException is throw when getting 
128                                 // (and not setting) the ApplicationBase property
129                                 Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
130                         }
131                         catch (NotSupportedException) {
132                                 // however the path is invalid only on Windows
133                                 // (same exceptions as Path.GetFullPath)
134                                 if (!RunningOnWindows)
135                                         throw;
136                         }
137 #else
138                         // under 1.x a "bad" path containing ":" will be returned "as-is"
139                         // but the name is legal for linux so we return a full path
140                         if (RunningOnWindows)
141                                 Assert.AreEqual ("lala:la", setup.ApplicationBase);
142                         else
143                                 Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
144 #endif
145                 }
146
147                 [Test]
148                 public void ApplicationBase5 ()
149                 {
150                         // This is failing because of (probably) a windows-ism, so don't worry
151                         AppDomainSetup setup = new AppDomainSetup ();
152                         setup.ApplicationBase = "file:///lala:la";
153 #if NET_2_0
154                         try {
155                                 // under 2.0 the NotSupportedException is throw when getting 
156                                 // (and not setting) the ApplicationBase property
157                                 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
158                         }
159                         catch (NotSupportedException) {
160                                 // however the path is invalid only on Windows
161                                 // (same exceptions as Path.GetFullPath)
162                                 if (!RunningOnWindows)
163                                         throw;
164                         }
165 #else
166                         // under 1.x a "bad" path containing ":" will be returned "as-is"
167                         // but the name is legal for linux so we return a full path
168                         if (RunningOnWindows)
169                                 Assert.AreEqual ("lala:la", setup.ApplicationBase);
170                         else
171                                 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
172 #endif
173                 }
174
175                 [Test]
176                 public void ApplicationBase6 ()
177                 {
178                         AppDomainSetup setup = new AppDomainSetup ();
179                         setup.ApplicationBase = "la?lala";
180                         // paths containing "?" are *always* bad on Windows
181                         // but are legal for linux so we return a full path
182                         if (RunningOnWindows) {
183                                 try {
184                                         // ArgumentException is throw when getting 
185                                         // (and not setting) the ApplicationBase property
186                                         Assert.Fail ("setup.ApplicationBase returned :" + setup.ApplicationBase);
187                                 }
188                                 catch (ArgumentException) {
189                                 }
190                                 catch (Exception e) {
191                                         Assert.Fail ("Unexpected exception: " + e.ToString ());
192                                 }
193                         } else {
194                                 Assert.AreEqual (Path.GetFullPath ("la?lala"), setup.ApplicationBase);
195                         }
196                 }
197         }
198 }