/* See LICENSE file for copyright and license details. */ #include "libcoopgamma.h" #include #include #include #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wunsuffixed-float-constants" #endif static int streq(const char *a, const char *b) { if (!a != !b) return 0; return !a || !strcmp(a, b); } static int rampseq(const libcoopgamma_ramps_t *a, const libcoopgamma_ramps_t *b, libcoopgamma_depth_t depth) { size_t nr, ng, nb, width; if (a->u8.red_size != b->u8.red_size || a->u8.green_size != b->u8.green_size || a->u8.blue_size != b->u8.blue_size) return 0; if (depth == -2) width = sizeof(double); else if (depth == -1) width = sizeof(float); else width = ((size_t)depth) / 8; nr = a->u8.red_size * width; ng = a->u8.green_size * width; nb = a->u8.blue_size * width; if (memcmp(a->u8.red, b->u8.red, nr + ng + nb) || memcmp(a->u8.green, b->u8.green, ng + nb) || memcmp(a->u8.blue, b->u8.blue, nb)) return 0; return 1; } int main(void) { libcoopgamma_filter_t filter1, filter2; libcoopgamma_crtc_info_t crtc1, crtc2; libcoopgamma_filter_query_t query1, query2; libcoopgamma_filter_table_t table1, table2; libcoopgamma_context_t ctx1, ctx2; libcoopgamma_async_context_t async1, async2; size_t n, m, i; char *buf; filter1.priority = INT64_MIN; filter1.crtc = (char []){"CRTC"}; filter1.class = (char []){"A::B::C::D"}; filter1.lifespan = LIBCOOPGAMMA_UNTIL_REMOVAL; filter1.depth = LIBCOOPGAMMA_DOUBLE; filter1.ramps.d.red_size = 4; filter1.ramps.d.green_size = 5; filter1.ramps.d.blue_size = 6; filter1.ramps.d.red = (double[]){0.0, 0.1, 0.2, 0.5, 0.3, 0.11, 0.22, 0.45, 0.9, -1, -0.5, 0, 0.5, 1, 1.5}; filter1.ramps.d.green = filter1.ramps.d.red + filter1.ramps.d.red_size; filter1.ramps.d.blue = filter1.ramps.d.green + filter1.ramps.d.green_size; crtc1.cooperative = 0; crtc1.depth = LIBCOOPGAMMA_DOUBLE; crtc1.supported = LIBCOOPGAMMA_YES; crtc1.red_size = 4; crtc1.green_size = 5; crtc1.blue_size = 6; crtc1.colourspace = LIBCOOPGAMMA_SRGB; crtc1.have_gamut = 1; crtc1.red_x = 100; crtc1.red_y = 50; crtc1.green_x = 300; crtc1.green_y = 350; crtc1.blue_x = 200; crtc1.blue_y = 260; crtc1.white_x = 500; crtc1.white_y = 999; query1.high_priority = INT64_MIN; query1.low_priority = INT64_MIN; query1.crtc = (char []){"crtc"}; query1.coalesce = 1; table1.red_size = 4; table1.green_size = 5; table1.blue_size = 6; table1.filter_count = 2; table1.filters = (libcoopgamma_queried_filter_t[]){ { .priority = INT64_MAX, .class = (char []){"a::b::c"}, .ramps.d = {.red_size = 4, .green_size = 5, .blue_size = 6, .red = (double[]){0.0, 0.1, 0.2, 0.5, 0.3, 0.11, 0.22, 0.45, 0.9, -1, -0.5, 0, 0.5, 1, 1.5}, .green = NULL, /* set later */ .blue = NULL /* set later */} }, { .priority = INT64_MAX - 1, .class = NULL, .ramps.d = {.red_size = 4, .green_size = 5, .blue_size = 6, .red = (double[]){0.02, 0.12, 0.22, 0.52, 0.32, 0.112, 0.222, 0.452, 0.92, -12, -0.52, 0.2, 0.52, 12, 1.52}, .green = NULL, /* set later */ .blue = NULL /* set later */} } }; table1.depth = LIBCOOPGAMMA_DOUBLE; table1.filters[0].ramps.d.green = table1.filters[0].ramps.d.red + table1.filters[0].ramps.d.red_size; table1.filters[1].ramps.d.green = table1.filters[1].ramps.d.red + table1.filters[1].ramps.d.red_size; table1.filters[0].ramps.d.blue = table1.filters[0].ramps.d.green + table1.filters[0].ramps.d.green_size; table1.filters[1].ramps.d.blue = table1.filters[1].ramps.d.green + table1.filters[1].ramps.d.green_size; ctx1.error.number = UINT64_MAX; ctx1.error.custom = 1; ctx1.error.server_side = 0; ctx1.error.description = (char []){"description"}; ctx1.fd = 3; ctx1.have_all_headers = 1; ctx1.bad_message = 0; ctx1.blocking = 2; ctx1.message_id = UINT32_MAX; ctx1.in_response_to = UINT32_MAX - 1; ctx1.outbound = (char []){"0123456789"}; ctx1.outbound_head = 7; ctx1.outbound_tail = 2; ctx1.outbound_size = 10; ctx1.inbound = (char []){"abcdefghi"}; ctx1.inbound_head = 6; ctx1.inbound_tail = 3; ctx1.inbound_size = 9; ctx1.length = 100; ctx1.curline = 5; async1.message_id = UINT32_MAX; async1.coalesce = 1; n = libcoopgamma_filter_marshal(&filter1, NULL); n += libcoopgamma_crtc_info_marshal(&crtc1, NULL); n += libcoopgamma_filter_query_marshal(&query1, NULL); n += libcoopgamma_filter_table_marshal(&table1, NULL); n += libcoopgamma_context_marshal(&ctx1, NULL); n += libcoopgamma_async_context_marshal(&async1, NULL); buf = malloc(n); n = libcoopgamma_filter_marshal(&filter1, buf); n += libcoopgamma_crtc_info_marshal(&crtc1, &buf[n]); n += libcoopgamma_filter_query_marshal(&query1, &buf[n]); n += libcoopgamma_filter_table_marshal(&table1, &buf[n]); n += libcoopgamma_context_marshal(&ctx1, &buf[n]); n += libcoopgamma_async_context_marshal(&async1, &buf[n]); if (libcoopgamma_filter_unmarshal(&filter2, buf, &m)) return 1; else n = m; if (libcoopgamma_crtc_info_unmarshal(&crtc2, &buf[n], &m)) return 2; else n += m; if (libcoopgamma_filter_query_unmarshal(&query2, &buf[n], &m)) return 3; else n += m; if (libcoopgamma_filter_table_unmarshal(&table2, &buf[n], &m)) return 4; else n += m; if (libcoopgamma_context_unmarshal(&ctx2, &buf[n], &m)) return 5; else n += m; if (libcoopgamma_async_context_unmarshal(&async2, &buf[n], &m)) return 6; free(buf); if (filter1.priority != filter2.priority || !streq(filter1.crtc, filter2.crtc) || !streq(filter1.class, filter2.class) || filter1.lifespan != filter2.lifespan || filter1.depth != filter2.depth || !rampseq(&filter1.ramps, &filter2.ramps, filter1.depth)) return 7; if (crtc1.cooperative != crtc2.cooperative || crtc1.depth != crtc2.depth || crtc1.supported != crtc2.supported || crtc1.red_size != crtc2.red_size || crtc1.green_size != crtc2.green_size || crtc1.blue_size != crtc2.blue_size || crtc1.colourspace != crtc2.colourspace || crtc1.have_gamut != crtc2.have_gamut || crtc1.red_x != crtc2.red_x || crtc1.red_y != crtc2.red_y || crtc1.green_x != crtc2.green_x || crtc1.green_y != crtc2.green_y || crtc1.blue_x != crtc2.blue_x || crtc1.blue_y != crtc2.blue_y || crtc1.white_x != crtc2.white_x || crtc1.white_y != crtc2.white_y) return 8; if (query1.high_priority != query2.high_priority || query1.low_priority != query2.low_priority || !streq(query1.crtc, query2.crtc) || query1.coalesce != query2.coalesce) return 9; if (table1.red_size != table2.red_size || table1.green_size != table2.green_size || table1.blue_size != table2.blue_size || table1.filter_count != table2.filter_count || table1.depth != table2.depth) return 10; for (i = 0; i < table1.filter_count; i++) if (table1.filters[i].priority != table2.filters[i].priority || !streq(table1.filters[i].class, table2.filters[i].class) || !rampseq(&table1.filters[i].ramps, &table2.filters[i].ramps, table1.depth)) return 11; if (ctx1.error.number != ctx2.error.number || ctx1.error.custom != ctx2.error.custom || ctx1.error.server_side != ctx2.error.server_side || !streq(ctx1.error.description, ctx2.error.description)) return 12; if (ctx1.fd != ctx2.fd || ctx1.have_all_headers != ctx2.have_all_headers || ctx1.bad_message != ctx2.bad_message || ctx1.blocking != ctx2.blocking || ctx1.message_id != ctx2.message_id || ctx1.in_response_to != ctx2.in_response_to || ctx1.length != ctx2.length || ctx1.curline != ctx2.curline) return 13; if (ctx2.outbound_head > ctx2.outbound_size || ctx2.outbound_tail > ctx2.outbound_size || ctx2.inbound_head > ctx2.inbound_size || ctx2.inbound_tail > ctx2.inbound_size) return 14; if ((n = ctx1.outbound_head - ctx1.outbound_tail) != ctx2.outbound_head - ctx2.outbound_tail || (m = ctx1.inbound_head - ctx1.inbound_tail) != ctx2.inbound_head - ctx2.inbound_tail) return 15; if (memcmp(ctx1.outbound + ctx1.outbound_tail, ctx2.outbound + ctx2.outbound_tail, n) || memcmp(ctx1.inbound + ctx1.inbound_tail, ctx2.inbound + ctx2.inbound_tail, m)) return 16; if (async1.message_id != async2.message_id || async1.coalesce != async2.coalesce) return 17; libcoopgamma_context_destroy(&ctx2, 1); libcoopgamma_filter_destroy(&filter2); libcoopgamma_filter_query_destroy(&query2); libcoopgamma_filter_table_destroy(&table2); return 0; }