OLD | NEW |
(Empty) | |
| 1 /* |
| 2 ** Copyright (c) 2012 The Khronos Group Inc. |
| 3 ** |
| 4 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 5 ** copy of this software and/or associated documentation files (the |
| 6 ** "Materials"), to deal in the Materials without restriction, including |
| 7 ** without limitation the rights to use, copy, modify, merge, publish, |
| 8 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 9 ** permit persons to whom the Materials are furnished to do so, subject to |
| 10 ** the following conditions: |
| 11 ** |
| 12 ** The above copyright notice and this permission notice shall be included |
| 13 ** in all copies or substantial portions of the Materials. |
| 14 ** |
| 15 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 22 */ |
| 23 |
| 24 // ArgGenerators contains argument generators for WebGL functions. |
| 25 // The argument generators are used for running random tests against the WebGL |
| 26 // functions. |
| 27 // |
| 28 // ArgGenerators is an object consisting of functionName : argGen -properties. |
| 29 // |
| 30 // functionName is a WebGL context function name and the argGen is an argument |
| 31 // generator object that encapsulates the requirements to run |
| 32 // randomly generated tests on the WebGL function. |
| 33 // |
| 34 // An argGen object has the following methods: |
| 35 // - setup -- set up state for testing the GL function, returns values |
| 36 // that need cleanup in teardown. Run once before entering a |
| 37 // test loop. |
| 38 // - teardown -- do cleanup on setup's return values after testing is complete |
| 39 // - generate -- generate a valid set of random arguments for the GL function |
| 40 // - returnValueCleanup -- do cleanup on value returned by the tested GL funct
ion |
| 41 // - cleanup -- do cleanup on generated arguments from generate |
| 42 // - checkArgValidity -- check if passed args are valid. Has a call signature |
| 43 // that matches generate's return value. Returns true |
| 44 // if args are valid, false if not. |
| 45 // |
| 46 // Example test loop that demonstrates how the function args and return |
| 47 // values flow together: |
| 48 // |
| 49 // var setupArgs = argGen.setup(); |
| 50 // for (var i=0; i<numberOfTests; i++) { |
| 51 // var generatedArgs = argGen.generate.apply(argGen, setupArgs); |
| 52 // var validArgs = argGen.checkArgValidity.apply(argGen, generatedArgs); |
| 53 // var rv = call the GL function with generatedArgs; |
| 54 // argGen.returnValueCleanup(rv); |
| 55 // argGen.cleanup.apply(argGen, generatedArgs); |
| 56 // } |
| 57 // argGen.teardown.apply(argGen, setupArgs); |
| 58 // |
| 59 ArgGenerators = { |
| 60 |
| 61 // GL functions in alphabetical order |
| 62 |
| 63 // C |
| 64 |
| 65 checkFramebufferStatus : { |
| 66 generate : function() { |
| 67 return [Math.random() > 0.5 ? null : GL.createFramebuffer()]; |
| 68 }, |
| 69 checkArgValidity : function(fbo) { |
| 70 if (fbo != null) |
| 71 GL.bindFramebuffer(GL.FRAMEBUFFER, fbo); |
| 72 return fbo == null || GL.isFramebuffer(fbo); |
| 73 }, |
| 74 cleanup : function(fbo){ |
| 75 GL.bindFramebuffer(GL.FRAMEBUFFER, null); |
| 76 if (fbo != null) |
| 77 try{ GL.deleteFramebuffer(fbo); } catch(e) {} |
| 78 } |
| 79 }, |
| 80 clear : { |
| 81 generate : function() { return [clearMask.random()]; }, |
| 82 checkArgValidity : function(mask) { return clearMask.has(mask); } |
| 83 }, |
| 84 clearColor : { |
| 85 generate : function() { return randomColor(); }, |
| 86 teardown : function() { GL.clearColor(0,0,0,0); } |
| 87 }, |
| 88 clearDepth : { |
| 89 generate : function() { return [Math.random()]; }, |
| 90 teardown : function() { GL.clearDepth(1); } |
| 91 }, |
| 92 clearStencil : { |
| 93 generate : function() { return [randomStencil()]; }, |
| 94 teardown : function() { GL.clearStencil(0); } |
| 95 }, |
| 96 colorMask : { |
| 97 generate : function() { |
| 98 return [randomBool(), randomBool(), randomBool(), randomBool()]; |
| 99 }, |
| 100 teardown : function() { GL.colorMask(true, true, true, true); } |
| 101 }, |
| 102 compileShader : {}, // FIXME |
| 103 copyTexImage2D : {}, // FIXME |
| 104 copyTexSubImage2D : {}, // FIXME |
| 105 createBuffer : { |
| 106 generate : function() { return []; }, |
| 107 returnValueCleanup : function(o) { GL.deleteBuffer(o); } |
| 108 }, |
| 109 createFramebuffer : { |
| 110 generate : function() { return []; }, |
| 111 returnValueCleanup : function(o) { GL.deleteFramebuffer(o); } |
| 112 }, |
| 113 createProgram : { |
| 114 generate : function() { return []; }, |
| 115 returnValueCleanup : function(o) { GL.deleteProgram(o); } |
| 116 }, |
| 117 createRenderbuffer : { |
| 118 generate : function() { return []; }, |
| 119 returnValueCleanup : function(o) { GL.deleteRenderbuffer(o); } |
| 120 }, |
| 121 createShader : { |
| 122 generate : function() { return [shaderType.random()]; }, |
| 123 checkArgValidity : function(t) { return shaderType.has(t); }, |
| 124 returnValueCleanup : function(o) { GL.deleteShader(o); } |
| 125 }, |
| 126 createTexture : { |
| 127 generate : function() { return []; }, |
| 128 returnValueCleanup : function(o) { GL.deleteTexture(o); } |
| 129 }, |
| 130 cullFace : { |
| 131 generate : function() { return [cullFace.random()]; }, |
| 132 checkArgValidity : function(f) { return cullFace.has(f); }, |
| 133 teardown : function() { GL.cullFace(GL.BACK); } |
| 134 } |
| 135 |
| 136 }; |
OLD | NEW |