From 80a78b91c2905fcacf0236d63a9f4e3d7e576d7e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 5 Mar 2021 23:30:24 +0100 Subject: minor fixes + add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 2 +- common.h | 4 +- libgamma.h | 9 +- libgamma_error_min.c | 6 +- libgamma_method_count.c | 6 +- libgamma_perror.c | 7 +- libgamma_strerror.c | 8 +- libgamma_strerror_r.c | 21 +- libgamma_subpixel_order_count.c | 6 +- libgamma_value_of_connector_type.c | 5 +- libgamma_value_of_error.c | 2 +- libgamma_value_of_subpixel_order.c | 5 +- test.c | 794 ++++++++++++++++++++++++++++++++++--- 13 files changed, 782 insertions(+), 93 deletions(-) diff --git a/Makefile b/Makefile index 41a9607..9d64823 100644 --- a/Makefile +++ b/Makefile @@ -180,7 +180,7 @@ libgamma.$(LIBEXT): $(LOBJ) test.o: test.c libgamma.h $(CC) -c -o $@ test.c $(CFLAGS) $(CPPFLAGS) -test: test.o +test: test.o libgamma.a $(CC) -o $@ test.o libgamma.a $(LDFLAGS_METHODS) $(LDFLAGS) install: libgamma.a libgamma.$(LIBEXT) diff --git a/common.h b/common.h index c13c067..8cad179 100644 --- a/common.h +++ b/common.h @@ -48,7 +48,7 @@ _(LIBGAMMA_CONNECTOR_DISABLED, "Connector is disabled")\ _(LIBGAMMA_OPEN_CRTC_FAILED, "Could not open CRTC")\ _(LIBGAMMA_CRTC_INFO_NOT_SUPPORTED, "CRTC information is not supported")\ - _(LIBGAMMA_GAMMA_RAMP_READ_FAILED, "Could not read readm gamma ramp")\ + _(LIBGAMMA_GAMMA_RAMP_READ_FAILED, "Could not read from gamma ramp")\ _(LIBGAMMA_GAMMA_RAMP_WRITE_FAILED, "Could not write to gamma ramp")\ _(LIBGAMMA_GAMMA_RAMP_SIZE_CHANGED, "Gamma ramp size changed")\ _(LIBGAMMA_MIXED_GAMMA_RAMP_SIZE, "Mixed gamma ramp size")\ @@ -63,7 +63,7 @@ _(LIBGAMMA_DEVICE_REQUIRE_GROUP, "Device requires group membership")\ _(LIBGAMMA_GRAPHICS_CARD_REMOVED, "Graphics card was removed")\ _(LIBGAMMA_STATE_UNKNOWN, "Unknown state")\ - _(LIBGAMMA_CONNECTOR_UNKNOWN, "Unknwon connector")\ + _(LIBGAMMA_CONNECTOR_UNKNOWN, "Unknown connector")\ _(LIBGAMMA_CONNECTOR_TYPE_NOT_RECOGNISED, "Connector type not recognised")\ _(LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED, "Subpixel order not recognised")\ _(LIBGAMMA_EDID_LENGTH_UNSUPPORTED, "Unsupported EDID length")\ diff --git a/libgamma.h b/libgamma.h index afbe6f3..f1aa0ce 100644 --- a/libgamma.h +++ b/libgamma.h @@ -1582,7 +1582,7 @@ LIBGAMMA_GCC_ONLY__(__attribute__((__warn_unused_result__, __const__))) const char *libgamma_name_of_error(int); /** - * Get the value of a `libgamma` error definition refered to by name + * Get the value of a `libgamma` error definition referred to by name * * @param name The name of the definition associated with the error code * @return The error code, zero if the name is `NULL` @@ -1642,7 +1642,6 @@ void libgamma_group_name_set(const char *); - /** * Get the name of an adjustment method, * for example "randr" for `LIBGAMMA_METHOD_X_RANDR` @@ -1725,7 +1724,8 @@ const char *libgamma_const_of_connector_type(int); * @param connector The name of the connector type, for example * "VGA" or "LIBGAMMA_CONNECTOR_TYPE_VGA" * @return The connector type; for example `LIBGAMMA_CONNECTOR_TYPE_VGA` - * for "VGA" and "LIBGAMMA_CONNECTOR_TYPE_VGA" + * for "VGA" and "LIBGAMMA_CONNECTOR_TYPE_VGA"; + * `LIBGAMMA_CONNECTOR_TYPE_NOT_RECOGNISED` of not defined */ LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__, __access__(__read_only__, 1), __pure__))) int libgamma_value_of_connector_type(const char *); @@ -1764,7 +1764,8 @@ const char *libgamma_const_of_subpixel_order(int); * @param order The name of the subpixel order, for example * "Horizontal RGB" or "LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB" * @return The subpixel order; for example `LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB` - * for "Horizontal RGB" and "LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB" + * for "Horizontal RGB" and "LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB"; + * `LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED` of not defined */ LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__, __access__(__read_only__, 1), __pure__))) int libgamma_value_of_subpixel_order(const char *); diff --git a/libgamma_error_min.c b/libgamma_error_min.c index 199429c..b71ef9c 100644 --- a/libgamma_error_min.c +++ b/libgamma_error_min.c @@ -2,9 +2,13 @@ #include "common.h" +#define X(...) -1 + /** * The number of the libgamma error with the * lowest number in the version of the library * that the program is linked against */ -const int libgamma_error_min = LIBGAMMA_ERROR_MIN; +const int libgamma_error_min = LIST_ERRORS(X); + +#undef X diff --git a/libgamma_method_count.c b/libgamma_method_count.c index 34dd4fa..1f66e86 100644 --- a/libgamma_method_count.c +++ b/libgamma_method_count.c @@ -2,6 +2,8 @@ #include "common.h" +#define X(...) +1 + /** * The number adjustment methods provided by the * version this library the program is linked @@ -10,4 +12,6 @@ * This number includes both compile-time enabled * and compile-time disabled adjustment methods */ -const int libgamma_method_count = LIBGAMMA_METHOD_COUNT; +const int libgamma_method_count = LIST_METHODS(X); + +#undef X diff --git a/libgamma_perror.c b/libgamma_perror.c index 92060d8..62af75a 100644 --- a/libgamma_perror.c +++ b/libgamma_perror.c @@ -19,6 +19,8 @@ libgamma_perror(const char *name, int error_code) if (error_code == LIBGAMMA_DEVICE_REQUIRE_GROUP) { gid = (intmax_t)libgamma_group_gid_get(); + if (!gid) + goto fallback; gname = libgamma_group_name_get(); if (!gname) { if (name && *name) @@ -27,11 +29,12 @@ libgamma_perror(const char *name, int error_code) fprintf(stderr, "%s in group %ji\n", desc, gid); } else { if (name && *name) - fprintf(stderr, "%s: %s in group %s (%ji)\n", name, desc, gname, gid); + fprintf(stderr, "%s: %s in the %s group (%ji)\n", name, desc, gname, gid); else - fprintf(stderr, "%s in group %s (%ji)\n", desc, gname, gid); + fprintf(stderr, "%s in the %s group (%ji)\n", desc, gname, gid); } } else { + fallback: if (name && *name) fprintf(stderr, "%s: %s\n", name, desc); else diff --git a/libgamma_strerror.c b/libgamma_strerror.c index 77d4c89..8df7b46 100644 --- a/libgamma_strerror.c +++ b/libgamma_strerror.c @@ -14,19 +14,15 @@ const char * libgamma_strerror(int error_code) { - const char *desc; if (error_code == LIBGAMMA_ERRNO_SET) error_code = errno; switch (error_code) { #define X(NAME, DESC)\ case NAME:\ - desc = DESC;\ - break; + return DESC; LIST_ERRORS(X) #undef X default: - desc = NULL; - break; + return error_code < 0 ? NULL : strerror(error_code); } - return desc ? desc : error_code < 0 ? NULL : strerror(error_code); } diff --git a/libgamma_strerror_r.c b/libgamma_strerror_r.c index 781558c..c95d8a9 100644 --- a/libgamma_strerror_r.c +++ b/libgamma_strerror_r.c @@ -26,16 +26,14 @@ libgamma_strerror_r(int error_code, char buf[], size_t bufsize) switch (error_code) { #define X(NAME, DESC)\ case NAME:\ - desc = DESC;\ - break; + return DESC; LIST_ERRORS(X) #undef X default: - desc = NULL; break; } - if (desc) - return desc; + if (bufsize) + *buf = '\0'; if (error_code >= 0) { saved_errno = errno; desc = _Generic(strerror_r(error_code, buf, bufsize), @@ -43,19 +41,20 @@ libgamma_strerror_r(int error_code, char buf[], size_t bufsize) int: (errno = (int)(intptr_t)strerror_r(error_code, buf, bufsize)) ? NULL : buf, /* GNU strerror_r */ char *: (char *)(intptr_t)strerror_r(error_code, buf, bufsize)); + if (desc == buf && (!bufsize || !*buf)) + desc = NULL; if (desc) { errno = saved_errno; - if (!buf || strcmp(buf, "No error information")) - return buf; + if (!desc || strcmp(desc, "No error information")) + return desc; } else if (errno == ERANGE) { return buf; } else { errno = saved_errno; } } - if (!buf) - return buf; - *buf = '\0'; /* TODO what happended here? */ - snprintf(buf, bufsize, "Unknown error #%i\n", error_code); + if (!bufsize) + return NULL; + snprintf(buf, bufsize, "Unknown error #%i", error_code); return buf; } diff --git a/libgamma_subpixel_order_count.c b/libgamma_subpixel_order_count.c index d77a748..05adb51 100644 --- a/libgamma_subpixel_order_count.c +++ b/libgamma_subpixel_order_count.c @@ -2,8 +2,12 @@ #include "common.h" +#define X(...) +1 + /** * The number of values defined in `libgamma_subpixel_order_t` * in the version of the library the program is linked against */ -const int libgamma_subpixel_order_count = LIBGAMMA_SUBPIXEL_ORDER_COUNT; +const int libgamma_subpixel_order_count = LIST_SUBPIXEL_ORDERS(X); + +#undef X diff --git a/libgamma_value_of_connector_type.c b/libgamma_value_of_connector_type.c index 5ffdaf5..249422e 100644 --- a/libgamma_value_of_connector_type.c +++ b/libgamma_value_of_connector_type.c @@ -8,7 +8,8 @@ * @param connector The name of the connector type, for example * "VGA" or "LIBGAMMA_CONNECTOR_TYPE_VGA" * @return The connector type; for example `LIBGAMMA_CONNECTOR_TYPE_VGA` - * for "VGA" and "LIBGAMMA_CONNECTOR_TYPE_VGA" + * for "VGA" and "LIBGAMMA_CONNECTOR_TYPE_VGA"; + * `LIBGAMMA_CONNECTOR_TYPE_NOT_RECOGNISED` of not defined */ int libgamma_value_of_connector_type(const char *connector) @@ -25,5 +26,5 @@ libgamma_value_of_connector_type(const char *connector) LIST_CONNECTOR_TYPES(X) #undef X - return 0; + return LIBGAMMA_CONNECTOR_TYPE_NOT_RECOGNISED; } diff --git a/libgamma_value_of_error.c b/libgamma_value_of_error.c index 41ca40f..16fc941 100644 --- a/libgamma_value_of_error.c +++ b/libgamma_value_of_error.c @@ -3,7 +3,7 @@ /** - * Get the value of a `libgamma` error definition refered to by name + * Get the value of a `libgamma` error definition referred to by name * * @param name The name of the definition associated with the error code * @return The error code, zero if the name is `NULL` diff --git a/libgamma_value_of_subpixel_order.c b/libgamma_value_of_subpixel_order.c index 163fed2..33c2a6f 100644 --- a/libgamma_value_of_subpixel_order.c +++ b/libgamma_value_of_subpixel_order.c @@ -8,7 +8,8 @@ * @param order The name of the subpixel order, for example * "Horizontal RGB" or "LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB" * @return The subpixel order; for example `LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB` - * for "Horizontal RGB" and "LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB" + * for "Horizontal RGB" and "LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB"; + * `LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED` of not defined */ int libgamma_value_of_subpixel_order(const char *order) @@ -25,5 +26,5 @@ libgamma_value_of_subpixel_order(const char *order) LIST_SUBPIXEL_ORDERS(X) #undef X - return 0; + return LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED; } diff --git a/test.c b/test.c index 9dfa598..c5ec4ea 100644 --- a/test.c +++ b/test.c @@ -2,12 +2,19 @@ #include "libgamma.h" #include +#include +#include #include #include #include #include +#include #include +#ifdef __WIN32__ +# define gid_t short +#endif + #if LIBGAMMA_CRTC_INFO_COUNT != 13 # warning CRTC information fields have been updated @@ -179,9 +186,9 @@ list_methods(const char *description, int *methods, int operation) size_t i, n = libgamma_list_methods(methods, LIBGAMMA_METHOD_COUNT, operation); /* Print adjustment method list */ - printf("%s:\n", description); + printf("%s:", description); for (i = 0; i < n; i++) - printf(" %s\n", method_name(methods[i])); + printf(" %s", method_name(methods[i])); printf("\n"); } @@ -205,6 +212,7 @@ list_methods_lists(void) list_methods("Available real non-fake adjustment methods", methods, 2); list_methods("Recommended adjustment methods", methods, 1); list_methods("Recommended non-fake adjustment methods", methods, 0); + printf("\n"); } @@ -604,69 +612,734 @@ crtc_information(libgamma_crtc_state_t *restrict crtc) /** - * The error API + * Test that count macros are set to the same values as the count variables */ void -error_test(void) +test_count_consts(void) { - int i; - - /* Test that naming and name dereferencing - of errors work. Because the mappings in - these [`libgamma_value_of_error` and - `libgamma_name_of_error`] functions are - generated, it should work if and only if - one test passes, assumming the errors are - unique whihc is tested in the end of this - function. */ - printf("Testing error API using LIBGAMMA_STATE_UNKNOWN:\n"); - printf(" Expecting %i: %i\n", LIBGAMMA_STATE_UNKNOWN, libgamma_value_of_error("LIBGAMMA_STATE_UNKNOWN")); - printf(" Expecting %s: %s\n", "LIBGAMMA_STATE_UNKNOWN", libgamma_name_of_error(LIBGAMMA_STATE_UNKNOWN)); - printf("\n"); - - /* Test that `libgamma_perror` can print - libgamma errors and system errors, and - handle success in the same with as `perror`. */ - printf("Testing libgamma_perror:\n"); - libgamma_perror(" Expecting LIBGAMMA_STATE_UNKNOWN", LIBGAMMA_STATE_UNKNOWN); - libgamma_perror(" Expecting a description for ENOMEM", ENOMEM); - libgamma_perror(" Expecting a description for successfulness", 0); - /* Test that `libgamma_perror` handles - `LIBGAMMA_ERRNO_SET` correctly. */ - libgamma_perror(" Expecting a description for ENOMEM", (errno = ENOMEM, LIBGAMMA_ERRNO_SET)); - /* That that `libgamma_perror` handles - `LIBGAMMA_DEVICE_REQUIRE_GROUP` - correctly both when the required - group's name is known and when it - is unknown. */ - libgamma_group_gid_set(10); - libgamma_group_name_set("test"); - libgamma_perror(" Expecting 'LIBGAMMA_DEVICE_REQUIRE_GROUP: test (10)'", LIBGAMMA_DEVICE_REQUIRE_GROUP); - libgamma_group_name_set(NULL); - libgamma_perror(" Expecting 'LIBGAMMA_DEVICE_REQUIRE_GROUP: 10'", LIBGAMMA_DEVICE_REQUIRE_GROUP); - printf("\n"); - - /* That all libgamma error codes - are unique. This is done by - getting the name associated - with an error code and the getting - the error code associated that - name and test that the same - error code is returned as put in, - for each libgamma error code. */ - printf("Testing error code uniqueness: "); - for (i = -1; i >= LIBGAMMA_ERROR_MIN; i--) { - if (libgamma_value_of_error(libgamma_name_of_error(i)) != i) { - printf("failed\n"); - goto not_unique; - } + if (LIBGAMMA_ERROR_MIN != libgamma_error_min) { + fprintf(stderr, "LIBGAMMA_ERROR_MIN != libgamma_error_min\n"); + exit(1); + } + if (LIBGAMMA_METHOD_COUNT != libgamma_method_count) { + fprintf(stderr, "LIBGAMMA_METHOD_COUNT != libgamma_method_count\n"); + exit(1); + } + if (LIBGAMMA_CONNECTOR_TYPE_COUNT != libgamma_connector_type_count) { + fprintf(stderr, "LIBGAMMA_CONNECTOR_TYPE_COUNT != libgamma_connector_type_count\n"); + exit(1); + } + if (LIBGAMMA_SUBPIXEL_ORDER_COUNT != libgamma_subpixel_order_count) { + fprintf(stderr, "LIBGAMMA_SUBPIXEL_ORDER_COUNT != libgamma_subpixel_order_count\n"); + exit(1); + } +} + + +/** + * Test functions for connector types + */ +void +test_connector_types(void) +{ + size_t n = 0; + char buf[128], *w; + const char *r; + +#define X(CONST)\ + do {\ + if ((unsigned int)CONST >= (unsigned int)LIBGAMMA_CONNECTOR_TYPE_COUNT) {\ + fprintf(stderr, "%s >= LIBGAMMA_CONNECTOR_TYPE_COUNT\n", #CONST);\ + exit(1);\ + }\ + if (!libgamma_const_of_connector_type(CONST)) {\ + fprintf(stderr, "libgamma_const_of_connector_type(%s) == NULL\n", #CONST);\ + exit(1);\ + }\ + if (!libgamma_name_of_connector_type(CONST)) {\ + fprintf(stderr, "libgamma_name_of_connector_type(%s) == NULL\n", #CONST);\ + exit(1);\ + }\ + if (strcmp(libgamma_const_of_connector_type(CONST), #CONST)) {\ + fprintf(stderr, "libgamma_const_of_connector_type(%s) != \"%s\"\n", #CONST, #CONST);\ + exit(1);\ + }\ + if (libgamma_value_of_connector_type(#CONST) != CONST) {\ + fprintf(stderr, "libgamma_value_of_connector_type(\"%s\") != %s\n", #CONST, #CONST);\ + exit(1);\ + }\ + if (libgamma_value_of_connector_type(libgamma_name_of_connector_type(CONST)) != CONST) {\ + fprintf(stderr, "libgamma_value_of_connector_type(libgamma_name_of_connector_type(%s)) != %s\n",\ + #CONST, #CONST);\ + exit(1);\ + }\ + if (libgamma_value_of_connector_type(#CONST) != CONST) {\ + fprintf(stderr, "libgamma_value_of_connector_type(\"%s\") != %s\n", #CONST, #CONST);\ + exit(1);\ + }\ + if (strlen(libgamma_name_of_connector_type(CONST)) >= sizeof(buf)) {\ + fprintf(stderr, "strlen(libgamma_name_of_connector_type(%s) >= %zu\n", #CONST, sizeof(buf));\ + exit(1);\ + }\ + r = libgamma_name_of_connector_type(CONST);\ + for (w = buf; *r; r++)\ + if (*r != ' ' && *r != '-')\ + *w++ = *r;\ + *w = '\0';\ + if (strcasecmp(buf, &#CONST[sizeof("LIBGAMMA_CONNECTOR_TYPE_") - 1])) {\ + fprintf(stderr, "libgamma_name_of_connector_type(%s) without [ -] != %s, ignoreing case\n",\ + #CONST, &#CONST[sizeof("LIBGAMMA_CONNECTOR_TYPE_") - 1]);\ + exit(1);\ + }\ + n += 1;\ + } while (0) + + X(LIBGAMMA_CONNECTOR_TYPE_Unknown); + X(LIBGAMMA_CONNECTOR_TYPE_VGA); + X(LIBGAMMA_CONNECTOR_TYPE_DVI); + X(LIBGAMMA_CONNECTOR_TYPE_DVII); + X(LIBGAMMA_CONNECTOR_TYPE_DVID); + X(LIBGAMMA_CONNECTOR_TYPE_DVIA); + X(LIBGAMMA_CONNECTOR_TYPE_Composite); + X(LIBGAMMA_CONNECTOR_TYPE_SVIDEO); + X(LIBGAMMA_CONNECTOR_TYPE_LVDS); + X(LIBGAMMA_CONNECTOR_TYPE_Component); + X(LIBGAMMA_CONNECTOR_TYPE_9PinDIN); + X(LIBGAMMA_CONNECTOR_TYPE_DisplayPort); + X(LIBGAMMA_CONNECTOR_TYPE_HDMI); + X(LIBGAMMA_CONNECTOR_TYPE_HDMIA); + X(LIBGAMMA_CONNECTOR_TYPE_HDMIB); + X(LIBGAMMA_CONNECTOR_TYPE_TV); + X(LIBGAMMA_CONNECTOR_TYPE_eDP); + X(LIBGAMMA_CONNECTOR_TYPE_VIRTUAL); + X(LIBGAMMA_CONNECTOR_TYPE_DSI); + X(LIBGAMMA_CONNECTOR_TYPE_LFP); + X(LIBGAMMA_CONNECTOR_TYPE_DPI); + X(LIBGAMMA_CONNECTOR_TYPE_WRITEBACK); + X(LIBGAMMA_CONNECTOR_TYPE_SPI); + +#undef X + + if (n != LIBGAMMA_CONNECTOR_TYPE_COUNT) { + fprintf(stderr, "List of connector types in `test_connector_types` must be updated"); + exit(1); + } + + if (libgamma_name_of_connector_type(-1)) { + fprintf(stderr, "libgamma_name_of_connector_type() != NULL\n"); + exit(1); + } + if (libgamma_const_of_connector_type(-1)) { + fprintf(stderr, "libgamma_const_of_connector_type() != NULL\n"); + exit(1); + } + if (libgamma_value_of_connector_type("") != LIBGAMMA_CONNECTOR_TYPE_NOT_RECOGNISED) { + fprintf(stderr, "libgamma_value_of_connector_type() != LIBGAMMA_CONNECTOR_TYPE_NOT_RECOGNISED\n"); + exit(1); } - printf("passed\n"); -not_unique: - printf("\n"); } +/** + * Test functions for subpixel orders + */ +void +test_subpixel_orders(void) +{ + size_t n = 0; + char buf[128], *w; + const char *r; + +#define X(CONST)\ + do {\ + if ((unsigned int)CONST >= (unsigned int)LIBGAMMA_SUBPIXEL_ORDER_COUNT) {\ + fprintf(stderr, "%s >= LIBGAMMA_SUBPIXEL_ORDER_COUNT\n", #CONST);\ + exit(1);\ + }\ + if (!libgamma_const_of_subpixel_order(CONST)) {\ + fprintf(stderr, "libgamma_const_of_subpixel_order(%s) == NULL\n", #CONST);\ + exit(1);\ + }\ + if (!libgamma_name_of_subpixel_order(CONST)) {\ + fprintf(stderr, "libgamma_name_of_subpixel_order(%s) == NULL\n", #CONST);\ + exit(1);\ + }\ + if (strcmp(libgamma_const_of_subpixel_order(CONST), #CONST)) {\ + fprintf(stderr, "libgamma_const_of_subpixel_order(%s) != \"%s\"\n", #CONST, #CONST);\ + exit(1);\ + }\ + if (libgamma_value_of_subpixel_order(#CONST) != CONST) {\ + fprintf(stderr, "libgamma_value_of_subpixel_order(\"%s\") != %s\n", #CONST, #CONST);\ + exit(1);\ + }\ + if (libgamma_value_of_subpixel_order(libgamma_name_of_subpixel_order(CONST)) != CONST) {\ + fprintf(stderr, "libgamma_value_of_subpixel_order(libgamma_name_of_subpixel_order(%s)) != %s\n",\ + #CONST, #CONST);\ + exit(1);\ + }\ + if (libgamma_value_of_subpixel_order(#CONST) != CONST) {\ + fprintf(stderr, "libgamma_value_of_subpixel_order(\"%s\") != %s\n", #CONST, #CONST);\ + exit(1);\ + }\ + if (strlen(libgamma_name_of_subpixel_order(CONST)) >= sizeof(buf)) {\ + fprintf(stderr, "strlen(libgamma_name_of_subpixel_order(%s) >= %zu\n", #CONST, sizeof(buf));\ + exit(1);\ + }\ + r = libgamma_name_of_subpixel_order(CONST);\ + for (w = buf; *r; r++)\ + *w++ = *r == ' ' ? '_' : *r;\ + *w = '\0';\ + if (strcasecmp(buf, &#CONST[sizeof("LIBGAMMA_SUBPIXEL_ORDER_") - 1])) {\ + fprintf(stderr, "libgamma_name_of_subpixel_order(%s) with '_' for ' ' != %s, ignoreing case\n",\ + #CONST, &#CONST[sizeof("LIBGAMMA_SUBPIXEL_ORDER_") - 1]);\ + exit(1);\ + }\ + n += 1;\ + } while (0) + + X(LIBGAMMA_SUBPIXEL_ORDER_UNKNOWN); + X(LIBGAMMA_SUBPIXEL_ORDER_NONE); + X(LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB); + X(LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_BGR); + X(LIBGAMMA_SUBPIXEL_ORDER_VERTICAL_RGB); + X(LIBGAMMA_SUBPIXEL_ORDER_VERTICAL_BGR); + +#undef X + + if (n != LIBGAMMA_SUBPIXEL_ORDER_COUNT) { + fprintf(stderr, "List of subpixel orders in `test_subpixel_orders` must be updated"); + exit(1); + } + + if (libgamma_name_of_subpixel_order(-1)) { + fprintf(stderr, "libgamma_name_of_subpixel_order() != NULL\n"); + exit(1); + } + if (libgamma_const_of_subpixel_order(-1)) { + fprintf(stderr, "libgamma_const_of_subpixel_order() != NULL\n"); + exit(1); + } + if (libgamma_value_of_subpixel_order("") != LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED) { + fprintf(stderr, "libgamma_value_of_subpixel_order() != LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED\n"); + exit(1); + } +} + + +/** + * Test functions for errors + */ +void +test_errors(void) +{ + int n = 0, fds[2], flags; + char buf[1024], buf2[1100]; + FILE *fp, *err = stderr; + ssize_t r; + + alarm(2); + pipe(fds); + fp = fdopen(fds[1], "w"); + flags = fcntl(fds[0], F_GETFL); + fcntl(fds[0], F_SETFL, flags | O_NONBLOCK); + +#define X(CONST)\ + do {\ + if (CONST >= 0) {\ + fprintf(stderr, "%s >= 0\n", #CONST);\ + exit(1);\ + }\ + if (CONST < LIBGAMMA_ERROR_MIN) {\ + fprintf(stderr, "%s < LIBGAMMA_ERROR_MIN\n", #CONST);\ + exit(1);\ + }\ + if (!libgamma_name_of_error(CONST)) {\ + fprintf(stderr, "libgamma_name_of_error(%s) == NULL\n", #CONST);\ + exit(1);\ + }\ + if (strcmp(libgamma_name_of_error(CONST), #CONST)) {\ + fprintf(stderr, "libgamma_name_of_error(%s) != \"%s\"\n", #CONST, #CONST);\ + exit(1);\ + }\ + if (libgamma_value_of_error(#CONST) != CONST) {\ + fprintf(stderr, "libgamma_value_of_error(\"%s\") != %s\n", #CONST, #CONST);\ + exit(1);\ + }\ + libgamma_group_gid_set(0);\ + libgamma_group_name_set(NULL);\ + if (CONST != LIBGAMMA_ERRNO_SET) {\ + if (!libgamma_strerror(CONST)) {\ + fprintf(stderr, "libgamma_strerror(%s) == NULL\n", #CONST);\ + exit(1);\ + }\ + if (!libgamma_strerror_r(CONST, buf, sizeof(buf))) {\ + fprintf(stderr, "libgamma_strerror_r(%s, buf, sizeof(buf)) == NULL\n", #CONST);\ + exit(1);\ + }\ + if (strcmp(libgamma_strerror_r(CONST, buf, sizeof(buf)), libgamma_strerror(CONST))) {\ + fprintf(stderr, "libgamma_strerror_r(%s, buf, sizeof(buf)) != libgamma_strerror(%s)\n",\ + #CONST, #CONST);\ + exit(1);\ + }\ + stderr = fp;\ + libgamma_perror(NULL, CONST);\ + stderr = err;\ + fflush(fp);\ + r = read(fds[0], buf, sizeof(buf));\ + if (r <= 0 || buf[r - 1] != '\n') {\ + fprintf(stderr, "libgamma_perror(NULL, %s) failed\n", #CONST);\ + exit(1);\ + }\ + buf[r - 1] = '\0';\ + if (strcmp(buf, libgamma_strerror(CONST))) {\ + fprintf(stderr, "libgamma_perror(NULL, %s) failed\n", #CONST);\ + exit(1);\ + }\ + stderr = fp;\ + libgamma_perror("", CONST);\ + stderr = err;\ + fflush(fp);\ + r = read(fds[0], buf, sizeof(buf));\ + if (r <= 0 || buf[r - 1] != '\n') {\ + fprintf(stderr, "libgamma_perror(\"\", %s) failed\n", #CONST);\ + exit(1);\ + }\ + buf[r - 1] = '\0';\ + if (strcmp(buf, libgamma_strerror(CONST))) {\ + fprintf(stderr, "libgamma_perror(\"\", %s) failed\n", #CONST);\ + exit(1);\ + }\ + stderr = fp;\ + libgamma_perror("prefix", CONST);\ + stderr = err;\ + fflush(fp);\ + r = read(fds[0], buf, sizeof(buf));\ + if (r <= 0 || buf[r - 1] != '\n') {\ + fprintf(stderr, "libgamma_perror(\"prefix\", %s) failed\n", #CONST);\ + exit(1);\ + }\ + buf[r - 1] = '\0';\ + if (strncmp(buf, "prefix: ", 8)) {\ + fprintf(stderr, "libgamma_perror(\"prefix\", %s) failed\n", #CONST);\ + exit(1);\ + }\ + if (strcmp(&buf[8], libgamma_strerror(CONST))) {\ + fprintf(stderr, "libgamma_perror(\"prefix\", %s) failed\n", #CONST);\ + exit(1);\ + }\ + }\ + libgamma_group_gid_set((gid_t)n);\ + if (libgamma_group_gid_get() != (gid_t)n) {\ + fprintf(stderr, "libgamma_group_gid_get() != (gid_t)n\n");\ + exit(1);\ + }\ + n += 1;\ + } while (0) + + X(LIBGAMMA_ERRNO_SET); + X(LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD); + X(LIBGAMMA_NO_SUCH_SITE); + X(LIBGAMMA_NO_SUCH_PARTITION); + X(LIBGAMMA_NO_SUCH_CRTC); + X(LIBGAMMA_IMPOSSIBLE_AMOUNT); + X(LIBGAMMA_CONNECTOR_DISABLED); + X(LIBGAMMA_OPEN_CRTC_FAILED); + X(LIBGAMMA_CRTC_INFO_NOT_SUPPORTED); + X(LIBGAMMA_GAMMA_RAMP_READ_FAILED); + X(LIBGAMMA_GAMMA_RAMP_WRITE_FAILED); + X(LIBGAMMA_GAMMA_RAMP_SIZE_CHANGED); + X(LIBGAMMA_MIXED_GAMMA_RAMP_SIZE); + X(LIBGAMMA_WRONG_GAMMA_RAMP_SIZE); + X(LIBGAMMA_SINGLETON_GAMMA_RAMP); + X(LIBGAMMA_LIST_CRTCS_FAILED); + X(LIBGAMMA_ACQUIRING_MODE_RESOURCES_FAILED); + X(LIBGAMMA_NEGATIVE_PARTITION_COUNT); + X(LIBGAMMA_NEGATIVE_CRTC_COUNT); + X(LIBGAMMA_DEVICE_RESTRICTED); + X(LIBGAMMA_DEVICE_ACCESS_FAILED); + X(LIBGAMMA_DEVICE_REQUIRE_GROUP); + X(LIBGAMMA_GRAPHICS_CARD_REMOVED); + X(LIBGAMMA_STATE_UNKNOWN); + X(LIBGAMMA_CONNECTOR_UNKNOWN); + X(LIBGAMMA_CONNECTOR_TYPE_NOT_RECOGNISED); + X(LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED); + X(LIBGAMMA_EDID_LENGTH_UNSUPPORTED); + X(LIBGAMMA_EDID_WRONG_MAGIC_NUMBER); + X(LIBGAMMA_EDID_REVISION_UNSUPPORTED); + X(LIBGAMMA_GAMMA_NOT_SPECIFIED); + X(LIBGAMMA_EDID_CHECKSUM_ERROR); + X(LIBGAMMA_GAMMA_NOT_SPECIFIED_AND_EDID_CHECKSUM_ERROR); + X(LIBGAMMA_GAMMA_RAMPS_SIZE_QUERY_FAILED); + X(LIBGAMMA_OPEN_PARTITION_FAILED); + X(LIBGAMMA_OPEN_SITE_FAILED); + X(LIBGAMMA_PROTOCOL_VERSION_QUERY_FAILED); + X(LIBGAMMA_PROTOCOL_VERSION_NOT_SUPPORTED); + X(LIBGAMMA_LIST_PARTITIONS_FAILED); + X(LIBGAMMA_NULL_PARTITION); + X(LIBGAMMA_NOT_CONNECTED); + X(LIBGAMMA_REPLY_VALUE_EXTRACTION_FAILED); + X(LIBGAMMA_EDID_NOT_FOUND); + X(LIBGAMMA_LIST_PROPERTIES_FAILED); + X(LIBGAMMA_PROPERTY_VALUE_QUERY_FAILED); + X(LIBGAMMA_OUTPUT_INFORMATION_QUERY_FAILED); + +#undef X + + if (-n != LIBGAMMA_ERROR_MIN) { + fprintf(stderr, "List of errors in `test_errors` must be updated"); + exit(1); + } + + if (libgamma_value_of_error(NULL)) { + fprintf(stderr, "libgamma_value_of_error(NULL) != 0\n"); + exit(1); + } + if (libgamma_value_of_error("")) { + fprintf(stderr, "libgamma_value_of_error() != 0\n"); + exit(1); + } + if (libgamma_name_of_error(1000)) { + fprintf(stderr, "libgamma_name_of_error() != NULL\n"); + exit(1); + } + if (libgamma_strerror(LIBGAMMA_ERROR_MIN - 1)) { + fprintf(stderr, "libgamma_strerror(LIBGAMMA_ERROR_MIN - 1) != NULL\n"); + exit(1); + } + if (!libgamma_strerror_r(LIBGAMMA_ERROR_MIN - 1, buf, sizeof(buf))) { + fprintf(stderr, "libgamma_strerror_r(LIBGAMMA_ERROR_MIN - 1, buf, sizeof(buf)) == NULL\n"); + exit(1); + } + if (!libgamma_strerror_r(INT_MAX, buf, sizeof(buf))) { + fprintf(stderr, "libgamma_strerror_r(INT_MAX, buf, sizeof(buf)) == NULL\n"); + exit(1); + } + + /* Just a few of the errors */ + if (strcmp(libgamma_strerror(LIBGAMMA_NO_SUCH_SITE), "No such site")) { + fprintf(stderr, "libgamma_strerror(LIBGAMMA_NO_SUCH_SITE) != \"No such site\"\n"); + exit(1); + } + if (strcmp(libgamma_strerror(LIBGAMMA_NO_SUCH_PARTITION), "No such partition")) { + fprintf(stderr, "libgamma_strerror(LIBGAMMA_NO_SUCH_PARTITION) != \"No such partition\"\n"); + exit(1); + } + if (strcmp(libgamma_strerror(LIBGAMMA_NO_SUCH_CRTC), "No such CRTC")) { + fprintf(stderr, "libgamma_strerror(LIBGAMMA_NO_SUCH_CRTC) != \"No such CRTC\"\n"); + exit(1); + } + if (strcmp(libgamma_strerror(LIBGAMMA_SINGLETON_GAMMA_RAMP), "Single-stop gamma ramp")) { + fprintf(stderr, "libgamma_strerror(LIBGAMMA_SINGLETON_GAMMA_RAMP) != \"Single-stop gamma ramp\"\n"); + exit(1); + } + if (strcmp(libgamma_strerror(LIBGAMMA_GRAPHICS_CARD_REMOVED), "Graphics card was removed")) { + fprintf(stderr, "libgamma_strerror(LIBGAMMA_GRAPHICS_CARD_REMOVED) != \"Graphics card was removed\"\n"); + exit(1); + } + if (strcmp(libgamma_strerror(LIBGAMMA_DEVICE_RESTRICTED), "Device is restricted to root")) { + fprintf(stderr, "libgamma_strerror(LIBGAMMA_DEVICE_RESTRICTED) != \"Device is restricted to root\"\n"); + exit(1); + } + + errno = -1; + if (!libgamma_strerror(0)) { + fprintf(stderr, "libgamma_strerror(0) == NULL\n"); + exit(1); + } + if (!libgamma_strerror(ENOMEM)) { + fprintf(stderr, "libgamma_strerror(ENOMEM) == NULL\n"); + exit(1); + } + if (!libgamma_strerror(ERANGE)) { + fprintf(stderr, "libgamma_strerror(ERANGE) == NULL\n"); + exit(1); + } + if (!libgamma_strerror(EDOM)) { + fprintf(stderr, "libgamma_strerror(EDOM) == NULL\n"); + exit(1); + } + errno = 0; + if (!libgamma_strerror(LIBGAMMA_ERRNO_SET)) { + fprintf(stderr, "libgamma_strerror(0 via LIBGAMMA_ERRNO_SET) == NULL\n"); + exit(1); + } + errno = ENOMEM; + if (!libgamma_strerror(LIBGAMMA_ERRNO_SET)) { + fprintf(stderr, "libgamma_strerror(ENOMEM via LIBGAMMA_ERRNO_SET) == NULL\n"); + exit(1); + } + errno = ERANGE; + if (!libgamma_strerror(LIBGAMMA_ERRNO_SET)) { + fprintf(stderr, "libgamma_strerror(ERANGE via LIBGAMMA_ERRNO_SET) == NULL\n"); + exit(1); + } + errno = EDOM; + if (!libgamma_strerror(LIBGAMMA_ERRNO_SET)) { + fprintf(stderr, "libgamma_strerror(EDOM via LIBGAMMA_ERRNO_SET) == NULL\n"); + exit(1); + } + + errno = -1; + if (strcmp(libgamma_strerror(0), strerror(0))) { + fprintf(stderr, "libgamma_strerror(0) != strerror(0)\n"); + exit(1); + } + if (strcmp(libgamma_strerror(ENOMEM), strerror(ENOMEM))) { + fprintf(stderr, "libgamma_strerror(ENOMEM) != strerror(ENOMEM)\n"); + exit(1); + } + if (strcmp(libgamma_strerror(ERANGE), strerror(ERANGE))) { + fprintf(stderr, "libgamma_strerror(ERANGE) != strerror(ERANGE)\n"); + exit(1); + } + if (strcmp(libgamma_strerror(EDOM), strerror(EDOM))) { + fprintf(stderr, "libgamma_strerror(EDOM) != strerror(EDOM)\n"); + exit(1); + } + errno = 0; + if (strcmp(libgamma_strerror(LIBGAMMA_ERRNO_SET), strerror(0))) { + fprintf(stderr, "libgamma_strerror(0 via LIBGAMMA_ERRNO_SET) != strerror(0)\n"); + exit(1); + } + errno = ENOMEM; + if (strcmp(libgamma_strerror(LIBGAMMA_ERRNO_SET), strerror(ENOMEM))) { + fprintf(stderr, "libgamma_strerror(ENOMEM via LIBGAMMA_ERRNO_SET) != strerror(ENOMEM)\n"); + exit(1); + } + errno = ERANGE; + if (strcmp(libgamma_strerror(LIBGAMMA_ERRNO_SET), strerror(ERANGE))) { + fprintf(stderr, "libgamma_strerror(ERANGE via LIBGAMMA_ERRNO_SET) != strerror(ERANGE)\n"); + exit(1); + } + errno = EDOM; + if (strcmp(libgamma_strerror(LIBGAMMA_ERRNO_SET), strerror(EDOM))) { + fprintf(stderr, "libgamma_strerror(EDOM via LIBGAMMA_ERRNO_SET) != strerror(EDOM)\n"); + exit(1); + } + + errno = -1; + if (!libgamma_strerror_r(0, buf, sizeof(buf))) { + fprintf(stderr, "libgamma_strerror_r(0, buf, sizeof(buf)) == NULL\n"); + exit(1); + } + if (!libgamma_strerror_r(ENOMEM, buf, sizeof(buf))) { + fprintf(stderr, "libgamma_strerror_r(ENOMEM, buf, sizeof(buf)) == NULL\n"); + exit(1); + } + if (!libgamma_strerror_r(ERANGE, buf, sizeof(buf))) { + fprintf(stderr, "libgamma_strerror_r(ERANGE, buf, sizeof(buf)) == NULL\n"); + exit(1); + } + if (!libgamma_strerror_r(EDOM, buf, sizeof(buf))) { + fprintf(stderr, "libgamma_strerror_r(EDOM, buf, sizeof(buf)) == NULL\n"); + exit(1); + } + errno = 0; + if (!libgamma_strerror_r(LIBGAMMA_ERRNO_SET, buf, sizeof(buf))) { + fprintf(stderr, "libgamma_strerror_r(0 via LIBGAMMA_ERRNO_SET, buf, sizeof(buf)) == NULL\n"); + exit(1); + } + errno = ENOMEM; + if (!libgamma_strerror_r(LIBGAMMA_ERRNO_SET, buf, sizeof(buf))) { + fprintf(stderr, "libgamma_strerror_r(ENOMEM via LIBGAMMA_ERRNO_SET, buf, sizeof(buf)) == NULL\n"); + exit(1); + } + errno = ERANGE; + if (!libgamma_strerror_r(LIBGAMMA_ERRNO_SET, buf, sizeof(buf))) { + fprintf(stderr, "libgamma_strerror_r(ERANGE via LIBGAMMA_ERRNO_SET, buf, sizeof(buf)) == NULL\n"); + exit(1); + } + errno = EDOM; + if (!libgamma_strerror_r(LIBGAMMA_ERRNO_SET, buf, sizeof(buf))) { + fprintf(stderr, "libgamma_strerror_r(EDOM via LIBGAMMA_ERRNO_SET, buf, sizeof(buf)) == NULL\n"); + exit(1); + } + + errno = -1; + if (strcmp(libgamma_strerror_r(0, buf, sizeof(buf)), strerror(0))) { + fprintf(stderr, "libgamma_strerror_r(0, buf, sizeof(buf)) != strerror(0)\n"); + exit(1); + } + if (strcmp(libgamma_strerror_r(ENOMEM, buf, sizeof(buf)), strerror(ENOMEM))) { + fprintf(stderr, "libgamma_strerror_r(ENOMEM, buf, sizeof(buf)) != strerror(ENOMEM)\n"); + exit(1); + } + if (strcmp(libgamma_strerror_r(ERANGE, buf, sizeof(buf)), strerror(ERANGE))) { + fprintf(stderr, "libgamma_strerror_r(ERANGE, buf, sizeof(buf)) != strerror(ERANGE)\n"); + exit(1); + } + if (strcmp(libgamma_strerror_r(EDOM, buf, sizeof(buf)), strerror(EDOM))) { + fprintf(stderr, "libgamma_strerror_r(EDOM, buf, sizeof(buf)) != strerror(EDOM)\n"); + exit(1); + } + errno = 0; + if (strcmp(libgamma_strerror_r(LIBGAMMA_ERRNO_SET, buf, sizeof(buf)), strerror(0))) { + fprintf(stderr, "libgamma_strerror_r(0 via LIBGAMMA_ERRNO_SET, buf, sizeof(buf)) != strerror(0)\n"); + exit(1); + } + errno = ENOMEM; + if (strcmp(libgamma_strerror_r(LIBGAMMA_ERRNO_SET, buf, sizeof(buf)), strerror(ENOMEM))) { + fprintf(stderr, "libgamma_strerror_r(ENOMEM via LIBGAMMA_ERRNO_SET, buf, sizeof(buf)) != strerror(ENOMEM)\n"); + exit(1); + } + errno = ERANGE; + if (strcmp(libgamma_strerror_r(LIBGAMMA_ERRNO_SET, buf, sizeof(buf)), strerror(ERANGE))) { + fprintf(stderr, "libgamma_strerror_r(ERANGE via LIBGAMMA_ERRNO_SET, buf, sizeof(buf)) != strerror(ERANGE)\n"); + exit(1); + } + errno = EDOM; + if (strcmp(libgamma_strerror_r(LIBGAMMA_ERRNO_SET, buf, sizeof(buf)), strerror(EDOM))) { + fprintf(stderr, "libgamma_strerror_r(EDOM via LIBGAMMA_ERRNO_SET, buf, sizeof(buf)) != strerror(EDOM)\n"); + exit(1); + } + + libgamma_group_name_set(NULL); + if (libgamma_group_name_get()) { + fprintf(stderr, "libgamma_group_name_get() != NULL\n"); + exit(1); + } + libgamma_group_name_set("group"); + if (!libgamma_group_name_get()) { + fprintf(stderr, "libgamma_group_name_get() == NULL\n"); + exit(1); + } + if (strcmp(libgamma_group_name_get(), "group")) { + fprintf(stderr, "libgamma_group_name_get() != \"group\"\n"); + exit(1); + } + libgamma_group_name_set(""); + if (libgamma_group_name_get()) { + fprintf(stderr, "libgamma_group_name_get() != NULL\n"); + exit(1); + } + libgamma_group_name_set("name"); + if (!libgamma_group_name_get()) { + fprintf(stderr, "libgamma_group_name_get() == NULL\n"); + exit(1); + } + if (strcmp(libgamma_group_name_get(), "name")) { + fprintf(stderr, "libgamma_group_name_get() != \"name\"\n"); + exit(1); + } + libgamma_group_name_set(NULL); + if (libgamma_group_name_get()) { + fprintf(stderr, "libgamma_group_name_get() != NULL\n"); + exit(1); + } + + libgamma_group_gid_set(5); + snprintf(buf2, sizeof(buf2), "%s in group 5", libgamma_strerror(LIBGAMMA_DEVICE_REQUIRE_GROUP)); + + stderr = fp; + libgamma_perror(NULL, LIBGAMMA_DEVICE_REQUIRE_GROUP); + stderr = err; + fflush(fp); + r = read(fds[0], buf, sizeof(buf)); + if (r <= 0 || buf[r - 1] != '\n') { + fprintf(stderr, "libgamma_perror(NULL, LIBGAMMA_DEVICE_REQUIRE_GROUP) failed\n"); + exit(1); + } + buf[r - 1] = '\0'; + if (strcmp(buf, buf2)) { + fprintf(stderr, "libgamma_perror(NULL, LIBGAMMA_DEVICE_REQUIRE_GROUP) failed\n"); + exit(1); + } + + stderr = fp; + libgamma_perror("", LIBGAMMA_DEVICE_REQUIRE_GROUP); + stderr = err; + fflush(fp); + r = read(fds[0], buf, sizeof(buf)); + if (r <= 0 || buf[r - 1] != '\n') { + fprintf(stderr, "libgamma_perror(\"\", LIBGAMMA_DEVICE_REQUIRE_GROUP) failed\n"); + exit(1); + } + buf[r - 1] = '\0'; + if (strcmp(buf, buf2)) { + fprintf(stderr, "libgamma_perror(\"\", LIBGAMMA_DEVICE_REQUIRE_GROUP) failed\n"); + exit(1); + } + + stderr = fp; + libgamma_perror("prefix", LIBGAMMA_DEVICE_REQUIRE_GROUP); + stderr = err; + fflush(fp); + r = read(fds[0], buf, sizeof(buf)); + if (r <= 0 || buf[r - 1] != '\n') { + fprintf(stderr, "libgamma_perror(\"prefix\", %s) failed\n", LIBGAMMA_DEVICE_REQUIRE_GROUP); + exit(1); + } + buf[r - 1] = '\0'; + if (strncmp(buf, "prefix: ", 8)) { + fprintf(stderr, "libgamma_perror(\"prefix\", %s) failed\n", LIBGAMMA_DEVICE_REQUIRE_GROUP); + exit(1); + } + if (strcmp(&buf[8], buf2)) { + fprintf(stderr, "libgamma_perror(\"prefix\", %s) failed\n", LIBGAMMA_DEVICE_REQUIRE_GROUP); + exit(1); + } + + libgamma_group_gid_set(5); + libgamma_group_name_set("grp"); + snprintf(buf2, sizeof(buf2), "%s in the grp group (5)", libgamma_strerror(LIBGAMMA_DEVICE_REQUIRE_GROUP)); + + stderr = fp; + libgamma_perror(NULL, LIBGAMMA_DEVICE_REQUIRE_GROUP); + stderr = err; + fflush(fp); + r = read(fds[0], buf, sizeof(buf)); + if (r <= 0 || buf[r - 1] != '\n') { + fprintf(stderr, "libgamma_perror(NULL, LIBGAMMA_DEVICE_REQUIRE_GROUP) failed\n"); + exit(1); + } + buf[r - 1] = '\0'; + if (strcmp(buf, buf2)) { + fprintf(stderr, "libgamma_perror(NULL, LIBGAMMA_DEVICE_REQUIRE_GROUP) failed\n"); + exit(1); + } + + stderr = fp; + libgamma_perror("", LIBGAMMA_DEVICE_REQUIRE_GROUP); + stderr = err; + fflush(fp); + r = read(fds[0], buf, sizeof(buf)); + if (r <= 0 || buf[r - 1] != '\n') { + fprintf(stderr, "libgamma_perror(\"\", LIBGAMMA_DEVICE_REQUIRE_GROUP) failed\n"); + exit(1); + } + buf[r - 1] = '\0'; + if (strcmp(buf, buf2)) { + fprintf(stderr, "libgamma_perror(\"\", LIBGAMMA_DEVICE_REQUIRE_GROUP) failed\n"); + exit(1); + } + + stderr = fp; + libgamma_perror("prefix", LIBGAMMA_DEVICE_REQUIRE_GROUP); + stderr = err; + fflush(fp); + r = read(fds[0], buf, sizeof(buf)); + if (r <= 0 || buf[r - 1] != '\n') { + fprintf(stderr, "libgamma_perror(\"prefix\", %s) failed\n", LIBGAMMA_DEVICE_REQUIRE_GROUP); + exit(1); + } + buf[r - 1] = '\0'; + if (strncmp(buf, "prefix: ", 8)) { + fprintf(stderr, "libgamma_perror(\"prefix\", %s) failed\n", LIBGAMMA_DEVICE_REQUIRE_GROUP); + exit(1); + } + if (strcmp(&buf[8], buf2)) { + fprintf(stderr, "libgamma_perror(\"prefix\", %s) failed\n", LIBGAMMA_DEVICE_REQUIRE_GROUP); + exit(1); + } + + libgamma_group_gid_set(0); + libgamma_group_name_set(NULL); + + fclose(fp); + close(fds[0]); + alarm(0); +} + /** * Test libgamma @@ -690,11 +1363,14 @@ main(void) int r, rr = 0; /* Test miscellaneous parts of the library */ + test_count_consts(); + test_connector_types(); + test_subpixel_orders(); + test_errors(); list_methods_lists(); method_availability(); list_default_sites(); method_capabilities(); - error_test(); /* Select monitor for tests over CRTC:s, partitions and sites */ if (select_monitor(site_state, part_state, crtc_state)) -- cgit v1.2.3-70-g09d2