From 4a9ce6e2555dfaf9155fa279f25667350377f688 Mon Sep 17 00:00:00 2001 From: Daniil Rozanov Date: Sat, 15 Mar 2025 18:03:23 +0400 Subject: feat: chtype wrap --- tests/curs_char/curs_char.cpp | 173 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 tests/curs_char/curs_char.cpp (limited to 'tests/curs_char') 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 +#define NCURSES_CPP_CHAR_VALUE_AS_PUBLIC + +#include +#include + +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('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('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('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('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; +} -- cgit v1.2.3