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 // B-4 |
| 41 |
| 42 bufferSubData : { |
| 43 setup : function() { |
| 44 var buf = GL.createBuffer(); |
| 45 var ebuf = GL.createBuffer(); |
| 46 GL.bindBuffer(GL.ARRAY_BUFFER, buf); |
| 47 GL.bufferData(GL.ARRAY_BUFFER, 256, GL.STATIC_DRAW); |
| 48 GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, ebuf); |
| 49 GL.bufferData(GL.ELEMENT_ARRAY_BUFFER, 256, GL.STATIC_DRAW); |
| 50 return [buf, ebuf]; |
| 51 }, |
| 52 generate : function(buf, ebuf) { |
| 53 var d = randomBufferSubData(256); |
| 54 return [bufferTarget.random(), d.offset, d.data]; |
| 55 }, |
| 56 checkArgValidity : function(target, offset, data) { |
| 57 return bufferTarget.has(target) && offset >= 0 && data.byteLength >= 0 &&
offset + data.byteLength <= 256; |
| 58 }, |
| 59 teardown : function(buf, ebuf) { |
| 60 GL.deleteBuffer(buf); |
| 61 GL.deleteBuffer(ebuf); |
| 62 }, |
| 63 } |
| 64 |
| 65 }; |
OLD | NEW |