summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniil Rozanov <dev@rozanov.info>2025-03-15 18:03:23 +0400
committerDaniil Rozanov <dev@rozanov.info>2025-03-15 18:03:23 +0400
commit4a9ce6e2555dfaf9155fa279f25667350377f688 (patch)
tree11bc0ea3a7b1c0be2c47419b7058d46d16e5f9f4 /tests
feat: chtype wrap
Diffstat (limited to 'tests')
-rw-r--r--tests/colors/colors.cpp47
-rw-r--r--tests/curs_char/curs_char.cpp173
-rw-r--r--tests/flags/flags.cpp23
-rw-r--r--tests/multiflags/multiflags.cpp64
4 files changed, 307 insertions, 0 deletions
diff --git a/tests/colors/colors.cpp b/tests/colors/colors.cpp
new file mode 100644
index 0000000..dfed275
--- /dev/null
+++ b/tests/colors/colors.cpp
@@ -0,0 +1,47 @@
+#include <cassert>
+#include <cstdlib>
+#include <ncurses.h>
+#include <ncurses/colors.hpp>
+
+using uc = unsigned char;
+
+void test_color(int index, uc r, uc g, uc b) {
+ short r_, g_, b_;
+ assert(color_content(static_cast<short>(index), &r_, &g_, &b_) == OK);
+ assert(static_cast<unsigned char>(ncurses::curses_to_rgb(r_) == r));
+ assert(static_cast<unsigned char>(ncurses::curses_to_rgb(g_) == g));
+ assert(static_cast<unsigned char>(ncurses::curses_to_rgb(b_) == b));
+}
+
+void test_color_pair(int index, int a_index, int a_r, int a_g, int a_b,
+ int b_index, int b_r, int b_g, int b_b) {
+ short a_index_, a_r_, a_g_, a_b_, b_index_, b_r_, b_g_, b_b_;
+ assert(pair_content(index, &a_index_, &b_index_) == OK);
+ assert(a_index_ == a_index && b_index_ == b_index);
+ test_color(a_index, a_r, a_g, a_b);
+ test_color(b_index, b_r, b_g, b_b);
+}
+
+int main(int argc, char *argv[]) {
+ initscr();
+ if (has_colors() == FALSE) {
+ endwin();
+ std::exit(1);
+ }
+ start_color();
+
+ uc i = 0;
+ while (1) {
+ assert(i == ncurses::curses_to_rgb(ncurses::rgb_to_curses(i)));
+ if (i == 255)
+ break;
+ i++;
+ }
+
+ // TODO: what if user wants to use color/pair as rvalue, or instantiate it as
+ // a variable? Problem is current realization only accepts api as above.
+ // Should I forbid anything else or somehow extend functionality?
+
+ endwin();
+ return 0;
+}
diff --git a/tests/curs_char/curs_char.cpp b/tests/curs_char/curs_char.cpp
new file mode 100644
index 0000000..a076e89
--- /dev/null
+++ b/tests/curs_char/curs_char.cpp
@@ -0,0 +1,173 @@
+#include <cassert>
+#define NCURSES_CPP_CHAR_VALUE_AS_PUBLIC
+
+#include <ncurses.h>
+#include <ncurses/curs_char.hpp>
+
+int main(int argc, char *argv[]) {
+ using namespace NCURSES_CPP_NAMESPACE;
+ // # Bitwise operators (member and global)
+ {
+ // ## With attr
+ curs_char c = 'a';
+ assert(c.value_ == static_cast<curs_char::value_type>('a'));
+ assert((c & attr::altcharset).value_ == ('a' & A_ALTCHARSET));
+ assert((c | attr::altcharset).value_ == ('a' | A_ALTCHARSET));
+ assert((c ^ attr::altcharset).value_ == ('a' ^ A_ALTCHARSET));
+ assert((attr::altcharset & c).value_ == ('a' & A_ALTCHARSET));
+ assert((attr::altcharset | c).value_ == ('a' | A_ALTCHARSET));
+ assert((attr::altcharset ^ c).value_ == ('a' ^ A_ALTCHARSET));
+ assert(('a' & attr::altcharset).value_ == ('a' & A_ALTCHARSET));
+ assert(('a' | attr::altcharset).value_ == ('a' | A_ALTCHARSET));
+ assert(('a' ^ attr::altcharset).value_ == ('a' ^ A_ALTCHARSET));
+ assert((attr::altcharset & 'a').value_ == ('a' & A_ALTCHARSET));
+ assert((attr::altcharset | 'a').value_ == ('a' | A_ALTCHARSET));
+ assert((attr::altcharset ^ 'a').value_ == ('a' ^ A_ALTCHARSET));
+
+ // ## With attr_flags
+ c = 'b';
+ assert(c.value_ == static_cast<curs_char::value_type>('b'));
+ assert((c & (attr::bold | attr::dim)).value_ == ('b' & (A_BOLD | A_DIM)));
+ assert((c | (attr::bold | attr::dim)).value_ == ('b' | (A_BOLD | A_DIM)));
+ assert((c ^ (attr::bold | attr::dim)).value_ == ('b' ^ (A_BOLD | A_DIM)));
+ assert(((attr::bold | attr::dim) & c).value_ == ('b' & (A_BOLD | A_DIM)));
+ assert(((attr::bold | attr::dim) | c).value_ == ('b' | (A_BOLD | A_DIM)));
+ assert(((attr::bold | attr::dim) ^ c).value_ == ('b' ^ (A_BOLD | A_DIM)));
+ assert(('b' & (attr::bold | attr::dim)).value_ == ('b' & (A_BOLD | A_DIM)));
+ assert(('b' | (attr::bold | attr::dim)).value_ == ('b' | (A_BOLD | A_DIM)));
+ assert(('b' ^ (attr::bold | attr::dim)).value_ == ('b' ^ (A_BOLD | A_DIM)));
+ assert(((attr::bold | attr::dim) & 'b').value_ == ('b' & (A_BOLD | A_DIM)));
+ assert(((attr::bold | attr::dim) | 'b').value_ == ('b' | (A_BOLD | A_DIM)));
+ assert(((attr::bold | attr::dim) ^ 'b').value_ == ('b' ^ (A_BOLD | A_DIM)));
+
+ // ## With color_pair
+ c = 'c';
+ assert(c.value_ == static_cast<curs_char::value_type>('c'));
+ assert((c & color_pair(10)).value_ == ('c' & COLOR_PAIR(10)));
+ assert((c | color_pair(10)).value_ == ('c' | COLOR_PAIR(10)));
+ assert((c ^ color_pair(10)).value_ == ('c' ^ COLOR_PAIR(10)));
+ assert((color_pair(10) & c).value_ == ('c' & COLOR_PAIR(10)));
+ assert((color_pair(10) | c).value_ == ('c' | COLOR_PAIR(10)));
+ assert((color_pair(10) ^ c).value_ == ('c' ^ COLOR_PAIR(10)));
+ assert(('c' & color_pair(10)).value_ == ('c' & COLOR_PAIR(10)));
+ assert(('c' | color_pair(10)).value_ == ('c' | COLOR_PAIR(10)));
+ assert(('c' ^ color_pair(10)).value_ == ('c' ^ COLOR_PAIR(10)));
+ assert((color_pair(10) & 'c').value_ == ('c' & COLOR_PAIR(10)));
+ assert((color_pair(10) | 'c').value_ == ('c' | COLOR_PAIR(10)));
+ assert((color_pair(10) ^ 'c').value_ == ('c' ^ COLOR_PAIR(10)));
+
+ // ## With full_attrs
+ // clang-format off
+ c = 'd';
+ assert(c.value_ == static_cast<curs_char::value_type>('d'));
+ assert((c & (attr::invis | attr::standout | color_pair(3))).value_ == ('d' & (A_INVIS | A_STANDOUT | COLOR_PAIR(3))));
+ assert((c | (attr::invis | attr::standout | color_pair(3))).value_ == ('d' | A_INVIS | A_STANDOUT | COLOR_PAIR(3)));
+ assert((c ^ (attr::invis | attr::standout | color_pair(3))).value_ == ('d' ^ (A_INVIS | A_STANDOUT | COLOR_PAIR(3))));
+ assert(((attr::invis | attr::standout | color_pair(3)) & c).value_ == ('d' & (A_INVIS | A_STANDOUT | COLOR_PAIR(3))));
+ assert(((attr::invis | attr::standout | color_pair(3)) | c).value_ == ('d' | A_INVIS | A_STANDOUT | COLOR_PAIR(3)));
+ assert(((attr::invis | attr::standout | color_pair(3)) ^ c).value_ == ('d' ^ (A_INVIS | A_STANDOUT | COLOR_PAIR(3))));
+ assert(('d' & (attr::invis | attr::standout | color_pair(3))).value_ == ('d' & (A_INVIS | A_STANDOUT | COLOR_PAIR(3))));
+ assert(('d' | (attr::invis | attr::standout | color_pair(3))).value_ == ('d' | A_INVIS | A_STANDOUT | COLOR_PAIR(3)));
+ assert(('d' ^ (attr::invis | attr::standout | color_pair(3))).value_ == ('d' ^ (A_INVIS | A_STANDOUT | COLOR_PAIR(3))));
+ assert(((attr::invis | attr::standout | color_pair(3)) & 'd').value_ == ('d' & (A_INVIS | A_STANDOUT | COLOR_PAIR(3))));
+ assert(((attr::invis | attr::standout | color_pair(3)) | 'd').value_ == ('d' | A_INVIS | A_STANDOUT | COLOR_PAIR(3)));
+ assert(((attr::invis | attr::standout | color_pair(3)) ^ 'd').value_ == ('d' ^ (A_INVIS | A_STANDOUT | COLOR_PAIR(3))));
+ // clang-format on
+ }
+ // # Assignment operators
+ {
+ // # With attr
+ {
+ curs_char c = 'a';
+ c &= attr::altcharset;
+ assert(c.value_ == ('a' & A_ALTCHARSET));
+ }
+ {
+ curs_char c = 'a';
+ c |= attr::altcharset;
+ assert(c.value_ == ('a' | A_ALTCHARSET));
+ }
+ {
+ curs_char c = 'a';
+ c ^= attr::altcharset;
+ assert(c.value_ == ('a' ^ A_ALTCHARSET));
+ }
+ // # With attr_flags
+ {
+ curs_char c = 'a';
+ c &= (attr::altcharset | attr::blink);
+ assert(c.value_ == ('a' & (A_ALTCHARSET | A_BLINK)));
+ }
+ {
+ curs_char c = 'a';
+ c |= (attr::altcharset | attr::blink);
+ assert(c.value_ == ('a' & (A_ALTCHARSET | A_BLINK)));
+ }
+ {
+ curs_char c = 'a';
+ c ^= (attr::altcharset | attr::blink);
+ assert(c.value_ == ('a' & (A_ALTCHARSET | A_BLINK)));
+ }
+ // # With color_pair
+ {
+ curs_char c = 'a';
+ c &= color_pair(7);
+ assert(c.value_ == ('a' & (COLOR_PAIR(10))));
+ }
+ {
+ curs_char c = 'a';
+ c |= color_pair(7);
+ assert(c.value_ == ('a' | (COLOR_PAIR(10))));
+ }
+ {
+ curs_char c = 'a';
+ c ^= color_pair(7);
+ assert(c.value_ == ('a' ^ (COLOR_PAIR(10))));
+ }
+ //
+ // # With full_attrs
+ {
+ curs_char c = 'a';
+ c &= (attr::invis | attr::standout | color_pair(3));
+ assert(c.value_ == ('a' & (A_INVIS | A_STANDOUT | COLOR_PAIR(3))));
+ }
+ {
+ curs_char c = 'a';
+ c |= (attr::invis | attr::standout | color_pair(3));
+ assert(c.value_ == ('a' | A_INVIS | A_STANDOUT | COLOR_PAIR(3)));
+ }
+ {
+ curs_char c = 'a';
+ c ^= (attr::invis | attr::standout | color_pair(3));
+ assert(c.value_ == ('a' ^ (A_INVIS | A_STANDOUT | COLOR_PAIR(3))));
+ }
+ }
+ // # Relational operators
+ {
+ curs_char a = 'a';
+ curs_char b = 'b';
+ curs_char c = 'a';
+ assert(a == a);
+ assert(a == c);
+ assert(a != b);
+ assert(a < b);
+ assert(a <= b);
+ assert(b > a);
+ assert(b >= a);
+
+ assert(b == 'b');
+ assert(b != 'a');
+ assert(b > 'a');
+ assert(b >= 'a');
+ assert(b < 'c');
+ assert(b <= 'c');
+
+ assert('b' == b);
+ assert('a' != b);
+ assert('a' < b);
+ assert('a' <= b);
+ assert('c' > b);
+ assert('c' >= b);
+ }
+ return 0;
+}
diff --git a/tests/flags/flags.cpp b/tests/flags/flags.cpp
new file mode 100644
index 0000000..101a6ec
--- /dev/null
+++ b/tests/flags/flags.cpp
@@ -0,0 +1,23 @@
+#include <ncurses.h>
+#define NCURSES_CPP_FLAGS_MASK_TYPE_AS_PUBLIC
+
+#include <cassert>
+#include <ncurses/char_attributes.hpp>
+
+int main(int argc, char *argv[]) {
+ ncurses::attr_flags attr1;
+ assert(attr1.mask_ == 0);
+
+ attr1 = ncurses::attr::blink;
+ assert(attr1.mask_ == A_BLINK);
+
+ auto attr2(attr1);
+ assert(attr2.mask_ == A_BLINK);
+
+ attr1 = ncurses::attr::blink | ncurses::attr::underline;
+ assert(attr1.mask_ == (A_BLINK | A_UNDERLINE));
+
+ attr1 = ncurses::attr::dim | ncurses::attr::chartext | ncurses::attr::bold;
+ assert(attr1.mask_ == (A_DIM | A_CHARTEXT | A_BOLD));
+ return 0;
+}
diff --git a/tests/multiflags/multiflags.cpp b/tests/multiflags/multiflags.cpp
new file mode 100644
index 0000000..e689892
--- /dev/null
+++ b/tests/multiflags/multiflags.cpp
@@ -0,0 +1,64 @@
+#include <ncurses.h>
+#define NCURSES_CPP_FLAGS_MASK_TYPE_AS_PUBLIC
+
+#include <cassert>
+#include <ncurses/char_attributes.hpp>
+#include <ncurses/colors.hpp>
+#include <ncurses/utils/multiflags.hpp>
+
+using namespace ncurses;
+
+template <> struct is_applyable<color_pair, attr> : std::true_type {};
+
+using full_attrs = multiflags<attr, color_pair>;
+
+int main(int argc, char *argv[]) {
+ {
+ full_attrs attr;
+ assert(attr.value_ == 0);
+
+ attr = attr::blink;
+ assert(attr.value_ == A_BLINK);
+
+ attr = color_pair(22);
+ assert(attr.value_ == COLOR_PAIR(22));
+
+ attr = attr::bold | attr::italic | attr::top;
+ assert(attr.value_ == (A_TOP | A_ITALIC | A_BOLD));
+ }
+ {
+ full_attrs attr = attr::color | color_pair(10);
+ assert(attr.value_ == (A_COLOR | COLOR_PAIR(10)));
+ }
+ {
+ full_attrs attr = color_pair(10) | attr::color;
+ assert(attr.value_ == (A_COLOR | COLOR_PAIR(10)));
+ }
+ {
+ full_attrs attr = color_pair(11) | attr::altcharset | attr::dim;
+ assert(attr.value_ == (A_ALTCHARSET | A_DIM | COLOR_PAIR(11)));
+ }
+ {
+ full_attrs attr = attr::top | color_pair(30);
+ assert(attr != color_pair(1));
+ assert(attr != attr::chartext);
+ assert(attr != (attr::bold | attr::dim));
+ assert(attr != (attr::bold | attr::dim | color_pair(1)));
+ assert(attr == (full_attrs(attr::top) | color_pair(30)));
+ }
+ {
+ full_attrs attr;
+ // attr_flags to full_attrs
+ attr = attr_flags(attr::top | attr::dim | attr::bold);
+ // color + attr to full_attrs + attr to full_attrs
+ attr = color_pair(1) | attr::top | attr::bold;
+
+ // color + attr_flags to full_attrs
+ attr = color_pair(2) | (attr::top & attr::bold);
+
+ // attr_flags + color to full_attrs
+ attr = (attr::top & attr::bold) | color_pair(2);
+ }
+
+ return 0;
+}