aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-04-29 09:49:10 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2025-04-29 09:49:10 +0200
commitb28badc80cd1f8893f21360678bc5e0df7eb8330 (patch)
tree3ab1a276da77001f0e14fe58e468cd6ca1909a07
parent58b44326ad2aaae710797745b800c61f65725ebb (diff)
downloadlanes-b28badc80cd1f8893f21360678bc5e0df7eb8330.tar.gz
lanes-b28badc80cd1f8893f21360678bc5e0df7eb8330.tar.bz2
lanes-b28badc80cd1f8893f21360678bc5e0df7eb8330.zip
Split unittest lanes.configure.allocator
-rw-r--r--unit_tests/init_and_shutdown.cpp78
1 files changed, 47 insertions, 31 deletions
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'")
58// ################################################################################################# 58// #################################################################################################
59 59
60// allocator should be "protected", a C function returning a suitable userdata, or nil 60// allocator should be "protected", a C function returning a suitable userdata, or nil
61TEST_CASE("lanes.configure.allocator") 61TEST_CASE("lanes.configure.allocator/bool_number_table_string")
62{ 62{
63 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; 63 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };
64 64
@@ -90,50 +90,33 @@ TEST_CASE("lanes.configure.allocator")
90 90
91 // --------------------------------------------------------------------------------------------- 91 // ---------------------------------------------------------------------------------------------
92 92
93 SECTION("allocator = <Lua function>")
94 {
95 L.requireFailure("require 'lanes'.configure{allocator = function() return {}, 12, 'yoy' end}");
96 }
97
98 // ---------------------------------------------------------------------------------------------
99
100 SECTION("allocator = <bad C function>")
101 {
102 // a C function that doesn't return what we expect should cause an error too
103 // TODO: for some reason, we use os.getenv here because using 'print' as the culprit, the tests deadlock in Release builds
104 L.requireFailure("return type(require 'lanes'.configure{allocator = os.getenv})");
105 }
106
107 // ---------------------------------------------------------------------------------------------
108
109 SECTION("allocator = <string with a typo>") 93 SECTION("allocator = <string with a typo>")
110 { 94 {
111 // oops, a typo 95 // oops, a typo
112 L.requireFailure("require 'lanes'.configure{allocator = 'Protected'}"); 96 L.requireFailure("require 'lanes'.configure{allocator = 'Protected'}");
113 } 97 }
98}
99
100// #################################################################################################
101
102TEST_CASE("lanes.configure.allocator/bad_functions")
103{
104 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };
114 105
115 // --------------------------------------------------------------------------------------------- 106 // ---------------------------------------------------------------------------------------------
116 107
117 SECTION("allocator = 'protected'") 108 SECTION("allocator = <Lua function>")
118 { 109 {
119 // no typo, should work 110 L.requireFailure("require 'lanes'.configure{allocator = function() return {}, 12, 'yoy' end}");
120 // TODO: Investigate why this test crashes when unloading lanes_core.dll when running against Lua 5.1 and Lua 5.2 RELEASE ONLY!
121 L.requireSuccess("require 'lanes'.configure{allocator = 'protected'}");
122 } 111 }
123 112
124 // --------------------------------------------------------------------------------------------- 113 // ---------------------------------------------------------------------------------------------
125 114
126 SECTION("allocator = <good custom C allocator>") 115 SECTION("allocator = <bad C function>")
127 { 116 {
128 // a function that provides what we expect is fine 117 // a C function that doesn't return what we expect should cause an error too
129 static constexpr lua_CFunction _provideAllocator = +[](lua_State* const L_) { 118 // TODO: for some reason, we use os.getenv here because using 'print' as the culprit, the tests deadlock in Release builds
130 lanes::AllocatorDefinition* const _def{ new (L_) lanes::AllocatorDefinition{} }; 119 L.requireFailure("return type(require 'lanes'.configure{allocator = os.getenv})");
131 _def->initFrom(L_);
132 return 1;
133 };
134 lua_pushcfunction(L, _provideAllocator);
135 lua_setglobal(L, "ProvideAllocator");
136 L.requireSuccess("require 'lanes'.configure{allocator = ProvideAllocator}");
137 } 120 }
138 121
139 // --------------------------------------------------------------------------------------------- 122 // ---------------------------------------------------------------------------------------------
@@ -192,6 +175,39 @@ TEST_CASE("lanes.configure.allocator")
192 175
193// ################################################################################################# 176// #################################################################################################
194 177
178TEST_CASE("lanes.configure.allocator/good_function")
179{
180 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };
181
182 SECTION("allocator = <good custom C allocator>")
183 {
184 // a function that provides what we expect is fine
185 static constexpr lua_CFunction _provideAllocator = +[](lua_State* const L_) {
186 lanes::AllocatorDefinition* const _def{ new (L_) lanes::AllocatorDefinition{} };
187 _def->initFrom(L_);
188 return 1;
189 };
190 lua_pushcfunction(L, _provideAllocator);
191 lua_setglobal(L, "ProvideAllocator");
192 L.requireSuccess("require 'lanes'.configure{allocator = ProvideAllocator}");
193 }
194}
195
196// #################################################################################################
197
198// TODO: Investigate why this test crashes when unloading lanes_core.dll when running against Lua 5.1 and Lua 5.2 RELEASE ONLY!
199// apparently, the mutex of ProtectedAllocator is deemed still in use. Crash goes away if I don't use it in protected_lua_Alloc
200TEST_CASE(("lanes.configure.allocator/protected"))
201{
202 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };
203
204 // no typo, should work
205 L.requireSuccess("require 'lanes'.configure{allocator = 'protected'}");
206}
207
208
209// #################################################################################################
210
195TEST_CASE("lanes.configure.internal_allocator") 211TEST_CASE("lanes.configure.internal_allocator")
196{ 212{
197 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; 213 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };