mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-09 15:50:30 +01:00
test: Cleanup macros
The ARRAY_LENGTH macro is used by many tests, although sometimes it is named ARRAY_SIZE. Define it just once in cairo-test.h and reuse it. In a similar way, MAX() and MIN() are currently defined in some specific tests, while they could be reused.
This commit is contained in:
parent
4ef32a36ba
commit
75fea162d9
20 changed files with 52 additions and 70 deletions
|
|
@ -46,10 +46,8 @@ static const struct color {
|
|||
{ 1, 0, 1 },
|
||||
{ .5, .5, .5 },
|
||||
};
|
||||
#define NUM_COLORS (sizeof (color) / sizeof (color[0]))
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#define NUM_COLORS ARRAY_LENGTH (color)
|
||||
|
||||
static void
|
||||
object (cairo_t *cr, const struct color *fg, const struct color *bg)
|
||||
|
|
|
|||
|
|
@ -97,7 +97,6 @@
|
|||
#undef Cursor
|
||||
#endif
|
||||
|
||||
#define ARRAY_LENGTH(array) (sizeof (array) / sizeof ((array)[0]))
|
||||
#define surface_has_type(surface,type) (cairo_surface_get_type (surface) == (type))
|
||||
|
||||
typedef cairo_test_status_t (* surface_test_func_t) (cairo_surface_t *surface);
|
||||
|
|
|
|||
|
|
@ -79,6 +79,18 @@ cairo_test_NaN (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef ARRAY_LENGTH
|
||||
#define ARRAY_LENGTH(__array) ((int) (sizeof (__array) / sizeof (__array[0])))
|
||||
#endif
|
||||
|
||||
#define CAIRO_TEST_OUTPUT_DIR "output"
|
||||
|
||||
#define CAIRO_TEST_LOG_SUFFIX ".log"
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include "cairo-test.h"
|
||||
|
||||
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
|
||||
typedef enum {
|
||||
CLEAR,
|
||||
CLEARED,
|
||||
|
|
|
|||
|
|
@ -37,8 +37,6 @@
|
|||
* for a specific bug).
|
||||
*/
|
||||
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
#define GENERATE_REF 0
|
||||
|
||||
/* For determining whether we establish the clip path before or after
|
||||
|
|
|
|||
|
|
@ -122,9 +122,8 @@ static void (* const draw_funcs[])(cairo_t *cr, int x, int y) = {
|
|||
|
||||
#define N_OPERATORS (1 + CAIRO_OPERATOR_SATURATE - CAIRO_OPERATOR_CLEAR)
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
|
||||
#define IMAGE_WIDTH (N_OPERATORS * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_LENGTH (draw_funcs) * (HEIGHT + PAD) + PAD)
|
||||
|
||||
static cairo_test_status_t
|
||||
draw (cairo_t *cr, int width, int height)
|
||||
|
|
@ -139,7 +138,7 @@ draw (cairo_t *cr, int width, int height)
|
|||
CAIRO_FONT_WEIGHT_NORMAL);
|
||||
cairo_set_font_size (cr, 0.9 * HEIGHT);
|
||||
|
||||
for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
|
||||
for (j = 0; j < ARRAY_LENGTH (draw_funcs); j++) {
|
||||
for (op = CAIRO_OPERATOR_CLEAR; op < N_OPERATORS; op++) {
|
||||
x = op * (WIDTH + PAD) + PAD;
|
||||
y = j * (HEIGHT + PAD) + PAD;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@
|
|||
|
||||
#include "cairo-test.h"
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
|
||||
|
||||
/* Lengths of the dashes of the dash patterns */
|
||||
static const double dashes[] = { 2, 2, 4, 4 };
|
||||
/* Dash offset in userspace units
|
||||
|
|
@ -45,8 +43,8 @@ static const double int_offset[] = { -2, -1, 0, 1, 2 };
|
|||
|
||||
#define PAD 6
|
||||
#define STROKE_LENGTH 32
|
||||
#define IMAGE_WIDTH (PAD + (STROKE_LENGTH + PAD) * ARRAY_SIZE(dashes))
|
||||
#define IMAGE_HEIGHT (PAD + PAD * ARRAY_SIZE(int_offset) + PAD * ARRAY_SIZE(frac_offset) * ARRAY_SIZE(int_offset))
|
||||
#define IMAGE_WIDTH (PAD + (STROKE_LENGTH + PAD) * ARRAY_LENGTH (dashes))
|
||||
#define IMAGE_HEIGHT (PAD + PAD * ARRAY_LENGTH (int_offset) + PAD * ARRAY_LENGTH (frac_offset) * ARRAY_LENGTH (int_offset))
|
||||
|
||||
|
||||
static cairo_test_status_t
|
||||
|
|
@ -62,13 +60,13 @@ draw (cairo_t *cr, int width, int height)
|
|||
cairo_set_line_width (cr, 2);
|
||||
|
||||
total = 0.0;
|
||||
for (k = 0; k < ARRAY_SIZE(dashes); ++k) {
|
||||
for (k = 0; k < ARRAY_LENGTH (dashes); ++k) {
|
||||
total += dashes[k];
|
||||
for (i = 0; i < ARRAY_SIZE(frac_offset); ++i) {
|
||||
for (j = 0; j < ARRAY_SIZE(int_offset); ++j) {
|
||||
for (i = 0; i < ARRAY_LENGTH (frac_offset); ++i) {
|
||||
for (j = 0; j < ARRAY_LENGTH (int_offset); ++j) {
|
||||
cairo_set_dash (cr, dashes, k + 1, frac_offset[i] + total * int_offset[j]);
|
||||
cairo_move_to (cr, (STROKE_LENGTH + PAD) * k + PAD, PAD * (i + j + ARRAY_SIZE(frac_offset) * j + 1));
|
||||
cairo_line_to (cr, (STROKE_LENGTH + PAD) * (k + 1), PAD * (i + j + ARRAY_SIZE(frac_offset) * j + 1));
|
||||
cairo_move_to (cr, (STROKE_LENGTH + PAD) * k + PAD, PAD * (i + j + ARRAY_LENGTH (frac_offset) * j + 1));
|
||||
cairo_line_to (cr, (STROKE_LENGTH + PAD) * (k + 1), PAD * (i + j + ARRAY_LENGTH (frac_offset) * j + 1));
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,6 @@
|
|||
|
||||
#include "cairo-test.h"
|
||||
|
||||
#ifndef ARRAY_LENGTH
|
||||
#define ARRAY_LENGTH(A) (int) (sizeof (A) / sizeof ((A)[0]))
|
||||
#endif
|
||||
|
||||
#define PAD 5
|
||||
|
||||
static cairo_test_status_t
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@
|
|||
#define PAD 3.0
|
||||
#define LINE_WIDTH 6.0
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
static cairo_test_status_t
|
||||
draw (cairo_t *cr, int width, int height)
|
||||
{
|
||||
|
|
@ -40,7 +38,7 @@ draw (cairo_t *cr, int width, int height)
|
|||
|
||||
cairo_set_source_rgb (cr, 1, 0, 0);
|
||||
|
||||
for (i=0; i<ARRAY_SIZE(cap); i++) {
|
||||
for (i = 0; i < ARRAY_LENGTH (cap); i++) {
|
||||
cairo_save (cr);
|
||||
|
||||
cairo_set_line_cap (cr, cap[i]);
|
||||
|
|
|
|||
|
|
@ -143,8 +143,6 @@ scale_path_not_line_width (cairo_t *cr)
|
|||
cairo_restore (cr);
|
||||
}
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
|
||||
|
||||
static cairo_test_status_t
|
||||
draw (cairo_t *cr, int width, int height)
|
||||
{
|
||||
|
|
|
|||
13
test/mask.c
13
test/mask.c
|
|
@ -180,9 +180,8 @@ static void (* const clip_funcs[])(cairo_t *cr, int x, int y) = {
|
|||
clip_circle,
|
||||
};
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
|
||||
#define IMAGE_WIDTH (ARRAY_SIZE (pattern_funcs) * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_SIZE (mask_funcs) * ARRAY_SIZE (clip_funcs) * (HEIGHT + PAD) + PAD)
|
||||
#define IMAGE_WIDTH (ARRAY_LENGTH (pattern_funcs) * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_LENGTH (mask_funcs) * ARRAY_LENGTH (clip_funcs) * (HEIGHT + PAD) + PAD)
|
||||
|
||||
static cairo_test_status_t
|
||||
draw (cairo_t *cr, int width, int height)
|
||||
|
|
@ -201,11 +200,11 @@ draw (cairo_t *cr, int width, int height)
|
|||
cr2 = cairo_create (tmp_surface);
|
||||
cairo_surface_destroy (tmp_surface);
|
||||
|
||||
for (k = 0; k < ARRAY_SIZE (clip_funcs); k++) {
|
||||
for (j = 0; j < ARRAY_SIZE (mask_funcs); j++) {
|
||||
for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) {
|
||||
for (k = 0; k < ARRAY_LENGTH (clip_funcs); k++) {
|
||||
for (j = 0; j < ARRAY_LENGTH (mask_funcs); j++) {
|
||||
for (i = 0; i < ARRAY_LENGTH (pattern_funcs); i++) {
|
||||
int x = i * (WIDTH + PAD) + PAD;
|
||||
int y = (ARRAY_SIZE (mask_funcs) * k + j) * (HEIGHT + PAD) + PAD;
|
||||
int y = (ARRAY_LENGTH (mask_funcs) * k + j) * (HEIGHT + PAD) + PAD;
|
||||
|
||||
/* Clear intermediate surface we are going to be drawing onto */
|
||||
cairo_save (cr2);
|
||||
|
|
|
|||
|
|
@ -138,9 +138,8 @@ static void (* const draw_funcs[])(cairo_t *cr, int x, int y) = {
|
|||
draw_rects
|
||||
};
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
|
||||
#define IMAGE_WIDTH (ARRAY_SIZE (pattern_funcs) * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD)
|
||||
#define IMAGE_WIDTH (ARRAY_LENGTH (pattern_funcs) * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_LENGTH (draw_funcs) * (HEIGHT + PAD) + PAD)
|
||||
|
||||
static cairo_test_status_t
|
||||
draw (cairo_t *cr, int width, int height)
|
||||
|
|
@ -153,8 +152,8 @@ draw (cairo_t *cr, int width, int height)
|
|||
CAIRO_FONT_SLANT_NORMAL,
|
||||
CAIRO_FONT_WEIGHT_NORMAL);
|
||||
|
||||
for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
|
||||
for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) {
|
||||
for (j = 0; j < ARRAY_LENGTH (draw_funcs); j++) {
|
||||
for (i = 0; i < ARRAY_LENGTH (pattern_funcs); i++) {
|
||||
x = i * (WIDTH + PAD) + PAD;
|
||||
y = j * (HEIGHT + PAD) + PAD;
|
||||
|
||||
|
|
|
|||
|
|
@ -175,9 +175,8 @@ static void (* const draw_funcs[])(cairo_t *cr, int x, int y) = {
|
|||
draw_rects
|
||||
};
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
|
||||
#define IMAGE_WIDTH (ARRAY_SIZE (pattern_funcs) * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD)
|
||||
#define IMAGE_WIDTH (ARRAY_LENGTH (pattern_funcs) * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_LENGTH (draw_funcs) * (HEIGHT + PAD) + PAD)
|
||||
|
||||
static cairo_test_status_t
|
||||
draw (cairo_t *cr, int width, int height)
|
||||
|
|
@ -190,8 +189,8 @@ draw (cairo_t *cr, int width, int height)
|
|||
CAIRO_FONT_SLANT_NORMAL,
|
||||
CAIRO_FONT_WEIGHT_NORMAL);
|
||||
|
||||
for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
|
||||
for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) {
|
||||
for (j = 0; j < ARRAY_LENGTH (draw_funcs); j++) {
|
||||
for (i = 0; i < ARRAY_LENGTH (pattern_funcs); i++) {
|
||||
x = i * (WIDTH + PAD) + PAD;
|
||||
y = j * (HEIGHT + PAD) + PAD;
|
||||
|
||||
|
|
|
|||
|
|
@ -40,8 +40,6 @@
|
|||
#define MM_TO_POINTS(mm) ((mm) / 25.4 * 72.0)
|
||||
#define TEXT_SIZE 12
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
static struct {
|
||||
const char *page_size;
|
||||
const char *page_size_alias;
|
||||
|
|
@ -110,7 +108,7 @@ preamble (cairo_test_context_t *ctx)
|
|||
CAIRO_FONT_WEIGHT_NORMAL);
|
||||
cairo_set_font_size (cr, TEXT_SIZE);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (pages); i++) {
|
||||
for (i = 0; i < ARRAY_LENGTH (pages); i++) {
|
||||
cairo_pdf_surface_set_size (surface,
|
||||
pages[i].width_in_points,
|
||||
pages[i].height_in_points);
|
||||
|
|
|
|||
|
|
@ -43,8 +43,6 @@
|
|||
#define MM_TO_POINTS(mm) ((mm) / 25.4 * 72.0)
|
||||
#define TEXT_SIZE 12
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
static struct {
|
||||
const char *page_size;
|
||||
const char *page_size_alias;
|
||||
|
|
@ -123,7 +121,7 @@ preamble (cairo_test_context_t *ctx)
|
|||
CAIRO_FONT_WEIGHT_NORMAL);
|
||||
cairo_set_font_size (cr, TEXT_SIZE);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (pages); i++) {
|
||||
for (i = 0; i < ARRAY_LENGTH (pages); i++) {
|
||||
cairo_ps_surface_set_size (surface,
|
||||
pages[i].width_in_points,
|
||||
pages[i].height_in_points);
|
||||
|
|
|
|||
|
|
@ -99,8 +99,8 @@ create_pattern (int index)
|
|||
radius1 = radiuses[NUM_GRADIENTS - index - 1];
|
||||
|
||||
/* center the gradient */
|
||||
left = fmin (x0 - radius0, x1 - radius1);
|
||||
right = fmax (x0 + radius0, x1 + radius1);
|
||||
left = MIN (x0 - radius0, x1 - radius1);
|
||||
right = MAX (x0 + radius0, x1 + radius1);
|
||||
center = (left + right) * 0.5;
|
||||
x0 -= center;
|
||||
x1 -= center;
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@
|
|||
|
||||
#include "cairo-test.h"
|
||||
|
||||
#define ARRAY_LENGTH(array) (sizeof (array) / sizeof ((array)[0]))
|
||||
|
||||
#define TARGET_SIZE 10
|
||||
|
||||
#define SUB_SIZE 15
|
||||
|
|
|
|||
|
|
@ -167,9 +167,8 @@ static void (* const clip_funcs[])(cairo_t *cr, int x, int y) = {
|
|||
clip_circle,
|
||||
};
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
|
||||
#define IMAGE_WIDTH (ARRAY_SIZE (pattern_funcs) * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * ARRAY_SIZE (clip_funcs) * (HEIGHT + PAD) + PAD)
|
||||
#define IMAGE_WIDTH (ARRAY_LENGTH (pattern_funcs) * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_LENGTH (draw_funcs) * ARRAY_LENGTH (clip_funcs) * (HEIGHT + PAD) + PAD)
|
||||
|
||||
static cairo_test_status_t
|
||||
draw (cairo_t *cr, int width, int height)
|
||||
|
|
@ -177,11 +176,11 @@ draw (cairo_t *cr, int width, int height)
|
|||
const cairo_test_context_t *ctx = cairo_test_get_context (cr);
|
||||
size_t i, j, k, x, y;
|
||||
|
||||
for (k = 0; k < ARRAY_SIZE (clip_funcs); k++) {
|
||||
for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
|
||||
for (i = 0; i < ARRAY_SIZE (pattern_funcs); i++) {
|
||||
for (k = 0; k < ARRAY_LENGTH (clip_funcs); k++) {
|
||||
for (j = 0; j < ARRAY_LENGTH (draw_funcs); j++) {
|
||||
for (i = 0; i < ARRAY_LENGTH (pattern_funcs); i++) {
|
||||
x = i * (WIDTH + PAD) + PAD;
|
||||
y = (ARRAY_SIZE (draw_funcs) * k + j) * (HEIGHT + PAD) + PAD;
|
||||
y = (ARRAY_LENGTH (draw_funcs) * k + j) * (HEIGHT + PAD) + PAD;
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
|
|
|
|||
|
|
@ -126,9 +126,8 @@ static cairo_operator_t operators[] = {
|
|||
CAIRO_OPERATOR_DEST_IN, CAIRO_OPERATOR_DEST_ATOP
|
||||
};
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
|
||||
#define IMAGE_WIDTH (ARRAY_SIZE (operators) * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD)
|
||||
#define IMAGE_WIDTH (ARRAY_LENGTH (operators) * (WIDTH + PAD) + PAD)
|
||||
#define IMAGE_HEIGHT (ARRAY_LENGTH (draw_funcs) * (HEIGHT + PAD) + PAD)
|
||||
|
||||
static cairo_test_status_t
|
||||
draw (cairo_t *cr, int width, int height)
|
||||
|
|
@ -141,8 +140,8 @@ draw (cairo_t *cr, int width, int height)
|
|||
CAIRO_FONT_SLANT_NORMAL,
|
||||
CAIRO_FONT_WEIGHT_NORMAL);
|
||||
|
||||
for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) {
|
||||
for (i = 0; i < ARRAY_SIZE (operators); i++) {
|
||||
for (j = 0; j < ARRAY_LENGTH (draw_funcs); j++) {
|
||||
for (i = 0; i < ARRAY_LENGTH (operators); i++) {
|
||||
x = i * (WIDTH + PAD) + PAD;
|
||||
y = j * (HEIGHT + PAD) + PAD;
|
||||
|
||||
|
|
|
|||
|
|
@ -135,8 +135,6 @@ mask_with_extend_none (cairo_t *cr)
|
|||
cairo_surface_destroy (surface);
|
||||
}
|
||||
|
||||
#define ARRAY_LENGTH(array) (sizeof (array) / sizeof ((array)[0]))
|
||||
|
||||
typedef void (* mask_func_t) (cairo_t *);
|
||||
|
||||
static mask_func_t mask_funcs[] = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue