[ox/event] Add Event package

This commit is contained in:
2021-07-16 20:43:07 -05:00
parent b27d6671fc
commit 950712b85e
7 changed files with 327 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.10)
add_executable(
EventTest
tests.cpp
)
target_link_libraries(EventTest OxEvent)
add_test("[ox/event] Test 1" EventTest "test1")

50
deps/ox/src/ox/event/test/tests.cpp vendored Normal file
View File

@@ -0,0 +1,50 @@
/*
* Copyright 2015 - 2021 gary@drinkingtea.net
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#undef NDEBUG
#include <map>
#include <functional>
#include <ox/event/signal.hpp>
#include <ox/std/std.hpp>
struct TestStruct: public ox::SignalHandler {
int value = 0;
ox::Error method(int i) noexcept {
value = i;
return OxError(0);
}
};
std::map<std::string, std::function<ox::Error()>> tests = {
{
"test1",
[] {
ox::Signal<ox::Error(int)> signal;
signal.connect([](int i) -> ox::Error {
return OxError(i != 5);
});
TestStruct ts;
signal.connect(&ts, &TestStruct::method);
oxReturnError(signal.emitCheckError(5));
oxReturnError(OxError(ts.value != 5));
return OxError(0);
}
},
};
int main(int argc, const char **args) {
if (argc > 1) {
auto testName = args[1];
if (tests.find(testName) != tests.end()) {
oxAssert(tests[testName](), "Test returned Error");
return 0;
}
}
return -1;
}