2019-11-17 15:25:40 +00:00
|
|
|
#include <string>
|
|
|
|
#include <cstdlib>
|
2019-12-27 22:20:20 +00:00
|
|
|
#include <iostream>
|
2019-11-17 14:53:59 +00:00
|
|
|
#include "main.h"
|
2020-02-18 17:36:16 +00:00
|
|
|
#include "internal.h"
|
2019-11-17 14:53:59 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("NotcursesBase") {
|
2020-06-16 03:58:43 +00:00
|
|
|
auto nc_ = testing_notcurses();
|
2020-05-17 11:57:21 +00:00
|
|
|
if(!nc_){
|
|
|
|
return;
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
|
|
|
SUBCASE("NotcursesVersionString") {
|
|
|
|
const char* ver = notcurses_version();
|
|
|
|
REQUIRE(ver);
|
|
|
|
REQUIRE(0 < strlen(ver));
|
|
|
|
std::cout << "notcurses version " << ver << std::endl;
|
2019-11-19 01:57:33 +00:00
|
|
|
}
|
2019-11-19 10:33:38 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("TermDimensions") {
|
|
|
|
int x, y;
|
|
|
|
notcurses_term_dim_yx(nc_, &y, &x);
|
|
|
|
auto stry = getenv("LINES");
|
|
|
|
if(stry){
|
|
|
|
auto envy = std::stoi(stry, nullptr);
|
|
|
|
CHECK(envy == y);
|
2019-11-23 17:28:42 +00:00
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
auto strx = getenv("COLUMNS");
|
|
|
|
if(stry){
|
|
|
|
auto envx = std::stoi(strx, nullptr);
|
|
|
|
CHECK(envx == x);
|
2019-12-12 14:08:06 +00:00
|
|
|
}
|
2019-11-23 17:28:42 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 09:39:41 +00:00
|
|
|
SUBCASE("RefreshSameSize") {
|
2019-12-27 22:20:20 +00:00
|
|
|
int x, y;
|
|
|
|
notcurses_term_dim_yx(nc_, &y, &x);
|
|
|
|
int newx, newy;
|
2020-04-08 09:39:41 +00:00
|
|
|
CHECK(0 == notcurses_refresh(nc_, &newy, &newx));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(newx == x);
|
|
|
|
CHECK(newy == y);
|
2019-11-17 15:25:40 +00:00
|
|
|
}
|
2019-11-21 11:38:21 +00:00
|
|
|
|
2020-02-02 08:14:45 +00:00
|
|
|
// we should at least have NCSTYLE_BOLD everywhere, i should think?
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("CursesStyles") {
|
|
|
|
unsigned attrs = notcurses_supported_styles(nc_);
|
2020-02-02 08:14:45 +00:00
|
|
|
CHECK(1 == !!(NCSTYLE_BOLD & attrs));
|
2019-12-27 22:20:20 +00:00
|
|
|
}
|
2019-11-27 22:22:13 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
// it is an error to attempt to destroy the standard plane
|
|
|
|
SUBCASE("RejectDestroyStdPlane") {
|
|
|
|
ncplane* ncp = notcurses_stdplane(nc_);
|
|
|
|
REQUIRE(ncp);
|
|
|
|
REQUIRE(0 > ncplane_destroy(ncp));
|
|
|
|
}
|
2019-11-28 20:19:54 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
// it is an error to attempt to move the standard plane
|
|
|
|
SUBCASE("RejectMoveStdPlane") {
|
|
|
|
ncplane* ncp = notcurses_stdplane(nc_);
|
|
|
|
REQUIRE(ncp);
|
|
|
|
REQUIRE(0 > ncplane_move_yx(ncp, 1, 1));
|
|
|
|
}
|
2019-12-10 11:02:49 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
// create planes partitioning the entirety of the screen, one at each coordinate
|
|
|
|
SUBCASE("TileScreenWithPlanes") {
|
|
|
|
int maxx, maxy;
|
|
|
|
notcurses_term_dim_yx(nc_, &maxy, &maxx);
|
|
|
|
auto total = maxx * maxy;
|
2020-05-07 04:53:01 +00:00
|
|
|
auto planes = new struct ncplane*[total];
|
2019-12-27 22:20:20 +00:00
|
|
|
int* planesecrets = new int[total];
|
|
|
|
for(int y = 0 ; y < maxy ; ++y){
|
|
|
|
for(int x = 0 ; x < maxx ; ++x){
|
|
|
|
const auto idx = y * maxx + x;
|
2019-12-30 07:28:40 +00:00
|
|
|
planes[idx] = ncplane_new(nc_, 1, 1, y, x, &planesecrets[idx]);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(planes[idx]);
|
|
|
|
}
|
2019-11-28 20:19:54 +00:00
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(0 == notcurses_render(nc_));
|
|
|
|
for(int y = 0 ; y < maxy ; ++y){
|
|
|
|
for(int x = 0 ; x < maxx ; ++x){
|
|
|
|
const auto idx = y * maxx + x;
|
|
|
|
auto userptr = ncplane_userptr(planes[idx]);
|
|
|
|
REQUIRE(userptr);
|
|
|
|
CHECK(userptr == &planesecrets[idx]);
|
|
|
|
REQUIRE(0 == ncplane_destroy(planes[idx]));
|
|
|
|
}
|
2019-11-28 20:19:54 +00:00
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
delete[] planesecrets;
|
|
|
|
delete[] planes;
|
|
|
|
REQUIRE(0 == notcurses_render(nc_));
|
2019-11-28 20:19:54 +00:00
|
|
|
}
|
2019-12-08 18:00:19 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("ChannelSetFGAlpha"){
|
|
|
|
uint64_t channel = 0;
|
|
|
|
CHECK(0 > channels_set_fg_alpha(&channel, -1));
|
|
|
|
CHECK(0 > channels_set_fg_alpha(&channel, 4));
|
|
|
|
CHECK(0 == channels_set_fg_alpha(&channel, CELL_ALPHA_OPAQUE));
|
2019-12-30 04:47:42 +00:00
|
|
|
CHECK(CELL_ALPHA_OPAQUE == channels_fg_alpha(channel));
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(channels_fg_default_p(channel));
|
|
|
|
CHECK(channels_bg_default_p(channel));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == channels_set_fg_alpha(&channel, CELL_ALPHA_HIGHCONTRAST));
|
2019-12-30 04:47:42 +00:00
|
|
|
CHECK(CELL_ALPHA_HIGHCONTRAST == channels_fg_alpha(channel));
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(!channels_fg_default_p(channel));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(channels_bg_default_p(channel));
|
|
|
|
}
|
2019-12-08 18:00:19 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("ChannelSetBGAlpha"){
|
|
|
|
uint64_t channel = 0;
|
|
|
|
CHECK(0 > channels_set_bg_alpha(&channel, -1));
|
|
|
|
CHECK(0 > channels_set_bg_alpha(&channel, 4));
|
|
|
|
CHECK(0 == channels_set_bg_alpha(&channel, CELL_ALPHA_OPAQUE));
|
2019-12-30 04:47:42 +00:00
|
|
|
CHECK(CELL_ALPHA_OPAQUE == channels_bg_alpha(channel));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == channels_set_bg_alpha(&channel, CELL_ALPHA_TRANSPARENT));
|
|
|
|
CHECK(0 > channels_set_bg_alpha(&channel, CELL_ALPHA_HIGHCONTRAST));
|
2019-12-30 04:47:42 +00:00
|
|
|
CHECK(CELL_ALPHA_TRANSPARENT == channels_bg_alpha(channel));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(channels_fg_default_p(channel));
|
2020-02-23 17:11:28 +00:00
|
|
|
CHECK(!channels_bg_default_p(channel));
|
2019-12-27 22:20:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SUBCASE("Stats"){
|
|
|
|
struct ncstats stats;
|
|
|
|
notcurses_stats(nc_, &stats);
|
|
|
|
CHECK(0 == stats.renders);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
notcurses_stats(nc_, &stats);
|
|
|
|
CHECK(1 == stats.renders);
|
2019-12-29 08:24:32 +00:00
|
|
|
notcurses_reset_stats(nc_, &stats);
|
2019-12-27 22:20:20 +00:00
|
|
|
notcurses_stats(nc_, &stats);
|
|
|
|
CHECK(0 == stats.renders);
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
2019-12-20 05:05:03 +00:00
|
|
|
|
|
|
|
}
|