Merge branch 'master' into cooper_features
This commit is contained in:
commit
00264b4942
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,6 +1,9 @@
|
|||||||
[submodule "src/sol"]
|
[submodule "src/sol"]
|
||||||
path = src/sol
|
path = src/sol
|
||||||
url = https://github.com/ThePhD/sol2.git
|
url = https://github.com/ThePhD/sol2.git
|
||||||
|
[submodule "tests/gtest"]
|
||||||
|
path = tests/gtest
|
||||||
|
url = https://github.com/google/googletest.git
|
||||||
[submodule "lua-tests/luaunit"]
|
[submodule "lua-tests/luaunit"]
|
||||||
path = lua-tests/luaunit
|
path = lua-tests/luaunit
|
||||||
url = https://github.com/bluebird75/luaunit
|
url = https://github.com/bluebird75/luaunit
|
||||||
|
|||||||
@ -13,6 +13,11 @@ FILE(GLOB SOURCES src/*.cpp src/*.h)
|
|||||||
|
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
|
# Supress CMP0042
|
||||||
|
set(CMAKE_MACOSX_RPATH 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(woofer SHARED ${SOURCES})
|
add_library(woofer SHARED ${SOURCES})
|
||||||
target_link_libraries(woofer -lpthread ${LUA_LIBRARY})
|
target_link_libraries(woofer -lpthread ${LUA_LIBRARY})
|
||||||
|
|
||||||
@ -21,8 +26,21 @@ set(ENABLE_WARNINGS "-Wall -Wextra -pedantic")
|
|||||||
set(BUILD_FLAVOR "-O3 -UNDEBUG")
|
set(BUILD_FLAVOR "-O3 -UNDEBUG")
|
||||||
set_target_properties(woofer PROPERTIES COMPILE_FLAGS "${ENABLE_WARNINGS} ${GENERAL} ${BUILD_FLAVOR}")
|
set_target_properties(woofer PROPERTIES COMPILE_FLAGS "${ENABLE_WARNINGS} ${GENERAL} ${BUILD_FLAVOR}")
|
||||||
|
|
||||||
|
#----------
|
||||||
|
# TESTS ---
|
||||||
|
#----------
|
||||||
|
|
||||||
|
FILE(GLOB TEST_SOURCES tests/*.cpp)
|
||||||
|
set(GTEST_DIR tests/gtest/googletest)
|
||||||
|
|
||||||
|
include_directories(${GTEST_DIR}/include ${GTEST_DIR})
|
||||||
|
add_executable(tests ${TEST_SOURCES} ${GTEST_DIR}/src/gtest-all.cc)
|
||||||
|
target_link_libraries(tests woofer)
|
||||||
|
|
||||||
|
set_target_properties(tests PROPERTIES COMPILE_FLAGS "${ENABLE_WARNINGS} ${GENERAL} ${BUILD_FLAVOR}")
|
||||||
|
|
||||||
#----------
|
#----------
|
||||||
# INSTALL -
|
# INSTALL -
|
||||||
#----------
|
#----------
|
||||||
|
|
||||||
install(FILES ${LUA_SOURCES} DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
install(FILES ${LUA_SOURCES} DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
||||||
|
|||||||
1
tests/gtest
Submodule
1
tests/gtest
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 5e7fd50e17b6edf1cadff973d0ec68966cf3265e
|
||||||
@ -1,18 +1,26 @@
|
|||||||
#include <boost/test/unit_test.hpp>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "shared-table.h"
|
#include "shared-table.h"
|
||||||
#include "lua-utils.h"
|
|
||||||
|
|
||||||
#include <logging.h>
|
|
||||||
|
|
||||||
using namespace core;
|
using namespace core;
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(singleThreadSet) {
|
namespace {
|
||||||
|
|
||||||
|
void bootstrapState(sol::state& lua) {
|
||||||
|
lua.open_libraries(
|
||||||
|
sol::lib::base,
|
||||||
|
sol::lib::string
|
||||||
|
);
|
||||||
|
SharedTable::bind(lua);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(sharedTable, singleThreadSet) {
|
||||||
|
SharedTable st;
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
bootstrapState(lua);
|
bootstrapState(lua);
|
||||||
|
|
||||||
SharedTable st;
|
|
||||||
|
|
||||||
lua["st"] = &st;
|
lua["st"] = &st;
|
||||||
|
|
||||||
auto res1 = lua.script(R"(
|
auto res1 = lua.script(R"(
|
||||||
@ -23,14 +31,14 @@ st.del = "secret"
|
|||||||
st.del = nil
|
st.del = nil
|
||||||
)");
|
)");
|
||||||
if (!res1.valid()) {
|
if (!res1.valid()) {
|
||||||
BOOST_FAIL("Set res1 failed");
|
FAIL() << "Set res1 failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_CHECK(lua["st"]["fst"] == std::string("first"));
|
ASSERT_EQ(lua["st"]["fst"], std::string("first"));
|
||||||
BOOST_CHECK(lua["st"]["snd"] == (double)2);
|
ASSERT_EQ(lua["st"]["snd"], (double)2);
|
||||||
BOOST_CHECK(lua["st"]["thr"] == true);
|
ASSERT_EQ(lua["st"]["thr"], true);
|
||||||
BOOST_CHECK(lua["st"]["del"] == sol::nil);
|
ASSERT_EQ(lua["st"]["del"], sol::nil);
|
||||||
BOOST_CHECK(lua["st"]["nex"] == sol::nil);
|
ASSERT_EQ(lua["st"]["nex"], sol::nil);
|
||||||
|
|
||||||
auto res2 = lua.script(R"(
|
auto res2 = lua.script(R"(
|
||||||
st[1] = 3
|
st[1] = 3
|
||||||
@ -41,30 +49,30 @@ st[42] = nil
|
|||||||
st.deleted = st[42] == nil
|
st.deleted = st[42] == nil
|
||||||
)");
|
)");
|
||||||
if (!res2.valid()) {
|
if (!res2.valid()) {
|
||||||
BOOST_FAIL("Set res2 failed");
|
FAIL() << "Set res2 failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_CHECK(lua["st"][1] == 3);
|
ASSERT_EQ(lua["st"][1], 3);
|
||||||
BOOST_CHECK(lua["st"][2] == std::string("number"));
|
ASSERT_EQ(lua["st"][2], std::string("number"));
|
||||||
BOOST_CHECK(lua["st"][-1] == false);
|
ASSERT_EQ(lua["st"][-1], false);
|
||||||
BOOST_CHECK(lua["st"]["deleted"] == true);
|
ASSERT_EQ(lua["st"]["deleted"], true);
|
||||||
|
|
||||||
auto res3 = lua.script(R"(
|
auto res3 = lua.script(R"(
|
||||||
st[true] = false
|
st[true] = false
|
||||||
st[false] = 9
|
st[false] = 9
|
||||||
)");
|
)");
|
||||||
if (!res3.valid()) {
|
if (!res3.valid()) {
|
||||||
BOOST_FAIL("Set res3 failed");
|
FAIL() << "Set res3 failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_CHECK(lua["st"][true] == false);
|
ASSERT_EQ(lua["st"][true], false);
|
||||||
BOOST_CHECK(lua["st"][false] == 9);
|
ASSERT_EQ(lua["st"][false], 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(asGlobalTable) {
|
TEST(sharedTable, asGlobalTable) {
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
SharedTable st;
|
SharedTable st;
|
||||||
bootstrapState(lua);
|
SharedTable::bind(lua);
|
||||||
|
|
||||||
lua["st"] = &st;
|
lua["st"] = &st;
|
||||||
|
|
||||||
@ -75,12 +83,12 @@ b = false
|
|||||||
s = "Oo"
|
s = "Oo"
|
||||||
)");
|
)");
|
||||||
|
|
||||||
BOOST_CHECK(lua["n"] == 1);
|
ASSERT_EQ(lua["n"], 1);
|
||||||
BOOST_CHECK(lua["b"] == false);
|
ASSERT_EQ(lua["b"], false);
|
||||||
BOOST_CHECK(lua["s"] == std::string("Oo"));
|
ASSERT_EQ(lua["s"], std::string("Oo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(severalStates) {
|
TEST(sharedTable, severalStates) {
|
||||||
sol::state lua1, lua2;
|
sol::state lua1, lua2;
|
||||||
bootstrapState(lua1);
|
bootstrapState(lua1);
|
||||||
bootstrapState(lua2);
|
bootstrapState(lua2);
|
||||||
@ -96,19 +104,19 @@ cats.sparky = false
|
|||||||
cats.wow = 3
|
cats.wow = 3
|
||||||
)");
|
)");
|
||||||
|
|
||||||
BOOST_CHECK(lua2["dogs"]["fluffy"] == std::string("gav"));
|
ASSERT_EQ(lua2["dogs"]["fluffy"], std::string("gav"));
|
||||||
BOOST_CHECK(lua2["dogs"]["sparky"] == false);
|
ASSERT_EQ(lua2["dogs"]["sparky"], false);
|
||||||
BOOST_CHECK(lua2["dogs"]["wow"] == 3);
|
ASSERT_EQ(lua2["dogs"]["wow"], 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multipleThreads) {
|
TEST(sharedTable, multipleThreads) {
|
||||||
SharedTable st;
|
SharedTable st;
|
||||||
|
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
|
|
||||||
threads.emplace_back([&](){
|
threads.emplace_back([&](){
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
bootstrapState(lua);
|
bootstrapState(lua);;
|
||||||
lua["st"] = &st;
|
lua["st"] = &st;
|
||||||
lua.script(R"(
|
lua.script(R"(
|
||||||
while not st.ready do end
|
while not st.ready do end
|
||||||
@ -140,12 +148,12 @@ st.thr = true)");
|
|||||||
|
|
||||||
for(auto& thread : threads) { thread.join(); }
|
for(auto& thread : threads) { thread.join(); }
|
||||||
|
|
||||||
BOOST_CHECK(lua["st"]["fst"] == true);
|
ASSERT_EQ(lua["st"]["fst"], true);
|
||||||
BOOST_CHECK(lua["st"]["snd"] == true);
|
ASSERT_EQ(lua["st"]["snd"], true);
|
||||||
BOOST_CHECK(lua["st"]["thr"] == true);
|
ASSERT_EQ(lua["st"]["thr"], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(nestedTables) {
|
TEST(sharedTable, nestedTables) {
|
||||||
SharedTable recursive, st1, st2;
|
SharedTable recursive, st1, st2;
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
bootstrapState(lua);
|
bootstrapState(lua);
|
||||||
@ -160,11 +168,11 @@ st1.proxy.value = true
|
|||||||
recursive.next = recursive
|
recursive.next = recursive
|
||||||
recursive.val = "yes"
|
recursive.val = "yes"
|
||||||
)");
|
)");
|
||||||
BOOST_CHECK(lua["st2"]["value"] == true);
|
ASSERT_EQ(lua["st2"]["value"], true);
|
||||||
BOOST_CHECK(lua["recursive"]["next"]["next"]["next"]["val"] == std::string("yes"));
|
ASSERT_EQ(lua["recursive"]["next"]["next"]["next"]["val"], std::string("yes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(playingWithFunctions) {
|
TEST(sharedTable, playingWithFunctions) {
|
||||||
SharedTable st;
|
SharedTable st;
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
bootstrapState(lua);
|
bootstrapState(lua);
|
||||||
@ -180,7 +188,7 @@ st.fn()
|
|||||||
)");
|
)");
|
||||||
|
|
||||||
sol::function sf = lua["st"]["fn"];
|
sol::function sf = lua["st"]["fn"];
|
||||||
BOOST_CHECK((bool)sf());
|
ASSERT_TRUE((bool)sf());
|
||||||
|
|
||||||
sol::state lua2;
|
sol::state lua2;
|
||||||
bootstrapState(lua2);
|
bootstrapState(lua2);
|
||||||
@ -194,5 +202,5 @@ end
|
|||||||
|
|
||||||
sol::function sf2 = lua["st"]["fn2"];
|
sol::function sf2 = lua["st"]["fn2"];
|
||||||
|
|
||||||
BOOST_CHECK(sf2(std::string("SUCCESS")).get<std::string>() == std::string("*SUCCESS*"));
|
ASSERT_EQ(sf2(std::string("SUCCESS")).get<std::string>(), std::string("*SUCCESS*"));
|
||||||
}
|
}
|
||||||
|
|||||||
6
tests/test_main.cpp
Normal file
6
tests/test_main.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user