xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
<root> / tests / colmgr / basic.c (fed22fcdf7802efac22ae40e4b5c509237db9943) (2,134B) (mode 100644) [raw]
#include <stic.h>

#include <curses.h>

#include <limits.h>

#include "../../src/ui/colors.h"
#include "../../src/ui/color_manager.h"
#include "../../src/utils/macros.h"

#include "test.h"

static int count_available_pairs(int seed, int max);

SETUP()
{
	colmgr_reset();
}

TEST(number_of_available_pairs)
{
	assert_int_equal(CUSTOM_COLOR_PAIRS,
			count_available_pairs(INUSE_SEED, INT_MAX));
}

TEST(number_of_available_pairs_after_reset)
{
	(void)count_available_pairs(INUSE_SEED, INT_MAX);
	colmgr_reset();
	assert_int_equal(CUSTOM_COLOR_PAIRS,
			count_available_pairs(INUSE_SEED, INT_MAX));
}

TEST(compression)
{
	assert_int_equal(CUSTOM_COLOR_PAIRS,
			count_available_pairs(UNUSED_SEED, CUSTOM_COLOR_PAIRS));
	assert_int_equal(CUSTOM_COLOR_PAIRS,
			count_available_pairs(INUSE_SEED, INT_MAX));
}

static int
count_available_pairs(int seed, int max)
{
	int i = 0;
	while(i < max && colmgr_get_pair(seed, i) != 0)
	{
		++i;
	}
	return i;
}

TEST(reuse_of_existing_pair)
{
	assert_int_equal(colmgr_get_pair(1, 1), colmgr_get_pair(1, 1));
}

TEST(negative_fg_and_or_bg)
{
	assert_true(colmgr_get_pair(-1, 0) >= 0);
	assert_true(colmgr_get_pair(0, -1) >= 0);
	assert_true(colmgr_get_pair(-1, -1) >= 0);
}

TEST(auto_compression_on_out_of_pairs)
{
	int i;

	/* Mark upper half of custom colors as used. */
	for(i = 0; i < CUSTOM_COLOR_PAIRS/2; ++i)
	{
		assert_int_equal(RESERVED_COLOR_PAIRS + i, colmgr_get_pair(UNUSED_SEED, i));
	}
	for(i = CUSTOM_COLOR_PAIRS/2; i < CUSTOM_COLOR_PAIRS; ++i)
	{
		assert_int_equal(RESERVED_COLOR_PAIRS + i, colmgr_get_pair(INUSE_SEED, i));
	}

	/* Cause compression. */
	assert_int_equal(RESERVED_COLOR_PAIRS + DIV_ROUND_UP(CUSTOM_COLOR_PAIRS, 2),
			colmgr_get_pair(INUSE_SEED, CUSTOM_COLOR_PAIRS));

	/* Verify that all used colors were moved to the bottom half. */
	for(i = RESERVED_COLOR_PAIRS; i < RESERVED_COLOR_PAIRS + CUSTOM_COLOR_PAIRS/2;
			++i)
	{
		assert_int_equal(INUSE_SEED, colors[i][0]);
		assert_int_equal(CUSTOM_COLOR_PAIRS/2 + i, colors[i][1]);
	}
}

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master