Rename GP_Context -> GP_Pixmap
[gfxprim.git] / tests / gfx / LineAA.c
blobc559cf87b2de09f97858bf47f870b1ff39c8ba36
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include <string.h>
24 #include <errno.h>
25 #include <sys/stat.h>
27 #include <core/GP_Pixmap.h>
28 #include <gfx/GP_LineAA.h>
30 #include "tst_test.h"
32 #include "common.h"
34 struct testcase {
35 /* line description */
36 GP_Coord x0;
37 GP_Coord y0;
38 GP_Coord x1;
39 GP_Coord y1;
41 /* expected result */
42 GP_Size w, h;
43 const char pixmap[];
46 static int test_line(const struct testcase *t)
48 GP_Pixmap *c;
49 int err;
51 c = GP_PixmapAlloc(t->w, t->h, GP_PIXEL_G8);
53 if (c == NULL) {
54 tst_err("Failed to allocate pixmap");
55 return TST_UNTESTED;
58 /* zero the pixels buffer */
59 memset(c->pixels, 0, c->w * c->h);
61 GP_LineAA(c, t->x0, t->y0, t->x1, t->y1, 0xff);
63 err = compare_buffers(t->pixmap, c);
65 if (err)
66 return TST_FAILED;
68 return TST_SUCCESS;
71 static struct testcase testcase_line_1px = {
72 .x0 = (1<<8) + (1<<7),
73 .y0 = (1<<8) + (1<<7),
74 .x1 = (1<<8) + (1<<7),
75 .y1 = (1<<8) + (1<<7),
77 .w = 3,
78 .h = 3,
80 .pixmap = {
81 0x00, 0x00, 0x00,
82 0x00, 0xff, 0x00,
83 0x00, 0x00, 0x00,
87 static struct testcase testcase_line_2px = {
88 .x0 = (1<<8),
89 .y0 = (1<<8),
90 .x1 = (2<<8),
91 .y1 = (2<<8),
93 .w = 4,
94 .h = 4,
96 .pixmap = {
97 0x00, 0x00, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00,
99 0x00, 0x00, 0x00, 0x00,
100 0x00, 0x00, 0x00, 0x00,
104 static struct testcase testcase_line_2px_h = {
105 .x0 = (1<<8),
106 .y0 = (1<<8),
107 .x1 = (2<<8),
108 .y1 = (1<<8),
110 .w = 4,
111 .h = 4,
113 .pixmap = {
114 0x00, 0x00, 0x00, 0x00,
115 0x00, 0x00, 0x00, 0x00,
116 0x00, 0x00, 0x00, 0x00,
117 0x00, 0x00, 0x00, 0x00,
121 static struct testcase testcase_line_2px_v = {
122 .x0 = (1<<8),
123 .y0 = (1<<8),
124 .x1 = (1<<8),
125 .y1 = (2<<8),
127 .w = 4,
128 .h = 4,
130 .pixmap = {
131 0x00, 0x00, 0x00, 0x00,
132 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00,
134 0x00, 0x00, 0x00, 0x00,
139 const struct tst_suite tst_suite = {
140 .suite_name = "LineAA Testsuite",
141 .tests = {
142 {.name = "LineAA 1px",
143 .tst_fn = test_line,
144 .data = &testcase_line_1px},
146 {.name = "LineAA 2px",
147 .tst_fn = test_line,
148 .data = &testcase_line_2px},
150 {.name = "LineAA 2px horizontal",
151 .tst_fn = test_line,
152 .data = &testcase_line_2px_h},
154 {.name = "LineAA 2px vertical",
155 .tst_fn = test_line,
156 .data = &testcase_line_2px_v},
158 {.name = NULL}