mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-11-10 01:30:36 +00:00
Fix some issues that windows noticed with volatile handling.
Improve some docs.
This commit is contained in:
+23
-3
@@ -189,7 +189,7 @@ care how many times it was called, right?
|
||||
StopIgnore:
|
||||
-------
|
||||
|
||||
Maybe you want to ignore a particular function for part of a test but dont want to
|
||||
Maybe you want to ignore a particular function for part of a test but don't want to
|
||||
ignore it later on. In that case, you want to use StopIgnore which will cancel the
|
||||
previously called Ignore or IgnoreAndReturn requiring you to Expect or otherwise
|
||||
handle the call to a function.
|
||||
@@ -199,6 +199,25 @@ handle the call to a function.
|
||||
* `retval func(void)` => `void func_StopIgnore(void)`
|
||||
* `retval func(params)` => `void func_StopIgnore(void)`
|
||||
|
||||
It's important to note that the effect of this function is immediate and applies to
|
||||
this function's stack of expectations. So the following will work as intended:
|
||||
|
||||
```
|
||||
Blah_Ignore();
|
||||
funcThatMightCallBlahButWeDoNotCare();
|
||||
Blah_StopIgnore();
|
||||
funcThatWeWantToMakeSureDoesNotCallBlah();
|
||||
```
|
||||
|
||||
But this is NOT going to work, because StopIgnore immediately cancels ignore:
|
||||
|
||||
```
|
||||
Blah_Ignore();
|
||||
Blah_StopIgnore();
|
||||
funcThatMightCallBlahButWeDoNotCare();
|
||||
funcThatWeWantToMakeSureDoesNotCallBlah();
|
||||
```
|
||||
|
||||
IgnoreStateless:
|
||||
----------------
|
||||
|
||||
@@ -951,8 +970,9 @@ that exposes them as virtual methods and modify your code to inject mocks at
|
||||
run-time... but there is another way!
|
||||
|
||||
Simply use CMock to mock the static member methods and a C++ mocking framework
|
||||
to handle the virtual methods. (Yes, you can mix mocks from CMock and a C++
|
||||
mocking framework together in the same test!)
|
||||
to handle the virtual methods. CMock does NOT mock non-static members. For those,
|
||||
you'll need an actual C++ mocking framework. (Yes, you can mix mocks from CMock
|
||||
and a C++ mocking framework together in the same test!)
|
||||
|
||||
Keep in mind that since C++ mocking frameworks often link the real object to the
|
||||
unit test too, we need to resolve multiple definition errors with something like
|
||||
|
||||
@@ -80,12 +80,11 @@ class CMockGeneratorPluginReturnThruPtr
|
||||
arg_name = arg[:name]
|
||||
next unless @utils.ptr_or_str?(arg[:type]) && !(arg[:const?])
|
||||
|
||||
dest_cast = arg[:volatile?] ? '(void*)(CMOCK_MEM_PTR_AS_INT)' : '(void*)'
|
||||
lines << " if (Mock.#{function[:name]}_IgnoreBool && cmock_call_instance != NULL &&\n"
|
||||
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(#{dest_cast}#{arg_name}, (const void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n"
|
||||
lines << " CMOCK_MEMCPY((void*)#{arg_name}, (const void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n"
|
||||
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size);\n"
|
||||
lines << " }\n"
|
||||
end
|
||||
@@ -136,11 +135,10 @@ class CMockGeneratorPluginReturnThruPtr
|
||||
arg_name = arg[:name]
|
||||
next unless @utils.ptr_or_str?(arg[:type]) && !(arg[:const?])
|
||||
|
||||
dest_cast = arg[:volatile?] ? '(void*)(CMOCK_MEM_PTR_AS_INT)' : '(void*)'
|
||||
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(#{dest_cast}#{arg_name}, (const void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n"
|
||||
lines << " CMOCK_MEMCPY((void*)#{arg_name}, (const void*)cmock_call_instance->ReturnThruPtr_#{arg_name}_Val,\n"
|
||||
lines << " cmock_call_instance->ReturnThruPtr_#{arg_name}_Size);\n"
|
||||
lines << " }\n"
|
||||
end
|
||||
|
||||
@@ -253,14 +253,14 @@ describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnTh
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
it "uses (void*)(CMOCK_MEM_PTR_AS_INT) cast in mock_implementation for volatile pointer arg" do
|
||||
it "uses (void*) cast in mock_implementation for volatile pointer arg" do
|
||||
volatile_ptr_func_expect()
|
||||
|
||||
expected =
|
||||
" if (cmock_call_instance->ReturnThruPtr_foo_handle_Used)\n" +
|
||||
" {\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(foo_handle, cmock_line, CMockStringPtrIsNULL);\n" +
|
||||
" CMOCK_MEMCPY((void*)(CMOCK_MEM_PTR_AS_INT)foo_handle, (const void*)cmock_call_instance->ReturnThruPtr_foo_handle_Val,\n" +
|
||||
" CMOCK_MEMCPY((void*)foo_handle, (const void*)cmock_call_instance->ReturnThruPtr_foo_handle_Val,\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_foo_handle_Size);\n" +
|
||||
" }\n"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user