diff options
author | Mattias Andrée <maandree@kth.se> | 2023-01-08 22:39:00 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-01-08 22:39:00 +0100 |
commit | 68d533e7fdbbd33d720412aaab1848200b6c8863 (patch) | |
tree | e6310d970993ccb4886d6e6a4e2924cce0f14d89 | |
parent | Fix warnings (diff) | |
download | libfonts-68d533e7fdbbd33d720412aaab1848200b6c8863.tar.gz libfonts-68d533e7fdbbd33d720412aaab1848200b6c8863.tar.bz2 libfonts-68d533e7fdbbd33d720412aaab1848200b6c8863.tar.xz |
m + add tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | common.h | 91 | ||||
-rw-r--r-- | libfonts_calculate_subpixel_order.c | 14 | ||||
-rw-r--r-- | libfonts_parse_aa__.c | 46 | ||||
-rw-r--r-- | libfonts_parse_order__.c | 99 | ||||
-rw-r--r-- | libfonts_parse_uint32__.c | 38 |
5 files changed, 184 insertions, 104 deletions
@@ -31,6 +31,97 @@ X(11, "v-coloured-text-aa", vertical_colour_text_antialiasing, LIBFONTS_ANTIALIASING_GREYSCALE, libfonts_parse_aa__) _\ X(12, "d-coloured-text-aa", diagonal_colour_text_antialiasing, LIBFONTS_ANTIALIASING_GREYSCALE, libfonts_parse_aa__) +#define LIST_ANTIALIASINGS(X, _)\ + X(LIBFONTS_ANTIALIASING_UNSPECIFIED, "unspecified") _\ + X(LIBFONTS_ANTIALIASING_NONE, "none") _\ + X(LIBFONTS_ANTIALIASING_NONE, "aliased") _\ + X(LIBFONTS_ANTIALIASING_GREYSCALE, "greyscale") _\ + X(LIBFONTS_ANTIALIASING_GREYSCALE, "grayscale") _\ + X(LIBFONTS_ANTIALIASING_GREYSCALE, "grey") _\ + X(LIBFONTS_ANTIALIASING_GREYSCALE, "gray") _\ + X(LIBFONTS_ANTIALIASING_GREYSCALE, "antialiased") _\ + X(LIBFONTS_ANTIALIASING_GREYSCALE_FORCED, "greyscale!") _\ + X(LIBFONTS_ANTIALIASING_GREYSCALE_FORCED, "grayscale!") _\ + X(LIBFONTS_ANTIALIASING_GREYSCALE_FORCED, "grey!") _\ + X(LIBFONTS_ANTIALIASING_GREYSCALE_FORCED, "gray!") _\ + X(LIBFONTS_ANTIALIASING_GREYSCALE_FORCED, "antialiased!") _\ + X(LIBFONTS_ANTIALIASING_SUBPIXEL, "subpixel") _\ + X(LIBFONTS_ANTIALIASING_SUBPIXEL, "glitter") _\ + X(LIBFONTS_ANTIALIASING_SUBPIXEL_FORCED, "subpixel!") _\ + X(LIBFONTS_ANTIALIASING_SUBPIXEL_FORCED, "glitter!") + +#define LIST_SUBPIXEL_ORDERS(X, _)\ + X(LIBFONTS_SUBPIXEL_ORDER_UNKNOWN, "unknown") _\ + X(LIBFONTS_SUBPIXEL_ORDER_NONRGB, "non-rgb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_NONLINEAR, "non-linear") _\ + X(LIBFONTS_SUBPIXEL_ORDER_OTHER, "other") _\ + X(LIBFONTS_SUBPIXEL_ORDER_RGB, "rgb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_R_G_B, "r:g:b") _\ + X(LIBFONTS_SUBPIXEL_ORDER_R_G_B, "vrgb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BGR, "bgr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_B_G_R, "b:g:r") _\ + X(LIBFONTS_SUBPIXEL_ORDER_B_G_R, "vbgr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_GBR, "gbr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_G_B_R, "g:b:r") _\ + X(LIBFONTS_SUBPIXEL_ORDER_G_B_R, "vgbr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_RBG, "rbg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_R_B_G, "r:b:g") _\ + X(LIBFONTS_SUBPIXEL_ORDER_R_B_G, "vrbg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BRG, "brg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_B_R_G, "b:r:g") _\ + X(LIBFONTS_SUBPIXEL_ORDER_B_R_G, "vbrg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_GRB, "grb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_G_R_B, "g:r:b") _\ + X(LIBFONTS_SUBPIXEL_ORDER_G_R_B, "vgrb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_RR_GB, "rr:gb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_GR_BR, "gr:br") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BG_RR, "bg:rr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_RB_RG, "rb:rg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_RR_BG, "rr:bg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BR_GR, "br:gr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_GB_RR, "gb:rr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_RG_RB, "rg:rb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_GG_RB, "gg:rb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_RG_BG, "rg:bg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BR_GG, "br:gg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_GB_GR, "gb:gr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_GG_BR, "gg:br") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BG_RG, "bg:rg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_RB_GG, "rb:gg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_GR_GB, "gr:gb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BB_RG, "bb:rg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_RB_GB, "rb:gb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_GR_BB, "gr:bb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BG_BR, "bg:br") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BB_GR, "bb:gr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_GB_RB, "gb:rb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_RG_BB, "rg:bb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BR_BG, "br:bg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RR_GB, "balanced rr:gb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GR_BR, "balanced gr:br") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BG_RR, "balanced bg:rr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RB_RG, "balanced rb:rg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RR_BG, "balanced rr:bg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BR_GR, "balanced br:gr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GB_RR, "balanced gb:rr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RG_RB, "balanced rg:rb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GG_RB, "balanced gg:rb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RG_BG, "balanced rg:bg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BR_GG, "balanced br:gg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GB_GR, "balanced gb:gr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GG_BR, "balanced gg:br") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BG_RG, "balanced bg:rg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RB_GG, "balanced rb:gg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GR_GB, "balanced gr:gb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BB_RG, "balanced bb:rg") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RB_GB, "balanced rb:gb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GR_BB, "balanced gr:bb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BG_BR, "balanced bg:br") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BB_GR, "balanced bb:gr") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GB_RB, "balanced gb:rb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RG_BB, "balanced rg:bb") _\ + X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BR_BG, "balanced br:bg") + static inline void transform(double *x_out, double *y_out, double x, double y, const struct libfonts_transformation *transformation) diff --git a/libfonts_calculate_subpixel_order.c b/libfonts_calculate_subpixel_order.c index 5727fc9..d674be0 100644 --- a/libfonts_calculate_subpixel_order.c +++ b/libfonts_calculate_subpixel_order.c @@ -173,22 +173,22 @@ test(int xtrans, int ytrans, int zscale, int xscale, int yscale) do {\ FLIP_(A, B);\ FLIP_(B, A);\ - } while(0) + } while (0) #define FLOP(A, B)\ do {\ FLOP_(A, B);\ FLOP_(B, A);\ - } while(0) + } while (0) #define TRANSPOSE(A, B)\ do {\ TRANSPOSE_(A, B);\ TRANSPOSE_(B, A);\ - } while(0) + } while (0) #define ANTITRANSPOSE(A, B)\ do {\ ANTITRANSPOSE_(A, B);\ ANTITRANSPOSE_(B, A);\ - } while(0) + } while (0) #define NONLINEAR(IN) NONLINEAR_(IN, NONLINEAR) #define UNKNOWN(IN) UNKNOWN_(IN, UNKNOWN) @@ -201,17 +201,17 @@ test(int xtrans, int ytrans, int zscale, int xscale, int yscale) do {\ M(A, B);\ M(BALANCED_##A, BALANCED_##B);\ - } while(0) + } while (0) #define NONLINEARX(A)\ do {\ NONLINEAR(A);\ NONLINEAR(BALANCED_##A);\ - } while(0) + } while (0) #define UNKNOWNX(A)\ do {\ UNKNOWN(A);\ UNKNOWN(BALANCED_##A);\ - } while(0) + } while (0) struct libfonts_transformation asis_matrix = {.m = { {+xscale, 0, xtrans}, diff --git a/libfonts_parse_aa__.c b/libfonts_parse_aa__.c index 5946b1c..0ed9a3d 100644 --- a/libfonts_parse_aa__.c +++ b/libfonts_parse_aa__.c @@ -3,25 +3,6 @@ #ifndef TEST -#define LIST_ANTIALIASINGS(X)\ - X(LIBFONTS_ANTIALIASING_UNSPECIFIED, "unspecified")\ - X(LIBFONTS_ANTIALIASING_NONE, "none")\ - X(LIBFONTS_ANTIALIASING_NONE, "aliased")\ - X(LIBFONTS_ANTIALIASING_GREYSCALE, "greyscale")\ - X(LIBFONTS_ANTIALIASING_GREYSCALE, "grayscale")\ - X(LIBFONTS_ANTIALIASING_GREYSCALE, "grey")\ - X(LIBFONTS_ANTIALIASING_GREYSCALE, "gray")\ - X(LIBFONTS_ANTIALIASING_GREYSCALE, "antialiased")\ - X(LIBFONTS_ANTIALIASING_GREYSCALE_FORCED, "greyscale!")\ - X(LIBFONTS_ANTIALIASING_GREYSCALE_FORCED, "grayscale!")\ - X(LIBFONTS_ANTIALIASING_GREYSCALE_FORCED, "grey!")\ - X(LIBFONTS_ANTIALIASING_GREYSCALE_FORCED, "gray!")\ - X(LIBFONTS_ANTIALIASING_GREYSCALE_FORCED, "antialiased!")\ - X(LIBFONTS_ANTIALIASING_SUBPIXEL, "subpixel")\ - X(LIBFONTS_ANTIALIASING_SUBPIXEL, "glitter")\ - X(LIBFONTS_ANTIALIASING_SUBPIXEL_FORCED, "subpixel!")\ - X(LIBFONTS_ANTIALIASING_SUBPIXEL_FORCED, "glitter!") - int libfonts_parse_aa__(enum libfonts_antialiasing *outp, const char *value) { @@ -29,7 +10,7 @@ libfonts_parse_aa__(enum libfonts_antialiasing *outp, const char *value) if (!strcasecmp(value, S)) {\ *outp = C;\ } else - LIST_ANTIALIASINGS(X) { + LIST_ANTIALIASINGS(X,) { return 0; } #undef X @@ -44,7 +25,30 @@ libfonts_parse_aa__(enum libfonts_antialiasing *outp, const char *value) int main(void) { - return 0; /* TODO add test */ + enum libfonts_antialiasing res; + char buf[1024]; + size_t i; + +#define X(C, S)\ + do {\ + res = 999;\ + ASSERT(libfonts_parse_aa__(&res, S) == 1);\ + ASSERT(res == C);\ + strcpy(buf, S);\ + for (i = 0; buf[i]; i++)\ + buf[i] = toupper(buf[i]);\ + res = 999;\ + ASSERT(libfonts_parse_aa__(&res, buf) == 1);\ + ASSERT(res == C);\ + } while (0) + LIST_ANTIALIASINGS(X, ;); +#undef X + + res = 999; + ASSERT(libfonts_parse_aa__(&res, " something else ") == 0); + ASSERT(res == 999); + + return 0; } diff --git a/libfonts_parse_order__.c b/libfonts_parse_order__.c index 53b4aa4..349347e 100644 --- a/libfonts_parse_order__.c +++ b/libfonts_parse_order__.c @@ -3,78 +3,6 @@ #ifndef TEST -#define LIST_SUBPIXEL_ORDERS(X)\ - X(LIBFONTS_SUBPIXEL_ORDER_UNKNOWN, "unknown")\ - X(LIBFONTS_SUBPIXEL_ORDER_NONRGB, "non-rgb")\ - X(LIBFONTS_SUBPIXEL_ORDER_NONLINEAR, "non-linear")\ - X(LIBFONTS_SUBPIXEL_ORDER_OTHER, "other")\ - X(LIBFONTS_SUBPIXEL_ORDER_RGB, "rgb")\ - X(LIBFONTS_SUBPIXEL_ORDER_R_G_B, "r:g:b")\ - X(LIBFONTS_SUBPIXEL_ORDER_R_G_B, "vrgb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BGR, "bgr")\ - X(LIBFONTS_SUBPIXEL_ORDER_B_G_R, "b:g:r")\ - X(LIBFONTS_SUBPIXEL_ORDER_B_G_R, "vbgr")\ - X(LIBFONTS_SUBPIXEL_ORDER_GBR, "gbr")\ - X(LIBFONTS_SUBPIXEL_ORDER_G_B_R, "g:b:r")\ - X(LIBFONTS_SUBPIXEL_ORDER_G_B_R, "vgbr")\ - X(LIBFONTS_SUBPIXEL_ORDER_RBG, "rbg")\ - X(LIBFONTS_SUBPIXEL_ORDER_R_B_G, "r:b:g")\ - X(LIBFONTS_SUBPIXEL_ORDER_R_B_G, "vrbg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BRG, "brg")\ - X(LIBFONTS_SUBPIXEL_ORDER_B_R_G, "b:r:g")\ - X(LIBFONTS_SUBPIXEL_ORDER_B_R_G, "vbrg")\ - X(LIBFONTS_SUBPIXEL_ORDER_GRB, "grb")\ - X(LIBFONTS_SUBPIXEL_ORDER_G_R_B, "g:r:b")\ - X(LIBFONTS_SUBPIXEL_ORDER_G_R_B, "vgrb")\ - X(LIBFONTS_SUBPIXEL_ORDER_RR_GB, "rr:gb")\ - X(LIBFONTS_SUBPIXEL_ORDER_GR_BR, "gr:br")\ - X(LIBFONTS_SUBPIXEL_ORDER_BG_RR, "bg:rr")\ - X(LIBFONTS_SUBPIXEL_ORDER_RB_RG, "rb:rg")\ - X(LIBFONTS_SUBPIXEL_ORDER_RR_BG, "rr:bg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BR_GR, "br:gr")\ - X(LIBFONTS_SUBPIXEL_ORDER_GB_RR, "gb:rr")\ - X(LIBFONTS_SUBPIXEL_ORDER_RG_RB, "rg:rb")\ - X(LIBFONTS_SUBPIXEL_ORDER_GG_RB, "gg:rb")\ - X(LIBFONTS_SUBPIXEL_ORDER_RG_BG, "rg:bg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BR_GG, "br:gg")\ - X(LIBFONTS_SUBPIXEL_ORDER_GB_GR, "gb:gr")\ - X(LIBFONTS_SUBPIXEL_ORDER_GG_BR, "gg:br")\ - X(LIBFONTS_SUBPIXEL_ORDER_BG_RG, "bg:rg")\ - X(LIBFONTS_SUBPIXEL_ORDER_RB_GG, "rb:gg")\ - X(LIBFONTS_SUBPIXEL_ORDER_GR_GB, "gr:gb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BB_RG, "bb:rg")\ - X(LIBFONTS_SUBPIXEL_ORDER_RB_GB, "rb:gb")\ - X(LIBFONTS_SUBPIXEL_ORDER_GR_BB, "gr:bb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BG_BR, "bg:br")\ - X(LIBFONTS_SUBPIXEL_ORDER_BB_GR, "bb:gr")\ - X(LIBFONTS_SUBPIXEL_ORDER_GB_RB, "gb:rb")\ - X(LIBFONTS_SUBPIXEL_ORDER_RG_BB, "rg:bb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BR_BG, "br:bg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RR_GB, "balanced rr:gb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GR_BR, "balanced gr:br")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BG_RR, "balanced bg:rr")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RB_RG, "balanced rb:rg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RR_BG, "balanced rr:bg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BR_GR, "balanced br:gr")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GB_RR, "balanced gb:rr")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RG_RB, "balanced rg:rb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GG_RB, "balanced gg:rb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RG_BG, "balanced rg:bg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BR_GG, "balanced br:gg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GB_GR, "balanced gb:gr")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GG_BR, "balanced gg:br")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BG_RG, "balanced bg:rg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RB_GG, "balanced rb:gg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GR_GB, "balanced gr:gb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BB_RG, "balanced bb:rg")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RB_GB, "balanced rb:gb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GR_BB, "balanced gr:bb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BG_BR, "balanced bg:br")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BB_GR, "balanced bb:gr")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_GB_RB, "balanced gb:rb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_RG_BB, "balanced rg:bb")\ - X(LIBFONTS_SUBPIXEL_ORDER_BALANCED_BR_BG, "balanced br:bg") - int libfonts_parse_order__(enum libfonts_subpixel_order *outp, const char *value) { @@ -82,7 +10,7 @@ libfonts_parse_order__(enum libfonts_subpixel_order *outp, const char *value) if (!strcasecmp(value, S)) {\ *outp = C;\ } else - LIST_SUBPIXEL_ORDERS(X) { + LIST_SUBPIXEL_ORDERS(X,) { *outp = LIBFONTS_SUBPIXEL_ORDER_OTHER; return 0; } @@ -98,7 +26,30 @@ libfonts_parse_order__(enum libfonts_subpixel_order *outp, const char *value) int main(void) { - return 0; /* TODO add test */ + enum libfonts_subpixel_order res; + char buf[1024]; + size_t i; + +#define X(C, S)\ + do {\ + res = 999;\ + ASSERT(libfonts_parse_order__(&res, S) == 1);\ + ASSERT(res == C);\ + strcpy(buf, S);\ + for (i = 0; buf[i]; i++)\ + buf[i] = toupper(buf[i]);\ + res = 999;\ + ASSERT(libfonts_parse_order__(&res, buf) == 1);\ + ASSERT(res == C);\ + } while (0) + LIST_SUBPIXEL_ORDERS(X, ;); +#undef X + + res = 999; + ASSERT(libfonts_parse_order__(&res, " something else ") == 0); + ASSERT(res == LIBFONTS_SUBPIXEL_ORDER_OTHER); + + return 0; } diff --git a/libfonts_parse_uint32__.c b/libfonts_parse_uint32__.c index f87f19e..d35ddd3 100644 --- a/libfonts_parse_uint32__.c +++ b/libfonts_parse_uint32__.c @@ -11,7 +11,7 @@ libfonts_parse_uint32__(uint32_t *outp, const char *value) if (!*value) return 0; while (isdigit(*value)) { - digit = (*value & 15); + digit = (*value++ & 15); if (out > (UINT32_C(0xFFFFFFFF) - digit) / 10) return 0; out = out * 10 + digit; @@ -29,7 +29,41 @@ libfonts_parse_uint32__(uint32_t *outp, const char *value) int main(void) { - return 0; /* TODO add test */ + uint32_t res; + +#define F(S)\ + do {\ + res = 999;\ + ASSERT(libfonts_parse_uint32__(&res, S) == 0);\ + ASSERT(res == 999);\ + } while (0) + +#define T(N)\ + do {\ + res = (uint32_t)(UINT32_C(N) ^ UINT32_C(0x87654321));\ + ASSERT(libfonts_parse_uint32__(&res, #N) == 1);\ + ASSERT(res == UINT32_C(N));\ + res ^= UINT32_C(0x87654321);\ + ASSERT(libfonts_parse_uint32__(&res, "+"#N) == 1);\ + ASSERT(res == UINT32_C(N));\ + F("-"#N);\ + } while (0) + + T(0); + T(10); + T(12); + T(1235); + T(53251); + T(4294967294); + T(4294967295); + + F("4294967296"); + F("11111111111"); + F("+"); + F("100x"); + F("a"); + + return 0; } |