/* Compile with cc -o testcase testcase.c -lXext -lX11 */ #include #include #include #include #include #include #include #include #include static volatile int errorCaught = 0; extern int _XDefaultError(Display *dpy, XErrorEvent *event); static int myXErrorCallback(Display *dpy, XErrorEvent *event) { errorCaught = 1; if (event->error_code == BadAlloc) { printf("TEST PASSED: illegal call returned BadAlloc\n"); return 0; } else if (event->error_code == BadImplementation) { printf("Test returned BadImplementation - not supported on this graphics card\n"); return 0; } else { return _XDefaultError(dpy, event); } } int main(int argc, char **argv) { int testno; int result = 0; Display *dpy; int major, minor; char *answer; XShmSegmentInfo shm_info; int image_size = 8192; int width = 32768, height = 32768, depth = 32; dpy = XOpenDisplay(NULL); if (dpy == NULL) { fprintf(stderr, "Can't open display %s\n", XDisplayName(NULL)); exit(1); } if (XShmQueryExtension(dpy) == False) { printf("MIT-SHM Extension NOT present on display - cannot test\n"); return 1; } memset(&shm_info, 0, sizeof(XShmSegmentInfo)); shm_info.shmid = shmget(IPC_PRIVATE, image_size, IPC_CREAT|0777); if (shm_info.shmid < 0) { perror("Test setup failed: shmget"); exit(1); } shm_info.shmaddr = shmat(shm_info.shmid, 0, 0); shm_info.readOnly = False; if (!XShmAttach(dpy, &shm_info)) { fprintf(stderr, "Test setup failed: XShmAttach\n"); exit(1); } XSync(dpy, False); XSetErrorHandler(myXErrorCallback); XShmCreatePixmap(dpy, DefaultRootWindow(dpy), shm_info.shmaddr, &shm_info, width, height, depth); XSync(dpy, False); XShmDetach(dpy, &shm_info); shmdt(shm_info.shmaddr); shmctl (shm_info.shmid, IPC_RMID, 0); XCloseDisplay(dpy); if (errorCaught == 0) printf("TEST FAILED: No error messages recieved!\n"); }