From b0318dae692375f02f30cc0d8bf84e508dea9b2e Mon Sep 17 00:00:00 2001 From: Leif Middelschulte Date: Wed, 1 Aug 2012 12:53:17 +0000 Subject: [PATCH] Add test for 'natural' C++ std::string handling in C (char*). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-c@13482 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/c/Makefile.in | 1 + .../c/c_backend_cpp_natural_std_string_runme.c | 16 ++++++++++++++++ .../c_backend_cpp_natural_std_string.i | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c create mode 100644 Examples/test-suite/c_backend_cpp_natural_std_string.i diff --git a/Examples/test-suite/c/Makefile.in b/Examples/test-suite/c/Makefile.in index 8963f4623..ceb761453 100644 --- a/Examples/test-suite/c/Makefile.in +++ b/Examples/test-suite/c/Makefile.in @@ -23,6 +23,7 @@ CPP_TEST_CASES += \ cpp_basic_global_var_atom \ cpp_basic_global_var_class \ cpp_basic_namespaced_class \ + c_backend_cpp_natural_std_string \ c_backend_cpp_exception # diff --git a/Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c b/Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c new file mode 100644 index 000000000..2cd9e7d65 --- /dev/null +++ b/Examples/test-suite/c/c_backend_cpp_natural_std_string_runme.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include "c_backend_cpp_natural_std_string/c_backend_cpp_natural_std_string_proxy.h" + +int main() +{ + char *myComposedString = myStringAppend("World, ", "Hello!"); + + assert(myComposedString); + assert(strcmp(myComposedString, "World, Hello!") == 0); + + free(myComposedString); + + return 0; +} \ No newline at end of file diff --git a/Examples/test-suite/c_backend_cpp_natural_std_string.i b/Examples/test-suite/c_backend_cpp_natural_std_string.i new file mode 100644 index 000000000..6bf8e6bd2 --- /dev/null +++ b/Examples/test-suite/c_backend_cpp_natural_std_string.i @@ -0,0 +1,13 @@ +%module c_backend_cpp_natural_std_string + +%feature ("nspace", "1"); + +%include std_string.i + +%inline %{ + static std::string& myStringAppend(std::string &someString, const std::string &appendedString) + { + someString += appendedString; + return someString; + } +%} \ No newline at end of file