[babl] tests: add CHECK_CONV_FLOAT to common.inc
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] tests: add CHECK_CONV_FLOAT to common.inc
- Date: Thu, 8 Jun 2017 17:58:21 +0000 (UTC)
commit c8b5eee3f86a49bd093929f0bd16ef780de88c67
Author: Ell <ell_se yahoo com>
Date: Thu Jun 8 09:02:35 2017 -0400
tests: add CHECK_CONV_FLOAT to common.inc
Like CHECK_CONV, but for floating point destination types.
Use CHECK_CONV_FLOAT in hsva.c and hsl.c, instead of custom
CHECK_CONV implementations. To be used by another test soon.
tests/common.inc | 26 ++++++++++++++++++++++++++
tests/hsl.c | 42 +++++++++---------------------------------
tests/hsva.c | 41 +++++++++--------------------------------
3 files changed, 44 insertions(+), 65 deletions(-)
---
diff --git a/tests/common.inc b/tests/common.inc
index 501644a..bca5056 100644
--- a/tests/common.inc
+++ b/tests/common.inc
@@ -1,4 +1,5 @@
+#include <math.h>
#include "babl/babl-introspect.h"
#define CHECK_CONV(test_name, componenttype, src_fmt, dst_fmt, src_pix, expected_pix) \
@@ -25,3 +26,28 @@
} \
} \
}
+
+#define CHECK_CONV_FLOAT(test_name, componenttype, max_error, src_fmt, dst_fmt, src_pix, expected_pix) \
+ { \
+ const Babl *fish; \
+ int i; \
+ fish = babl_fish (src_fmt, dst_fmt); \
+ if (!fish) \
+ { \
+ printf (" %s failed to make fish\n", test_name); \
+ OK = 0; \
+ } \
+ for (i = 0; i < sizeof(src_pix)/sizeof(src_pix[0]); i ++) \
+ { \
+ int c;\
+ componenttype result[10]; \
+ babl_process (fish, src_pix[i], result, 1); \
+ for (c = 0; c < sizeof(expected_pix[i])/sizeof(expected_pix[i][0]); c++) \
+ if (fabs(result[c] - expected_pix[i][c]) > max_error) \
+ { \
+ printf (" %s failed #%i[%i] got %lf expected %lf\n", test_name, i, c, result[c],
expected_pix[i][c]); \
+ OK = 0; \
+ babl_introspect((Babl *)fish); \
+ } \
+ } \
+ }
diff --git a/tests/hsl.c b/tests/hsl.c
index 4b24db2..ab71747 100644
--- a/tests/hsl.c
+++ b/tests/hsl.c
@@ -15,36 +15,12 @@
* <http://www.gnu.org/licenses/>.
*/
-#include <math.h>
#include <stdio.h>
#include "config.h"
#include "babl.h"
-#define CHECK_CONV(test_name, componenttype, src_fmt, dst_fmt, src_pix, expected_pix) \
- { \
- const Babl *fish; \
- int i; \
- fish = babl_fish (src_fmt, dst_fmt); \
- if (!fish) \
- { \
- printf (" %s failed to make fish\n", test_name); \
- OK = 0; \
- } \
- for (i = 0; i < sizeof(src_pix)/sizeof(src_pix[0]); i ++) \
- { \
- int c; \
- componenttype result[10]; \
- babl_process (fish, src_pix[i], result, 1); \
- for (c = 0; c < sizeof(expected_pix[i])/sizeof(expected_pix[i][0]); c++) \
- if (fabs(result[c] - expected_pix[i][c]) > 0.001) \
- { \
- printf (" %s failed #%i[%i] got %lf expected %lf\n", \
- test_name, i, c, result[c], expected_pix[i][c]); \
- OK = 0; \
- } \
- } \
- }
+#include "common.inc"
int
@@ -95,15 +71,15 @@ main (int argc,
babl_init ();
- CHECK_CONV ("rgba to hsla ", float,
- babl_format ("RGBA float"),
- babl_format ("HSLA float"),
- rgba, hsla);
+ CHECK_CONV_FLOAT ("rgba to hsla ", float, 0.001,
+ babl_format ("RGBA float"),
+ babl_format ("HSLA float"),
+ rgba, hsla);
- CHECK_CONV ("hsla to rgba ", float,
- babl_format ("HSLA float"),
- babl_format ("RGBA float"),
- hsla, rgba);
+ CHECK_CONV_FLOAT ("hsla to rgba ", float, 0.001,
+ babl_format ("HSLA float"),
+ babl_format ("RGBA float"),
+ hsla, rgba);
babl_exit ();
diff --git a/tests/hsva.c b/tests/hsva.c
index a29f506..97a723a 100644
--- a/tests/hsva.c
+++ b/tests/hsva.c
@@ -24,34 +24,11 @@
#include "config.h"
#include <stdlib.h>
-#include <math.h>
#include <stdio.h>
#include <assert.h>
#include "babl.h"
-#define CHECK_CONV(test_name, componenttype, src_fmt, dst_fmt, src_pix, expected_pix) \
- { \
- const Babl *fish; \
- int i; \
- fish = babl_fish (src_fmt, dst_fmt); \
- if (!fish) \
- { \
- printf (" %s failed to make fish\n", test_name); \
- OK = 0; \
- } \
- for (i = 0; i < sizeof(src_pix)/sizeof(src_pix[0]); i ++) \
- { \
- int c;\
- componenttype result[10]; \
- babl_process (fish, src_pix[i], result, 1); \
- for (c = 0; c < sizeof(expected_pix[i])/sizeof(expected_pix[i][0]); c++) \
- if (fabs(result[c] - expected_pix[i][c]) > 0.001) \
- { \
- printf (" %s failed #%i[%i] got %lf expected %lf\n", test_name, i, c, result[c],
expected_pix[i][c]); \
- OK = 0; \
- } \
- } \
- }
+#include "common.inc"
int
@@ -100,15 +77,15 @@ main (int argc,
babl_init ();
- CHECK_CONV ("rgba to hsva ", float,
- babl_format ("RGBA float"),
- babl_format ("HSVA float"),
- rgba, hsva);
+ CHECK_CONV_FLOAT ("rgba to hsva ", float, 0.001,
+ babl_format ("RGBA float"),
+ babl_format ("HSVA float"),
+ rgba, hsva);
- CHECK_CONV ("hsva to rgba ", float,
- babl_format ("HSVA float"),
- babl_format ("RGBA float"),
- hsva, rgba);
+ CHECK_CONV_FLOAT ("rgba to hsva ", float, 0.001,
+ babl_format ("HSVA float"),
+ babl_format ("RGBA float"),
+ hsva, rgba);
babl_exit ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]