summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2011-03-16 16:48:18 +0100
committerAndrea Canciani <ranma42@gmail.com>2011-03-17 17:45:57 +0100
commit75fea162d985bea622afa59771fb2d07f5241d1b (patch)
tree5876692cd2ba574481210fae292eaf7f06005028
parent4ef32a36ba1e457e8dd6244a6483866d33477aac (diff)
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.
-rw-r--r--test/aliasing.c6
-rw-r--r--test/api-special-cases.c1
-rw-r--r--test/cairo-test.h12
-rw-r--r--test/clear-source.c1
-rw-r--r--test/clip-group-shapes.c2
-rw-r--r--test/clip-operator.c5
-rw-r--r--test/dash-offset.c16
-rw-r--r--test/degenerate-dash.c4
-rw-r--r--test/degenerate-path.c4
-rw-r--r--test/line-width-scale.c2
-rw-r--r--test/mask.c13
-rw-r--r--test/operator-clear.c9
-rw-r--r--test/operator-source.c9
-rw-r--r--test/pdf-features.c4
-rw-r--r--test/ps-features.c4
-rw-r--r--test/radial-gradient.c4
-rw-r--r--test/subsurface-outside-target.c2
-rw-r--r--test/trap-clip.c13
-rw-r--r--test/unbounded-operator.c9
-rw-r--r--test/zero-mask.c2
20 files changed, 52 insertions, 70 deletions
diff --git a/test/aliasing.c b/test/aliasing.c
index 78a6d031..73c1f1ae 100644
--- a/test/aliasing.c
+++ b/test/aliasing.c
@@ -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)
diff --git a/test/api-special-cases.c b/test/api-special-cases.c
index 6e51fe60..dbe9eb2c 100644
--- a/test/api-special-cases.c
+++ b/test/api-special-cases.c
@@ -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);
diff --git a/test/cairo-test.h b/test/cairo-test.h
index c7abd3d6..c4f38c55 100644
--- a/test/cairo-test.h
+++ b/test/cairo-test.h
@@ -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"
diff --git a/test/clear-source.c b/test/clear-source.c
index 4583bfb0..a4c3db2f 100644
--- a/test/clear-source.c
+++ b/test/clear-source.c
@@ -26,7 +26,6 @@
#include "cairo-test.h"
-#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
typedef enum {
CLEAR,
CLEARED,
diff --git a/test/clip-group-shapes.c b/test/clip-group-shapes.c
index aefaa559..88bb9b3d 100644
--- a/test/clip-group-shapes.c
+++ b/test/clip-group-shapes.c
@@ -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
diff --git a/test/clip-operator.c b/test/clip-operator.c
index ec437e02..aaa34453 100644
--- a/test/clip-operator.c
+++ b/test/clip-operator.c
@@ -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;
diff --git a/test/dash-offset.c b/test/dash-offset.c
index 3699cacb..0e536870 100644
--- a/test/dash-offset.c
+++ b/test/dash-offset.c
@@ -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);
}
}
diff --git a/test/degenerate-dash.c b/test/degenerate-dash.c
index 961eeb5b..c13792f5 100644
--- a/test/degenerate-dash.c
+++ b/test/degenerate-dash.c
@@ -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
diff --git a/test/degenerate-path.c b/test/degenerate-path.c
index 97cf7b28..c6907300 100644
--- a/test/degenerate-path.c
+++ b/test/degenerate-path.c
@@ -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]);
diff --git a/test/line-width-scale.c b/test/line-width-scale.c
index 68e1f111..037b887f 100644
--- a/test/line-width-scale.c
+++ b/test/line-width-scale.c
@@ -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)
{
diff --git a/test/mask.c b/test/mask.c
index 451054e3..cc722d38 100644
--- a/test/mask.c
+++ b/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);
diff --git a/test/operator-clear.c b/test/operator-clear.c
index a1cf9810..aac39f3d 100644
--- a/test/operator-clear.c
+++ b/test/operator-clear.c
@@ -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;
diff --git a/test/operator-source.c b/test/operator-source.c
index c92b4ad7..d734167c 100644
--- a/test/operator-source.c
+++ b/test/operator-source.c
@@ -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;
diff --git a/test/pdf-features.c b/test/pdf-features.c
index 31099c94..f8850c4c 100644
--- a/test/pdf-features.c
+++ b/test/pdf-features.c
@@ -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);
diff --git a/test/ps-features.c b/test/ps-features.c
index c1fb7308..e3cf9b46 100644
--- a/test/ps-features.c
+++ b/test/ps-features.c
@@ -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);
diff --git a/test/radial-gradient.c b/test/radial-gradient.c
index 25ced708..026876b1 100644
--- a/test/radial-gradient.c
+++ b/test/radial-gradient.c
@@ -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;
diff --git a/test/subsurface-outside-target.c b/test/subsurface-outside-target.c
index c60ca8ae..5e84a840 100644
--- a/test/subsurface-outside-target.c
+++ b/test/subsurface-outside-target.c
@@ -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
diff --git a/test/trap-clip.c b/test/trap-clip.c
index 0999d971..acfcafcb 100644
--- a/test/trap-clip.c
+++ b/test/trap-clip.c
@@ -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);
diff --git a/test/unbounded-operator.c b/test/unbounded-operator.c
index 065bff91..6e132fb2 100644
--- a/test/unbounded-operator.c
+++ b/test/unbounded-operator.c
@@ -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;
diff --git a/test/zero-mask.c b/test/zero-mask.c
index 5ea0709f..29edd0a5 100644
--- a/test/zero-mask.c
+++ b/test/zero-mask.c
@@ -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[] = {