diff options
author | Vitor Sousa <vitorsousasilva@gmail.com> | 2017-06-07 20:49:50 -0300 |
---|---|---|
committer | Vitor Sousa <vitorsousasilva@gmail.com> | 2017-06-07 20:49:50 -0300 |
commit | ff524e59cd2626b365c94095d75c9354792ca620 (patch) | |
tree | 8862f192d3809f5904afccbe64d796cec258c22d | |
parent | 6525e774dbd1972e72c249b0fa6c7cf096b2f25f (diff) | |
download | efl-ff524e59cd2626b365c94095d75c9354792ca620.tar.gz |
eina_mono: add example for eina.Error
-rw-r--r-- | src/Makefile_Efl_Mono.am | 1 | ||||
-rw-r--r-- | src/tests/efl_mono/examples/EinaError01.cs | 76 |
2 files changed, 77 insertions, 0 deletions
diff --git a/src/Makefile_Efl_Mono.am b/src/Makefile_Efl_Mono.am index 79743750d3..d87cdfc741 100644 --- a/src/Makefile_Efl_Mono.am +++ b/src/Makefile_Efl_Mono.am @@ -179,6 +179,7 @@ check_PROGRAMS += tests/efl_mono/efl_mono.exe TESTS += tests/efl_mono/mono_test_driver.sh tests_efl_mono_examples = \ + tests/efl_mono/examples/EinaError01.cs \ tests/efl_mono/examples/EinaBinbuf01.cs \ tests/efl_mono/examples/EinaArray01.cs \ tests/efl_mono/examples/EinaHash01.cs \ diff --git a/src/tests/efl_mono/examples/EinaError01.cs b/src/tests/efl_mono/examples/EinaError01.cs new file mode 100644 index 0000000000..b1be4e3e9a --- /dev/null +++ b/src/tests/efl_mono/examples/EinaError01.cs @@ -0,0 +1,76 @@ +using static System.Console; + +namespace TestSuite +{ + +class TestExampleEinaError01 +{ + private static bool RegisterdErrors = false; + private static eina.Error MyErrorNegative; + private static eina.Error MyErrorNull; + + private static void testFunc(int n, string s) + { + if (!RegisterdErrors) + { + MyErrorNegative = eina.Error.Register("Negative number"); + MyErrorNull = eina.Error.Register("NULL pointer"); + RegisterdErrors = true; + } + + if (n < 0) + { + eina.Error.Set(MyErrorNegative); + return; + } + + if (s == null) + { + eina.Error.Set(MyErrorNull); + return; + } + } + + public static void EinaError01() + { + // Handling Eina_Error with exception + try + { + testFunc(-1, "abc"); + eina.Error.RaiseIfOcurred(); + } + catch(efl.EflException e) + { + WriteLine($"Caught error: {e.Message}"); + } + + // Handling Eina_Error directly + testFunc(42, null); + eina.Error err = eina.Error.Get(); + if (err != 0) + { + WriteLine($"Error set: {err.Message}"); + } + eina.Error.Clear(); + + // No error set + try + { + testFunc(42, "abc"); + + eina.Error.RaiseIfOcurred(); + + err = eina.Error.Get(); + WriteLine($"Really no error? {err == eina.Error.NO_ERROR}."); + } + catch + { + WriteLine("Unspected error!!!"); + } + + WriteLine("No error message is empty string: \"{0}\"", eina.Error.NO_ERROR.Message); + WriteLine("No error message is empty string: \"{0}\"", eina.Error.MsgGet(0)); + } +} + +} |