diff options
author | Adam Domurad <[email protected]> | 2012-12-20 11:28:28 -0500 |
---|---|---|
committer | Adam Domurad <[email protected]> | 2012-12-20 11:28:28 -0500 |
commit | 04a95e4790705edd9d0997db94176dc19f326729 (patch) | |
tree | 2cae4c4bdab8d8a81f4ff2f19b0363afa0a95b55 /tests/cpp-unit-tests/browser_mock.cc | |
parent | a0b5dd482361349be15b1787103eda7930e59adb (diff) |
C++ unit testing: Add a tracked-allocation implementation of operator-new
Two tests that catch memory leaks are also added.
For the purposes of verifying the patch works, the fix is in a separate changeset.
Diffstat (limited to 'tests/cpp-unit-tests/browser_mock.cc')
-rw-r--r-- | tests/cpp-unit-tests/browser_mock.cc | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/cpp-unit-tests/browser_mock.cc b/tests/cpp-unit-tests/browser_mock.cc index 040910b..6b01224 100644 --- a/tests/cpp-unit-tests/browser_mock.cc +++ b/tests/cpp-unit-tests/browser_mock.cc @@ -37,7 +37,7 @@ // Browser mock functions. Add more as needed. #include <cstring> -#include <set> +#include "checked_allocations.h" #include "UnitTest++.h" @@ -45,7 +45,7 @@ #include "IcedTeaNPPlugin.h" -static std::set<void*> __allocations; +static AllocationSet __allocations; // It is expected that these will only run during a unit test static void* mock_memalloc(uint32_t size) { @@ -63,11 +63,29 @@ static void mock_memfree(void* ptr) { } } +static NPObject* mock_retainobject(NPObject* obj) { + obj->referenceCount++; + return obj; +} + +static void mock_releaseobject(NPObject* obj) { + if (--(obj->referenceCount) == 0) { + if (obj->_class->deallocate) { + obj->_class->deallocate(obj); + } else { + free(obj); + } + } +} + void browsermock_setup_functions() { memset(&browser_functions, 0, sizeof(NPNetscapeFuncs)); browser_functions.memalloc = &mock_memalloc; browser_functions.memfree = &mock_memfree; + + browser_functions.retainobject = &mock_retainobject; + browser_functions.releaseobject= &mock_releaseobject; } void browsermock_clear_state() { |