diff options
Diffstat (limited to 'tests/cpp-unit-tests')
-rw-r--r-- | tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc | 14 | ||||
-rw-r--r-- | tests/cpp-unit-tests/browser_mock.cc | 12 |
2 files changed, 24 insertions, 2 deletions
diff --git a/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc b/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc index e8e9289..7df0a1e 100644 --- a/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc +++ b/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc @@ -34,15 +34,16 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ +#include <fstream> #include <UnitTest++.h> #include <npapi.h> #include "browser_mock.h" +#include "MemoryLeakDetector.h" #include "IcedTeaPluginUtils.h" #include "IcedTeaNPPlugin.h" -#include <fstream> TEST(NPVariantAsString) { NPVariant var; @@ -84,6 +85,17 @@ TEST(NPVariantStringCopy) { CHECK_EQUAL(0, browsermock_unfreed_allocations()); } +TEST(NPIdentifierAsString) { + // NB: Mocked definition of 'utf8fromidentifier' simply reads NPIdentifier as a char* string. + const char test_string[] = "foobar"; + MemoryLeakDetector leak_detector; + /* Ensure destruction */{ + std::string str = IcedTeaPluginUtilities::NPIdentifierAsString((NPIdentifier)test_string); + CHECK_EQUAL(test_string, str); + } + CHECK_EQUAL(0, leak_detector.memory_leaks()); +} + TEST(trim) { std::string toBeTrimmed = std::string(" testX "); IcedTeaPluginUtilities::trim (toBeTrimmed); diff --git a/tests/cpp-unit-tests/browser_mock.cc b/tests/cpp-unit-tests/browser_mock.cc index e333be7..8724687 100644 --- a/tests/cpp-unit-tests/browser_mock.cc +++ b/tests/cpp-unit-tests/browser_mock.cc @@ -90,6 +90,15 @@ static NPObject* mock_createobject(NPP instance, NPClass* np_class) { return obj; } +static NPUTF8* mock_utf8fromidentifier(NPIdentifier id) { + // Treat NPIdentifier (== void pointer) as a pointer to characters for simplicity + const NPUTF8* str = (const NPUTF8*) id; + // We expect this string to be freed with 'memfree' + NPUTF8* copy = (NPUTF8*) mock_memalloc(strlen(str) + 1); + memcpy(copy, str, strlen(str) + 1); + return copy; +} + void browsermock_setup_functions() { memset(&browser_functions, 0, sizeof(NPNetscapeFuncs)); @@ -98,7 +107,8 @@ void browsermock_setup_functions() { browser_functions.createobject = &mock_createobject; browser_functions.retainobject = &mock_retainobject; - browser_functions.releaseobject= &mock_releaseobject; + browser_functions.releaseobject = &mock_releaseobject; + browser_functions.utf8fromidentifier = &mock_utf8fromidentifier; } void browsermock_clear_state() { |