swig/Examples/test-suite/csharp
William S Fulton d3a20504be Fix multicharacter constants to have type int, not char
A character constant containing more than one character, e.g. 'ab', has
type int per both the C standard (6.4.4.4p10) and the C++ standard
([lex.ccon], which describes it as a "multicharacter literal"). SWIG
previously classified every character constant as char regardless of
length, which caused the generated wrapper accessor for a constant such
as #define X 'ab' to be declared char instead of int, silently
truncating the value.

The literal text is left untouched (SWIG does not evaluate constant
expressions), only the internal type tag changes, so the real compiler
that builds the generated wrapper still computes the (implementation
defined) value, exactly as it would for hand written C/C++ code.

Add a new C-only multichar_constant.i test case with per-language runme
files, and keep the new csharp/java char_constant runme files (which
had no coverage before) for the existing, unrelated character constant
checks.

Compiling a real multicharacter constant always triggers GCC's
-Wmultichar warning. #pragma GCC diagnostic ignored "-Wmultichar" does
not suppress it: this is a known, longstanding GCC C++ front-end bug
(gcc.gnu.org PR57241/PR53431, fixed in GCC 13) - verified locally that
it fails identically on GCC 11 and 12 regardless of file- or
function-level pragma scope, while working fine in C or with GCC 13+
or Clang (which also defines __GNUC__ but doesn't have this bug).

The new testcase avoids the warning entirely, with no build system
changes needed:

- The %inline global variable imulti_ab uses the real literal (guarded
  by the pragma) wherever that's known to work, and otherwise falls
  back to reconstructing the identical value GCC's own packing of
  'ab' produces (most significant byte first) without writing a
  multicharacter literal at all - the same symbol name and type either
  way, so the generated accessor links correctly regardless of which
  branch was compiled.
- The #define-driven MULTICHAR_AB constant (whose registration code is
  auto-generated per target language, so a similar fallback isn't
  portable to hand-write once for every language) is skipped entirely
  for octave and javascript's node/napi/v8 engines, the only
  configurations that always compile the generated wrapper as C++
  regardless of SWIG's own -c/-c++ mode (their runtime APIs require
  it) and so would otherwise still hit the GCC bug above.

Verified against both GCC 13 (default) and GCC 11 (matching the actual
CI toolchain that originally failed) across all configured languages.

