2020-02-01 22:36:42 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include <cstring>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
TEST_CASE("MenuTest") {
|
|
|
|
notcurses_options nopts{};
|
|
|
|
nopts.inhibit_alternate_screen = true;
|
|
|
|
nopts.suppress_banner = true;
|
2020-05-17 11:57:21 +00:00
|
|
|
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
|
|
|
|
if(!nc_){
|
|
|
|
return;
|
|
|
|
}
|
2020-02-01 22:36:42 +00:00
|
|
|
struct ncplane* n_ = notcurses_stdplane(nc_);
|
|
|
|
REQUIRE(n_);
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
2020-02-03 18:08:45 +00:00
|
|
|
// an empty menu ought be rejected
|
|
|
|
SUBCASE("EmptyMenuTopReject") {
|
2020-02-02 11:02:57 +00:00
|
|
|
struct ncmenu_options opts{};
|
2020-05-09 12:41:19 +00:00
|
|
|
struct ncmenu* ncm = ncmenu_create(n_, &opts);
|
2020-02-03 18:08:45 +00:00
|
|
|
REQUIRE(nullptr == ncm);
|
2020-02-01 22:36:42 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-10 20:18:28 +00:00
|
|
|
ncmenu_destroy(ncm);
|
2020-02-01 22:36:42 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 18:08:45 +00:00
|
|
|
SUBCASE("EmptyMenuBottomReject") {
|
2020-02-02 11:02:57 +00:00
|
|
|
struct ncmenu_options opts{};
|
2020-05-09 12:41:19 +00:00
|
|
|
opts.flags = NCMENU_OPTIONS_BOTTOM;
|
|
|
|
struct ncmenu* ncm = ncmenu_create(n_, &opts);
|
2020-02-03 18:08:45 +00:00
|
|
|
REQUIRE(nullptr == ncm);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-10 20:18:28 +00:00
|
|
|
ncmenu_destroy(ncm);
|
2020-02-03 18:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// an empty section ought be rejected
|
|
|
|
SUBCASE("EmptySectionReject") {
|
|
|
|
struct ncmenu_options opts{};
|
|
|
|
struct ncmenu_section sections[] = {
|
2020-02-09 03:24:31 +00:00
|
|
|
{ .name = strdup("Empty"), .itemcount = 0, .items = nullptr, .shortcut = ncinput(), },
|
2020-02-03 18:08:45 +00:00
|
|
|
};
|
|
|
|
opts.sections = sections;
|
|
|
|
opts.sectioncount = sizeof(sections) / sizeof(*sections);
|
2020-05-09 12:41:19 +00:00
|
|
|
struct ncmenu* ncm = ncmenu_create(n_, &opts);
|
2020-02-03 18:08:45 +00:00
|
|
|
REQUIRE(nullptr == ncm);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-10 20:18:28 +00:00
|
|
|
ncmenu_destroy(ncm);
|
2020-02-03 18:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// a section with only separators ought be rejected
|
|
|
|
SUBCASE("SeparatorSectionReject") {
|
|
|
|
struct ncmenu_item empty_items[] = {
|
2020-02-09 03:24:31 +00:00
|
|
|
{ .desc = nullptr, .shortcut = ncinput(), },
|
2020-02-03 18:08:45 +00:00
|
|
|
};
|
|
|
|
struct ncmenu_section sections[] = {
|
2020-02-09 03:24:31 +00:00
|
|
|
{ .name = strdup("Empty"), .itemcount = 1, .items = empty_items, .shortcut = ncinput(), },
|
2020-02-03 18:08:45 +00:00
|
|
|
};
|
|
|
|
struct ncmenu_options opts{};
|
|
|
|
opts.sections = sections;
|
|
|
|
opts.sectioncount = sizeof(sections) / sizeof(*sections);
|
2020-05-09 12:41:19 +00:00
|
|
|
struct ncmenu* ncm = ncmenu_create(n_, &opts);
|
2020-02-03 18:08:45 +00:00
|
|
|
REQUIRE(nullptr == ncm);
|
2020-02-01 22:36:42 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-10 20:18:28 +00:00
|
|
|
ncmenu_destroy(ncm);
|
2020-02-01 22:36:42 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 17:46:40 +00:00
|
|
|
SUBCASE("MenuOneSection") {
|
|
|
|
struct ncmenu_item file_items[] = {
|
2020-02-09 03:24:31 +00:00
|
|
|
{ .desc = strdup("I would like a new file"), .shortcut = ncinput(), },
|
2020-02-03 17:46:40 +00:00
|
|
|
};
|
|
|
|
struct ncmenu_section sections[] = {
|
2020-02-09 03:24:31 +00:00
|
|
|
{ .name = strdup("File"), .itemcount = sizeof(file_items) / sizeof(*file_items), .items = file_items, .shortcut = ncinput(), },
|
2020-02-03 17:46:40 +00:00
|
|
|
};
|
|
|
|
struct ncmenu_options opts{};
|
|
|
|
opts.sections = sections;
|
|
|
|
opts.sectioncount = sizeof(sections) / sizeof(*sections);
|
2020-05-09 12:41:19 +00:00
|
|
|
struct ncmenu* ncm = ncmenu_create(n_, &opts);
|
2020-02-03 17:46:40 +00:00
|
|
|
REQUIRE(nullptr != ncm);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-10 20:18:28 +00:00
|
|
|
ncmenu_destroy(ncm);
|
2020-02-04 05:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// don't call ncmenu_destroy(), invoking destruction in notcurses_stop()
|
|
|
|
SUBCASE("MenuNoFree") {
|
|
|
|
struct ncmenu_item file_items[] = {
|
2020-02-09 03:24:31 +00:00
|
|
|
{ .desc = strdup("I would like a new file"), .shortcut = ncinput(), },
|
2020-02-04 05:08:03 +00:00
|
|
|
};
|
|
|
|
struct ncmenu_section sections[] = {
|
2020-02-09 03:24:31 +00:00
|
|
|
{ .name = strdup("File"), .itemcount = sizeof(file_items) / sizeof(*file_items), .items = file_items, .shortcut = ncinput(), },
|
2020-02-04 05:08:03 +00:00
|
|
|
};
|
|
|
|
struct ncmenu_options opts{};
|
|
|
|
opts.sections = sections;
|
|
|
|
opts.sectioncount = sizeof(sections) / sizeof(*sections);
|
2020-05-09 12:41:19 +00:00
|
|
|
struct ncmenu* ncm = ncmenu_create(n_, &opts);
|
2020-02-04 05:08:03 +00:00
|
|
|
REQUIRE(nullptr != ncm);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-03 17:46:40 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 10:13:13 +00:00
|
|
|
SUBCASE("RightAlignedSection") {
|
|
|
|
struct ncmenu_item items[] = {
|
|
|
|
{ .desc = strdup("Yet another crappy item"), .shortcut = {}, },
|
|
|
|
};
|
|
|
|
struct ncmenu_section sections[] = {
|
|
|
|
{ .name = strdup("Left section"), .itemcount = sizeof(items) / sizeof(*items),
|
|
|
|
.items = items, .shortcut = {}, },
|
|
|
|
{ .name = nullptr, .itemcount = sizeof(items) / sizeof(*items),
|
|
|
|
.items = items, .shortcut = {}, },
|
|
|
|
{ .name = strdup("Right section"), .itemcount = sizeof(items) / sizeof(*items),
|
|
|
|
.items = items, .shortcut = {}, },
|
|
|
|
};
|
|
|
|
struct ncmenu_options opts{};
|
|
|
|
opts.sections = sections;
|
|
|
|
opts.sectioncount = sizeof(sections) / sizeof(*sections);
|
2020-05-09 12:41:19 +00:00
|
|
|
struct ncmenu* ncm = ncmenu_create(n_, &opts);
|
2020-02-09 10:13:13 +00:00
|
|
|
REQUIRE(nullptr != ncm);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-10 20:18:28 +00:00
|
|
|
ncmenu_destroy(ncm);
|
2020-02-09 10:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// you must have sections, not just an alignment NULL section
|
|
|
|
SUBCASE("OnlyAlignRejected") {
|
|
|
|
struct ncmenu_section sections[] = {
|
|
|
|
{ .name = nullptr, .itemcount = 0, .items = nullptr, .shortcut = {}, },
|
|
|
|
};
|
|
|
|
struct ncmenu_options opts{};
|
|
|
|
opts.sections = sections;
|
|
|
|
opts.sectioncount = sizeof(sections) / sizeof(*sections);
|
2020-05-09 12:41:19 +00:00
|
|
|
struct ncmenu* ncm = ncmenu_create(n_, &opts);
|
2020-02-09 10:13:13 +00:00
|
|
|
REQUIRE(nullptr == ncm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// you can only shift to right alignment once in a menu
|
|
|
|
SUBCASE("DoubleAlignRejected") {
|
|
|
|
struct ncmenu_item items[] = {
|
|
|
|
{ .desc = strdup("Yet another crappy item"), .shortcut = {}, },
|
|
|
|
};
|
|
|
|
struct ncmenu_section sections[] = {
|
|
|
|
{ .name = strdup("Left section"), .itemcount = sizeof(items) / sizeof(*items),
|
|
|
|
.items = items, .shortcut = {}, },
|
|
|
|
{ .name = nullptr, .itemcount = sizeof(items) / sizeof(*items),
|
|
|
|
.items = items, .shortcut = {}, },
|
|
|
|
{ .name = nullptr, .itemcount = sizeof(items) / sizeof(*items),
|
|
|
|
.items = items, .shortcut = {}, },
|
|
|
|
{ .name = strdup("Right section"), .itemcount = sizeof(items) / sizeof(*items),
|
|
|
|
.items = items, .shortcut = {}, },
|
|
|
|
};
|
|
|
|
struct ncmenu_options opts{};
|
|
|
|
opts.sections = sections;
|
|
|
|
opts.sectioncount = sizeof(sections) / sizeof(*sections);
|
2020-05-09 12:41:19 +00:00
|
|
|
struct ncmenu* ncm = ncmenu_create(n_, &opts);
|
2020-02-09 10:13:13 +00:00
|
|
|
REQUIRE(nullptr == ncm);
|
|
|
|
}
|
|
|
|
|
2020-02-03 20:20:40 +00:00
|
|
|
SUBCASE("VeryLongMenu") {
|
|
|
|
struct ncmenu_item items[] = {
|
2020-02-09 03:24:31 +00:00
|
|
|
{ .desc = strdup("Generic menu entry"), .shortcut = ncinput(), },
|
2020-02-03 20:20:40 +00:00
|
|
|
};
|
|
|
|
struct ncmenu_section sections[] = {
|
2020-02-09 03:24:31 +00:00
|
|
|
{ .name = strdup("antidisestablishmentarianism"), .itemcount = sizeof(items) / sizeof(*items), .items = items, .shortcut = ncinput(), },
|
|
|
|
{ .name = strdup("floccinaucinihilipilification"), .itemcount = sizeof(items) / sizeof(*items), .items = items, .shortcut = ncinput(), },
|
|
|
|
{ .name = strdup("pneumonoultramicroscopicsilicovolcanoconiosis"), .itemcount = sizeof(items) / sizeof(*items), .items = items, .shortcut = ncinput(), },
|
|
|
|
{ .name = strdup("supercalifragilisticexpialidocious"), .itemcount = sizeof(items) / sizeof(*items), .items = items, .shortcut = ncinput(), },
|
|
|
|
{ .name = strdup("Incomprehensibilities"), .itemcount = sizeof(items) / sizeof(*items), .items = items, .shortcut = ncinput(), },
|
2020-02-03 20:20:40 +00:00
|
|
|
};
|
|
|
|
struct ncmenu_options opts{};
|
|
|
|
opts.sections = sections;
|
|
|
|
opts.sectioncount = sizeof(sections) / sizeof(*sections);
|
2020-05-09 12:41:19 +00:00
|
|
|
struct ncmenu* ncm = ncmenu_create(n_, &opts);
|
2020-02-03 20:20:40 +00:00
|
|
|
REQUIRE(nullptr != ncm);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-10 20:18:28 +00:00
|
|
|
ncmenu_destroy(ncm);
|
2020-02-03 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
2020-02-01 22:36:42 +00:00
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
|
|
|
}
|