more tests
This commit is contained in:
parent
c159f37771
commit
646755c7be
@ -23,7 +23,10 @@ set(
|
||||
set(TARGET_MAIN main)
|
||||
set(TARGET_ASYNC async)
|
||||
set(TARGET_CHECK check)
|
||||
set(TARGET_IDLE idle)
|
||||
set(TARGET_LOOP loop)
|
||||
set(TARGET_PREPARE prepare)
|
||||
set(TARGET_SELF self)
|
||||
set(TARGET_WORK work)
|
||||
|
||||
# Test TARGET_MAIN
|
||||
@ -50,6 +53,14 @@ target_include_directories(${TARGET_CHECK} PRIVATE ${COMMON_INCLUDE_DIRS})
|
||||
target_link_libraries(${TARGET_CHECK} PRIVATE ${COMMON_LINK_LIBS})
|
||||
add_test(NAME ${TARGET_CHECK} COMMAND ${TARGET_CHECK})
|
||||
|
||||
# Test TARGET_IDLE
|
||||
|
||||
set(TARGET_IDLE_SOURCES uvw/idle.cpp)
|
||||
add_executable(${TARGET_IDLE} ${TARGET_IDLE_SOURCES})
|
||||
target_include_directories(${TARGET_IDLE} PRIVATE ${COMMON_INCLUDE_DIRS})
|
||||
target_link_libraries(${TARGET_IDLE} PRIVATE ${COMMON_LINK_LIBS})
|
||||
add_test(NAME ${TARGET_IDLE} COMMAND ${TARGET_IDLE})
|
||||
|
||||
# Test TARGET_LOOP
|
||||
|
||||
set(TARGET_LOOP_SOURCES uvw/loop.cpp)
|
||||
@ -58,6 +69,22 @@ target_include_directories(${TARGET_LOOP} PRIVATE ${COMMON_INCLUDE_DIRS})
|
||||
target_link_libraries(${TARGET_LOOP} PRIVATE ${COMMON_LINK_LIBS})
|
||||
add_test(NAME ${TARGET_LOOP} COMMAND ${TARGET_LOOP})
|
||||
|
||||
# Test TARGET_PREPARE
|
||||
|
||||
set(TARGET_PREPARE_SOURCES uvw/prepare.cpp)
|
||||
add_executable(${TARGET_PREPARE} ${TARGET_PREPARE_SOURCES})
|
||||
target_include_directories(${TARGET_PREPARE} PRIVATE ${COMMON_INCLUDE_DIRS})
|
||||
target_link_libraries(${TARGET_PREPARE} PRIVATE ${COMMON_LINK_LIBS})
|
||||
add_test(NAME ${TARGET_PREPARE} COMMAND ${TARGET_PREPARE})
|
||||
|
||||
# Test TARGET_SELF
|
||||
|
||||
set(TARGET_SELF_SOURCES uvw/self.cpp)
|
||||
add_executable(${TARGET_SELF} ${TARGET_SELF_SOURCES})
|
||||
target_include_directories(${TARGET_SELF} PRIVATE ${COMMON_INCLUDE_DIRS})
|
||||
target_link_libraries(${TARGET_SELF} PRIVATE ${COMMON_LINK_LIBS})
|
||||
add_test(NAME ${TARGET_SELF} COMMAND ${TARGET_SELF})
|
||||
|
||||
# Test TARGET_WORK
|
||||
|
||||
set(TARGET_WORK_SOURCES uvw/work.cpp)
|
||||
|
||||
@ -9,12 +9,12 @@ TEST(Async, Send) {
|
||||
bool checkErrorEvent = false;
|
||||
bool checkAsyncEvent = false;
|
||||
|
||||
handle->on<uvw::ErrorEvent>([&checkErrorEvent](const uvw::ErrorEvent &, uvw::AsyncHandle &){
|
||||
handle->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &){
|
||||
ASSERT_FALSE(checkErrorEvent);
|
||||
checkErrorEvent = true;
|
||||
});
|
||||
|
||||
handle->on<uvw::AsyncEvent>([&checkAsyncEvent](const uvw::AsyncEvent &, uvw::AsyncHandle &handle){
|
||||
handle->on<uvw::AsyncEvent>([&checkAsyncEvent](const auto &, auto &handle){
|
||||
ASSERT_FALSE(checkAsyncEvent);
|
||||
checkAsyncEvent = true;
|
||||
handle.close();
|
||||
|
||||
@ -2,19 +2,19 @@
|
||||
#include <uvw.hpp>
|
||||
|
||||
|
||||
TEST(Check, PartiallyDone) {
|
||||
TEST(Check, StartAndStop) {
|
||||
auto loop = uvw::Loop::getDefault();
|
||||
auto handle = loop->resource<uvw::CheckHandle>();
|
||||
|
||||
bool checkErrorEvent = false;
|
||||
bool checkCheckEvent = false;
|
||||
|
||||
handle->on<uvw::ErrorEvent>([&checkErrorEvent](const uvw::ErrorEvent &, uvw::CheckHandle &){
|
||||
handle->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &){
|
||||
ASSERT_FALSE(checkErrorEvent);
|
||||
checkErrorEvent = true;
|
||||
});
|
||||
|
||||
handle->on<uvw::CheckEvent>([&checkCheckEvent](const uvw::CheckEvent &, uvw::CheckHandle &handle){
|
||||
handle->on<uvw::CheckEvent>([&checkCheckEvent](const auto &, auto &handle){
|
||||
ASSERT_FALSE(checkCheckEvent);
|
||||
checkCheckEvent = true;
|
||||
handle.stop();
|
||||
|
||||
52
test/uvw/idle.cpp
Normal file
52
test/uvw/idle.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <uvw.hpp>
|
||||
|
||||
|
||||
TEST(Idle, StartAndStop) {
|
||||
auto loop = uvw::Loop::getDefault();
|
||||
auto handle = loop->resource<uvw::IdleHandle>();
|
||||
|
||||
bool checkErrorEvent = false;
|
||||
bool checkIdleEvent = false;
|
||||
|
||||
handle->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &){
|
||||
ASSERT_FALSE(checkErrorEvent);
|
||||
checkErrorEvent = true;
|
||||
});
|
||||
|
||||
handle->on<uvw::IdleEvent>([&checkIdleEvent](const auto &, auto &handle){
|
||||
ASSERT_FALSE(checkIdleEvent);
|
||||
checkIdleEvent = true;
|
||||
handle.stop();
|
||||
handle.close();
|
||||
ASSERT_TRUE(handle.closing());
|
||||
});
|
||||
|
||||
handle->start();
|
||||
|
||||
ASSERT_TRUE(handle->active());
|
||||
ASSERT_FALSE(handle->closing());
|
||||
|
||||
loop->run<uvw::Loop::Mode::NOWAIT>();
|
||||
|
||||
ASSERT_FALSE(checkErrorEvent);
|
||||
ASSERT_TRUE(checkIdleEvent);
|
||||
}
|
||||
|
||||
|
||||
TEST(Idle, Fake) {
|
||||
auto loop = uvw::Loop::getDefault();
|
||||
auto handle = loop->resource<uvw::IdleHandle>();
|
||||
|
||||
auto l = [](const auto &, auto &){ ASSERT_FALSE(true); };
|
||||
handle->on<uvw::ErrorEvent>(l);
|
||||
handle->on<uvw::IdleEvent>(l);
|
||||
|
||||
handle->start();
|
||||
handle->close();
|
||||
|
||||
ASSERT_FALSE(handle->active());
|
||||
ASSERT_TRUE(handle->closing());
|
||||
|
||||
loop->run();
|
||||
}
|
||||
@ -15,7 +15,7 @@ TEST(Loop, PartiallyDone) {
|
||||
auto handle = loop->resource<uvw::PrepareHandle>();
|
||||
auto req = loop->resource<uvw::WorkReq>([](){});
|
||||
|
||||
auto err = [](uvw::ErrorEvent, auto &) { ASSERT_TRUE(false); };
|
||||
auto err = [](const auto &, auto &) { ASSERT_TRUE(false); };
|
||||
|
||||
loop->on<uvw::ErrorEvent>(err);
|
||||
req->on<uvw::ErrorEvent>(err);
|
||||
@ -27,7 +27,7 @@ TEST(Loop, PartiallyDone) {
|
||||
ASSERT_FALSE(loop->alive());
|
||||
|
||||
handle->start();
|
||||
handle->on<uvw::PrepareEvent>([](uvw::PrepareEvent, uvw::PrepareHandle &handle) {
|
||||
handle->on<uvw::PrepareEvent>([](const auto &, auto &handle) {
|
||||
handle.loop().walk([](uvw::BaseHandle &) {
|
||||
static bool trigger = true;
|
||||
ASSERT_TRUE(trigger);
|
||||
|
||||
52
test/uvw/prepare.cpp
Normal file
52
test/uvw/prepare.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <uvw.hpp>
|
||||
|
||||
|
||||
TEST(Prepare, StartAndStop) {
|
||||
auto loop = uvw::Loop::getDefault();
|
||||
auto handle = loop->resource<uvw::PrepareHandle>();
|
||||
|
||||
bool checkErrorEvent = false;
|
||||
bool checkPrepareEvent = false;
|
||||
|
||||
handle->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &){
|
||||
ASSERT_FALSE(checkErrorEvent);
|
||||
checkErrorEvent = true;
|
||||
});
|
||||
|
||||
handle->on<uvw::PrepareEvent>([&checkPrepareEvent](const auto &, auto &handle){
|
||||
ASSERT_FALSE(checkPrepareEvent);
|
||||
checkPrepareEvent = true;
|
||||
handle.stop();
|
||||
handle.close();
|
||||
ASSERT_TRUE(handle.closing());
|
||||
});
|
||||
|
||||
handle->start();
|
||||
|
||||
ASSERT_TRUE(handle->active());
|
||||
ASSERT_FALSE(handle->closing());
|
||||
|
||||
loop->run<uvw::Loop::Mode::NOWAIT>();
|
||||
|
||||
ASSERT_FALSE(checkErrorEvent);
|
||||
ASSERT_TRUE(checkPrepareEvent);
|
||||
}
|
||||
|
||||
|
||||
TEST(Prepare, Fake) {
|
||||
auto loop = uvw::Loop::getDefault();
|
||||
auto handle = loop->resource<uvw::PrepareHandle>();
|
||||
|
||||
auto l = [](const auto &, auto &){ ASSERT_FALSE(true); };
|
||||
handle->on<uvw::ErrorEvent>(l);
|
||||
handle->on<uvw::PrepareEvent>(l);
|
||||
|
||||
handle->start();
|
||||
handle->close();
|
||||
|
||||
ASSERT_FALSE(handle->active());
|
||||
ASSERT_TRUE(handle->closing());
|
||||
|
||||
loop->run();
|
||||
}
|
||||
23
test/uvw/self.cpp
Normal file
23
test/uvw/self.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <uvw.hpp>
|
||||
|
||||
|
||||
struct S: uvw::Self<S> { };
|
||||
|
||||
|
||||
TEST(Self, Basics) {
|
||||
std::shared_ptr<S> self = std::make_shared<S>();
|
||||
|
||||
ASSERT_TRUE(self.unique());
|
||||
ASSERT_FALSE(self->self());
|
||||
|
||||
self->leak();
|
||||
|
||||
ASSERT_FALSE(self.unique());
|
||||
ASSERT_TRUE(self->self());
|
||||
|
||||
self->reset();
|
||||
|
||||
ASSERT_TRUE(self.unique());
|
||||
ASSERT_FALSE(self->self());
|
||||
}
|
||||
@ -14,12 +14,12 @@ TEST(Work, RunTask) {
|
||||
checkTask = true;
|
||||
});
|
||||
|
||||
req->on<uvw::WorkEvent>([&checkWorkEvent](const uvw::WorkEvent &, uvw::WorkReq &){
|
||||
req->on<uvw::WorkEvent>([&checkWorkEvent](const auto &, auto &){
|
||||
ASSERT_FALSE(checkWorkEvent);
|
||||
checkWorkEvent = true;
|
||||
});
|
||||
|
||||
req->on<uvw::ErrorEvent>([&checkErrorEvent](const uvw::ErrorEvent &, uvw::WorkReq &){
|
||||
req->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &){
|
||||
ASSERT_FALSE(checkErrorEvent);
|
||||
checkErrorEvent = true;
|
||||
});
|
||||
@ -44,12 +44,12 @@ TEST(Work, Cancellation) {
|
||||
checkTask = true;
|
||||
});
|
||||
|
||||
req->on<uvw::WorkEvent>([&checkWorkEvent](const uvw::WorkEvent &, uvw::WorkReq &){
|
||||
req->on<uvw::WorkEvent>([&checkWorkEvent](const auto &, auto &){
|
||||
ASSERT_FALSE(checkWorkEvent);
|
||||
checkWorkEvent = true;
|
||||
});
|
||||
|
||||
req->on<uvw::ErrorEvent>([&checkErrorEvent](const uvw::ErrorEvent &, uvw::WorkReq &){
|
||||
req->on<uvw::ErrorEvent>([&checkErrorEvent](const auto &, auto &){
|
||||
ASSERT_FALSE(checkErrorEvent);
|
||||
checkErrorEvent = true;
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user