tests: tty + minor changes

This commit is contained in:
Michele Caini 2017-02-15 10:15:42 +01:00
parent be305657f1
commit d9d544e1b5
5 changed files with 44 additions and 4 deletions

View File

@ -46,6 +46,7 @@ set(TARGET_RESOURCE resource)
set(TARGET_SIGNAL signal)
set(TARGET_TCP tcp)
set(TARGET_TIMER timer)
set(TARGET_TTY tty)
set(TARGET_UDP udp)
set(TARGET_UTIL util)
set(TARGET_WORK work)
@ -175,6 +176,14 @@ target_include_directories(${TARGET_TIMER} PRIVATE ${COMMON_INCLUDE_DIRS})
target_link_libraries(${TARGET_TIMER} PRIVATE ${COMMON_LINK_LIBS})
add_test(NAME ${TARGET_TIMER} COMMAND ${TARGET_TIMER})
# Test TARGET_TTY
set(TARGET_TTY_SOURCES $<TARGET_OBJECTS:odr> uvw/tty.cpp)
add_executable(${TARGET_TTY} ${TARGET_TTY_SOURCES})
target_include_directories(${TARGET_TTY} PRIVATE ${COMMON_INCLUDE_DIRS})
target_link_libraries(${TARGET_TTY} PRIVATE ${COMMON_LINK_LIBS})
add_test(NAME ${TARGET_TTY} COMMAND ${TARGET_TTY})
# Test TARGET_UDP
set(TARGET_UDP_SOURCES $<TARGET_OBJECTS:odr> uvw/udp.cpp)

View File

@ -9,7 +9,7 @@ struct TestEmitter: uvw::Emitter<TestEmitter> {
};
TEST(Emitter, ClearAndClear) {
TEST(Emitter, EmptyAndClear) {
TestEmitter emitter{};
ASSERT_TRUE(emitter.empty());

View File

@ -16,8 +16,7 @@ TEST(Loop, DefaultLoop) {
}
TEST(Loop, PartiallyDone) {
TEST(Loop, Functionalities) {
auto loop = uvw::Loop::create();
auto handle = loop->resource<uvw::PrepareHandle>();
auto req = loop->resource<uvw::WorkReq>([]{});

View File

@ -7,7 +7,7 @@
struct Res: uvw::Resource<Res, int> { };
TEST(Resource, Basics) {
TEST(Resource, Functionalities) {
ASSERT_FALSE(std::is_copy_constructible<uvw::AsyncHandle>::value);
ASSERT_FALSE(std::is_copy_assignable<uvw::AsyncHandle>::value);

32
test/uvw/tty.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <gtest/gtest.h>
#include <uvw.hpp>
TEST(TTY, Functionalities) {
auto loop = uvw::Loop::getDefault();
auto handle = loop->resource<uvw::TTYHandle>(uvw::StdOUT, false);
auto timer = loop->resource<uvw::TimerHandle>();
bool checkWriteEvent = false;
handle->on<uvw::WriteEvent>([&checkWriteEvent](const auto &, auto &hndl){
ASSERT_FALSE(checkWriteEvent);
checkWriteEvent = true;
hndl.close();
});
timer->on<uvw::TimerEvent>([handle](const auto &, auto &hndl){
auto data = std::make_unique<char[]>('*');
handle->write(std::move(data), 1);
hndl.close();
});
ASSERT_TRUE(handle->reset());
ASSERT_TRUE(handle->mode(uvw::TTYHandle::Mode::NORMAL));
ASSERT_NO_THROW(handle->getWinSize());
timer->start(uvw::TimerHandle::Time{0}, uvw::TimerHandle::Time{0});
loop->run();
ASSERT_TRUE(checkWriteEvent);
}