This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via be558be3368503affa22139727420e1bdd01e27d (commit) from 785938474481fa23cda347fd25a3df7f0adde980 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/be558be3368503affa22139727420e1bdd01e...
commit be558be3368503affa22139727420e1bdd01e27d Author: Cyril Hrubis metan@ucw.cz Date: Wed Dec 5 22:39:35 2012 +0100
tests: Add basic polygon tests, more to come.
diff --git a/tests/gfx/Makefile b/tests/gfx/Makefile index d3c9b0e..1345a1f 100644 --- a/tests/gfx/Makefile +++ b/tests/gfx/Makefile @@ -3,11 +3,12 @@ include $(TOPDIR)/pre.mk
CSOURCES=$(shell echo *.c)
-APPS=gfx_benchmark Circle Line CircleSeg +APPS=gfx_benchmark Circle Line CircleSeg Polygon
Circle: common.o Line: common.o CircleSeg: common.o +Polygon: common.o
include ../tests.mk
diff --git a/tests/gfx/Polygon.c b/tests/gfx/Polygon.c new file mode 100644 index 0000000..96a7d72 --- /dev/null +++ b/tests/gfx/Polygon.c @@ -0,0 +1,214 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include <string.h> +#include <errno.h> +#include <sys/stat.h> + +#include <core/GP_Context.h> +#include <gfx/GP_Polygon.h> + +#include "tst_test.h" + +#include "common.h" + +struct testcase { + /* polygon description */ + unsigned int edge_count; + GP_Coord edges[20]; + + /* expected result */ + GP_Size w, h; + const char pixmap[]; +}; + +static int test_polygon(struct testcase *t) +{ + GP_Context *c; + int err; + + c = GP_ContextAlloc(t->w, t->h, GP_PIXEL_G8); + + if (c == NULL) { + tst_err("Failed to allocate context"); + return TST_UNTESTED; + } + + /* zero the pixels buffer */ + memset(c->pixels, 0, c->w * c->h); + + GP_FillPolygon(c, t->edge_count, t->edges, 1); + + err = compare_buffers(t->pixmap, c); + + if (err) { + tst_msg("Patterns are different"); + return TST_FAILED; + } + + return TST_SUCCESS; +} + +struct testcase testcase_1_edge = { + .edge_count = 1, + .edges = { + 1, 1, + }, + .w = 3, + .h = 3, + .pixmap = { + 0, 0, 0, + 0, 1, 0, + 0, 0, 0, + } +}; + +struct testcase testcase_5_edges_1px = { + .edge_count = 5, + .edges = { + 1, 1, + 1, 1, + 1, 1, + 1, 1, + 1, 1, + }, + .w = 3, + .h = 3, + .pixmap = { + 0, 0, 0, + 0, 1, 0, + 0, 0, 0, + } +}; + +struct testcase testcase_line_vert_3px = { + .edge_count = 2, + .edges = { + 1, 1, + 1, 3, + }, + .w = 5, + .h = 5, + .pixmap = { + 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, + } +}; + +struct testcase testcase_line_3px = { + .edge_count = 2, + .edges = { + 1, 1, + 2, 3, + }, + .w = 5, + .h = 5, + .pixmap = { + 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 1, 1, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, + } +}; + +struct testcase testcase_2x2_square = { + .edge_count = 4, + .edges = { + 1, 1, + 2, 1, + 2, 2, + 1, 2, + }, + .w = 4, + .h = 4, + .pixmap = { + 0, 0, 0, 0, + 0, 1, 1, 0, + 0, 1, 1, 0, + 0, 0, 0, 0, + } +}; + +struct testcase testcase_4px_triangle = { + .edge_count = 3, + .edges = { + 2, 1, + 1, 2, + 3, 2, + }, + .w = 5, + .h = 4, + .pixmap = { + 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 1, 1, 1, 0, + 0, 0, 0, 0, 0, + } +}; + + +static int test_1_edge(void) +{ + return test_polygon(&testcase_1_edge); +} + +static int test_5_edges_1px(void) +{ + return test_polygon(&testcase_5_edges_1px); +} + +static int test_line_vert_3px(void) +{ + return test_polygon(&testcase_line_vert_3px); +} + +static int test_line_3px(void) +{ + return test_polygon(&testcase_line_3px); +} + +static int test_2x2_square(void) +{ + return test_polygon(&testcase_2x2_square); +} + +static int test_4px_triangle(void) +{ + return test_polygon(&testcase_4px_triangle); +} + +const struct tst_suite tst_suite = { + .suite_name = "Polygon Testsuite", + .tests = { + {.name = "1 Edge Polygon", .tst_fn = test_1_edge}, + {.name = "5 Edges 1px Polygon", .tst_fn = test_5_edges_1px}, + {.name = "2x2 Square Polygon", .tst_fn = test_2x2_square}, + {.name = "Vert Line 3px Polygon", .tst_fn = test_line_vert_3px}, + {.name = "Line 3px Polygon", .tst_fn = test_line_3px}, + {.name = "Triangle 4px Polygon", .tst_fn = test_4px_triangle}, + {.name = NULL} + } +}; diff --git a/tests/gfx/runtest.sh b/tests/gfx/runtest.sh index bcef95e..bf430be 100755 --- a/tests/gfx/runtest.sh +++ b/tests/gfx/runtest.sh @@ -13,3 +13,4 @@ export LIBC_FATAL_STDERR_=1 LD_PRELOAD=`pwd`/../framework/libtst_preload.so LD_LIBRARY_PATH=../../build/ ./Circle "$@" LD_PRELOAD=`pwd`/../framework/libtst_preload.so LD_LIBRARY_PATH=../../build/ ./Line "$@" LD_PRELOAD=`pwd`/../framework/libtst_preload.so LD_LIBRARY_PATH=../../build/ ./CircleSeg "$@" +LD_PRELOAD=`pwd`/../framework/libtst_preload.so LD_LIBRARY_PATH=../../build/ ./Polygon "$@"
-----------------------------------------------------------------------
Summary of changes: tests/gfx/Makefile | 3 +- tests/gfx/Polygon.c | 214 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/gfx/runtest.sh | 1 + 3 files changed, 217 insertions(+), 1 deletions(-) create mode 100644 tests/gfx/Polygon.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.