tests + bug fixing

This commit is contained in:
Michele Caini 2016-08-01 09:18:37 +02:00
parent 4b5c29ce4a
commit 7e8005a90a
5 changed files with 82 additions and 2 deletions

View File

@ -125,7 +125,7 @@ public:
return (uv_run(loop.get(), UV_RUN_ONCE) == 0);
}
bool runWait() noexcept {
bool runNoWait() noexcept {
return (uv_run(loop.get(), UV_RUN_NOWAIT) == 0);
}

View File

@ -22,6 +22,7 @@ set(
set(TARGET_MAIN main)
set(TARGET_ASYNC async)
set(TARGET_CHECK check)
set(TARGET_LOOP loop)
set(TARGET_WORK work)
@ -41,6 +42,14 @@ target_include_directories(${TARGET_ASYNC} PRIVATE ${COMMON_INCLUDE_DIRS})
target_link_libraries(${TARGET_ASYNC} PRIVATE ${COMMON_LINK_LIBS})
add_test(NAME ${TARGET_ASYNC} COMMAND ${TARGET_ASYNC})
# Test TARGET_CHECK
set(TARGET_CHECK_SOURCES uvw/check.cpp)
add_executable(${TARGET_CHECK} ${TARGET_CHECK_SOURCES})
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_LOOP
set(TARGET_LOOP_SOURCES uvw/loop.cpp)

View File

@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include <uvw.hpp>
TEST(Async, Send) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::AsyncHandle>();
@ -30,3 +31,21 @@ TEST(Async, Send) {
ASSERT_FALSE(checkErrorEvent);
ASSERT_TRUE(checkAsyncEvent);
}
TEST(Async, Fake) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::AsyncHandle>();
auto l = [](const auto &, auto &){ ASSERT_FALSE(true); };
handle->on<uvw::ErrorEvent>(l);
handle->on<uvw::AsyncEvent>(l);
handle->send();
handle->close();
ASSERT_FALSE(handle->active());
ASSERT_TRUE(handle->closing());
loop->run();
}

52
test/uvw/check.cpp Normal file
View File

@ -0,0 +1,52 @@
#include <gtest/gtest.h>
#include <uvw.hpp>
TEST(Check, PartiallyDone) {
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 &){
ASSERT_FALSE(checkErrorEvent);
checkErrorEvent = true;
});
handle->on<uvw::CheckEvent>([&checkCheckEvent](const uvw::CheckEvent &, uvw::CheckHandle &handle){
ASSERT_FALSE(checkCheckEvent);
checkCheckEvent = true;
handle.stop();
handle.close();
ASSERT_TRUE(handle.closing());
});
handle->start();
ASSERT_TRUE(handle->active());
ASSERT_FALSE(handle->closing());
loop->runNoWait();
ASSERT_FALSE(checkErrorEvent);
ASSERT_TRUE(checkCheckEvent);
}
TEST(Check, Fake) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::CheckHandle>();
auto l = [](const auto &, auto &){ ASSERT_FALSE(true); };
handle->on<uvw::ErrorEvent>(l);
handle->on<uvw::CheckEvent>(l);
handle->start();
handle->close();
ASSERT_FALSE(handle->active());
ASSERT_TRUE(handle->closing());
loop->run();
}

View File

@ -43,7 +43,7 @@ TEST(Loop, PartiallyDone) {
loop->walk([](uvw::BaseHandle &) { ASSERT_TRUE(false); });
ASSERT_NO_THROW(loop->runOnce());
ASSERT_NO_THROW(loop->runWait());
ASSERT_NO_THROW(loop->runNoWait());
ASSERT_FALSE(loop->alive());
}