From 3bd4d94c4c1feab9b345f378055ee66ab4035e2c Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Wed, 8 Jul 2026 13:22:16 -0400 Subject: [PATCH] Fix warnings between clang and gcc usage --- examples/temp_sensor/src/TimerConfigurator.c | 2 +- lib/cmock_generator_plugin_expect.rb | 2 +- lib/cmock_generator_plugin_return_thru_ptr.rb | 9 +- lib/cmock_generator_utils.rb | 86 ++++++++++++------- src/cmock_internals.h | 5 ++ test/project.yml | 1 - .../all_plugins_but_other_limits.yml | 16 +--- .../test_interactions/all_plugins_coexist.yml | 8 +- .../basic_expect_and_return.yml | 2 +- .../const_primitives_handling.yml | 5 +- .../fancy_pointer_handling.yml | 4 +- .../test_interactions/pointer_handling.yml | 4 +- .../return_thru_ptr_expect_any_args.yml | 2 +- .../return_thru_ptr_ignore_arg.yml | 2 +- .../unity_void_pointer_compare.yml | 16 ++-- .../void_pointer_no_array_plugin.yml | 8 +- ...oid_pointer_treat_as_void_array_plugin.yml | 12 +-- ...k_generator_plugin_return_thru_ptr_test.rb | 2 +- 18 files changed, 106 insertions(+), 80 deletions(-) diff --git a/examples/temp_sensor/src/TimerConfigurator.c b/examples/temp_sensor/src/TimerConfigurator.c index 2f5c659..02fa620 100644 --- a/examples/temp_sensor/src/TimerConfigurator.c +++ b/examples/temp_sensor/src/TimerConfigurator.c @@ -20,7 +20,7 @@ void Timer_Reset(void) AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS; AT91C_BASE_TC0->TC_IDR = 0xffffffff; dummy = AT91C_BASE_TC0->TC_SR; - dummy = dummy; + (void)dummy; } void Timer_ConfigureMode(void) diff --git a/lib/cmock_generator_plugin_expect.rb b/lib/cmock_generator_plugin_expect.rb index 2255012..439b5bf 100644 --- a/lib/cmock_generator_plugin_expect.rb +++ b/lib/cmock_generator_plugin_expect.rb @@ -31,7 +31,7 @@ class CMockGeneratorPluginExpect lines << " #{function[:return][:type]} ReturnVal;\n" unless function[:return][:void?] lines << " int CallOrder;\n" if @ordered function[:args].each do |arg| - lines << " #{arg[:volatile?] ? "volatile #{arg[:type]}" : arg[:type]} Expected_#{arg[:name]};\n" + lines << " #{arg[:type]} Expected_#{arg[:name]};\n" end lines end diff --git a/lib/cmock_generator_plugin_return_thru_ptr.rb b/lib/cmock_generator_plugin_return_thru_ptr.rb index 85eb5f7..3a1aa62 100644 --- a/lib/cmock_generator_plugin_return_thru_ptr.rb +++ b/lib/cmock_generator_plugin_return_thru_ptr.rb @@ -72,6 +72,11 @@ class CMockGeneratorPluginReturnThruPtr lines end + def as_void_ptr(arg, arg_name) + # volatile pointers use CMOCK_DEVOLATILE_PTR to avoid -Wcast-qual + arg[:volatile?] ? "CMOCK_DEVOLATILE_PTR(#{arg_name})" : "(void*)#{arg_name}" + end + def mock_precheck_return_thru_ptr(function) return '' unless @ignore_used @@ -84,7 +89,7 @@ class CMockGeneratorPluginReturnThruPtr lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Used)\n" lines << " {\n" lines << " UNITY_TEST_ASSERT_NOT_NULL(#{arg_name}, cmock_line, CMockStringPtrIsNULL);\n" - lines << " CMOCK_MEMCPY((void*)#{arg_name}, (const void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n" + lines << " CMOCK_MEMCPY(#{as_void_ptr(arg, arg_name)}, (const void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n" lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size);\n" lines << " }\n" end @@ -138,7 +143,7 @@ class CMockGeneratorPluginReturnThruPtr lines << " if (cmock_call_instance->ReturnThruPtr_#{arg_name}_Used)\n" lines << " {\n" lines << " UNITY_TEST_ASSERT_NOT_NULL(#{arg_name}, cmock_line, CMockStringPtrIsNULL);\n" - lines << " CMOCK_MEMCPY((void*)#{arg_name}, (const void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n" + lines << " CMOCK_MEMCPY(#{as_void_ptr(arg, arg_name)}, (const void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n" lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size);\n" lines << " }\n" end diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb index edd7db7..59556f6 100644 --- a/lib/cmock_generator_utils.rb +++ b/lib/cmock_generator_utils.rb @@ -96,7 +96,16 @@ class CMockGeneratorUtils def code_assign_argument_quickly(dest, arg) if arg[:ptr?] || @treat_as.include?(arg[:type]) - cast = arg[:array_dims] ? "(#{arg[:type]})" : '' + # For volatile pointer args, cast through CMOCK_MEM_PTR_AS_INT (a pointer-sized + # integer) to avoid -Wdiscarded-qualifiers when storing in a non-volatile Expected_ + # struct field. + cast = if arg[:volatile?] + "(#{arg[:type]})(CMOCK_MEM_PTR_AS_INT)" + elsif arg[:array_dims] + "(#{arg[:type]})" + else + '' + end " #{dest} = #{cast}#{arg[:name]};\n" else assert_expr = "sizeof(#{arg[:name]}) == sizeof(#{arg[:type]}) ? 1 : -1" @@ -173,6 +182,18 @@ class CMockGeneratorUtils # private ###################### + # Returns the C expression for the actual arg when passed to Unity assertion macros. + # Unity macros cast actuals to UNITY_INTERNAL_PTR (const void*), which drops volatile. + # For volatile pointer args, CMOCK_DEVOLATILE_PTR routes through a pointer-sized integer + # to avoid -Wcast-qual. + def actual_arg_expr(arg, pre, arg_name) + if arg[:volatile?] && pre.empty? + "CMOCK_DEVOLATILE_PTR(#{arg_name})" + else + "#{pre}#{arg_name}" + end + end + def lookup_expect_type(_function, arg) c_type = arg[:type] arg_name = arg[:name] @@ -217,6 +238,7 @@ class CMockGeneratorUtils def code_verify_an_arg_expectation_with_no_arrays(function, arg) c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg) + actual_arg = actual_arg_expr(arg, pre, arg_name) elem_size = ptr_to_array_elem_size(arg, c_type) lines = '' lines << " if (!#{ignore})\n" if @ignore_arg @@ -225,27 +247,27 @@ class CMockGeneratorUtils case unity_func when 'UNITY_TEST_ASSERT_EQUAL_MEMORY' c_type_local = c_type.gsub(/\*$/, '') - lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{pre}#{arg_name}, sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n" + lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{actual_arg}, sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n" when 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY' if pre == '&' - lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{pre}#{arg_name}, #{elem_size}, cmock_line, CMockStringMismatch);\n" + lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{actual_arg}, #{elem_size}, cmock_line, CMockStringMismatch);\n" else lines << " if (#{pre}#{expected} == NULL)\n" - lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n" + lines << " { UNITY_TEST_ASSERT_NULL(#{actual_arg}, cmock_line, CMockStringExpNULL); }\n" lines << " else\n" - lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{pre}#{arg_name}, #{elem_size}, cmock_line, CMockStringMismatch); }\n" + lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{actual_arg}, #{elem_size}, cmock_line, CMockStringMismatch); }\n" end when /_ARRAY/ if pre == '&' - lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, CMockStringMismatch);\n" + lines << " #{unity_func}(#{pre}#{expected}, #{actual_arg}, 1, cmock_line, CMockStringMismatch);\n" else lines << " if (#{pre}#{expected} == NULL)\n" - lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n" + lines << " { UNITY_TEST_ASSERT_NULL(#{actual_arg}, cmock_line, CMockStringExpNULL); }\n" lines << " else\n" - lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, CMockStringMismatch); }\n" + lines << " { #{unity_func}(#{pre}#{expected}, #{actual_arg}, 1, cmock_line, CMockStringMismatch); }\n" end else - lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n" + lines << " #{unity_func}(#{pre}#{expected}, #{actual_arg}, cmock_line, CMockStringMismatch);\n" end lines << " }\n" lines @@ -253,6 +275,7 @@ class CMockGeneratorUtils def code_verify_an_arg_expectation_with_normal_arrays(function, arg) c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg) + actual_arg = actual_arg_expr(arg, pre, arg_name) depth_name = arg[:ptr?] || arg[:string?] ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1 elem_size = ptr_to_array_elem_size(arg, c_type) lines = '' @@ -262,33 +285,33 @@ class CMockGeneratorUtils case unity_func when 'UNITY_TEST_ASSERT_EQUAL_MEMORY' c_type_local = c_type.gsub(/\*$/, '') - lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{pre}#{arg_name}, sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n" + lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{actual_arg}, sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n" when 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY' if pre == '&' - lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{pre}#{arg_name}, #{elem_size}, cmock_line, CMockStringMismatch);\n" + lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{actual_arg}, #{elem_size}, cmock_line, CMockStringMismatch);\n" else lines << " if (#{pre}#{expected} == NULL)\n" - lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n" + lines << " { UNITY_TEST_ASSERT_NULL(#{actual_arg}, cmock_line, CMockStringExpNULL); }\n" lines << " else\n" - lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(#{pre}#{expected}, #{pre}#{arg_name}, #{elem_size}, #{depth_name}, cmock_line, CMockStringMismatch); }\n" + lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(#{pre}#{expected}, #{actual_arg}, #{elem_size}, #{depth_name}, cmock_line, CMockStringMismatch); }\n" end when /_ARRAY/ if pre == '&' - lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch);\n" + lines << " #{unity_func}(#{pre}#{expected}, #{actual_arg}, #{depth_name}, cmock_line, CMockStringMismatch);\n" else lines << " if (#{pre}#{expected} == NULL)\n" - lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n" + lines << " { UNITY_TEST_ASSERT_NULL(#{actual_arg}, cmock_line, CMockStringExpNULL); }\n" lines << " else\n" - lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch); }\n" + lines << " { #{unity_func}(#{pre}#{expected}, #{actual_arg}, #{depth_name}, cmock_line, CMockStringMismatch); }\n" end else if arg[:string?] lines << " if (#{depth_name} == 0)\n" - lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" + lines << " { #{unity_func}(#{pre}#{expected}, #{actual_arg}, cmock_line, CMockStringMismatch); }\n" lines << " else\n" - lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY((const void*)(#{pre}#{expected}), (const void*)(#{pre}#{arg_name}), (UNITY_UINT32)(#{depth_name}), cmock_line, CMockStringMismatch); }\n" + lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY((const void*)(#{pre}#{expected}), (const void*)(#{actual_arg}), (UNITY_UINT32)(#{depth_name}), cmock_line, CMockStringMismatch); }\n" else - lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n" + lines << " #{unity_func}(#{pre}#{expected}, #{actual_arg}, cmock_line, CMockStringMismatch);\n" end end lines << " }\n" @@ -297,6 +320,7 @@ class CMockGeneratorUtils def code_verify_an_arg_expectation_with_smart_arrays(function, arg) c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg) + actual_arg = actual_arg_expr(arg, pre, arg_name) depth_name = arg[:ptr?] || arg[:string?] ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1 elem_size = ptr_to_array_elem_size(arg, c_type) lines = '' @@ -306,35 +330,35 @@ class CMockGeneratorUtils case unity_func when 'UNITY_TEST_ASSERT_EQUAL_MEMORY' c_type_local = c_type.gsub(/\*$/, '') - lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{pre}#{arg_name}, sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n" + lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY(#{pre}#{expected}, #{actual_arg}, sizeof(#{c_type_local}), cmock_line, CMockStringMismatch);\n" when 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY' if pre == '&' - lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(#{pre}#{expected}, #{pre}#{arg_name}, #{elem_size}, #{depth_name}, cmock_line, CMockStringMismatch);\n" + lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(#{pre}#{expected}, #{actual_arg}, #{elem_size}, #{depth_name}, cmock_line, CMockStringMismatch);\n" else lines << " if (#{pre}#{expected} == NULL)\n" - lines << " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, CMockStringExpNULL); }\n" - lines << (depth_name != 1 ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" : '') + lines << " { UNITY_TEST_ASSERT_NULL(#{actual_arg}, cmock_line, CMockStringExpNULL); }\n" + lines << (depth_name != 1 ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{actual_arg}, cmock_line, CMockStringMismatch); }\n" : '') lines << " else\n" - lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(#{pre}#{expected}, #{pre}#{arg_name}, #{elem_size}, #{depth_name}, cmock_line, CMockStringMismatch); }\n" + lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(#{pre}#{expected}, #{actual_arg}, #{elem_size}, #{depth_name}, cmock_line, CMockStringMismatch); }\n" end when /_ARRAY/ if pre == '&' - lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch);\n" + lines << " #{unity_func}(#{pre}#{expected}, #{actual_arg}, #{depth_name}, cmock_line, CMockStringMismatch);\n" else lines << " if (#{pre}#{expected} == NULL)\n" - lines << " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, CMockStringExpNULL); }\n" - lines << (depth_name != 1 ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" : '') + lines << " { UNITY_TEST_ASSERT_NULL(#{actual_arg}, cmock_line, CMockStringExpNULL); }\n" + lines << (depth_name != 1 ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{actual_arg}, cmock_line, CMockStringMismatch); }\n" : '') lines << " else\n" - lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, CMockStringMismatch); }\n" + lines << " { #{unity_func}(#{pre}#{expected}, #{actual_arg}, #{depth_name}, cmock_line, CMockStringMismatch); }\n" end else if arg[:string?] lines << " if (#{depth_name} == 0)\n" - lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" + lines << " { #{unity_func}(#{pre}#{expected}, #{actual_arg}, cmock_line, CMockStringMismatch); }\n" lines << " else\n" - lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY((const void*)(#{pre}#{expected}), (const void*)(#{pre}#{arg_name}), (UNITY_UINT32)(#{depth_name}), cmock_line, CMockStringMismatch); }\n" + lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY((const void*)(#{pre}#{expected}), (const void*)(#{actual_arg}), (UNITY_UINT32)(#{depth_name}), cmock_line, CMockStringMismatch); }\n" else - lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch);\n" + lines << " #{unity_func}(#{pre}#{expected}, #{actual_arg}, cmock_line, CMockStringMismatch);\n" end end lines << " }\n" diff --git a/src/cmock_internals.h b/src/cmock_internals.h index 118e28c..07814db 100644 --- a/src/cmock_internals.h +++ b/src/cmock_internals.h @@ -95,6 +95,11 @@ extern const char* CMockStringMismatch; #define CMOCK_MEM_SIZE (32768) #endif +/* Cast a volatile pointer to void* for use with CMOCK_MEMCPY or Unity assertion + * macros. Routing through CMOCK_MEM_PTR_AS_INT (a pointer-sized integer) avoids + * -Wcast-qual without requiring compiler-specific pragmas or C99 intptr_t. */ +#define CMOCK_DEVOLATILE_PTR(p) ((void*)(CMOCK_MEM_PTR_AS_INT)(p)) + /* memory copy/set functions used by CMock internals and generated mocks. * Override to use custom implementations on targets without standard libc. */ #if !defined(CMOCK_MEMCPY) || !defined(CMOCK_MEMSET) diff --git a/test/project.yml b/test/project.yml index 336bbcb..bcc8816 100644 --- a/test/project.yml +++ b/test/project.yml @@ -14,7 +14,6 @@ - './system/generated/' :include: - './system/generated/' - - '../examples/test/' - '../src/' - '../vendor/unity/src/' - '../vendor/c_exception/lib/' diff --git a/test/system/test_interactions/all_plugins_but_other_limits.yml b/test/system/test_interactions/all_plugins_but_other_limits.yml index eb495d7..0aabbe3 100644 --- a/test/system/test_interactions/all_plugins_but_other_limits.yml +++ b/test/system/test_interactions/all_plugins_but_other_limits.yml @@ -200,9 +200,7 @@ :code: | test() { - const char* constretval = "This is a\0 silly string"; - char* retval = (char*)constretval; - bars_ExpectAndReturn(retval); + bars_ExpectAndReturn("This is a\0 silly string"); foos_Expect("This is a\0 wacky string"); function_c(); @@ -213,9 +211,7 @@ :code: | test() { - const char* constretval = "This is a silly string"; - char* retval = (char*)constretval; - bars_ExpectAndReturn(retval); + bars_ExpectAndReturn("This is a silly string"); foos_Expect("This is a wacky string"); function_c(); @@ -274,9 +270,7 @@ :code: | test() { - const char* constretval = "This is a\0 silly string"; - char* retval = (char*)constretval; - bars_ExpectAndReturn(retval); + bars_ExpectAndReturn("This is a\0 silly string"); foos_ExpectAndThrow("This is a\0 wacky string", 55); foos_Expect("err"); @@ -288,9 +282,7 @@ :code: | test() { - const char* constretval = "This is a\0 silly string"; - char* retval = (char*)constretval; - bars_ExpectAndReturn(retval); + bars_ExpectAndReturn("This is a\0 silly string"); foos_ExpectAndThrow("This is a\0 wacky string", 55); foos_Expect("wrong error"); diff --git a/test/system/test_interactions/all_plugins_coexist.yml b/test/system/test_interactions/all_plugins_coexist.yml index 39b6668..d37756e 100644 --- a/test/system/test_interactions/all_plugins_coexist.yml +++ b/test/system/test_interactions/all_plugins_coexist.yml @@ -216,7 +216,7 @@ test() { const char* retval = "This is a\0 silly string"; - bars_ExpectAndReturn((char*)retval); + bars_ExpectAndReturn(retval); foos_Expect("This is a\0 wacky string"); function_c(); @@ -228,7 +228,7 @@ test() { const char* retval = "This is a silly string"; - bars_ExpectAndReturn((char*)retval); + bars_ExpectAndReturn(retval); foos_Expect("This is a wacky string"); function_c(); @@ -288,7 +288,7 @@ test() { const char* retval = "This is a\0 silly string"; - bars_ExpectAndReturn((char*)retval); + bars_ExpectAndReturn(retval); foos_ExpectAndThrow("This is a\0 wacky string", 55); foos_Expect("err"); @@ -301,7 +301,7 @@ test() { const char* retval = "This is a\0 silly string"; - bars_ExpectAndReturn((char*)retval); + bars_ExpectAndReturn(retval); foos_ExpectAndThrow("This is a\0 wacky string", 55); foos_Expect("wrong error"); diff --git a/test/system/test_interactions/basic_expect_and_return.yml b/test/system/test_interactions/basic_expect_and_return.yml index 198b776..b1a92d9 100644 --- a/test/system/test_interactions/basic_expect_and_return.yml +++ b/test/system/test_interactions/basic_expect_and_return.yml @@ -96,7 +96,7 @@ test() { const char* retval = "moe"; - foo_char_strings_ExpectAndReturn("larry", "curly", (char*)retval); + foo_char_strings_ExpectAndReturn("larry", "curly", retval); TEST_ASSERT_EQUAL_STRING("moe", function_d("larry", "curly")); } diff --git a/test/system/test_interactions/const_primitives_handling.yml b/test/system/test_interactions/const_primitives_handling.yml index 83b285a..4be2b8a 100644 --- a/test/system/test_interactions/const_primitives_handling.yml +++ b/test/system/test_interactions/const_primitives_handling.yml @@ -68,8 +68,9 @@ :code: | test() { + char wrong_param2 = 'X'; foo_Expect( A, B, C ); - exercise_const1( (const char*)B, (char * const)A, C ); + exercise_const1( (const char*)B, &wrong_param2, C ); } - :pass: FALSE @@ -87,7 +88,7 @@ test() { bar_Expect( A, B, C ); - exercise_const2( A, (char * const)C, (const char *)B ); + exercise_const2( C, B, A ); } diff --git a/test/system/test_interactions/fancy_pointer_handling.yml b/test/system/test_interactions/fancy_pointer_handling.yml index 1839da4..5e8e957 100644 --- a/test/system/test_interactions/fancy_pointer_handling.yml +++ b/test/system/test_interactions/fancy_pointer_handling.yml @@ -165,7 +165,7 @@ test() { const char* retval = "This is a\0 silly string"; - bars_ExpectAndReturn((char*)retval); + bars_ExpectAndReturn(retval); foos_Expect("This is a\0 wacky string"); function_c(); @@ -177,7 +177,7 @@ test() { const char* retval = "This is a silly string"; - bars_ExpectAndReturn((char*)retval); + bars_ExpectAndReturn(retval); foos_Expect("This is a wacky string"); function_c(); diff --git a/test/system/test_interactions/pointer_handling.yml b/test/system/test_interactions/pointer_handling.yml index dd7d482..74a83a3 100644 --- a/test/system/test_interactions/pointer_handling.yml +++ b/test/system/test_interactions/pointer_handling.yml @@ -233,7 +233,7 @@ test() { const char* retval = "This is a\0 silly string"; - bars_ExpectAndReturn((char*)retval); + bars_ExpectAndReturn(retval); foos_Expect("This is a\0 wacky string"); function_b(); @@ -245,7 +245,7 @@ test() { const char* retval = "This is a silly string"; - bars_ExpectAndReturn((char*)retval); + bars_ExpectAndReturn(retval); foos_Expect("This is a wacky string"); function_b(); diff --git a/test/system/test_interactions/return_thru_ptr_expect_any_args.yml b/test/system/test_interactions/return_thru_ptr_expect_any_args.yml index 6a4f95d..f63040a 100644 --- a/test/system/test_interactions/return_thru_ptr_expect_any_args.yml +++ b/test/system/test_interactions/return_thru_ptr_expect_any_args.yml @@ -171,7 +171,7 @@ char r_a_ret[] = "FEEFI"; ptr_ret_array_Expect(r_a, lengthof(r_a)); - ptr_ret_array_ReturnArrayThruPtr_r(r_a_ret, (int)strlen(r_a_ret)); + ptr_ret_array_ReturnArrayThruPtr_r(r_a_ret, strlen(r_a_ret)); ptr_ret_array(r_a, lengthof(r_a)); TEST_ASSERT_EQUAL_STRING("FEEFIorooboo", r_a); } diff --git a/test/system/test_interactions/return_thru_ptr_ignore_arg.yml b/test/system/test_interactions/return_thru_ptr_ignore_arg.yml index ac3c681..508a185 100644 --- a/test/system/test_interactions/return_thru_ptr_ignore_arg.yml +++ b/test/system/test_interactions/return_thru_ptr_ignore_arg.yml @@ -173,7 +173,7 @@ char r_a_ret[] = "FEEFI"; ptr_ret_array_Expect(r_a, lengthof(r_a)); - ptr_ret_array_ReturnArrayThruPtr_r(r_a_ret, (int)strlen(r_a_ret)); + ptr_ret_array_ReturnArrayThruPtr_r(r_a_ret, strlen(r_a_ret)); ptr_ret_array(r_a, lengthof(r_a)); TEST_ASSERT_EQUAL_STRING("FEEFIorooboo", r_a); } diff --git a/test/system/test_interactions/unity_void_pointer_compare.yml b/test/system/test_interactions/unity_void_pointer_compare.yml index 33a4eb7..8be54af 100644 --- a/test/system/test_interactions/unity_void_pointer_compare.yml +++ b/test/system/test_interactions/unity_void_pointer_compare.yml @@ -45,8 +45,8 @@ :code: | test() { - char* a = (char*)("Hello"); - char* b = (char*)("Hello"); + char a[] = "Hello"; + char b[] = "Hello"; ret_v_ptr_ExpectAndReturn(a); get_v_ptr_Expect(b); get_v_ptr_typedefed_Expect((VOID_PTR)b); @@ -59,8 +59,8 @@ :code: | test() { - char* a = (char*)("Hello"); - char* b = (char*)("Hello"); + char a[] = "Hello"; + char b[] = "Hello"; ret_v_ptr_ExpectAndReturn(a); get_v_ptr_ExpectWithArray(b,5); get_v_ptr_typedefed_ExpectWithArray((VOID_PTR)b,5); @@ -73,8 +73,8 @@ :code: | test() { - char* a = (char*)("Hello"); - char* b = (char*)("Jello"); + char a[] = "Hello"; + char b[] = "Jello"; ret_v_ptr_ExpectAndReturn(a); get_v_ptr_Expect(b); get_v_ptr_typedefed_Expect((VOID_PTR)b); @@ -87,8 +87,8 @@ :code: | test() { - char* a = (char*)("Hello"); - char* b = (char*)("Hella"); + char a[] = "Hello"; + char b[] = "Hella"; ret_v_ptr_ExpectAndReturn(a); get_v_ptr_ExpectWithArray(b,5); get_v_ptr_typedefed_ExpectWithArray((VOID_PTR)b,5); diff --git a/test/system/test_interactions/void_pointer_no_array_plugin.yml b/test/system/test_interactions/void_pointer_no_array_plugin.yml index aed837f..5b65f91 100644 --- a/test/system/test_interactions/void_pointer_no_array_plugin.yml +++ b/test/system/test_interactions/void_pointer_no_array_plugin.yml @@ -54,7 +54,7 @@ :code: | test() { - char* a = (char*)("Hello"); + char a[] = "Hello"; get_v_ptr_Expect(a); function_a(a); } @@ -84,7 +84,7 @@ :code: | test() { - char* a = (char*)("Hello"); + char a[] = "Hello"; get_v_ptr_Expect(NULL); function_a(a); } @@ -94,7 +94,7 @@ :code: | test() { - char* a = (char*)("Hello"); + char a[] = "Hello"; get_const_v_ptr_Expect(a); function_b(a); } @@ -115,7 +115,7 @@ :code: | test() { - char* a = (char*)("Hello"); + char a[] = "Hello"; get_my_void_ptr_Expect(a); function_c(a); } diff --git a/test/system/test_interactions/void_pointer_treat_as_void_array_plugin.yml b/test/system/test_interactions/void_pointer_treat_as_void_array_plugin.yml index 3c5f173..1d9d1f3 100644 --- a/test/system/test_interactions/void_pointer_treat_as_void_array_plugin.yml +++ b/test/system/test_interactions/void_pointer_treat_as_void_array_plugin.yml @@ -43,7 +43,7 @@ :code: | test() { - char* a = (char*)("Hello"); + char a[] = "Hello"; get_my_void_ptr_Expect(a); function_a(a); } @@ -53,8 +53,8 @@ :code: | test() { - char* a = (char*)("Hello"); - char* b = (char*)("Hello"); + char a[] = "Hello"; + char b[] = "Hello"; get_my_void_ptr_ExpectWithArray(a, 5); function_a(b); } @@ -64,8 +64,8 @@ :code: | test() { - char* a = (char*)("Hello"); - char* b = (char*)("Jello"); + char a[] = "Hello"; + char b[] = "Jello"; get_my_void_ptr_ExpectWithArray(a, 5); function_a(b); } @@ -84,7 +84,7 @@ :code: | test() { - char* a = (char*)("Hello"); + char a[] = "Hello"; get_my_void_ptr_ExpectWithArray(a, 0); function_a(a); } diff --git a/test/unit/cmock_generator_plugin_return_thru_ptr_test.rb b/test/unit/cmock_generator_plugin_return_thru_ptr_test.rb index 61852bc..698bac0 100644 --- a/test/unit/cmock_generator_plugin_return_thru_ptr_test.rb +++ b/test/unit/cmock_generator_plugin_return_thru_ptr_test.rb @@ -260,7 +260,7 @@ describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnTh " if (cmock_call_instance->ReturnThruPtr_foo_handle_Used)\n" + " {\n" + " UNITY_TEST_ASSERT_NOT_NULL(foo_handle, cmock_line, CMockStringPtrIsNULL);\n" + - " CMOCK_MEMCPY((void*)foo_handle, (const void*)cmock_call_instance->ReturnThruPtr_foo_handle_Val,\n" + + " CMOCK_MEMCPY(CMOCK_DEVOLATILE_PTR(foo_handle), (const void*)cmock_call_instance->ReturnThruPtr_foo_handle_Val,\n" + " cmock_call_instance->ReturnThruPtr_foo_handle_Size);\n" + " }\n"