PageRenderTime 25ms CodeModel.GetById 20ms app.highlight 3ms RepoModel.GetById 1ms 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
  1using System;
  2using li_std_stringNamespace;
  3
  4public class runme
  5{
  6    static void Main() 
  7    {
  8        // Checking expected use of %typemap(in) std::string {}
  9        li_std_string.test_value("Fee");
 10
 11        // Checking expected result of %typemap(out) std::string {}
 12        if (li_std_string.test_value("Fi") != "Fi")
 13            throw new Exception("Test 1 failed");
 14
 15        // Verify type-checking for %typemap(in) std::string {}
 16        try {
 17            li_std_string.test_value(null);
 18            throw new Exception("Test 2 failed");
 19        } catch (ArgumentNullException) {
 20        }
 21
 22        // Checking expected use of %typemap(in) const std::string & {}
 23        li_std_string.test_const_reference("Fo");
 24
 25        // Checking expected result of %typemap(out) const std::string& {}
 26        if (li_std_string.test_const_reference("Fum") != "Fum")
 27            throw new Exception("Test 3 failed");
 28
 29        // Verify type-checking for %typemap(in) const std::string & {}
 30        try {
 31            li_std_string.test_const_reference(null);
 32            throw new Exception("Test 4 failed");
 33        } catch (ArgumentNullException) {
 34        }
 35
 36        //
 37        // Input and output typemaps for pointers and non-const references to
 38        // std::string are *not* supported; the following tests confirm
 39        // that none of these cases are slipping through.
 40        //
 41        
 42        SWIGTYPE_p_std__string stringPtr = null;
 43        
 44        stringPtr = li_std_string.test_pointer_out();
 45
 46        li_std_string.test_pointer(stringPtr);
 47
 48        stringPtr = li_std_string.test_const_pointer_out();
 49
 50        li_std_string.test_const_pointer(stringPtr);
 51
 52        stringPtr = li_std_string.test_reference_out();
 53
 54        li_std_string.test_reference(stringPtr);
 55
 56        // Check throw exception specification
 57        try {
 58            li_std_string.test_throw();
 59            throw new Exception("Test 5 failed");
 60        } catch (ApplicationException e) {
 61          if (e.Message != "test_throw message")
 62            throw new Exception("Test 5 string check: " + e.Message);
 63        }
 64        try {
 65            li_std_string.test_const_reference_throw();
 66            throw new Exception("Test 6 failed");
 67        } catch (ApplicationException e) {
 68          if (e.Message != "test_const_reference_throw message")
 69            throw new Exception("Test 6 string check: " + e.Message);
 70        }
 71
 72        // Global variables
 73        const string s = "initial string";
 74        if (li_std_string.GlobalString2 != "global string 2")
 75          throw new Exception("GlobalString2 test 1");
 76        li_std_string.GlobalString2 = s;
 77        if (li_std_string.GlobalString2 != s)
 78          throw new Exception("GlobalString2 test 2");
 79        if (li_std_string.ConstGlobalString != "const global string")
 80          throw new Exception("ConstGlobalString test");
 81
 82        // Member variables
 83        Structure myStructure = new Structure();
 84        if (myStructure.MemberString2 != "member string 2")
 85          throw new Exception("MemberString2 test 1");
 86        myStructure.MemberString2 = s;
 87        if (myStructure.MemberString2 != s)
 88          throw new Exception("MemberString2 test 2");
 89        if (myStructure.ConstMemberString != "const member string")
 90          throw new Exception("ConstMemberString test");
 91
 92        if (Structure.StaticMemberString2 != "static member string 2")
 93          throw new Exception("StaticMemberString2 test 1");
 94        Structure.StaticMemberString2 = s;
 95        if (Structure.StaticMemberString2 != s)
 96          throw new Exception("StaticMemberString2 test 2");
 97      if (Structure.ConstStaticMemberString != "const static member string")
 98        throw new Exception("ConstStaticMemberString test");
 99    }
100}