OLD | NEW |
(Empty) | |
| 1 // ArgGenerators contains argument generators for WebGL functions. |
| 2 // The argument generators are used for running random tests against the WebGL |
| 3 // functions. |
| 4 // |
| 5 // ArgGenerators is an object consisting of functionName : argGen -properties. |
| 6 // |
| 7 // functionName is a WebGL context function name and the argGen is an argument |
| 8 // generator object that encapsulates the requirements to run |
| 9 // randomly generated tests on the WebGL function. |
| 10 // |
| 11 // An argGen object has the following methods: |
| 12 // - setup -- set up state for testing the GL function, returns values |
| 13 // that need cleanup in teardown. Run once before entering a |
| 14 // test loop. |
| 15 // - teardown -- do cleanup on setup's return values after testing is complete |
| 16 // - generate -- generate a valid set of random arguments for the GL function |
| 17 // - returnValueCleanup -- do cleanup on value returned by the tested GL funct
ion |
| 18 // - cleanup -- do cleanup on generated arguments from generate |
| 19 // - checkArgValidity -- check if passed args are valid. Has a call signature |
| 20 // that matches generate's return value. Returns true |
| 21 // if args are valid, false if not. |
| 22 // |
| 23 // Example test loop that demonstrates how the function args and return |
| 24 // values flow together: |
| 25 // |
| 26 // var setupArgs = argGen.setup(); |
| 27 // for (var i=0; i<numberOfTests; i++) { |
| 28 // var generatedArgs = argGen.generate.apply(argGen, setupArgs); |
| 29 // var validArgs = argGen.checkArgValidity.apply(argGen, generatedArgs); |
| 30 // var rv = call the GL function with generatedArgs; |
| 31 // argGen.returnValueCleanup(rv); |
| 32 // argGen.cleanup.apply(argGen, generatedArgs); |
| 33 // } |
| 34 // argGen.teardown.apply(argGen, setupArgs); |
| 35 // |
| 36 ArgGenerators = { |
| 37 |
| 38 // GL functions in alphabetical order |
| 39 |
| 40 // A |
| 41 |
| 42 activeTexture : { |
| 43 generate : function() { return [textureUnit.random()]; }, |
| 44 checkArgValidity : function(t) { return textureUnit.has(t); }, |
| 45 teardown : function() { GL.activeTexture(GL.TEXTURE0); } |
| 46 }, |
| 47 attachShader : { |
| 48 generate : function() { |
| 49 var p = GL.createProgram(); |
| 50 var sh = GL.createShader(shaderType.random()); |
| 51 return [p, sh]; |
| 52 }, |
| 53 checkArgValidity : function(p, sh) { |
| 54 return GL.isProgram(p) && GL.isShader(sh) && !GL.getAttachedShaders(p).has
(sh); |
| 55 }, |
| 56 cleanup : function(p, sh) { |
| 57 try {GL.detachShader(p,sh);} catch(e) {} |
| 58 try {GL.deleteProgram(p);} catch(e) {} |
| 59 try {GL.deleteShader(sh);} catch(e) {} |
| 60 } |
| 61 } |
| 62 |
| 63 }; |
OLD | NEW |