OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <!-- |
| 6 |
| 7 /* |
| 8 ** Copyright (c) 2012 The Khronos Group Inc. |
| 9 ** |
| 10 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 11 ** copy of this software and/or associated documentation files (the |
| 12 ** "Materials"), to deal in the Materials without restriction, including |
| 13 ** without limitation the rights to use, copy, modify, merge, publish, |
| 14 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 15 ** permit persons to whom the Materials are furnished to do so, subject to |
| 16 ** the following conditions: |
| 17 ** |
| 18 ** The above copyright notice and this permission notice shall be included |
| 19 ** in all copies or substantial portions of the Materials. |
| 20 ** |
| 21 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 22 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 23 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 24 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 25 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 26 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 27 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 28 */ |
| 29 |
| 30 --> |
| 31 <link rel="stylesheet" type="text/css" href="../unit.css" /> |
| 32 <script type="application/x-javascript" src="../unit.js"></script> |
| 33 <script type="application/x-javascript" src="../util.js"></script> |
| 34 <script type="application/x-javascript" src="quickCheckAPI.js"></script> |
| 35 |
| 36 <script type="application/x-javascript"> |
| 37 |
| 38 // Test that all GL functions specified in ArgGenerators fail |
| 39 // when called with randomly generated invalid arguments |
| 40 // Works only on tests with checkArgValidity defined |
| 41 Tests.testInvalidArgs = function() { |
| 42 var randomTestCount = 100; |
| 43 for (var name in ArgGenerators) { |
| 44 try { |
| 45 if (!GL[name]) |
| 46 throw (new Error(name + " is missing from the WebGL context")); |
| 47 var argGen = ArgGenerators[name]; |
| 48 var alreadyTriedArgs = {}; |
| 49 if (!argGen.generate || !argGen.checkArgValidity) continue; |
| 50 // test each GL function with randomTestCount randomly generated valid arg
s |
| 51 argGeneratorTestRunner(argGen, function(args, gen, setupVars) { |
| 52 var mutatedArgs; |
| 53 var foundArgs = false; |
| 54 for (var j=0; j<100; j++) { |
| 55 mutatedArgs = mutateArgs(args); |
| 56 var validArgs = false; |
| 57 try { |
| 58 validArgs = gen.checkArgValidity.apply(gen, mutatedArgs); |
| 59 } catch(e) {} |
| 60 if (!validArgs) { |
| 61 if (gen.noAlreadyTriedCheck) { |
| 62 foundArgs = true; |
| 63 break; // found new invalid args |
| 64 } |
| 65 var src = Object.toSource(mutatedArgs); |
| 66 if (!alreadyTriedArgs[src]) { |
| 67 alreadyTriedArgs[src] = true; |
| 68 foundArgs = true; |
| 69 break; // found new invalid args |
| 70 } |
| 71 } |
| 72 } |
| 73 if (!foundArgs) |
| 74 return true; |
| 75 var ok = false; |
| 76 var rv; |
| 77 // assert that GL function fails when called with invalid args |
| 78 assertFail("This should fail: "+name+"("+argsToString(mutatedArgs)+")", |
| 79 function(){ |
| 80 GL.getError(); // clear off existing error |
| 81 rv = GL[name].apply(GL, mutatedArgs); |
| 82 throwError(GL, name); |
| 83 ok = true; |
| 84 }); |
| 85 // if we need to cleanup the return value, do it here |
| 86 // e.g. calling gl.deleteBuffer(rv) after testing gl.createBuffer() abov
e |
| 87 if (gen.returnValueCleanup && rv != null) { |
| 88 assertOk("Cleaning up return value after "+name+"("+argsToString(mutat
edArgs)+")", |
| 89 function() { gen.returnValueCleanup(rv); }); |
| 90 } |
| 91 GL.getError(); |
| 92 return !ok; |
| 93 }, argGen.testCount || randomTestCount); |
| 94 } catch(e) { |
| 95 testFailed(name, e.name, formatError(e)); |
| 96 } |
| 97 } |
| 98 } |
| 99 |
| 100 </script> |
| 101 <style>canvas{position:absolute;}</style> |
| 102 </head><body> |
| 103 </body></html> |
OLD | NEW |