Mercurial > sdl-ios-xcode
view src/video/Xext/XME/xme.c @ 4447:947201caa46e
Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware.
The Mac OS X project has a new target called testsdl which builds the automated test. I looked at using Xcode's native unit test support, but the impedance mismatch between the existing automated test structure and Apple's was more than I could handle.
As such, the testsdl application is a full blown proper OS X application, which means it is a self-contained .app bundle. This immediately revealed some problems from the automated test. The largest problem was the assumption about the current working directory and where to find resources. (I suspect Windows may have a similar problem depending on circumstance.) To open resources, the test was looking in directories relative to the SDL source directory, but this will not work well with self-contained .app bundles and Xcode which can place its built applications almost anywhere. And for real-world situations, this is pretty useless anyway.
So I modified SDL_RWFromFile to do special things on OS X. First, it will look for a file in the .app bundle. If not found, it will fallback and just call fopen as it used to do.
I also had to modify the automated test itself because it had a contrieved test which called fopen directly to do read from an existing FILE pointer. In addition, there was a write test. Since a .app bundle is likely going to be read-only, I added a special case for OS X to write to NSTemporaryDirectory.
I expect these changes should work for both Mac and iPhone OS (which includes iPad).
I will update the iPhone Xcode project next.
Finally, FYI, the X11 automated test seems to be failing. Below is my output.
Pending breakpoint 4 - "-[NSException raise]" resolved
Platform : All tests successful (2)
SDL_RWops : All tests successful (5)
Rect : All tests successful (1)
SDL_Surface : All tests successful (6)
Rendering with cocoa driver : All tests successful (3)
Assert Failed!
Blit output not the same.
Test Case 'Renderer x11'
Test Suite 'Rendering with x11 driver'
Last SDL error ''
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150
Rendering with x11 driver : Failed 1 out of 4 testcases!
Rendering with dummy driver : All tests successful (3)
SDL_Audio : All tests successful (1)
Tests run with SDL 1.3.0 revision 1095906
System is running Mac OS X and is little endian
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Sat, 08 May 2010 00:54:22 -0700 |
parents | 81dde1b00bf1 |
children |
line wrap: on
line source
/* * Copyright 1993-2001 by Xi Graphics, Inc. * All Rights Reserved. * * Please see the LICENSE file accompanying this distribution for licensing * information. * * Please send any bug fixes and modifications to src@xig.com. * * $XiGId: xme.c,v 1.2 2001/11/30 21:56:59 jon Exp $ * */ #define NEED_EVENTS #define NEED_REPLIES /* Apparently some X11 systems can't include this multiple times... */ #ifndef SDL_INCLUDED_XLIBINT_H #define SDL_INCLUDED_XLIBINT_H 1 #include <X11/Xlibint.h> #endif #include <X11/Xthreads.h> #include <X11/Xmd.h> #include <X11/Xproto.h> #include "../extensions/Xext.h" #include "../extensions/extutil.h" /*****************************************************************************/ #define XIGMISC_PROTOCOL_NAME "XiG-SUNDRY-NONSTANDARD" #define XIGMISC_MAJOR_VERSION 2 #define XIGMISC_MINOR_VERSION 0 #define XiGMiscNumberEvents 0 #define X_XiGMiscQueryVersion 0 #define X_XiGMiscQueryViews 1 #define X_XiGMiscQueryResolutions 2 #define X_XiGMiscChangeResolution 3 #define X_XiGMiscFullScreen 4 #define sz_xXiGMiscQueryVersionReq 8 #define sz_xXiGMiscQueryViewsReq 8 #define sz_xXiGMiscQueryResolutionsReq 8 #define sz_xXiGMiscChangeResolutionReq 16 #define sz_xXiGMiscFullScreenReq 16 #define sz_xXiGMiscQueryVersionReply 32 #define sz_xXiGMiscQueryViewsReply 32 #define sz_xXiGMiscQueryResolutionsReply 32 #define sz_xXiGMiscQueryFullScreenReply 32 /*******************************************************************/ typedef struct { CARD8 reqType; /* always codes->major_opcode */ CARD8 xigmiscReqType; /* always X_XiGMiscQueryVersion */ CARD16 length; CARD16 major; CARD16 minor; } xXiGMiscQueryVersionReq; typedef struct { CARD8 reqType; /* always codes->major_opcode */ CARD8 xigmiscReqType; /* always X_XiGMiscQueryViews */ CARD16 length; CARD8 screen; CARD8 pad0; CARD16 pad1; } xXiGMiscQueryViewsReq; typedef struct { CARD8 reqType; /* always codes->major_opcode */ CARD8 xigmiscReqType; /* always X_XiGMiscQueryResolutions */ CARD16 length; CARD8 screen; CARD8 view; CARD16 pad0; } xXiGMiscQueryResolutionsReq; typedef struct { CARD8 reqType; /* always codes->major_opcode */ CARD8 xigmiscReqType; /* always X_XiGMiscChangeResolution */ CARD16 length; CARD8 screen; CARD8 view; CARD16 pad0; CARD16 width; CARD16 height; INT32 refresh; } xXiGMiscChangeResolutionReq; typedef struct { CARD8 reqType; /* always codes->major_opcode */ CARD8 xigmiscReqType; /* always X_XiGMiscFullScreen */ CARD16 length; CARD8 screen; CARD8 pad0; CARD16 pad1; CARD32 window; CARD32 cmap; } xXiGMiscFullScreenReq; /*******************************************************************/ typedef struct { BYTE type; /* X_Reply */ CARD8 pad0; CARD16 sequenceNumber; CARD32 length; CARD16 major; CARD16 minor; CARD32 pad1; CARD32 pad2; CARD32 pad3; CARD32 pad4; CARD32 pad5; } xXiGMiscQueryVersionReply; typedef struct { BYTE type; /* X_Reply */ CARD8 pad0; CARD16 sequenceNumber; CARD32 length; CARD32 nviews; CARD32 pad1; CARD32 pad2; CARD32 pad3; CARD32 pad4; CARD32 pad5; } xXiGMiscQueryViewsReply; typedef struct { BYTE type; /* X_Reply */ CARD8 pad0; CARD16 sequenceNumber; CARD32 length; CARD16 active; CARD16 nresolutions; CARD32 pad1; CARD32 pad2; CARD32 pad3; CARD32 pad4; CARD32 pad5; } xXiGMiscQueryResolutionsReply; typedef struct { BYTE type; /* X_Reply */ BOOL success; CARD16 sequenceNumber; CARD32 length; CARD32 pad1; CARD32 pad2; CARD32 pad3; CARD32 pad4; CARD32 pad5; CARD32 pad6; } xXiGMiscFullScreenReply; /*******************************************************************/ typedef struct { INT16 x; INT16 y; CARD16 w; CARD16 h; } XiGMiscViewInfo; typedef struct { CARD16 width; CARD16 height; INT32 refresh; } XiGMiscResolutionInfo; /*****************************************************************************/ static XExtensionInfo *xigmisc_info = NULL; static char *xigmisc_extension_name = XIGMISC_PROTOCOL_NAME; #define XiGMiscCheckExtension(dpy,i,val) \ XextCheckExtension (dpy, i, xigmisc_extension_name, val) #define XiGMiscSimpleCheckExtension(dpy,i) \ XextSimpleCheckExtension (dpy, i, xigmisc_extension_name) #if defined(__STDC__) && !defined(UNIXCPP) #define XiGMiscGetReq(name,req,info) GetReq (name, req); \ req->reqType = info->codes->major_opcode; \ req->xigmiscReqType = X_##name; #define XiGMiscGetReqExtra(name,n,req,info) GetReqExtra (name, n, req); \ req->reqType = info->codes->major_opcode; \ req->xigmicReqType = X_##name; #else #define XiGMiscGetReq(name,req,info) GetReq (name, req); \ req->reqType = info->codes->major_opcode; \ req->xigmiscReqType = X_/**/name; #define XiGMiscGetReqExtra(name,n,req,info) GetReqExtra (name, n, req); \ req->reqType = info->codes->major_opcode; \ req->xigmiscReqType = X_/**/name; #endif /* * find_display - locate the display info block */ static int XiGMiscCloseDisplay(); static XExtensionHooks xigmisc_extension_hooks = { NULL, /* create_gc */ NULL, /* copy_gc */ NULL, /* flush_gc */ NULL, /* free_gc */ NULL, /* create_font */ NULL, /* free_font */ XiGMiscCloseDisplay, /* close_display */ NULL, /* wire_to_event */ NULL, /* event_to_wire */ NULL, /* error */ NULL, /* error_string */ }; static XEXT_GENERATE_CLOSE_DISPLAY(XiGMiscCloseDisplay, xigmisc_info) static XEXT_GENERATE_FIND_DISPLAY(XiGMiscFindDisplay, xigmisc_info, xigmisc_extension_name, &xigmisc_extension_hooks, XiGMiscNumberEvents, NULL) /*****************************************************************************/ Bool XiGMiscQueryVersion(Display * dpy, int *major, int *minor) { int opcode, event, error; xXiGMiscQueryVersionReq *req; xXiGMiscQueryVersionReply rep; XExtDisplayInfo *info = XiGMiscFindDisplay(dpy); if (!XQueryExtension(dpy, XIGMISC_PROTOCOL_NAME, &opcode, &event, &error)) return xFalse; XiGMiscCheckExtension(dpy, info, xFalse); LockDisplay(dpy); XiGMiscGetReq(XiGMiscQueryVersion, req, info); req->major = XIGMISC_MAJOR_VERSION; req->minor = XIGMISC_MINOR_VERSION; if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) { UnlockDisplay(dpy); SyncHandle(); return xFalse; } *major = rep.major; *minor = rep.minor; UnlockDisplay(dpy); SyncHandle(); return xTrue; } int XiGMiscQueryViews(Display * dpy, int screen, XiGMiscViewInfo ** pviews) { int n, size; XiGMiscViewInfo *views; xXiGMiscQueryViewsReq *req; xXiGMiscQueryViewsReply rep; XExtDisplayInfo *info = XiGMiscFindDisplay(dpy); XiGMiscCheckExtension(dpy, info, 0); LockDisplay(dpy); XiGMiscGetReq(XiGMiscQueryViews, req, info); req->screen = screen; if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return 0; } n = rep.nviews; if (n > 0) { size = sizeof(XiGMiscViewInfo) * n; views = (XiGMiscViewInfo *) Xmalloc(size); if (!views) { _XEatData(dpy, (unsigned long) size); UnlockDisplay(dpy); SyncHandle(); return 0; } _XReadPad(dpy, (void *) views, size); *pviews = views; } UnlockDisplay(dpy); SyncHandle(); return n; } int XiGMiscQueryResolutions(Display * dpy, int screen, int view, int *pactive, XiGMiscResolutionInfo ** presolutions) { int n, size; XiGMiscResolutionInfo *resolutions; xXiGMiscQueryResolutionsReq *req; xXiGMiscQueryResolutionsReply rep; XExtDisplayInfo *info = XiGMiscFindDisplay(dpy); XiGMiscCheckExtension(dpy, info, 0); LockDisplay(dpy); XiGMiscGetReq(XiGMiscQueryResolutions, req, info); req->screen = screen; req->view = view; if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return 0; } n = rep.nresolutions; if (n > 0) { size = sizeof(XiGMiscResolutionInfo) * n; resolutions = (XiGMiscResolutionInfo *) Xmalloc(size); if (!resolutions) { _XEatData(dpy, (unsigned long) size); UnlockDisplay(dpy); SyncHandle(); return 0; } _XReadPad(dpy, (void *) resolutions, size); *presolutions = resolutions; *pactive = rep.active; } UnlockDisplay(dpy); SyncHandle(); return n; } void XiGMiscChangeResolution(Display * dpy, int screen, int view, int width, int height, int refresh) { xXiGMiscChangeResolutionReq *req; XExtDisplayInfo *info = XiGMiscFindDisplay(dpy); XiGMiscSimpleCheckExtension(dpy, info); LockDisplay(dpy); XiGMiscGetReq(XiGMiscChangeResolution, req, info); req->screen = screen; req->view = view; req->width = width; req->height = height; req->refresh = refresh; UnlockDisplay(dpy); SyncHandle(); } Bool XiGMiscFullScreen(Display * dpy, int screen, XID window, XID cmap) { xXiGMiscFullScreenReq *req; xXiGMiscFullScreenReply rep; XExtDisplayInfo *info = XiGMiscFindDisplay(dpy); XiGMiscCheckExtension(dpy, info, xFalse); LockDisplay(dpy); XiGMiscGetReq(XiGMiscFullScreen, req, info); req->screen = screen; req->pad0 = 0; req->pad1 = 0; req->window = window; req->cmap = cmap; if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) { UnlockDisplay(dpy); SyncHandle(); return xFalse; } UnlockDisplay(dpy); SyncHandle(); return (rep.success ? xTrue : xFalse); } /* SDL addition from Ryan: free memory used by xme. */ void XiGMiscDestroy(void) { if (xigmisc_info) { XextDestroyExtension(xigmisc_info); xigmisc_info = NULL; } } /* vi: set ts=4 sw=4 expandtab: */