mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-08 01:10:23 +00:00
[tester] kill memory leaks in two unit tests
This commit is contained in:
parent
ce2a6dc686
commit
01c6f8ba3d
52
src/tests/multiselector.cpp
Normal file
52
src/tests/multiselector.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "main.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
TEST_CASE("Multiselectors") {
|
||||
auto nc_ = testing_notcurses();
|
||||
if(!nc_){
|
||||
return;
|
||||
}
|
||||
struct ncplane* n_ = notcurses_stdplane(nc_);
|
||||
REQUIRE(n_);
|
||||
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
||||
|
||||
// multiselector can't be bound to the standard plane
|
||||
SUBCASE("RefuseStandardPlane") {
|
||||
ncmultiselector_options s{};
|
||||
struct ncmultiselector* ns = ncmultiselector_create(n_, &s);
|
||||
REQUIRE(nullptr == ns);
|
||||
}
|
||||
|
||||
// create a multiselector, but don't explicitly destroy it, thus testing the
|
||||
// context shutdown cleanup path
|
||||
SUBCASE("ImplicitDestroy") {
|
||||
ncmultiselector_options s{};
|
||||
struct ncplane_options nopts{};
|
||||
nopts.rows = 1;
|
||||
nopts.cols = 1;
|
||||
struct ncplane* n = ncplane_create(n_, &nopts);
|
||||
REQUIRE(nullptr != n);
|
||||
struct ncmultiselector* ns = ncmultiselector_create(n, &s);
|
||||
REQUIRE(ns);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
}
|
||||
|
||||
// now do the same, but with a plane we have created.
|
||||
SUBCASE("RefuseBoundCreatedPlane") {
|
||||
struct ncplane_options nopts{};
|
||||
nopts.rows = ncplane_dim_y(n_);
|
||||
nopts.cols = ncplane_dim_x(n_);
|
||||
auto ncp = ncplane_create(n_, &nopts);
|
||||
REQUIRE(nullptr != ncp);
|
||||
ncmultiselector_options s{};
|
||||
struct ncmultiselector* ns = ncmultiselector_create(ncp, &s);
|
||||
REQUIRE(ns);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
struct ncmultiselector* fail = ncmultiselector_create(ncp, &s);
|
||||
CHECK(nullptr == fail);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
}
|
||||
|
||||
CHECK(0 == notcurses_stop(nc_));
|
||||
}
|
@ -27,8 +27,7 @@ TEST_CASE("Readers") {
|
||||
};
|
||||
auto ncp = ncplane_create(notcurses_stdplane(nc_), &nopts);
|
||||
uint64_t echannels = NCCHANNELS_INITIALIZER(0xff, 0x44, 0xff, 0, 0, 0);
|
||||
ncplane_set_base(ncp, notcurses_canutf8(nc_) ? strdup("▒") : strdup("x"),
|
||||
0, echannels);
|
||||
ncplane_set_base(ncp, notcurses_canutf8(nc_) ? "\u2592" : "x", 0, echannels);
|
||||
auto nr = ncreader_create(ncp, &opts);
|
||||
REQUIRE(nullptr != nr);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
|
@ -66,6 +66,7 @@ TEST_CASE("Stacking") {
|
||||
// ought yield space with white background FIXME currently just yields
|
||||
// a lower half block
|
||||
CHECK(0 == strcmp("\u2584", egc));
|
||||
free(egc);
|
||||
CHECK(0xffffff == ncchannels_fg_rgb(channels));
|
||||
CHECK(0xffffff == ncchannels_bg_rgb(channels));
|
||||
CHECK(0 == ncplane_destroy(top));
|
||||
@ -151,6 +152,7 @@ TEST_CASE("Stacking") {
|
||||
// ought yield space with white background FIXME currently just yields
|
||||
// an upper half block
|
||||
CHECK(0 == strcmp("\u2580", egc));
|
||||
free(egc);
|
||||
CHECK(0x00ff00 == ncchannels_fg_rgb(channels));
|
||||
CHECK(0x00ff00 == ncchannels_bg_rgb(channels));
|
||||
CHECK(0 == ncplane_destroy(top));
|
||||
|
Loading…
Reference in New Issue
Block a user