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/colors/colors.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/colors/colors.cpp (limited to 'tests/colors') 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 +#include +#include +#include + +using uc = unsigned char; + +void test_color(int index, uc r, uc g, uc b) { + short r_, g_, b_; + assert(color_content(static_cast(index), &r_, &g_, &b_) == OK); + assert(static_cast(ncurses::curses_to_rgb(r_) == r)); + assert(static_cast(ncurses::curses_to_rgb(g_) == g)); + assert(static_cast(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; +} -- cgit v1.2.3