[Cleanup] Removed TARGET_JVM
[mono.git] / mcs / class / System.Configuration / Test / Util / TestUtil.cs
1 //
2 // TestUtil.cs
3 //
4 // Author:
5 //       Martin Baulig <martin.baulig@xamarin.com>
6 //
7 // Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26 using System;
27 using System.IO;
28 using System.Reflection;
29
30 namespace MonoTests.System.Configuration.Util {
31         
32         public static class TestUtil {
33
34                 public static void RunWithTempFile (Action<string> action)
35                 {
36                         var filename = Path.GetTempFileName ();
37                         
38                         try {
39                                 File.Delete (filename);
40                                 action (filename);
41                         } finally {
42                                 if (File.Exists (filename))
43                                         File.Delete (filename);
44                         }
45                 }
46
47                 // Action<T1,T2> doesn't exist in .NET 2.0
48                 public delegate void MyAction<T1,T2> (T1 t1, T2 t2);
49
50                 public static void RunWithTempFiles (MyAction<string,string> action)
51                 {
52                         var file1 = Path.GetTempFileName ();
53                         var file2 = Path.GetTempFileName ();
54                         
55                         try {
56                                 File.Delete (file1);
57                                 File.Delete (file2);
58                                 action (file1, file2);
59                         } finally {
60                                 if (File.Exists (file1))
61                                         File.Delete (file1);
62                                 if (File.Exists (file2))
63                                         File.Delete (file2);
64                         }
65                 }
66
67                 public static string DotNetVersion {
68                         get {
69 #if NET_4_5
70                                 return "net_4_5";
71 #elif NET_4_0
72                                 return "net_4_0";
73 #else
74                                 return "net_2_0";
75 #endif
76                         }
77                 }
78
79                 public static string ThisDllName {
80                         get {
81                                 var asm = Assembly.GetCallingAssembly ();
82                                 return Path.GetFileName (asm.Location);
83                         }
84                 }
85
86                 public static string ThisConfigFileName {
87                         get {
88                                 var asm = Assembly.GetCallingAssembly ();
89                                 var exe = Path.GetFileName (asm.Location);
90                                 return exe + ".config";
91                         }
92                 }
93         }
94 }
95