summaryrefslogtreecommitdiff
path: root/tests/colors/colors.cpp
blob: dfed2754d8ecb2034ed6ceaef73b0f752afee073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
}