aboutsummaryrefslogblamecommitdiffstats
path: root/rtgrpblib_reset_raster.c
blob: a3b81dfe813017b981f70e95de9ab8d73517a9a8 (plain) (tree)
1
2
3
4
5
6
7
8
9







                                                                   
                                                                 















                                                                          

























































































                                                                          


      
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


int
rtgrpblib_reset_raster(RASTER *raster, size_t width, size_t height)
{
	if (!width || !height || width > raster->size / height) {
		errno = EINVAL;
		return -1;
	}

	raster->width = width;
	raster->height = height;
	memset(raster->cells, 0, width * height * sizeof(*raster->cells));
	return 0;
}


#else

int
main(void)
{
	
	RASTER *raster;
	size_t i, n, size;

	raster = rtgrpblib_create_raster(10, 20);
	ASSERT(raster);
	ASSERT(raster->width == 10);
	ASSERT(raster->height == 20);
	raster->draftness = 10;
	size = raster->width * raster->height;
	ASSERT(raster->size == size);

	errno = 0;
	ASSERT(rtgrpblib_reset_raster(raster, 10, 21) == -1);
	ASSERT(errno == EINVAL);
	ASSERT(raster->width == 10);
	ASSERT(raster->height == 20);
	ASSERT(raster->size == size);
	ASSERT(raster->draftness == 10);

	errno = 0;
	ASSERT(rtgrpblib_reset_raster(raster, 11, 20) == -1);
	ASSERT(errno == EINVAL);
	ASSERT(raster->width == 10);
	ASSERT(raster->height == 20);
	ASSERT(raster->size == size);
	ASSERT(raster->draftness == 10);

	errno = 0;
	ASSERT(rtgrpblib_reset_raster(raster, 1, 0) == -1);
	ASSERT(errno == EINVAL);
	ASSERT(raster->width == 10);
	ASSERT(raster->height == 20);
	ASSERT(raster->size == size);
	ASSERT(raster->draftness == 10);

	errno = 0;
	ASSERT(rtgrpblib_reset_raster(raster, 0, 1) == -1);
	ASSERT(errno == EINVAL);
	ASSERT(raster->width == 10);
	ASSERT(raster->height == 20);
	ASSERT(raster->size == size);
	ASSERT(raster->draftness == 10);

	errno = 0;
	ASSERT(rtgrpblib_reset_raster(raster, 0, 0) == -1);
	ASSERT(errno == EINVAL);
	ASSERT(raster->width == 10);
	ASSERT(raster->height == 20);
	ASSERT(raster->size == size);
	ASSERT(raster->draftness == 10);

	memset(raster->cells, 100, raster->size * sizeof(*raster->cells));
	ASSERT(!rtgrpblib_reset_raster(raster, 5, 10));
	ASSERT(raster->width == 5);
	ASSERT(raster->height == 10);
	ASSERT(raster->size == size);
	ASSERT(raster->draftness == 10);
	n = raster->width * raster->height;
	for (i = 0; i < n; i++) {
		ASSERT(!raster->cells[i].cell_coverage);
		ASSERT(!raster->cells[i].opposite_coverage);
	}

	memset(raster->cells, 100, raster->size * sizeof(*raster->cells));
	ASSERT(!rtgrpblib_reset_raster(raster, 5, 30));
	ASSERT(raster->width == 5);
	ASSERT(raster->height == 30);
	ASSERT(raster->size == size);
	ASSERT(raster->draftness == 10);
	n = raster->width * raster->height;
	for (i = 0; i < n; i++) {
		ASSERT(!raster->cells[i].cell_coverage);
		ASSERT(!raster->cells[i].opposite_coverage);
	}

	memset(raster->cells, 100, raster->size * sizeof(*raster->cells));
	ASSERT(!rtgrpblib_reset_raster(raster, 15, 10));
	ASSERT(raster->width == 15);
	ASSERT(raster->height == 10);
	ASSERT(raster->size == size);
	ASSERT(raster->draftness == 10);
	n = raster->width * raster->height;
	for (i = 0; i < n; i++) {
		ASSERT(!raster->cells[i].cell_coverage);
		ASSERT(!raster->cells[i].opposite_coverage);
	}

	free(raster);
	return 0;
}

#endif