From 2824b0cbb66e715490e1ef13250bd675d87b32d9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 2 Jun 2010 20:53:17 +0000 Subject: rel-2.0.0 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/tags/rel-2.0.0@12089 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- trunk/Examples/test-suite/csharp/Makefile.in | 88 +++ trunk/Examples/test-suite/csharp/README | 42 ++ .../Examples/test-suite/csharp/aggregate_runme.cs | 28 + .../test-suite/csharp/allprotected_runme.cs | 71 +++ .../test-suite/csharp/apply_strings_runme.cs | 16 + trunk/Examples/test-suite/csharp/bools_runme.cs | 29 + trunk/Examples/test-suite/csharp/catches_runme.cs | 66 +++ .../test-suite/csharp/char_strings_runme.cs | 155 +++++ .../Examples/test-suite/csharp/constover_runme.cs | 34 ++ .../test-suite/csharp/csharp_attributes_runme.cs | 266 +++++++++ .../test-suite/csharp/csharp_exceptions_runme.cs | 342 +++++++++++ .../test-suite/csharp/csharp_lib_arrays_runme.cs | 70 +++ .../test-suite/csharp/csharp_prepost_runme.cs | 70 +++ .../test-suite/csharp/csharp_typemaps_runme.cs | 113 ++++ .../test-suite/csharp/default_args_runme.cs | 143 +++++ .../test-suite/csharp/default_constructor_runme.cs | 24 + .../test-suite/csharp/director_basic_runme.cs | 74 +++ .../test-suite/csharp/director_classes_runme.cs | 180 ++++++ .../test-suite/csharp/director_classic_runme.cs | 314 ++++++++++ .../test-suite/csharp/director_ignore_runme.cs | 57 ++ .../test-suite/csharp/director_primitives_runme.cs | 127 ++++ .../test-suite/csharp/director_protected_runme.cs | 72 +++ .../test-suite/csharp/director_string_runme.cs | 53 ++ .../test-suite/csharp/enum_thorough_runme.cs | 410 +++++++++++++ .../csharp/enum_thorough_simple_runme.cs | 410 +++++++++++++ .../csharp/enum_thorough_typesafe_runme.cs | 410 +++++++++++++ .../test-suite/csharp/exception_order_runme.cs | 48 ++ trunk/Examples/test-suite/csharp/imports_runme.cs | 18 + .../csharp/inherit_target_language_runme.cs | 24 + .../csharp/intermediary_classname_runme.cs | 21 + .../test-suite/csharp/li_attribute_runme.cs | 78 +++ .../csharp/li_boost_shared_ptr_bits_runme.cs | 17 + .../test-suite/csharp/li_boost_shared_ptr_runme.cs | 589 +++++++++++++++++++ .../test-suite/csharp/li_std_combinations_runme.cs | 31 + .../test-suite/csharp/li_std_except_runme.cs | 24 + .../Examples/test-suite/csharp/li_std_map_runme.cs | 238 ++++++++ .../test-suite/csharp/li_std_string_runme.cs | 100 ++++ .../test-suite/csharp/li_std_vector_runme.cs | 638 +++++++++++++++++++++ .../test-suite/csharp/li_std_wstring_runme.cs | 76 +++ .../test-suite/csharp/li_typemaps_runme.cs | 101 ++++ .../Examples/test-suite/csharp/long_long_runme.cs | 41 ++ .../test-suite/csharp/member_pointer_runme.cs | 47 ++ .../test-suite/csharp/nspace_extend_runme.cs | 39 ++ trunk/Examples/test-suite/csharp/nspace_runme.cs | 76 +++ .../test-suite/csharp/operator_overload_runme.cs | 46 ++ .../csharp/overload_complicated_runme.cs | 55 ++ .../test-suite/csharp/overload_template_runme.cs | 152 +++++ .../test-suite/csharp/pointer_reference_runme.cs | 18 + .../test-suite/csharp/preproc_constants_c_runme.cs | 70 +++ .../test-suite/csharp/preproc_constants_runme.cs | 69 +++ trunk/Examples/test-suite/csharp/sizet_runme.cs | 18 + trunk/Examples/test-suite/csharp/sneaky1_runme.cs | 20 + .../csharp/special_variable_macros_runme.cs | 22 + trunk/Examples/test-suite/csharp/threads_runme.cs | 61 ++ .../test-suite/csharp/throw_exception_runme.cs | 24 + .../test-suite/csharp/typemap_namespace_runme.cs | 16 + .../test-suite/csharp/typemap_out_optimal_runme.cs | 13 + trunk/Examples/test-suite/csharp/varargs_runme.cs | 20 + .../test-suite/csharp/virtual_poly_runme.cs | 51 ++ 59 files changed, 6525 insertions(+) create mode 100644 trunk/Examples/test-suite/csharp/Makefile.in create mode 100644 trunk/Examples/test-suite/csharp/README create mode 100644 trunk/Examples/test-suite/csharp/aggregate_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/allprotected_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/apply_strings_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/bools_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/catches_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/char_strings_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/constover_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/csharp_attributes_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/csharp_exceptions_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/csharp_lib_arrays_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/csharp_prepost_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/csharp_typemaps_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/default_args_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/default_constructor_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/director_basic_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/director_classes_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/director_classic_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/director_ignore_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/director_primitives_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/director_protected_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/director_string_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/enum_thorough_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/enum_thorough_simple_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/enum_thorough_typesafe_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/exception_order_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/imports_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/inherit_target_language_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/intermediary_classname_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/li_attribute_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/li_std_combinations_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/li_std_except_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/li_std_map_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/li_std_string_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/li_std_vector_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/li_std_wstring_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/li_typemaps_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/long_long_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/member_pointer_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/nspace_extend_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/nspace_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/operator_overload_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/overload_complicated_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/overload_template_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/pointer_reference_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/preproc_constants_c_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/preproc_constants_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/sizet_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/sneaky1_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/special_variable_macros_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/threads_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/throw_exception_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/typemap_namespace_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/typemap_out_optimal_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/varargs_runme.cs create mode 100644 trunk/Examples/test-suite/csharp/virtual_poly_runme.cs (limited to 'trunk/Examples/test-suite/csharp') diff --git a/trunk/Examples/test-suite/csharp/Makefile.in b/trunk/Examples/test-suite/csharp/Makefile.in new file mode 100644 index 000000000..afb29dfbf --- /dev/null +++ b/trunk/Examples/test-suite/csharp/Makefile.in @@ -0,0 +1,88 @@ +####################################################################### +# Makefile for C# test-suite +####################################################################### + +LANGUAGE = csharp +SCRIPTSUFFIX = _runme.cs +INTERPRETER = @CSHARPCILINTERPRETER@ +CSHARPPATHSEPARATOR = "@CSHARPPATHSEPARATOR@" +CSHARPCYGPATH_W = @CSHARPCYGPATH_W@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@/.. +top_builddir = @top_builddir@/.. + +CPP_TEST_CASES = \ + csharp_attributes \ + csharp_exceptions \ + csharp_features \ + csharp_lib_arrays \ + csharp_prepost \ + csharp_typemaps \ + enum_thorough_simple \ + enum_thorough_typesafe \ + exception_partial_info \ + intermediary_classname + +include $(srcdir)/../common.mk + +# Overridden variables here +SWIGOPT += -namespace $*Namespace +INTERFACEDIR = ../../ + +CSHARPFLAGSSPECIAL = + +# Custom tests - tests with additional commandline options +intermediary_classname.cpptest: SWIGOPT += -dllimport intermediary_classname +csharp_lib_arrays.cpptest: CSHARPFLAGSSPECIAL = -unsafe + +# Rules for the different types of tests +%.cpptest: + $(setup) + +(cd $* && $(swig_and_compile_cpp)) + +$(run_testcase) + +%.ctest: + $(setup) + +(cd $* && $(swig_and_compile_c)) + +$(run_testcase) + +%.multicpptest: + $(setup) + +(cd $* && $(swig_and_compile_multi_cpp)) + +$(run_testcase) + +# Makes a directory for the testcase if it does not exist +setup = \ + if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ + echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \ + else \ + echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \ + fi; \ + if [ ! -d $* ]; then \ + mkdir $*; \ + fi + +# Compiles C# files then runs the testcase. A testcase is only run if +# a file is found which has _runme.cs appended after the testcase name. +# Note C# uses LD_LIBRARY_PATH under Unix, PATH under Cygwin/Windows and SHLIB_PATH on HPUX. +run_testcase = \ + if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \ + $(MAKE) -f $*/$(top_builddir)/$(EXAMPLES)/Makefile \ + CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -out:$*_runme.exe' \ + CSHARPSRCS='`$(CSHARPCYGPATH_W) $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)` `find $* -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile && \ + env LD_LIBRARY_PATH="$*:$$LD_LIBRARY_PATH" PATH="$*:$$PATH" SHLIB_PATH="$*:$$SHLIB_PATH" $(RUNTOOL) $(INTERPRETER) $*_runme.exe; \ + else \ + cd $* && \ + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \ + CSHARPFLAGS='-nologo $(CSHARPFLAGSSPECIAL) -t:module -out:$*.netmodule' \ + CSHARPSRCS='`find . -name "*.cs" -exec $(CSHARPCYGPATH_W) "{}" \+`' csharp_compile; \ + fi + +# Clean: remove testcase directories +%.clean: + @if [ -d $* ]; then \ + rm -rf $*; \ + fi + +clean: + @rm -f *.exe *.exe.mdb diff --git a/trunk/Examples/test-suite/csharp/README b/trunk/Examples/test-suite/csharp/README new file mode 100644 index 000000000..96dea942c --- /dev/null +++ b/trunk/Examples/test-suite/csharp/README @@ -0,0 +1,42 @@ +SWIG testsuite README file +-------------------------- + +This testsuite is here to ensure SWIG can handle a wide range of c/c++ +syntax. The testsuite comprises many testcases in this directory. Each +test case is tested under each of the language modules thereby +thoroughly testing all of SWIG. It ensures that each of the language +modules are at a similar standard. + +Those modules that support shadow classes run the tests producing +shadow classes to test the full language module functionality. + +Some test cases need a runtime test. These need implementing in each +of the language modules. The language modules look for a file in the +language specific test-suite directory which has _runme appended after +the testcase name. If one is found it will be run as part of the test. + +Some language modules add to this common set of test cases for +language specific tests. These can be found in the appropriate +language test-suite directory. There is also a README in each of the +language module directories. + +For each testcase a message showing which testcase is being tested is +displayed. Nothing else is printed unless the test fails. + + +Some Developer Guidelines +------------------------- + +Note that the whole test suite need not be run each time a testcase is +modified. An individual testcase may be run by going to the language +module test-suite directory and using make testcasename.xxx where xxx +is the type of test (eg cpptest). See common.mk. make -s doesn't print +any junk on the screen and is useful for emulating the way make check +works from the SWIG root directory. + +If there are runtime tests needed, don't print anything unless there +is an error in which case stderr is suggested. + +Please set the name of the module to the same name as the testcase, +otherwise modules will not be found. + diff --git a/trunk/Examples/test-suite/csharp/aggregate_runme.cs b/trunk/Examples/test-suite/csharp/aggregate_runme.cs new file mode 100644 index 000000000..ee6394b56 --- /dev/null +++ b/trunk/Examples/test-suite/csharp/aggregate_runme.cs @@ -0,0 +1,28 @@ +using System; +using aggregateNamespace; + +public class runme { + static void Main() { + + // Confirm that move() returns correct results under normal use + int result = aggregate.move(aggregate.UP); + if (result != aggregate.UP) throw new Exception("UP failed"); + + result = aggregate.move(aggregate.DOWN); + if (result != aggregate.DOWN) throw new Exception("DOWN failed"); + + result = aggregate.move(aggregate.LEFT); + if (result != aggregate.LEFT) throw new Exception("LEFT failed"); + + result = aggregate.move(aggregate.RIGHT); + if (result != aggregate.RIGHT) throw new Exception("RIGHT failed"); + + // Confirm that move() raises an exception when the contract is violated + try { + aggregate.move(0); + throw new Exception("0 test failed"); + } + catch (ArgumentOutOfRangeException) { + } + } +} diff --git a/trunk/Examples/test-suite/csharp/allprotected_runme.cs b/trunk/Examples/test-suite/csharp/allprotected_runme.cs new file mode 100644 index 000000000..99a791d58 --- /dev/null +++ b/trunk/Examples/test-suite/csharp/allprotected_runme.cs @@ -0,0 +1,71 @@ +using System; +using allprotectedNamespace; + +public class runme +{ + static void Main() + { + runme r = new runme(); + r.run(); + } + + void run() + { + MyProtectedBase mpb = new MyProtectedBase("MyProtectedBase"); + mpb.accessProtected(); + } +} + +class MyProtectedBase : ProtectedBase +{ + public MyProtectedBase(string name) : base(name) { + } + public void accessProtected() { + string s = virtualMethod(); + if (s != "ProtectedBase") + throw new Exception("Failed"); + + Klass k = instanceMethod(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = instanceOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = ProtectedBase.staticMethod(new Klass("abc")); + if (k.getName() != "abc") + throw new Exception("Failed"); + + k = ProtectedBase.staticOverloaded(new Klass("xyz")); + if (k.getName() != "xyz") + throw new Exception("Failed"); + + k = ProtectedBase.staticOverloaded(new Klass("xyz"), "abc"); + if (k.getName() != "abc") + throw new Exception("Failed"); + + instanceMemberVariable = 30; + int i = instanceMemberVariable; + if (i != 30) + throw new Exception("Failed"); + + staticMemberVariable = 40; + i = staticMemberVariable; + if (i != 40) + throw new Exception("Failed"); + + i = staticConstMemberVariable; + if (i != 20) + throw new Exception("Failed"); + + anEnum = ProtectedBase.AnEnum.EnumVal1; + ProtectedBase.AnEnum ae = anEnum; + if (ae != ProtectedBase.AnEnum.EnumVal1) + throw new Exception("Failed"); + } +} diff --git a/trunk/Examples/test-suite/csharp/apply_strings_runme.cs b/trunk/Examples/test-suite/csharp/apply_strings_runme.cs new file mode 100644 index 000000000..deaa5213b --- /dev/null +++ b/trunk/Examples/test-suite/csharp/apply_strings_runme.cs @@ -0,0 +1,16 @@ + +using System; +using apply_stringsNamespace; + +public class apply_strings_runme { + + private static string TEST_MESSAGE = "A message from target language to the C++ world and back again."; + + public static void Main() { + if (apply_strings.UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed"); + if (apply_strings.SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed"); + SWIGTYPE_p_char pChar = apply_strings.CharFunction(null); + if (pChar != null) throw new Exception("CharFunction failed"); + } +} + diff --git a/trunk/Examples/test-suite/csharp/bools_runme.cs b/trunk/Examples/test-suite/csharp/bools_runme.cs new file mode 100644 index 000000000..70620fcef --- /dev/null +++ b/trunk/Examples/test-suite/csharp/bools_runme.cs @@ -0,0 +1,29 @@ + +// This is the bool runtime testcase. It checks that the C++ bool type works. + +using System; +using boolsNamespace; + +public class bools_runme { + + public static void Main() { + + bool t = true; + bool f = false; + + check_bo(f); + check_bo(t); + } + + public static void check_bo(bool input) { + + for( int i=0; i<1000; i++ ) { + if( bools.bo(input) != input ) { + string ErrorMessage = "Runtime test check_bo failed."; + throw new Exception(ErrorMessage); + } + } + + } +} + diff --git a/trunk/Examples/test-suite/csharp/catches_runme.cs b/trunk/Examples/test-suite/csharp/catches_runme.cs new file mode 100644 index 000000000..2b5290eac --- /dev/null +++ b/trunk/Examples/test-suite/csharp/catches_runme.cs @@ -0,0 +1,66 @@ +using System; +using catchesNamespace; + +public class runme { + static void Main() { + // test_catches() + try { + catches.test_catches(1); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "C++ int exception thrown, value: 1") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + catches.test_catches(2); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "two") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + catches.test_catches(3); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "C++ ThreeException const & exception thrown") + throw new ApplicationException("bad exception order: " + e.Message); + } + + // test_exception_specification() + try { + catches.test_exception_specification(1); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "C++ int exception thrown, value: 1") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + catches.test_exception_specification(2); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "unknown exception") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + catches.test_exception_specification(3); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "unknown exception") + throw new ApplicationException("bad exception order: " + e.Message); + } + + // test_catches_all() + try { + catches.test_catches_all(1); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "unknown exception") + throw new ApplicationException("bad exception order: " + e.Message); + } + + } +} diff --git a/trunk/Examples/test-suite/csharp/char_strings_runme.cs b/trunk/Examples/test-suite/csharp/char_strings_runme.cs new file mode 100644 index 000000000..414d32b7a --- /dev/null +++ b/trunk/Examples/test-suite/csharp/char_strings_runme.cs @@ -0,0 +1,155 @@ + +using System; +using char_stringsNamespace; + +public class char_strings_runme { + + private static string CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible."; + private static string OTHERLAND_MSG = "Little message from the safe world."; + + public static void Main() { + + uint count = 10000; + uint i = 0; + + // get functions + for (i=0; i(i.ToString(), i * 18))) + throw new Exception("Contains test " + i + " failed"); + } + + // TryGetValue() test + int value; + bool rc = simap.TryGetValue("3", out value); + if (rc != true || value != (3 * 18)) + throw new Exception("TryGetValue test 1 failed"); + + rc = simap.TryGetValue("-1", out value); + if (rc != false) + throw new Exception("TryGetValue test 2 failed"); + + // Keys and Values test + { + IList keys = new List(simap.Keys); + IList values = new List(simap.Values); + if (keys.Count != collectionSize) + throw new Exception("Keys count test failed"); + + if (values.Count != collectionSize) + throw new Exception("Values count test failed"); + + for (int i = 0; i < keys.Count; i++) + { + if (simap[keys[i]] != values[i]) + throw new Exception("Keys and values test failed for index " + i); + } + } + + // Add and Remove test + for (int i = 100; i < 103; i++) + { + simap.Add(i.ToString(), i * 18); + if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18)) + throw new Exception("Add test failed for index " + i); + + simap.Remove(i.ToString()); + if (simap.ContainsKey(i.ToString())) + throw new Exception("Remove test failed for index " + i); + } + + for (int i = 200; i < 203; i++) + { + simap.Add(new KeyValuePair(i.ToString(), i * 18)); + if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18)) + throw new Exception("Add explicit test failed for index " + i); + + simap.Remove(new KeyValuePair(i.ToString(), i * 18)); + if (simap.ContainsKey(i.ToString())) + throw new Exception("Remove explicit test failed for index " + i); + } + + // Duplicate key test + try + { + simap.Add("3", 0); + throw new Exception("Adding duplicate key test failed"); + } + catch (ArgumentException) + { + } + + // CopyTo() test + { + KeyValuePair[] outputarray = new KeyValuePair[collectionSize]; + simap.CopyTo(outputarray); + foreach (KeyValuePair val in outputarray) + { + if (simap[val.Key] != val.Value) + throw new Exception("CopyTo (1) test failed, index:" + val.Key); + } + } + { + KeyValuePair[] outputarray = new KeyValuePair[midCollection + collectionSize]; + simap.CopyTo(outputarray, midCollection); + for (int i = midCollection; i < midCollection + collectionSize; i++) + { + KeyValuePair val = outputarray[i]; + if (simap[val.Key] != val.Value) + throw new Exception("CopyTo (2) test failed, index:" + val.Key); + } + } + { + KeyValuePair[] outputarray = new KeyValuePair[collectionSize - 1]; + try + { + simap.CopyTo(outputarray); + throw new Exception("CopyTo (4) test failed"); + } + catch (ArgumentException) + { + } + } + + // Clear test + simap.Clear(); + if (simap.Count != 0) + throw new Exception("Clear test failed"); + + // Test wrapped methods + for (int i = 1; i <= 5; i++) + { + simap[i.ToString()] = i; + } + double avg = li_std_map.valueAverage(simap); + if (avg != 3.0) + throw new Exception("Wrapped method valueAverage test failed. Got " + avg); + + string keyStringified = li_std_map.stringifyKeys(simap); + if (keyStringified != " 1 2 3 4 5") + throw new Exception("Wrapped method stringifyKeys test failed. Got " + keyStringified); + + // Test a map with a new complex type (Struct) + { + IntStructMap ismap = new IntStructMap(); + for (int i = 0; i < 10; i++) + { + ismap.Add(i, new Struct(i * 10.1)); + } + + if (ismap.Count != 10) + throw new Exception("Count test on complex type map failed"); + + foreach (KeyValuePair p in ismap) + { + if ((p.Key * 10.1) != p.Value.num) + throw new Exception("Iteration test on complex type map failed for index " + p.Key); + } + } + + // Test a map of pointers + { + IntStructPtrMap ispmap = new IntStructPtrMap(); + for (int i = 0; i < 10; i++) + { + ispmap.Add(i, new Struct(i * 10.1)); + } + + if (ispmap.Count != 10) + throw new Exception("Count test on complex type pointer map failed"); + + foreach (KeyValuePair p in ispmap) + { + if ((p.Key * 10.1) != p.Value.num) + throw new Exception("Iteration test on complex type pointer map failed for index " + p.Key); + } + } + { + IntStructConstPtrMap iscpmap = new IntStructConstPtrMap(); + for (int i = 0; i < 10; i++) + { + iscpmap.Add(i, new Struct(i * 10.1)); + } + + if (iscpmap.Count != 10) + throw new Exception("Count test on complex type const pointer map failed"); + + foreach (KeyValuePair p in iscpmap) + { + if ((p.Key * 10.1) != p.Value.num) + throw new Exception("Iteration test on complex type const pointer map failed for index " + p.Key); + } + } + + // Test complex type as key (Struct) + { + StructIntMap limap = new StructIntMap(); + Struct s7 = new Struct(7); + Struct s8 = new Struct(8); + limap[s7] = 8; + if (limap[s7] != 8) + throw new Exception("Assignment test on complex key map failed"); + + if (!limap.ContainsKey(s7)) + throw new Exception("Key test (1) on complex key map failed"); + + if (limap.ContainsKey(s8)) + throw new Exception("Key test (2) on complex key map failed"); + } + + // All done + } +} + diff --git a/trunk/Examples/test-suite/csharp/li_std_string_runme.cs b/trunk/Examples/test-suite/csharp/li_std_string_runme.cs new file mode 100644 index 000000000..4c9d71384 --- /dev/null +++ b/trunk/Examples/test-suite/csharp/li_std_string_runme.cs @@ -0,0 +1,100 @@ +using System; +using li_std_stringNamespace; + +public class runme +{ + static void Main() + { + // Checking expected use of %typemap(in) std::string {} + li_std_string.test_value("Fee"); + + // Checking expected result of %typemap(out) std::string {} + if (li_std_string.test_value("Fi") != "Fi") + throw new Exception("Test 1 failed"); + + // Verify type-checking for %typemap(in) std::string {} + try { + li_std_string.test_value(null); + throw new Exception("Test 2 failed"); + } catch (ArgumentNullException) { + } + + // Checking expected use of %typemap(in) const std::string & {} + li_std_string.test_const_reference("Fo"); + + // Checking expected result of %typemap(out) const std::string& {} + if (li_std_string.test_const_reference("Fum") != "Fum") + throw new Exception("Test 3 failed"); + + // Verify type-checking for %typemap(in) const std::string & {} + try { + li_std_string.test_const_reference(null); + throw new Exception("Test 4 failed"); + } catch (ArgumentNullException) { + } + + // + // Input and output typemaps for pointers and non-const references to + // std::string are *not* supported; the following tests confirm + // that none of these cases are slipping through. + // + + SWIGTYPE_p_std__string stringPtr = null; + + stringPtr = li_std_string.test_pointer_out(); + + li_std_string.test_pointer(stringPtr); + + stringPtr = li_std_string.test_const_pointer_out(); + + li_std_string.test_const_pointer(stringPtr); + + stringPtr = li_std_string.test_reference_out(); + + li_std_string.test_reference(stringPtr); + + // Check throw exception specification + try { + li_std_string.test_throw(); + throw new Exception("Test 5 failed"); + } catch (ApplicationException e) { + if (e.Message != "test_throw message") + throw new Exception("Test 5 string check: " + e.Message); + } + try { + li_std_string.test_const_reference_throw(); + throw new Exception("Test 6 failed"); + } catch (ApplicationException e) { + if (e.Message != "test_const_reference_throw message") + throw new Exception("Test 6 string check: " + e.Message); + } + + // Global variables + const string s = "initial string"; + if (li_std_string.GlobalString2 != "global string 2") + throw new Exception("GlobalString2 test 1"); + li_std_string.GlobalString2 = s; + if (li_std_string.GlobalString2 != s) + throw new Exception("GlobalString2 test 2"); + if (li_std_string.ConstGlobalString != "const global string") + throw new Exception("ConstGlobalString test"); + + // Member variables + Structure myStructure = new Structure(); + if (myStructure.MemberString2 != "member string 2") + throw new Exception("MemberString2 test 1"); + myStructure.MemberString2 = s; + if (myStructure.MemberString2 != s) + throw new Exception("MemberString2 test 2"); + if (myStructure.ConstMemberString != "const member string") + throw new Exception("ConstMemberString test"); + + if (Structure.StaticMemberString2 != "static member string 2") + throw new Exception("StaticMemberString2 test 1"); + Structure.StaticMemberString2 = s; + if (Structure.StaticMemberString2 != s) + throw new Exception("StaticMemberString2 test 2"); + if (Structure.ConstStaticMemberString != "const static member string") + throw new Exception("ConstStaticMemberString test"); + } +} diff --git a/trunk/Examples/test-suite/csharp/li_std_vector_runme.cs b/trunk/Examples/test-suite/csharp/li_std_vector_runme.cs new file mode 100644 index 000000000..617116d5a --- /dev/null +++ b/trunk/Examples/test-suite/csharp/li_std_vector_runme.cs @@ -0,0 +1,638 @@ +// This test tests all the methods in the C# collection wrapper + +using System; +using li_std_vectorNamespace; + +public class li_std_vector_runme { + + private static readonly int collectionSize = 20; + private static readonly int midCollection = collectionSize/2; + + public static DoubleVector myDoubleVector; + public static RealVector myRealVector; + + public static void Main() { + // Setup collection + DoubleVector vect = new DoubleVector(); + for (int i=0; i myEnumerator = dv.GetEnumerator(); + while ( myEnumerator.MoveNext() ) { + if (myEnumerator.Current != 77.7) + throw new Exception("Repeat (2) test failed"); + } + } +#endif + } + + { + // InsertRange() test + DoubleVector dvect = new DoubleVector(); + for (int i=0; i<5; i++) { + dvect.Add(1000.0*i); + } + vect.InsertRange(midCollection, dvect); + if (vect.Count != collectionSize+dvect.Count) + throw new Exception("InsertRange test size failed"); + + for (int i=0; i