From b28badc80cd1f8893f21360678bc5e0df7eb8330 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 29 Apr 2025 09:49:10 +0200 Subject: Split unittest lanes.configure.allocator --- unit_tests/init_and_shutdown.cpp | 78 ++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 31 deletions(-) (limited to 'unit_tests/init_and_shutdown.cpp') diff --git a/unit_tests/init_and_shutdown.cpp b/unit_tests/init_and_shutdown.cpp index 764e294..f2de2a7 100644 --- a/unit_tests/init_and_shutdown.cpp +++ b/unit_tests/init_and_shutdown.cpp @@ -58,7 +58,7 @@ TEST_CASE("lanes.require 'lanes'") // ################################################################################################# // allocator should be "protected", a C function returning a suitable userdata, or nil -TEST_CASE("lanes.configure.allocator") +TEST_CASE("lanes.configure.allocator/bool_number_table_string") { LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; @@ -90,50 +90,33 @@ TEST_CASE("lanes.configure.allocator") // --------------------------------------------------------------------------------------------- - SECTION("allocator = ") - { - L.requireFailure("require 'lanes'.configure{allocator = function() return {}, 12, 'yoy' end}"); - } - - // --------------------------------------------------------------------------------------------- - - SECTION("allocator = ") - { - // a C function that doesn't return what we expect should cause an error too - // TODO: for some reason, we use os.getenv here because using 'print' as the culprit, the tests deadlock in Release builds - L.requireFailure("return type(require 'lanes'.configure{allocator = os.getenv})"); - } - - // --------------------------------------------------------------------------------------------- - SECTION("allocator = ") { // oops, a typo L.requireFailure("require 'lanes'.configure{allocator = 'Protected'}"); } +} + +// ################################################################################################# + +TEST_CASE("lanes.configure.allocator/bad_functions") +{ + LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; // --------------------------------------------------------------------------------------------- - SECTION("allocator = 'protected'") + SECTION("allocator = ") { - // no typo, should work - // TODO: Investigate why this test crashes when unloading lanes_core.dll when running against Lua 5.1 and Lua 5.2 RELEASE ONLY! - L.requireSuccess("require 'lanes'.configure{allocator = 'protected'}"); + L.requireFailure("require 'lanes'.configure{allocator = function() return {}, 12, 'yoy' end}"); } // --------------------------------------------------------------------------------------------- - SECTION("allocator = ") + SECTION("allocator = ") { - // a function that provides what we expect is fine - static constexpr lua_CFunction _provideAllocator = +[](lua_State* const L_) { - lanes::AllocatorDefinition* const _def{ new (L_) lanes::AllocatorDefinition{} }; - _def->initFrom(L_); - return 1; - }; - lua_pushcfunction(L, _provideAllocator); - lua_setglobal(L, "ProvideAllocator"); - L.requireSuccess("require 'lanes'.configure{allocator = ProvideAllocator}"); + // a C function that doesn't return what we expect should cause an error too + // TODO: for some reason, we use os.getenv here because using 'print' as the culprit, the tests deadlock in Release builds + L.requireFailure("return type(require 'lanes'.configure{allocator = os.getenv})"); } // --------------------------------------------------------------------------------------------- @@ -190,6 +173,39 @@ TEST_CASE("lanes.configure.allocator") } } +// ################################################################################################# + +TEST_CASE("lanes.configure.allocator/good_function") +{ + LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; + + SECTION("allocator = ") + { + // a function that provides what we expect is fine + static constexpr lua_CFunction _provideAllocator = +[](lua_State* const L_) { + lanes::AllocatorDefinition* const _def{ new (L_) lanes::AllocatorDefinition{} }; + _def->initFrom(L_); + return 1; + }; + lua_pushcfunction(L, _provideAllocator); + lua_setglobal(L, "ProvideAllocator"); + L.requireSuccess("require 'lanes'.configure{allocator = ProvideAllocator}"); + } +} + +// ################################################################################################# + +// TODO: Investigate why this test crashes when unloading lanes_core.dll when running against Lua 5.1 and Lua 5.2 RELEASE ONLY! +// apparently, the mutex of ProtectedAllocator is deemed still in use. Crash goes away if I don't use it in protected_lua_Alloc +TEST_CASE(("lanes.configure.allocator/protected")) +{ + LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; + + // no typo, should work + L.requireSuccess("require 'lanes'.configure{allocator = 'protected'}"); +} + + // ################################################################################################# TEST_CASE("lanes.configure.internal_allocator") -- cgit v1.2.3-55-g6feb