Assisted-by: Claude Code (Sonnet 5)
2026-07-29 19:46:45 +01:00
..
Makefile.in Keep unsupported nested classes as ignored classes, not forward declarations 2026-06-08 07:57:22 +01:00
README csharp test-suite infrastructure 2003-03-04 23:00:21 +00:00
aggregate_runme.cs All tests now use the -namespace commandline option 2004-02-24 21:06:54 +00:00
allprotected_runme.cs Fix directors and allprotected mode and using declarations. 2023-06-24 12:29:59 +01:00
apply_strings_runme.cs ensure %apply with char*, unsigned char* and signed char* works 2006-05-03 20:58:19 +00:00
argcargvtest_runme.cs Fix indentation 2023-05-23 10:12:49 +12:00
bools_runme.cs remove executable bits 2009-05-01 06:21:56 +00:00
catches_runme.cs Fix exception handling when %catches is used in C# 2009-08-15 23:22:20 +00:00
catches_strings_runme.cs std::string throws typemaps 2022-09-19 09:09:29 +01:00
char_binary_rev_len_runme.cs Add typecheck. 2025-08-11 08:28:02 +01:00
char_binary_runme.cs Fixes of STRING/BYTES LENGTH typemaps. 2024-02-29 02:09:09 +01:00
char_constant_runme.cs Fix multicharacter constants to have type int, not char 2026-07-29 19:46:45 +01:00
char_strings_runme.cs Add char *& string typemaps to all languages and char_strings runme parity 2026-07-09 21:55:58 +01:00
complextest_runme.cs Fix C# std::complex pass by value typemaps 2017-10-02 19:07:24 +01:00
constover_runme.cs All tests now use the -namespace commandline option 2004-02-24 21:06:54 +00:00
cpp11_constexpr_friend_runme.cs Don't ignore overloaded friend functions that are also declared constexpr 2024-06-16 19:11:11 +01:00
cpp11_move_only_runme.cs Add missing use of move constructor 2024-03-06 21:46:58 +00:00
cpp11_move_only_valuewrapper_runme.cs Movable and move-only types supported in "out" typemaps. 2022-06-30 17:26:48 +01:00
cpp11_move_typemaps_runme.cs Add missing use of move constructor 2024-03-06 21:46:58 +00:00
cpp11_rvalue_reference_move_runme.cs rvalue reference outputs 2022-09-08 08:46:32 +01:00
cpp11_shared_ptr_template_upcast_runme.cs Applying shared_ptr template upcast fix to CSharp, adding CSharp test, and cleanup 2019-05-06 15:30:54 -04:00
cpp11_std_array_runme.cs std_array.i std_vector.i tweaks 2023-03-22 21:05:13 +00:00
cpp11_std_unique_ptr_runme.cs Add const std::unique_ptr & input typemaps 2024-03-06 21:46:58 +00:00
cpp11_std_unordered_map_runme.cs Replace empty() method with IsEmpty C# property in STL containers 2023-11-10 07:45:01 +00:00
cpp11_std_unordered_set_runme.cs Enhance the C# std::unordered_set testcase 2023-11-11 21:23:20 +00:00
cpp11_strongly_typed_enumerations_runme.cs R: Honour %rename of enum items in the generated R code 2026-07-15 00:24:05 +01:00
cpp17_director_string_view_runme.cs Fix std::string_view directorin for csharp (#3321) 2026-02-28 10:28:24 +00:00
cpp17_nested_namespaces_runme.cs Add c++17 nested namespaces runtime test for C# 2018-05-14 21:03:31 +01:00
cpp17_nspace_nested_namespaces_runme.cs Test c++17 nested namespaces and %nspace 2018-05-14 21:03:31 +01:00
cpp17_string_view_runme.cs Expand std::string_view test coverage 2023-05-26 16:19:05 +12:00
csharp_argument_defaults_feature_runme.cs feature("cs:defaultargs") interface test 2023-12-05 15:01:39 -06:00
csharp_attributes_runme.cs document directorinattributes and directoroutattributes 2009-10-01 18:16:09 +00:00
csharp_director_typemaps_runme.cs 'out' or 'ref' usage in a cstype typemap in directors 2019-11-26 19:32:34 +00:00
csharp_exceptions_runme.cs More diagnostics for csharp_exceptions testcase for diagnosing erratic failures 2014-05-25 12:00:42 +01:00
csharp_lib_arrays_bool_runme.cs Quieten failing bool[] testcase message 2019-07-16 19:46:32 +01:00
csharp_lib_arrays_runme.cs reverse merge last commit - 11348 2009-07-02 22:40:49 +00:00
csharp_prepost_runme.cs Fix spacing in generated code for csdirectorin 'pre', 'post' and 'terminator' attributes. Add some more tests for these attributes. 2013-01-11 19:47:10 +00:00
csharp_typemaps_runme.cs Add special variable imfuncname expansion for C# and D 2022-05-30 19:43:04 +01:00
default_args_runme.cs more %rename/%ignore tests 2004-11-09 21:27:02 +00:00
default_constructor_runme.cs Don't generate constructor wrappers if a base class has a private constructor 2015-07-07 20:15:55 +01:00
director_alternating_runme.cs Any 'using' statements in the protected section of a class were previously ignored with dirprot mode, certainly with Java and C#. Also directors - a call to a method being defined in the base class, not overridden in a subcalss, but again overridden in a class derived from the first subclass was not being dispatched correcly to the most derived class - affecting non-scripting languages. Fix for C# is based on recent fix for D. 2011-02-01 07:02:50 +00:00
director_basic_runme.cs Final tidy up for improved C# SwigDerviedClassHasMethod implementation 2022-05-26 08:44:51 +01:00
director_binary_string_rev_len_runme.cs Fix Length & string reverse order typemap. 2025-07-28 17:07:42 +02:00
director_binary_string_runme.cs Fixes of STRING/BYTES LENGTH typemaps. 2024-02-29 02:09:09 +01:00
director_classes_runme.cs Fix director_classes testcase failures on x86 2023-11-19 21:45:30 +13:00
director_classic_runme.cs remove executable bits 2009-05-01 06:21:56 +00:00
director_default_runme.cs director string testing additions 2022-02-12 12:09:01 +00:00
director_ignore_runme.cs %ignore director fixes 2006-09-22 23:29:34 +00:00
director_minimal_runme.cs Add a minimal director test (#3346) 2026-02-24 08:58:50 +00:00
director_nspace_runme.cs director_nspace fixes for C# for previous commit 2013-01-03 20:49:10 +00:00
director_pass_by_value_runme.cs Performance optimisation for directors for classes passed by value 2022-07-04 11:19:29 +01:00
director_primitives_runme.cs C# director runtime tests 2006-05-13 23:31:35 +00:00
director_property_runme.cs More director const std::string& testing and C# leak fix 2022-02-13 23:00:04 +00:00
director_protected_runme.cs Fix protected/private nested class referenced in generated upcast helper 2026-07-11 21:02:49 +01:00
director_shared_ptr_runme.cs shared_ptr tests cleanup 2026-03-26 08:37:18 +00:00
director_string_runme.cs Expand director_string_runme.* 2023-12-21 10:59:44 +13:00
director_using_member_scopes_runme.cs Using declarations, directors and overloaded methods 2022-03-10 22:18:23 +00:00
director_void_runme.cs Add C# support for void *VOID_INT_PTR member variables 2020-08-13 16:06:48 +01:00
director_wstring_runme.cs Add C# wchar_t * director typemaps 2022-05-04 21:37:47 +01:00
doxygen_basic_translate_runme.cs Fix in Csharp doxygen test 2024-09-13 12:17:54 +02:00
doxygen_checker.cs Add runtime tests for checking interface Doxygen docs 2026-02-11 19:02:36 +00:00
doxygen_interface_runme.cs Add runtime tests for checking interface Doxygen docs 2026-02-11 19:02:36 +00:00
doxygen_nested_class_runme.cs Add some tests for C# doxygen generation 2024-06-28 12:15:26 +00:00
doxygen_translate_runme.cs Add some tests for C# doxygen generation 2024-06-28 12:15:26 +00:00
enum_forward_runme.cs Fix C enum forward declarations in some target languages (notably Java) 2012-05-01 18:44:22 +00:00
enum_thorough_runme.cs SF bug #3195112 - fix wrapping of enums that are type char 2011-03-26 15:28:31 +00:00
enum_thorough_simple_runme.cs SF bug #3195112 - fix wrapping of enums that are type char 2011-03-26 15:28:31 +00:00
enum_thorough_typesafe_runme.cs Add more test case for char const expression in enum 2016-09-14 22:41:02 -07:00
exception_order_runme.cs Fix exception handling when %catches is used in C# 2009-08-15 23:22:20 +00:00
friends_runme.cs Wrap friend functions that are defined or declared within a namespace 2024-01-15 19:18:13 +00:00
imports_runme.cs enums added for testing across different SWIG generated modules 2004-04-22 20:32:48 +00:00
inherit_target_language_runme.cs Add test for notderived attribute in csbase/javabase typemap 2009-05-01 06:26:42 +00:00
intermediary_classname_runme.cs reverse merge last commit - 11348 2009-07-02 22:40:49 +00:00
li_attribute_runme.cs Add %attributeval and %attributestring to attribute.swg library 2009-02-13 22:42:45 +00:00
li_boost_shared_ptr_bits_runme.cs Fix shared_ptr of classes with private constructors and destructors. 2015-05-14 19:03:06 +01:00
li_boost_shared_ptr_director_runme.cs Add director shared_ptr typemaps for C# 2017-10-17 21:55:31 +01:00
li_boost_shared_ptr_runme.cs Improved C long handling for C# 2023-10-05 21:30:52 +01:00
li_cdata_bytes_cpp_runme.cs cdata.i changes and new test li_cdata_bytes 2026-05-25 13:16:09 +01:00
li_cdata_bytes_runme.cs cdata.i changes and new test li_cdata_bytes 2026-05-25 13:16:09 +01:00
li_cdata_cpp_runme.cs Fixes of STRING/BYTES LENGTH typemaps. 2024-02-29 02:09:09 +01:00
li_cdata_runme.cs Fixes of STRING/BYTES LENGTH typemaps. 2024-02-29 02:09:09 +01:00
li_constraints_runme.cs Add li_constraints test, testing 'constraints.i'. 2023-05-12 01:23:31 +02:00
li_std_auto_ptr_runme.cs Add missing typecheck typemaps for std::auto_ptr and std::unique_ptr 2022-09-17 10:23:51 +01:00
li_std_combinations_runme.cs Fix SWIG_STD_VECTOR_ENHANCED macro used in C# std::vector to work with commas 2010-06-01 23:10:22 +00:00
li_std_except_runme.cs Add std::bad_cast to std_except.i 2016-09-17 10:26:54 +02:00
li_std_list_runme.cs Potential null pointer deref fix for C# std::list wrappers 2025-08-18 19:00:45 +01:00
li_std_map_runme.cs Replace empty() method with IsEmpty C# property in STL containers 2023-11-10 07:45:01 +00:00
li_std_set_runme.cs Replace empty() method with IsEmpty C# property in STL containers 2023-11-10 07:45:01 +00:00
li_std_string_runme.cs Expand li_std_string_runme.* 2023-05-12 16:05:48 +12:00
li_std_vector_enum_runme.cs Fix #3475492 - iterating through std::vector wrappers of enumerations. 2012-03-13 07:10:24 +00:00
li_std_vector_runme.cs Replace empty() method with IsEmpty C# property in STL containers 2023-11-10 07:45:01 +00:00
li_std_wstring_runme.cs SWIGTYPE && input typemaps now assume object has been moved 2022-08-31 19:40:14 +01:00
li_swigtype_inout_runme.cs Add new swigtype_inout.i library containing SWIGTYPE *& OUTPUT typemaps. 2014-02-04 06:54:22 +00:00
li_typemaps_runme.cs lib_xxx to li_xxx name change fixes 2004-11-02 22:31:12 +00:00
long_long_runme.cs All tests now use the -namespace commandline option 2004-02-24 21:06:54 +00:00
member_pointer_runme.cs Remove obscure mpointer example and replace with member_pointer.i testcase and runtime examples 2007-08-09 23:47:13 +00:00
multichar_constant_runme.cs Fix multicharacter constants to have type int, not char 2026-07-29 19:46:45 +01:00
multiple_inheritance_abstract_runme.cs Fix Java %interface family of macros 2021-04-27 23:37:18 +01:00
multiple_inheritance_interfaces_runme.cs C# runtime test %interface regression fix for multiple inheritance and common bases 2024-09-11 08:04:18 +01:00
multiple_inheritance_nspace_runme.cs Fix Java %interface family of macros 2021-04-27 23:37:18 +01:00
multiple_inheritance_overload_runme.cs Fix warning in D test-suite 2022-03-28 19:30:47 +01:00
multiple_inheritance_shared_ptr_runme.cs Fix Java %interface family of macros 2021-04-27 23:37:18 +01:00
nested_class_runme.cs fixed %template declared within class, next to template declaration 2013-12-16 11:43:28 +04:00
nested_directors_runme.cs fixes for director class naming when nested classes are used 2014-03-13 18:58:29 +04:00
nested_in_template_runme.cs Avoid comparing doubles in nested_in_template.i unit test 2018-12-04 20:46:35 +01:00
nested_inheritance_interface_runme.cs nested_inheritance_interface testcase enhancement 2019-07-09 19:36:46 +01:00
nested_structs_runme.cs fixed %template declared within class, next to template declaration 2013-12-16 11:43:28 +04:00
nested_workaround_runme.cs fixed %template declared within class, next to template declaration 2013-12-16 11:43:28 +04:00
nspace_extend_runme.cs Test %extend and nspace feature 2010-03-08 23:02:53 +00:00
nspace_interface_runme.cs Fix Java using %interface and %nspace together 2026-03-06 08:23:26 +00:00
nspace_runme.cs [D] nspace support. 2011-03-13 00:32:26 +00:00
nspacemove_nested_runme.cs Fix %nspace and %nspacemove for nested classes and enums in a class 2024-06-01 08:04:08 +01:00
nspacemove_runme.cs Enhance %nspace with %nspacemove for moving symbols into a different target language namespace 2024-06-01 08:02:49 +01:00
nspacemove_stl_runme.cs Add nspacemove example for STL types 2024-06-01 08:04:14 +01:00
operator_overload_runme.cs C# testcase for operator== 2024-02-26 18:34:21 +00:00
overload_complicated_runme.cs remove executable bits 2009-05-01 06:21:56 +00:00
overload_template_runme.cs Rename max() to maximum() as max() is a built-in function in PHP. 2009-08-14 01:33:23 +00:00
pointer_reference_runme.cs Fix typecheck typemaps for SWIGTYPE *const& 2011-01-30 00:42:27 +00:00
preproc_constants_c_runme.cs Improved C long handling for C# 2023-10-05 21:30:52 +01:00
preproc_constants_runme.cs Improve handling of zero bytes in string literals 2024-08-30 11:07:15 +12:00
proxycode_runme.cs Add %proxycode directive for adding code into proxy classes for C#, D and Java 2017-01-13 20:43:50 +00:00
rename_pcre_encoder_runme.cs Add support for case conversion characters in regex substitutions. 2013-10-15 07:17:56 +01:00
rename_pcre_enum_runme.cs Add support for "[not]regexmatch" and "regextarget" to %rename. 2010-07-22 17:02:10 +00:00
rename_simple_runme.cs R - SF #3168676 Fix %rename not working for member variables and methods. Add new simple rename testcase with runtime tests for C# and R 2011-02-04 23:42:06 +00:00
sizet_runme.cs size_t tests 2006-10-17 21:41:39 +00:00
sneaky1_runme.cs fix for perl keyword 2006-03-07 23:05:11 +00:00
special_variable_attributes_runme.cs Cosmetic comment fix in testcase 2015-09-30 07:06:40 +01:00
special_variable_macros_runme.cs Add support for $n special variable expansion in the names of typemap local variables 2025-02-19 20:44:40 +00:00
string_constants_runme.cs Straighten out handling of char and string constants 2024-08-17 16:12:45 +12:00
template_nested_flat_runme.cs Add and improve Ruby test cases in the context of nesting and namespaces 2020-12-16 22:30:46 +01:00
template_nested_runme.cs fixed %template declared within class, next to template declaration 2013-12-16 11:43:28 +04:00
threads_runme.cs test strings in a multithreaded environment 2005-06-01 20:42:50 +00:00
throw_exception_runme.cs All tests now use the -namespace commandline option 2004-02-24 21:06:54 +00:00
typemap_namespace_runme.cs runtime test for C# added 2005-12-29 23:59:03 +00:00
typemap_out_optimal_runme.cs Rename debug in testcases to trace 2022-08-20 15:09:23 +01:00
varargs_runme.cs All tests now use the -namespace commandline option 2004-02-24 21:06:54 +00:00
virtual_poly_runme.cs Mono 1.1 warning fixes 2005-03-06 19:15:19 +00:00

README

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.