Mark tests as not working under 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                 [Category ("TargetJvmNotWorking")]
37                 public void ConfigurationFile_Relative_ApplicationBase ()
38                 {
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");
47                 }
48
49                 [Test]
50                 public void ConfigurationFile_Null ()
51                 {
52                         AppDomainSetup setup = new AppDomainSetup();
53                         Assert.IsNull(setup.ConfigurationFile);
54                 }
55
56                 [Test]
57                 [ExpectedException (typeof (MemberAccessException))] // The ApplicationBase must be set before retrieving this property
58                 [Category ("TargetJvmNotWorking")]
59                 public void ConfigurationFile_Relative_NoApplicationBase ()
60                 {
61                         AppDomainSetup setup = new AppDomainSetup();
62                         setup.ConfigurationFile = "blar.config";
63                         string configFile = setup.ConfigurationFile;
64                         if (configFile == null) {
65                                 // avoid compiler warning
66                         }
67                 }
68
69                 [Test]
70                 public void ConfigurationFile_Absolute_NoApplicationBase ()
71                 {
72                         AppDomainSetup setup = new AppDomainSetup();
73                         string configFile = Path.GetFullPath("blar.config");
74                         setup.ConfigurationFile = configFile;
75                         Assert.AreEqual(configFile, setup.ConfigurationFile);
76                 }
77
78                 [Test]
79                 [Category ("TargetJvmNotWorking")]
80                 public void ApplicationBase1 ()
81                 {
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)
88                         if (RunningOnWindows)
89                                 expected_path = "//" + expected_path;
90 #if NET_2_0
91                         try {
92                                 // under 2.0 the NotSupportedException is throw when getting 
93                                 // (and not setting) the ApplicationBase property
94                                 Assert.AreEqual (expected_path, setup.ApplicationBase);
95                         }
96                         catch (NotSupportedException) {
97                                 // however the path is invalid only on Windows
98                                 if (!RunningOnWindows)
99                                         throw;
100                         }
101 #else
102                         Assert.AreEqual (expected_path, setup.ApplicationBase);
103 #endif
104                 }
105
106                 [Test]
107                 [Category ("TargetJvmNotWorking")]
108                 public void ApplicationBase2 ()
109                 {
110                         AppDomainSetup setup = new AppDomainSetup ();
111                         setup.ApplicationBase = curDir;
112                         Assert.AreEqual (curDir, setup.ApplicationBase);
113                 }
114
115                 [Test]
116                 [Category ("TargetJvmNotWorking")]
117                 public void ApplicationBase3 ()
118                 {
119                         AppDomainSetup setup = new AppDomainSetup ();
120                         string expected = Path.Combine (Environment.CurrentDirectory, "lalala");
121                         setup.ApplicationBase = "lalala";
122                         Assert.AreEqual (expected, setup.ApplicationBase);
123                 }
124
125                 [Test]
126                 [Category ("TargetJvmNotWorking")]
127                 public void ApplicationBase4 ()
128                 {
129                         AppDomainSetup setup = new AppDomainSetup ();
130                         setup.ApplicationBase = "lala:la";
131 #if NET_2_0
132                         try {
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);
136                         }
137                         catch (NotSupportedException) {
138                                 // however the path is invalid only on Windows
139                                 // (same exceptions as Path.GetFullPath)
140                                 if (!RunningOnWindows)
141                                         throw;
142                         }
143 #else
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);
148                         else
149                                 Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
150 #endif
151                 }
152
153                 [Test]
154                 [Category ("TargetJvmNotWorking")]
155                 public void ApplicationBase5 ()
156                 {
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";
160 #if NET_2_0
161                         try {
162                                 // under 2.0 the NotSupportedException is throw when getting 
163                                 // (and not setting) the ApplicationBase property
164                                 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
165                         }
166                         catch (NotSupportedException) {
167                                 // however the path is invalid only on Windows
168                                 // (same exceptions as Path.GetFullPath)
169                                 if (!RunningOnWindows)
170                                         throw;
171                         }
172 #else
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);
177                         else
178                                 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
179 #endif
180                 }
181
182                 [Test]
183                 [Category ("TargetJvmNotWorking")]
184                 public void ApplicationBase6 ()
185                 {
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) {
191                                 try {
192                                         // ArgumentException is throw when getting 
193                                         // (and not setting) the ApplicationBase property
194                                         Assert.Fail ("setup.ApplicationBase returned :" + setup.ApplicationBase);
195                                 }
196                                 catch (ArgumentException) {
197                                 }
198                                 catch (Exception e) {
199                                         Assert.Fail ("Unexpected exception: " + e.ToString ());
200                                 }
201                         } else {
202                                 Assert.AreEqual (Path.GetFullPath ("la?lala"), setup.ApplicationBase);
203                         }
204                 }
205         }
206 }