Browse Source

Add test for lib utils

tags/1.9.4
falkTX 10 years ago
parent
commit
d52cfbdf8a
3 changed files with 32 additions and 9 deletions
  1. +26
    -5
      source/tests/CarlaUtils.cpp
  2. +5
    -3
      source/utils/CarlaLibUtils.hpp
  3. +1
    -1
      source/utils/CarlaShmUtils.hpp

+ 26
- 5
source/tests/CarlaUtils.cpp View File

@@ -36,6 +36,7 @@
#include "CarlaLv2Utils.hpp" #include "CarlaLv2Utils.hpp"
#include "CarlaVstUtils.hpp" #include "CarlaVstUtils.hpp"


#include "CarlaLibUtils.hpp"
#include "CarlaShmUtils.hpp" #include "CarlaShmUtils.hpp"


// used in dssi utils // used in dssi utils
@@ -46,14 +47,13 @@


// #include "CarlaBridgeUtils.hpp" // #include "CarlaBridgeUtils.hpp"
// #include "CarlaJuceUtils.hpp" // #include "CarlaJuceUtils.hpp"
// #include "CarlaLibUtils.hpp"
// #include "CarlaOscUtils.hpp" // #include "CarlaOscUtils.hpp"
// #include "CarlaStateUtils.hpp" // #include "CarlaStateUtils.hpp"


#if 0 #if 0
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


static void test_CarlaUtils() noexcept
static void test_CarlaUtils()
{ {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// misc functions // misc functions
@@ -493,7 +493,7 @@ static void test_CarlaEngineUtils() noexcept


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


static void test_CarlaLadspaUtils() noexcept
static void test_CarlaLadspaUtils()
{ {
LADSPA_Descriptor desc; LADSPA_Descriptor desc;
carla_zeroStruct(desc); carla_zeroStruct(desc);
@@ -550,7 +550,7 @@ static LV2_URID test_lv2_uridMap(LV2_URID_Map_Handle, const char*)
return 1; return 1;
} }


static void test_CarlaLv2Utils() noexcept
static void test_CarlaLv2Utils()
{ {
Lv2WorldClass& lv2World(Lv2WorldClass::getInstance()); Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
lv2World.initIfNeeded(); 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 { struct ShmStruct {
char stringStart[255]; char stringStart[255];
bool boolean; bool boolean;
@@ -709,6 +728,7 @@ static void test_CarlaShmUtils() noexcept
assert(! carla_is_shm_valid(shm)); assert(! carla_is_shm_valid(shm));
assert(! carla_is_shm_valid(shma)); assert(! carla_is_shm_valid(shma));
} }
#endif


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// main // main
@@ -729,7 +749,8 @@ int main()
test_CarlaVstUtils(); test_CarlaVstUtils();
#endif #endif


test_CarlaShmUtils();
test_CarlaLibUtils();
//test_CarlaShmUtils();


return 0; return 0;
} }


+ 5
- 3
source/utils/CarlaLibUtils.hpp View File

@@ -94,9 +94,11 @@ const char* lib_error(const char* const filename) noexcept
carla_zeroChar(libError, 2048+1); carla_zeroChar(libError, 2048+1);


try { 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); std::snprintf(libError, 2048, "%s: error code %li: %s", filename, winErrorCode, (const char*)winErrorString);
::LocalFree(winErrorString); ::LocalFree(winErrorString);


+ 1
- 1
source/utils/CarlaShmUtils.hpp View File

@@ -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. * @note One shared memory object can only have one mapping at a time.
*/ */
static inline static inline


Loading…
Cancel
Save