summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2017-07-03 19:05:55 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-07-13 19:00:53 -0300
commit0c1a69cd2ad78bbc51233bc67b7d0b0238d1d9af (patch)
tree2d1f101fadc6aaea5d3d6c638b7e674596d1a9d4
parentda6c685b8cfb6b95d38ac87c17913c4b98ed4e45 (diff)
mono: Move test utilities into its own file.
Separate assertion utilities from test discovery and running.
-rw-r--r--src/Makefile_Efl_Mono.am4
-rw-r--r--src/tests/efl_mono/Main.cs51
-rw-r--r--src/tests/efl_mono/TestUtils.cs55
3 files changed, 58 insertions, 52 deletions
diff --git a/src/Makefile_Efl_Mono.am b/src/Makefile_Efl_Mono.am
index ba1b138aaa..14edee9649 100644
--- a/src/Makefile_Efl_Mono.am
+++ b/src/Makefile_Efl_Mono.am
@@ -195,7 +195,9 @@ tests_efl_mono_efl_mono_exe_SOURCES = \
195 tests/efl_mono/Evas.cs \ 195 tests/efl_mono/Evas.cs \
196 tests/efl_mono/Events.cs \ 196 tests/efl_mono/Events.cs \
197 tests/efl_mono/FunctionPointers.cs \ 197 tests/efl_mono/FunctionPointers.cs \
198 tests/efl_mono/Strings.cs 198 tests/efl_mono/Strings.cs \
199 tests/efl_mono/TestUtils.cs
200
199 201
200tests/efl_mono/efl_mono.exe$(EXEEXT): $(tests_efl_mono_efl_mono_exe_SOURCES) tests/efl_mono/$(am__dirstamp) lib/efl_mono/libefl_mono.dll tests/efl_mono/libefl_mono_test.dll 202tests/efl_mono/efl_mono.exe$(EXEEXT): $(tests_efl_mono_efl_mono_exe_SOURCES) tests/efl_mono/$(am__dirstamp) lib/efl_mono/libefl_mono.dll tests/efl_mono/libefl_mono_test.dll
201 @rm -f tests/efl_mono/efl_mono_exe$(EXEEXT) 203 @rm -f tests/efl_mono/efl_mono_exe$(EXEEXT)
diff --git a/src/tests/efl_mono/Main.cs b/src/tests/efl_mono/Main.cs
index 71ef39ecc1..a1ea83fecb 100644
--- a/src/tests/efl_mono/Main.cs
+++ b/src/tests/efl_mono/Main.cs
@@ -4,57 +4,6 @@ using System.Runtime.CompilerServices;
4using System.Reflection; 4using System.Reflection;
5using System.Linq; 5using System.Linq;
6 6
7public class Test
8{
9 public static void Assert(bool res, String msg = "Assertion failed",
10 [CallerLineNumber] int line = 0,
11 [CallerFilePath] string file = null,
12 [CallerMemberName] string member = null)
13 {
14 if (!res)
15 throw new Exception($"Assertion failed: {file}:{line} ({member}) {msg}");
16 }
17
18 public static void AssertEquals<T>(T expected, T actual, String msg = "",
19 [CallerLineNumber] int line = 0,
20 [CallerFilePath] string file = null,
21 [CallerMemberName] string member = null) where T : System.IComparable<T>
22 {
23 if (expected.CompareTo(actual) != 0) {
24 if (msg == "")
25 msg = $"Expected \"{expected}\", actual \"{actual}\"";
26 throw new Exception($"{file}:{line} ({member}) {msg}");
27 }
28 }
29
30 public delegate void Operation();
31
32 public static void AssertRaises<T>(Operation op, String msg = "Exception not raised",
33 [CallerLineNumber] int line = 0,
34 [CallerFilePath] string file = null,
35 [CallerMemberName] string member = null) where T: Exception
36 {
37 try {
38 op();
39 } catch (T) {
40 return;
41 }
42 throw new Exception($"Assertion failed: {file}:{line} ({member}) {msg}");
43 }
44
45 public static void AssertNotRaises<T>(Operation op, String msg = "Exception raised.",
46 [CallerLineNumber] int line = 0,
47 [CallerFilePath] string file = null,
48 [CallerMemberName] string member = null) where T: Exception
49 {
50 try {
51 op();
52 } catch (T) {
53 throw new Exception($"Assertion failed: {file}:{line} ({member}) {msg}");
54 }
55 }
56}
57
58class TestMain 7class TestMain
59{ 8{
60 static Type[] GetTestCases(String name="") 9 static Type[] GetTestCases(String name="")
diff --git a/src/tests/efl_mono/TestUtils.cs b/src/tests/efl_mono/TestUtils.cs
new file mode 100644
index 0000000000..459394bf2d
--- /dev/null
+++ b/src/tests/efl_mono/TestUtils.cs
@@ -0,0 +1,55 @@
1using System;
2using System.Runtime.CompilerServices;
3
4public class Test
5{
6 public static void Assert(bool res, String msg = "Assertion failed",
7 [CallerLineNumber] int line = 0,
8 [CallerFilePath] string file = null,
9 [CallerMemberName] string member = null)
10 {
11 if (!res)
12 throw new Exception($"Assertion failed: {file}:{line} ({member}) {msg}");
13 }
14
15 public static void AssertEquals<T>(T expected, T actual, String msg = "",
16 [CallerLineNumber] int line = 0,
17 [CallerFilePath] string file = null,
18 [CallerMemberName] string member = null) where T : System.IComparable<T>
19 {
20 if (expected.CompareTo(actual) != 0) {
21 if (msg == "")
22 msg = $"Expected \"{expected}\", actual \"{actual}\"";
23 throw new Exception($"{file}:{line} ({member}) {msg}");
24 }
25 }
26
27 public delegate void Operation();
28
29 public static void AssertRaises<T>(Operation op, String msg = "Exception not raised",
30 [CallerLineNumber] int line = 0,
31 [CallerFilePath] string file = null,
32 [CallerMemberName] string member = null) where T: Exception
33 {
34 try {
35 op();
36 } catch (T) {
37 return;
38 }
39 throw new Exception($"Assertion failed: {file}:{line} ({member}) {msg}");
40 }
41
42 public static void AssertNotRaises<T>(Operation op, String msg = "Exception raised.",
43 [CallerLineNumber] int line = 0,
44 [CallerFilePath] string file = null,
45 [CallerMemberName] string member = null) where T: Exception
46 {
47 try {
48 op();
49 } catch (T) {
50 throw new Exception($"Assertion failed: {file}:{line} ({member}) {msg}");
51 }
52 }
53}
54
55