/* Host test for the NBCUR1 cursor bundle built by mkcursors * (make test-cursors): structure, a few Adwaita hotspots, the subsampled * spinner, and that every frame has visible pixels. */ #include #include #include #include "cursor_abi.h" static int fails; #define CHECK(c, ...) do { if (!(c)) { fails++; \ fprintf(stderr, "FAIL %s:%d: ", __FILE__, __LINE__); \ fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } } while (0) int main(int argc, char **argv) { const char *path = argc > 1 ? argv[1] : "cursors/adwaita24.cur"; FILE *f = fopen(path, "rb"); unsigned char *buf; long size; const struct cursor_file_hdr *h; const struct cursor_file_shape *s; unsigned int i, fr; if (!f) { perror(path); return 1; } fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); buf = malloc((size_t)size); if (!buf || fread(buf, 1, (size_t)size, f) != (size_t)size) return 1; fclose(f); h = (const struct cursor_file_hdr *)buf; s = (const struct cursor_file_shape *)(buf + sizeof(*h)); CHECK(memcmp(h->magic, CURSOR_FILE_MAGIC, 8) == 0, "magic"); CHECK(h->count == CURSOR_COUNT, "count %u", h->count); CHECK(h->nominal == 24, "nominal %u", h->nominal); if (fails) return 1; for (i = 0; i < h->count; i++) { unsigned int px = (unsigned int)s[i].w * s[i].h; CHECK(s[i].w == 24 && s[i].h == 24, "shape %u size %ux%u", i, s[i].w, s[i].h); CHECK(s[i].hot_x < s[i].w && s[i].hot_y < s[i].h, "shape %u hotspot", i); CHECK(s[i].frames >= 1, "shape %u frames", i); CHECK((s[i].offset & 3) == 0 && s[i].offset + px * 4u * s[i].frames <= (unsigned long)size, "shape %u range", i); for (fr = 0; fr < s[i].frames; fr++) { const unsigned int *p = (const unsigned int *) (buf + s[i].offset) + fr * px; unsigned int k, opaque = 0, bad = 0; for (k = 0; k < px; k++) { unsigned int a = p[k] >> 24; if (a) opaque++; /* Premultiplied: no channel above alpha. */ if (((p[k] >> 16) & 0xFF) > a || ((p[k] >> 8) & 0xFF) > a || (p[k] & 0xFF) > a) bad++; } CHECK(opaque > 10, "shape %u frame %u is empty", i, fr); CHECK(bad == 0, "shape %u frame %u not premultiplied", i, fr); } } /* Hotspots from the Adwaita 51 Xcursor files. */ CHECK(s[CURSOR_DEFAULT].hot_x == 3 && s[CURSOR_DEFAULT].hot_y == 1, "default hotspot"); CHECK(s[CURSOR_TEXT].hot_x == 11 && s[CURSOR_TEXT].hot_y == 12, "text hotspot"); CHECK(s[CURSOR_POINTER].hot_x == 7 && s[CURSOR_POINTER].hot_y == 5, "pointer hotspot"); /* move is Adwaita's all-resize (its own `move` is a symlink to the * arrow). */ CHECK(s[CURSOR_MOVE].hot_x == 12 && s[CURSOR_MOVE].hot_y == 11, "move hotspot"); /* 60 frames x 16 ms, every 4th kept: 15 frames x 64 ms. */ CHECK(s[CURSOR_WAIT].frames == 15 && s[CURSOR_WAIT].delay_ms == 64, "wait %u frames x %u ms", s[CURSOR_WAIT].frames, s[CURSOR_WAIT].delay_ms); CHECK(s[CURSOR_PROGRESS].frames == 15, "progress frames"); CHECK(s[CURSOR_DEFAULT].frames == 1 && s[CURSOR_DEFAULT].delay_ms == 0, "default is static"); i = h->count; free(buf); if (fails) { fprintf(stderr, "cursor_test: %d failure(s)\n", fails); return 1; } printf("cursor_test: %u shapes OK (%ld bytes)\n", i, size); return 0; }