[RFC] [PATCH 8/8] Added res-resourcebytes-test

Erkki Seppälä erkki.seppala at vincit.fi
Mon Dec 27 06:57:02 PST 2010


---
 Makefile                 |    9 +++
 res-resourcebytes-test.c |  122 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+), 0 deletions(-)
 create mode 100644 Makefile
 create mode 100644 res-resourcebytes-test.c

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..83fb6a1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+LDFLAGS=-lXRes
+CFLAGS=-g -O0 -W -Wall
+
+TARGETS=res-clientid-test res-resourcebytes-test 
+
+all: $(TARGETS)
+
+clean:
+	rm -f $(TARGETS) *.o *~ core
diff --git a/res-resourcebytes-test.c b/res-resourcebytes-test.c
new file mode 100644
index 0000000..bcdcce4
--- /dev/null
+++ b/res-resourcebytes-test.c
@@ -0,0 +1,122 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/XRes.h>
+#include <unistd.h>
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+    Display *display;
+    XID clientID = None;
+
+    if (argc < 2 || !(display = XOpenDisplay(argv[1]))) {
+        printf("Cannot open display or invalid number of arguments provided\n");
+        printf("Usage: %s :0 [client-id] [[resource/type] [[resource/type] ..]]\n", argv[0]);
+        return 1;
+    }
+
+    if (argc >= 3) {
+        int id;
+        if (sscanf(argv[2], "%x", &id)) {
+            clientID = id;
+        } else {
+            printf("Expected a hexadecimal number for client id\n");
+            return 1;
+        }
+    }
+
+    {
+        int                  major, minor;
+        if (!XResQueryVersion(display, &major, &minor)) {
+            printf("XResQueryVersion call failed\n");
+            return 1;
+        }
+
+        if (major != 1 || minor < 2) { 
+            printf("Invalid X-Resource extension version %d.%d, major 1 atleast minor 2 expected\n", major, minor);
+
+            return 1;
+        }
+    }
+
+    {
+        int event, error;
+
+        if (!XResQueryExtension(display, &event, &error)) {
+            printf("X-Resource extension not present\n");
+            return 1;
+        }
+    }
+
+    {
+        long                   num_sizes;
+        XResResourceSizeValue *sizes;
+        long                   c; 
+        long                   d;
+        XResResourceIdSpec     specs[10];
+        int                    numSpecs = 0;
+        if (argc <= 3) {
+            specs[0].resource = None;
+            specs[0].type = None;
+            ++numSpecs;
+        } else {
+            int argIdx;
+            for (argIdx = 3; argIdx < argc; ++argIdx) {
+                char *sep = strchr(argv[argIdx], '/');
+                if (sep) {
+                    unsigned id;
+                    unsigned atom;
+                    *sep = 0;
+                    if (sscanf(argv[argIdx], "%x", &id) &&
+                        sscanf(sep + 1, "%x", &atom)) {
+                        specs[numSpecs].resource = id;
+                        specs[numSpecs].type = atom;
+                        ++numSpecs;
+                        if (numSpecs > (int) (sizeof(specs) / sizeof(*specs))) {
+                            printf("Too many specs provided\n");
+                            return 1;
+                        }
+                    } else {
+                        printf("Expected a hexadecimal number for client id\n");
+                        return 1;
+                    }
+                } else {
+                    printf("resource/tpye needs to be two hexadecimal numbers separated by a slash\n");
+                    return 1;
+                }
+            }
+        }
+
+        printf("Requesting with %d specs\n", numSpecs);
+        XResQueryResourceBytes(display, clientID, numSpecs, specs, &num_sizes, &sizes);
+
+        printf("Got %ld sizes\n", num_sizes);
+        for (c = 0; c < num_sizes; ++c) {
+            XResResourceSizeValue *value = &sizes[c];
+            printf("%4ld", c);
+            printf(" %08x", (int) value->size.spec.resource);
+            printf(" %08x", (int) value->size.spec.type);
+            printf(" %8d", (int) value->size.bytes);
+            printf(" %3ld", value->size.ref_count);
+            printf(" %3ld", value->size.use_count);
+            printf(" %3ld", value->num_cross_references);
+            printf("\n");
+            for (d = 0; d < value->num_cross_references; ++d) {
+                XResResourceSizeSpec *spec = &value->cross_references[d];
+                printf("  %4ld", d);
+                printf(" %08x", (int) spec->spec.resource);
+                printf(" %08x", (int) spec->spec.type);
+                printf(" %8d", (int) spec->bytes);
+                printf(" %3ld", spec->ref_count);
+                printf(" %3ld", spec->use_count);
+                printf("\n");
+            }
+        }
+
+        XResResourceSizeValuesDestroy(num_sizes, sizes);
+    }
+
+    XCloseDisplay(display);
+    return 0;
+}
-- 
1.7.0.4



More information about the xorg-devel mailing list