2018-09-28 13:27:38 +08:00
|
|
|
// sol3
|
2017-12-20 17:58:32 +08:00
|
|
|
|
|
|
|
// The MIT License (MIT)
|
|
|
|
|
2019-03-13 17:18:06 +08:00
|
|
|
// Copyright (c) 2013-2019 Rapptz, ThePhD and contributors
|
2017-12-20 17:58:32 +08:00
|
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
// this software and associated documentation files (the "Software"), to deal in
|
|
|
|
// the Software without restriction, including without limitation the rights to
|
|
|
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
// subject to the following conditions:
|
|
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2017-11-10 06:41:46 +08:00
|
|
|
#define SOL_CHECK_ARGUMENTS 1
|
|
|
|
#define SOL_ENABLE_INTEROP 1
|
2016-12-10 13:25:25 +08:00
|
|
|
|
2018-09-28 13:27:38 +08:00
|
|
|
#include <sol/sol.hpp>
|
2016-12-10 13:25:25 +08:00
|
|
|
|
2017-11-10 06:41:46 +08:00
|
|
|
#include <catch.hpp>
|
|
|
|
|
2017-07-10 00:00:57 +08:00
|
|
|
TEST_CASE("storage/registry construction", "ensure entries from the registry can be retrieved") {
|
2017-09-22 07:24:21 +08:00
|
|
|
const auto& code = R"(
|
2016-12-10 13:25:25 +08:00
|
|
|
function f()
|
|
|
|
return 2
|
|
|
|
end
|
|
|
|
)";
|
|
|
|
|
2017-09-22 07:24:21 +08:00
|
|
|
sol::state lua;
|
2018-01-29 11:21:13 +08:00
|
|
|
{
|
|
|
|
auto r = lua.safe_script(code, sol::script_pass_on_error);
|
|
|
|
REQUIRE(r.valid());
|
|
|
|
}
|
2017-09-22 07:24:21 +08:00
|
|
|
sol::function f = lua["f"];
|
|
|
|
sol::reference r = lua["f"];
|
|
|
|
sol::function regf(lua, f);
|
|
|
|
sol::reference regr(lua, sol::ref_index(f.registry_index()));
|
|
|
|
bool isequal = f == r;
|
|
|
|
REQUIRE(isequal);
|
|
|
|
isequal = f == regf;
|
|
|
|
REQUIRE(isequal);
|
|
|
|
isequal = f == regr;
|
|
|
|
REQUIRE(isequal);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("storage/registry construction empty", "ensure entries from the registry can be retrieved") {
|
2016-12-10 13:25:25 +08:00
|
|
|
sol::state lua;
|
|
|
|
sol::function f = lua["f"];
|
|
|
|
sol::reference r = lua["f"];
|
2016-12-10 14:19:23 +08:00
|
|
|
sol::function regf(lua, f);
|
2016-12-10 13:25:25 +08:00
|
|
|
sol::reference regr(lua, sol::ref_index(f.registry_index()));
|
|
|
|
bool isequal = f == r;
|
|
|
|
REQUIRE(isequal);
|
|
|
|
isequal = f == regf;
|
|
|
|
REQUIRE(isequal);
|
|
|
|
isequal = f == regr;
|
|
|
|
REQUIRE(isequal);
|
|
|
|
}
|
|
|
|
|
2017-07-10 00:00:57 +08:00
|
|
|
TEST_CASE("storage/main thread", "ensure round-tripping and pulling out thread data even on 5.1 with a backup works") {
|
2016-12-10 13:25:25 +08:00
|
|
|
sol::state lua;
|
|
|
|
{
|
|
|
|
sol::stack_guard g(lua);
|
|
|
|
lua_State* orig = lua;
|
2016-12-10 19:15:39 +08:00
|
|
|
lua_State* ts = sol::main_thread(lua, lua);
|
2016-12-10 13:25:25 +08:00
|
|
|
REQUIRE(ts == orig);
|
|
|
|
}
|
2017-09-13 23:45:31 +08:00
|
|
|
{
|
|
|
|
sol::stack_guard g(lua);
|
|
|
|
lua_State* orig = lua;
|
|
|
|
lua_State* ts = sol::main_thread(lua);
|
|
|
|
REQUIRE(ts == orig);
|
|
|
|
}
|
2016-12-10 13:25:25 +08:00
|
|
|
}
|