aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/init_and_shutdown.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unit_tests/init_and_shutdown.cpp')
-rw-r--r--unit_tests/init_and_shutdown.cpp89
1 files changed, 53 insertions, 36 deletions
diff --git a/unit_tests/init_and_shutdown.cpp b/unit_tests/init_and_shutdown.cpp
index bd72157..69e4f1b 100644
--- a/unit_tests/init_and_shutdown.cpp
+++ b/unit_tests/init_and_shutdown.cpp
@@ -3,7 +3,7 @@
3 3
4// ################################################################################################# 4// #################################################################################################
5 5
6TEST_CASE("lanes.require 'lanes'") 6TEST_CASE("Lua.require_lanes")
7{ 7{
8 LuaState L{ LuaState::WithBaseLibs{ false }, LuaState::WithFixture{ false } }; 8 LuaState L{ LuaState::WithBaseLibs{ false }, LuaState::WithFixture{ false } };
9 9
@@ -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,49 +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 L.requireSuccess("require 'lanes'.configure{allocator = 'protected'}");
121 } 111 }
122 112
123 // --------------------------------------------------------------------------------------------- 113 // ---------------------------------------------------------------------------------------------
124 114
125 SECTION("allocator = <good custom C allocator>") 115 SECTION("allocator = <bad C function>")
126 { 116 {
127 // 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
128 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
129 lanes::AllocatorDefinition* const _def{ new (L_) lanes::AllocatorDefinition{} }; 119 L.requireFailure("return type(require 'lanes'.configure{allocator = os.getenv})");
130 _def->initFrom(L_);
131 return 1;
132 };
133 lua_pushcfunction(L, _provideAllocator);
134 lua_setglobal(L, "ProvideAllocator");
135 L.requireSuccess("require 'lanes'.configure{allocator = ProvideAllocator}");
136 } 120 }
137 121
138 // --------------------------------------------------------------------------------------------- 122 // ---------------------------------------------------------------------------------------------
@@ -191,6 +175,39 @@ TEST_CASE("lanes.configure.allocator")
191 175
192// ################################################################################################# 176// #################################################################################################
193 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 under AppVerifier on lanes_core.dll unload when running against Lua 5.1, 5.2 and 5.4 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
194TEST_CASE("lanes.configure.internal_allocator") 211TEST_CASE("lanes.configure.internal_allocator")
195{ 212{
196 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; 213 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };
@@ -401,7 +418,7 @@ TEST_CASE("lanes.configure.nb_user_keepers")
401 418
402// ################################################################################################# 419// #################################################################################################
403 420
404TEST_CASE("lanes.configure.on_state_create") 421TEST_CASE("lanes.configure.on_state_create/configuration")
405{ 422{
406 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; 423 LuaState L{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };
407 424
@@ -758,7 +775,7 @@ TEST_CASE("lanes.configure.unknown_setting")
758 775
759#if LUAJIT_FLAVOR() == 0 776#if LUAJIT_FLAVOR() == 0
760// TODO: this test crashes inside S.close() against LuaJIT. to be investigated 777// TODO: this test crashes inside S.close() against LuaJIT. to be investigated
761TEST_CASE("lanes.finally.no fixture") 778TEST_CASE("lanes.finally.no_fixture")
762{ 779{
763 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; 780 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };
764 // we need Lanes to be up. Since we run several 'scripts', we store it as a global 781 // we need Lanes to be up. Since we run several 'scripts', we store it as a global
@@ -779,7 +796,7 @@ TEST_CASE("lanes.finally.no fixture")
779 796
780// ################################################################################################# 797// #################################################################################################
781 798
782TEST_CASE("lanes.finally.with fixture") 799TEST_CASE("lanes.finally.with_fixture")
783{ 800{
784 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ true } }; 801 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ true } };
785 802
@@ -797,7 +814,7 @@ TEST_CASE("lanes.finally.with fixture")
797 814
798// ################################################################################################# 815// #################################################################################################
799 816
800TEST_CASE("lanes.finally.shutdown with an uncooperative lane") 817TEST_CASE("lanes.finally.shutdown_with_an_uncooperative_lane")
801{ 818{
802 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ true } }; 819 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ true } };
803 S.requireSuccess("lanes = require 'lanes'.configure()"); 820 S.requireSuccess("lanes = require 'lanes'.configure()");
@@ -846,7 +863,7 @@ namespace
846 863
847// ################################################################################################# 864// #################################################################################################
848 865
849TEST_CASE("lanes.on_state_create setting") 866TEST_CASE("lanes.configure.on_state_create/details")
850{ 867{
851 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } }; 868 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ false } };
852 869