PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/csharp/li_std_string_runme.cs

#
C# | 100 lines | 68 code | 18 blank | 14 comment | 26 complexity | cfeff69088c5a117033fa393f7ea8680 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. using System;
  2. using li_std_stringNamespace;
  3. public class runme
  4. {
  5. static void Main()
  6. {
  7. // Checking expected use of %typemap(in) std::string {}
  8. li_std_string.test_value("Fee");
  9. // Checking expected result of %typemap(out) std::string {}
  10. if (li_std_string.test_value("Fi") != "Fi")
  11. throw new Exception("Test 1 failed");
  12. // Verify type-checking for %typemap(in) std::string {}
  13. try {
  14. li_std_string.test_value(null);
  15. throw new Exception("Test 2 failed");
  16. } catch (ArgumentNullException) {
  17. }
  18. // Checking expected use of %typemap(in) const std::string & {}
  19. li_std_string.test_const_reference("Fo");
  20. // Checking expected result of %typemap(out) const std::string& {}
  21. if (li_std_string.test_const_reference("Fum") != "Fum")
  22. throw new Exception("Test 3 failed");
  23. // Verify type-checking for %typemap(in) const std::string & {}
  24. try {
  25. li_std_string.test_const_reference(null);
  26. throw new Exception("Test 4 failed");
  27. } catch (ArgumentNullException) {
  28. }
  29. //
  30. // Input and output typemaps for pointers and non-const references to
  31. // std::string are *not* supported; the following tests confirm
  32. // that none of these cases are slipping through.
  33. //
  34. SWIGTYPE_p_std__string stringPtr = null;
  35. stringPtr = li_std_string.test_pointer_out();
  36. li_std_string.test_pointer(stringPtr);
  37. stringPtr = li_std_string.test_const_pointer_out();
  38. li_std_string.test_const_pointer(stringPtr);
  39. stringPtr = li_std_string.test_reference_out();
  40. li_std_string.test_reference(stringPtr);
  41. // Check throw exception specification
  42. try {
  43. li_std_string.test_throw();
  44. throw new Exception("Test 5 failed");
  45. } catch (ApplicationException e) {
  46. if (e.Message != "test_throw message")
  47. throw new Exception("Test 5 string check: " + e.Message);
  48. }
  49. try {
  50. li_std_string.test_const_reference_throw();
  51. throw new Exception("Test 6 failed");
  52. } catch (ApplicationException e) {
  53. if (e.Message != "test_const_reference_throw message")
  54. throw new Exception("Test 6 string check: " + e.Message);
  55. }
  56. // Global variables
  57. const string s = "initial string";
  58. if (li_std_string.GlobalString2 != "global string 2")
  59. throw new Exception("GlobalString2 test 1");
  60. li_std_string.GlobalString2 = s;
  61. if (li_std_string.GlobalString2 != s)
  62. throw new Exception("GlobalString2 test 2");
  63. if (li_std_string.ConstGlobalString != "const global string")
  64. throw new Exception("ConstGlobalString test");
  65. // Member variables
  66. Structure myStructure = new Structure();
  67. if (myStructure.MemberString2 != "member string 2")
  68. throw new Exception("MemberString2 test 1");
  69. myStructure.MemberString2 = s;
  70. if (myStructure.MemberString2 != s)
  71. throw new Exception("MemberString2 test 2");
  72. if (myStructure.ConstMemberString != "const member string")
  73. throw new Exception("ConstMemberString test");
  74. if (Structure.StaticMemberString2 != "static member string 2")
  75. throw new Exception("StaticMemberString2 test 1");
  76. Structure.StaticMemberString2 = s;
  77. if (Structure.StaticMemberString2 != s)
  78. throw new Exception("StaticMemberString2 test 2");
  79. if (Structure.ConstStaticMemberString != "const static member string")
  80. throw new Exception("ConstStaticMemberString test");
  81. }
  82. }