]> git.draconx.ca Git - rrace.git/blobdiff - t/ewmhicon.c
Separate EWMH colour conversion from icon generation.
[rrace.git] / t / ewmhicon.c
index d7c6aea2276a1eb9b2da221707a002b95c32befc..5919363549a3f72bc779ba842f19753ded4cb854 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Test app for _NET_WM_ICON formatting.
- * Copyright © 2022 Nick Bowler
+ * Copyright © 2022-2023 Nick Bowler
  *
  * Use a fake colour scheme to generate an icon of the chosen size (16x16,
  * 24x24, 32x32 or 48x48) and display the pixels as characters.
 #include "icon.h"
 #include "colour.h"
 #include "help.h"
+#include "xtra.h"
 
 enum {
        SOPT_MAX = UCHAR_MAX,
        LOPT_W32VGA,
+       LOPT_TEST_CMAP,
        LOPT_MAX
 };
 
 static const char *progname = "ewmhicon";
 static const char sopts[] = "c:VH";
 static const struct option lopts[] = {
+       { "test-cmap", 0, NULL, LOPT_TEST_CMAP },
        { "colourseq", 1, NULL, 'c' },
        { "w32vga",    0, NULL, LOPT_W32VGA },
        { "version",   0, NULL, 'V' },
@@ -100,7 +103,7 @@ static void print_help(void)
 static void print_version(void)
 {
        printf("ewmhicon (%s) %s\n", PACKAGE, PACKAGE_VERSION);
-       printf("Copyright (C) 2022 Nick Bowler\n");
+       printf("Copyright (C) 2023 Nick Bowler\n");
        puts("License GPLv3+: GNU GPL version 3 or any later version");
        puts("This is free software: you are free to change and redistribute it.");
        puts("There is NO WARRANTY, to the extent permitted by law.");
@@ -408,11 +411,41 @@ static unsigned long *find_icon(unsigned long size, unsigned long *ewmhicon)
        return NULL;
 }
 
+static int test_ewmh_icon_prepare(void)
+{
+       int ret = EXIT_SUCCESS;
+       unsigned i;
+
+       XColor *template = (void *)colours;
+       XColor newmap[sizeof colours / sizeof colours[0][0]];
+
+       printf("1..%d\n", (int)XTRA_ARRAYSIZE(newmap));
+       for (i = 0; i < XTRA_ARRAYSIZE(newmap); i++) {
+               newmap[i] = template[i];
+               newmap[i].pixel = 0;
+       }
+
+       ewmh_icon_prepare_cmap(newmap, XTRA_ARRAYSIZE(newmap));
+       for (i = 0; i < XTRA_ARRAYSIZE(newmap); i++) {
+               XColor *c = &newmap[i];
+
+               if (c->pixel != template[i].pixel) {
+                       printf("not ");
+                       ret = EXIT_FAILURE;
+               }
+
+               printf("ok %u (%.4hx, %.4hx, %.4hx) -> %.8lx\n",
+                      i+1, c->red, c->green, c->blue, c->pixel);
+       }
+
+       return ret;
+}
+
 int main(int argc, char **argv)
 {
        unsigned long *ewmhicon, *icon, size, buf[9];
        char colourseq[10] = "000000000";
-       int w32vga = 0;
+       int w32vga = 0, test_cmap = 0;
        int opt;
 
        if (argc > 0)
@@ -427,6 +460,9 @@ int main(int argc, char **argv)
                case LOPT_W32VGA:
                        w32vga = 1;
                        break;
+               case LOPT_TEST_CMAP:
+                       test_cmap = 1;
+                       break;
                case 'H':
                        print_help();
                        return EXIT_SUCCESS;
@@ -439,6 +475,10 @@ int main(int argc, char **argv)
                }
        }
 
+       if (test_cmap) {
+               return test_ewmh_icon_prepare();
+       }
+
        if (argc != optind+1) {
                printf("%s: error: size not specified\n", progname);
                print_usage(stderr);