OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. |
| 5 ** |
| 6 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 7 ** copy of this software and/or associated documentation files (the |
| 8 ** "Materials"), to deal in the Materials without restriction, including |
| 9 ** without limitation the rights to use, copy, modify, merge, publish, |
| 10 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 11 ** permit persons to whom the Materials are furnished to do so, subject to |
| 12 ** the following conditions: |
| 13 ** |
| 14 ** The above copyright notice and this permission notice shall be included |
| 15 ** in all copies or substantial portions of the Materials. |
| 16 ** |
| 17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 */ |
| 25 |
| 26 --> |
| 27 <!DOCTYPE html> |
| 28 <html> |
| 29 <head> |
| 30 <meta charset="utf-8"> |
| 31 <title>texImage2D and texSubImage2D tests with invalid data</title> |
| 32 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 33 <script src="../../resources/js-test-pre.js"></script> |
| 34 <script src="../resources/webgl-test.js"></script> |
| 35 </head> |
| 36 <body> |
| 37 <div id="description"></div> |
| 38 <div id="console"></div> |
| 39 <canvas id="canvas" width="2" height="2"> </canvas> |
| 40 <script type="text/javascript"> |
| 41 description("texImage2D and texSubImage2D tests with invalid data"); |
| 42 |
| 43 var canvas = document.getElementById("canvas"); |
| 44 var gl = create3DContext(canvas); |
| 45 if (!gl) |
| 46 testFailed("Context created."); |
| 47 else |
| 48 testPassed("Context created."); |
| 49 |
| 50 var tex; |
| 51 |
| 52 function setup() { |
| 53 tex = gl.createTexture(); |
| 54 gl.bindTexture(gl.TEXTURE_2D, bug32619_tests.tex); |
| 55 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYT
E, null); |
| 56 } |
| 57 |
| 58 function teardown() { |
| 59 gl.deleteTexture(tex); |
| 60 } |
| 61 |
| 62 function test(desc, func, expected) { |
| 63 debug(desc); |
| 64 |
| 65 var exc = null; |
| 66 try { |
| 67 func(); |
| 68 } catch (x) { |
| 69 exc = x; |
| 70 } |
| 71 |
| 72 if (expected == gl.INVALID_OPERATION) { |
| 73 glErrorShouldBe(gl, expected); |
| 74 } else if (expected == "exception") { |
| 75 if (exc) { |
| 76 testPassed("threw exception"); |
| 77 } else { |
| 78 testFailed("did not throw exception"); |
| 79 } |
| 80 } |
| 81 } |
| 82 |
| 83 test("Passing a buffer not large enough to texImage2D should generate an INVALID
_OPERATION", |
| 84 function () { |
| 85 var tooSmall = new Uint8Array(64); |
| 86 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED
_BYTE, tooSmall); |
| 87 }, |
| 88 gl.INVALID_OPERATION); |
| 89 |
| 90 test("Passing texImage2D parameter data of Number type should throw an exception
", |
| 91 function () { |
| 92 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED
_BYTE, 42); |
| 93 }, |
| 94 "exception"); |
| 95 |
| 96 test("Passing texImage2D parameter data of String type should throw a TypeError"
, |
| 97 function () { |
| 98 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED
_BYTE, "not a buffer"); |
| 99 }, |
| 100 "exception"); |
| 101 test("Passing a buffer not large enough to texSubImage2D should generate an INVA
LID_OPERATION", |
| 102 function () { |
| 103 var tooSmall = new Uint8Array(64); |
| 104 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BY
TE, tooSmall); |
| 105 }, |
| 106 gl.INVALID_OPERATION); |
| 107 |
| 108 test("Passing texSubImage2D parameter data of Number type should throw a TypeErr
or", |
| 109 function () { |
| 110 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BY
TE, 42); |
| 111 }, |
| 112 "exception"); |
| 113 |
| 114 test("Passing texSubImage2D parameter data of String type should throw a TypeErr
or", |
| 115 function () { |
| 116 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BY
TE, "not a buffer"); |
| 117 }, |
| 118 "exception"); |
| 119 |
| 120 debug(""); |
| 121 successfullyParsed = true; |
| 122 </script> |
| 123 <script src="../../resources/js-test-post.js"></script> |
| 124 |
| 125 </body> |
| 126 </html> |
| 127 |
OLD | NEW |