aboutsummaryrefslogtreecommitdiff
path: root/unit_tests
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-03-11 11:55:01 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2025-03-11 11:55:01 +0100
commitaf3161e5265b56a3d33a1ed45597f85c34806928 (patch)
tree332101e2a95aebc09f907a73958de923be4b0a4d /unit_tests
parentb1822d8d07f8ee34cef2e7e74391695dd4e1ea81 (diff)
downloadlanes-af3161e5265b56a3d33a1ed45597f85c34806928.tar.gz
lanes-af3161e5265b56a3d33a1ed45597f85c34806928.tar.bz2
lanes-af3161e5265b56a3d33a1ed45597f85c34806928.zip
Sample module deep test renamed deep_userdata_example
Diffstat (limited to 'unit_tests')
-rw-r--r--unit_tests/deep_tests.cpp16
-rw-r--r--unit_tests/shared.cpp6
2 files changed, 11 insertions, 11 deletions
diff --git a/unit_tests/deep_tests.cpp b/unit_tests/deep_tests.cpp
index 2c9ccdf..e21072c 100644
--- a/unit_tests/deep_tests.cpp
+++ b/unit_tests/deep_tests.cpp
@@ -2,19 +2,19 @@
2#include "shared.h" 2#include "shared.h"
3 3
4// yeah it's dirty, I will do better someday 4// yeah it's dirty, I will do better someday
5#include "../deep_test/deep_test.cpp" 5#include "../deep_userdata_example/deep_userdata_example.cpp"
6 6
7 7
8// ################################################################################################# 8// #################################################################################################
9// ################################################################################################# 9// #################################################################################################
10 10
11TEST_CASE("misc.deep_test") 11TEST_CASE("misc.deep_userdata.example")
12{ 12{
13 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ true } }; 13 LuaState S{ LuaState::WithBaseLibs{ true }, LuaState::WithFixture{ true } };
14 S.requireSuccess( 14 S.requireSuccess(
15 " lanes = require 'lanes'.configure()" 15 " lanes = require 'lanes'.configure()"
16 " fixture = require 'fixture'" 16 " fixture = require 'fixture'"
17 " deep_test = require 'deep_test'" 17 " due = require 'deep_userdata_example'"
18 ); 18 );
19 19
20 SECTION("garbage collection collects") 20 SECTION("garbage collection collects")
@@ -24,8 +24,8 @@ TEST_CASE("misc.deep_test")
24 if constexpr (LUA_VERSION_NUM >= 503) { // Lua < 5.3 only supports a table uservalue 24 if constexpr (LUA_VERSION_NUM >= 503) { // Lua < 5.3 only supports a table uservalue
25 S.requireSuccess( 25 S.requireSuccess(
26 // create a deep userdata object without referencing it. First uservalue is a function, and should be called on __gc 26 // create a deep userdata object without referencing it. First uservalue is a function, and should be called on __gc
27 " deep_test.new_deep(1):setuv(1, function() collected = collected and collected + 1 or 1 end)" 27 " due.new_deep(1):setuv(1, function() collected = collected and collected + 1 or 1 end)"
28 " deep_test.new_deep(1):setuv(1, function() collected = collected and collected + 1 or 1 end)" 28 " due.new_deep(1):setuv(1, function() collected = collected and collected + 1 or 1 end)"
29 " collectgarbage()" // and collect it 29 " collectgarbage()" // and collect it
30 " assert(collected == 2)" 30 " assert(collected == 2)"
31 ); 31 );
@@ -37,7 +37,7 @@ TEST_CASE("misc.deep_test")
37 SECTION("reference counting") 37 SECTION("reference counting")
38 { 38 {
39 S.requireSuccess( 39 S.requireSuccess(
40 " d = deep_test.new_deep(1)" // create a deep userdata object 40 " d = due.new_deep(1)" // create a deep userdata object
41 " d:set(42)" // set some value 41 " d:set(42)" // set some value
42 " assert(d:refcount() == 1)" 42 " assert(d:refcount() == 1)"
43 ); 43 );
@@ -73,7 +73,7 @@ TEST_CASE("misc.deep_test")
73 SECTION("collection from inside a Linda") 73 SECTION("collection from inside a Linda")
74 { 74 {
75 S.requireSuccess( 75 S.requireSuccess(
76 " d = deep_test.new_deep(1)" // create a deep userdata object 76 " d = due.new_deep(1)" // create a deep userdata object
77 " d:set(42)" // set some value 77 " d:set(42)" // set some value
78 " assert(d:refcount() == 1)" 78 " assert(d:refcount() == 1)"
79 ); 79 );
@@ -89,7 +89,7 @@ TEST_CASE("misc.deep_test")
89 " l = nil" 89 " l = nil"
90 " collectgarbage()" // clears the linda, removes its storage from the keeper 90 " collectgarbage()" // clears the linda, removes its storage from the keeper
91 " lanes.collectgarbage()" // collect garbage inside the keepers too, to finish cleanup 91 " lanes.collectgarbage()" // collect garbage inside the keepers too, to finish cleanup
92 " assert(deep_test.get_deep_count() == 0)" 92 " assert(due.get_deep_count() == 0)"
93 ); 93 );
94 } 94 }
95} \ No newline at end of file 95} \ No newline at end of file
diff --git a/unit_tests/shared.cpp b/unit_tests/shared.cpp
index 0c9516f..08025f2 100644
--- a/unit_tests/shared.cpp
+++ b/unit_tests/shared.cpp
@@ -8,7 +8,7 @@
8// ################################################################################################# 8// #################################################################################################
9// ################################################################################################# 9// #################################################################################################
10 10
11LANES_API int luaopen_deep_test(lua_State* L_); 11LANES_API int luaopen_deep_userdata_example(lua_State* L_);
12 12
13namespace 13namespace
14{ 14{
@@ -70,7 +70,7 @@ namespace
70 // a function that enables any lane to require "fixture" 70 // a function that enables any lane to require "fixture"
71 lua_CFunction sOnStateCreate = +[](lua_State* const L_) { 71 lua_CFunction sOnStateCreate = +[](lua_State* const L_) {
72 PreloadModule(L_, "fixture", luaopen_fixture); 72 PreloadModule(L_, "fixture", luaopen_fixture);
73 PreloadModule(L_, "deep_test", luaopen_deep_test); 73 PreloadModule(L_, "deep_userdata_example", luaopen_deep_userdata_example);
74 return 0; 74 return 0;
75 }; 75 };
76 76
@@ -181,7 +181,7 @@ LuaState::LuaState(WithBaseLibs const withBaseLibs_, WithFixture const withFixtu
181 if (withFixture_) { 181 if (withFixture_) {
182 // make require "fixture" call luaopen_fixture 182 // make require "fixture" call luaopen_fixture
183 local::PreloadModule(L, "fixture", luaopen_fixture); 183 local::PreloadModule(L, "fixture", luaopen_fixture);
184 local::PreloadModule(L, "deep_test", luaopen_deep_test); 184 local::PreloadModule(L, "deep_userdata_example", luaopen_deep_userdata_example);
185 } 185 }
186 STACK_CHECK(L, 0); 186 STACK_CHECK(L, 0);
187} 187}