diff --git a/source/tests/CarlaUtils.cpp b/source/tests/CarlaUtils.cpp index 660348ed3..ba1b72f11 100644 --- a/source/tests/CarlaUtils.cpp +++ b/source/tests/CarlaUtils.cpp @@ -36,6 +36,7 @@ #include "CarlaLv2Utils.hpp" #include "CarlaVstUtils.hpp" +#include "CarlaLibUtils.hpp" #include "CarlaShmUtils.hpp" // used in dssi utils @@ -46,14 +47,13 @@ // #include "CarlaBridgeUtils.hpp" // #include "CarlaJuceUtils.hpp" -// #include "CarlaLibUtils.hpp" // #include "CarlaOscUtils.hpp" // #include "CarlaStateUtils.hpp" #if 0 // ----------------------------------------------------------------------- -static void test_CarlaUtils() noexcept +static void test_CarlaUtils() { // ------------------------------------------------------------------- // misc functions @@ -493,7 +493,7 @@ static void test_CarlaEngineUtils() noexcept // ----------------------------------------------------------------------- -static void test_CarlaLadspaUtils() noexcept +static void test_CarlaLadspaUtils() { LADSPA_Descriptor desc; carla_zeroStruct(desc); @@ -550,7 +550,7 @@ static LV2_URID test_lv2_uridMap(LV2_URID_Map_Handle, const char*) return 1; } -static void test_CarlaLv2Utils() noexcept +static void test_CarlaLv2Utils() { Lv2WorldClass& lv2World(Lv2WorldClass::getInstance()); lv2World.initIfNeeded(); @@ -608,6 +608,25 @@ static void test_CarlaVstUtils() noexcept // ----------------------------------------------------------------------- +static void test_CarlaLibUtils() noexcept +{ + void* const libNot = lib_open("/libzzzzz..."); + assert(libNot == nullptr); + carla_stdout("Force lib_open fail error results in: %s", lib_error("/libzzzzz...")); + + void* const lib = lib_open("/usr/lib/liblo.so"); + CARLA_SAFE_ASSERT_RETURN(lib != nullptr,); + + void* const libS = lib_symbol(lib, "lo_server_new"); + CARLA_SAFE_ASSERT(libS != nullptr); + + const bool closed = lib_close(lib); + CARLA_SAFE_ASSERT(closed); +} + +#if 0 +// ----------------------------------------------------------------------- + struct ShmStruct { char stringStart[255]; bool boolean; @@ -709,6 +728,7 @@ static void test_CarlaShmUtils() noexcept assert(! carla_is_shm_valid(shm)); assert(! carla_is_shm_valid(shma)); } +#endif // ----------------------------------------------------------------------- // main @@ -729,7 +749,8 @@ int main() test_CarlaVstUtils(); #endif - test_CarlaShmUtils(); + test_CarlaLibUtils(); + //test_CarlaShmUtils(); return 0; } diff --git a/source/utils/CarlaLibUtils.hpp b/source/utils/CarlaLibUtils.hpp index 26b9b1447..deeac6983 100644 --- a/source/utils/CarlaLibUtils.hpp +++ b/source/utils/CarlaLibUtils.hpp @@ -94,9 +94,11 @@ const char* lib_error(const char* const filename) noexcept carla_zeroChar(libError, 2048+1); try { - LPVOID winErrorString; - DWORD winErrorCode = ::GetLastError(); - ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, winErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&winErrorString, 0, nullptr); + const DWORD winErrorCode = ::GetLastError(); + const int winErrorFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS; + LPVOID winErrorString; + + ::FormatMessage(winErrorFlags, nullptr, winErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&winErrorString, 0, nullptr); std::snprintf(libError, 2048, "%s: error code %li: %s", filename, winErrorCode, (const char*)winErrorString); ::LocalFree(winErrorString); diff --git a/source/utils/CarlaShmUtils.hpp b/source/utils/CarlaShmUtils.hpp index 0c719b38c..f2369ee70 100644 --- a/source/utils/CarlaShmUtils.hpp +++ b/source/utils/CarlaShmUtils.hpp @@ -151,7 +151,7 @@ void carla_shm_close(shm_t& shm) noexcept } /* - * Map a shared memory object to @a size bytes and returns its address. + * Map a shared memory object to @a size bytes and return the memory address. * @note One shared memory object can only have one mapping at a time. */ static inline