FTXUI/src/ftxui/component/screen_interactive_test.cpp

69 lines
1.8 KiB
C++
Raw Normal View History

#include <gtest/gtest.h> // for Test, TestInfo (ptr only), TEST, EXPECT_EQ, Message, TestPartResult
#include <csignal> // for raise, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM
2022-06-12 23:08:22 +08:00
#include <ftxui/component/event.hpp> // for Event, Event::Custom
#include <tuple> // for _Swallow_assign, ignore
#include "ftxui/component/component.hpp" // for Renderer
#include "ftxui/component/screen_interactive.hpp"
2022-08-07 20:44:33 +08:00
#include "ftxui/dom/elements.hpp" // for text, Element
2022-04-17 21:47:20 +08:00
namespace ftxui {
namespace {
bool TestSignal(int signal) {
int called = 0;
// The tree of components. This defines how to navigate using the keyboard.
auto component = Renderer([&] {
called++;
std::ignore = std::raise(signal);
called++;
return text("");
});
auto screen = ScreenInteractive::FitComponent();
screen.Loop(component);
EXPECT_EQ(called, 2);
return true;
}
} // namespace
TEST(ScreenInteractive, Signal_SIGTERM) {
TestSignal(SIGTERM);
}
TEST(ScreenInteractive, Signal_SIGSEGV) {
TestSignal(SIGSEGV);
}
TEST(ScreenInteractive, Signal_SIGINT) {
TestSignal(SIGINT);
}
TEST(ScreenInteractive, Signal_SIGILL) {
TestSignal(SIGILL);
}
TEST(ScreenInteractive, Signal_SIGABRT) {
TestSignal(SIGABRT);
}
TEST(ScreenInteractive, Signal_SIGFPE) {
TestSignal(SIGFPE);
}
// Regression test for:
// https://github.com/ArthurSonzogni/FTXUI/issues/402
TEST(ScreenInteractive, PostEventToNonActive) {
auto screen = ScreenInteractive::FitComponent();
screen.Post(Event::Custom);
}
// Regression test for:
// https://github.com/ArthurSonzogni/FTXUI/issues/402
TEST(ScreenInteractive, PostTaskToNonActive) {
auto screen = ScreenInteractive::FitComponent();
screen.Post([] {});
}
2022-04-17 21:47:20 +08:00
} // namespace ftxui
// Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.