[PyOpenGL-Users] Re: Test-first and mock objects with PyOpenGL
Brought to you by:
mcfletch
From: Mike C. F. <mcf...@ro...> - 2002-04-20 07:13:30
|
I've never done unit testing with OpenGL code, but I'll give a shot at the problem. I'd guess the easiest test you could create would be to create an image that shows what you want and simply test whether that matches the image created by the new system. Problem there is that the original image would need to be generated by your system, so you'd have that anti-pattern (don't recall what the XP name is) where you rely on output of the system to check correctness of the system. If you really want to make the checks "manually predicted", you'd have to figure out particularly what calls, with what parameters you expected to get... all in all, sounds like a pain in the arse unless you're dropping in the "mockup" with the "known-good" system to generate a set of data... that's the same anti-pattern cropping up though. From a practical standpoint, replacing the whole GL with a mock-up seems a bit extreme (you'd have to figure out the internal state to do it right I'd think). You could easily write a script that just walks through the Python OpenGL.GL, OpenGL.GLU and OpenGL.GLUT modules replacing every method with a wrapped version which logs the method name, parameters and return values to somewhere. Check that log versus your expected results and you'd be golden (assuming you can create the set of "expected results" somehow). Tarn did something very similar a while back to introduce stronger error checking without changing the C code. Well, hope that helps somewhat, shout if anything I've said is unclear, Mike Phlip wrote: > Alpha OpenGL Engineers: > > I have a large spike-solution ("quicky non-production quality code > base") of PyOpenGL, and I want to refactor it into something healthy. > > I don't want to use GuruChecksOutput. This means I want tests that > reveal changes did not affect how the code call the GL libraries. > > The standard way to do this is to provide a MockObject in place of > something, call the tested functions, let them call into the > MockObject, and test what they told it. If these values did not change > then the refactor did not break anything important. > > However, I don't know if I have to Mock GL itself. Maybe I can replace > OpenGL's back-end with a Mock that renders not to the screen but into > my test code. > > Who has done this and knows the pattern for it? > -- _______________________________________ Mike C. Fletcher http://members.rogers.com/mcfletch/ |