OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <title>texImage2D and texSubImage2D tests with invalid data</title> |
| 6 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 7 <script src="../../resources/js-test-pre.js"></script> |
| 8 <script src="../resources/webgl-test.js"></script> |
| 9 </head> |
| 10 <body> |
| 11 <div id="description"></div> |
| 12 <div id="console"></div> |
| 13 <canvas id="canvas" width="2" height="2"> </canvas> |
| 14 <script type="text/javascript"> |
| 15 description("texImage2D and texSubImage2D tests with invalid data"); |
| 16 |
| 17 var canvas = document.getElementById("canvas"); |
| 18 var gl = create3DContext(canvas); |
| 19 if (!gl) |
| 20 testFailed("Context created."); |
| 21 else |
| 22 testPassed("Context created."); |
| 23 |
| 24 var tex; |
| 25 |
| 26 function setup() { |
| 27 tex = gl.createTexture(); |
| 28 gl.bindTexture(gl.TEXTURE_2D, bug32619_tests.tex); |
| 29 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYT
E, null); |
| 30 } |
| 31 |
| 32 function teardown() { |
| 33 gl.deleteTexture(tex); |
| 34 } |
| 35 |
| 36 function test(desc, func, expected) { |
| 37 debug(desc); |
| 38 |
| 39 var exc = null; |
| 40 try { |
| 41 func(); |
| 42 } catch (x) { |
| 43 exc = x; |
| 44 } |
| 45 |
| 46 if (expected == gl.INVALID_OPERATION) { |
| 47 glErrorShouldBe(gl, expected); |
| 48 } else if (expected == "exception") { |
| 49 if (exc) { |
| 50 testPassed("threw exception"); |
| 51 } else { |
| 52 testFailed("did not throw exception"); |
| 53 } |
| 54 } |
| 55 } |
| 56 |
| 57 test("Passing a buffer not large enough to texImage2D should generate an INVALID
_OPERATION", |
| 58 function () { |
| 59 var tooSmall = new Uint8Array(64); |
| 60 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNE
D_BYTE, tooSmall); |
| 61 }, |
| 62 gl.INVALID_OPERATION); |
| 63 |
| 64 test("Passing texImage2D parameter data of Number type should throw an exception
", |
| 65 function () { |
| 66 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_B
YTE, 42); |
| 67 }, |
| 68 "exception"); |
| 69 |
| 70 test("Passing texImage2D parameter data of String type should throw a TypeError"
, |
| 71 function () { |
| 72 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_B
YTE, "not a buffer"); |
| 73 }, |
| 74 "exception"); |
| 75 test("Passing a buffer not large enough to texSubImage2D should generate an INVA
LID_OPERATION", |
| 76 function () { |
| 77 var tooSmall = new Uint8Array(64); |
| 78 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_B
YTE, tooSmall); |
| 79 }, |
| 80 gl.INVALID_OPERATION); |
| 81 |
| 82 test("Passing texSubImage2D parameter data of Number type should throw a TypeErr
or", |
| 83 function () { |
| 84 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_B
YTE, 42); |
| 85 }, |
| 86 "exception"); |
| 87 |
| 88 test("Passing texSubImage2D parameter data of String type should throw a TypeErr
or", |
| 89 function () { |
| 90 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE
, "not a buffer"); |
| 91 }, |
| 92 "exception"); |
| 93 |
| 94 debug(""); |
| 95 successfullyParsed = true; |
| 96 </script> |
| 97 <script src="../../resources/js-test-post.js"></script> |
| 98 |
| 99 </body> |
| 100 </html> |
| 101 |
OLD | NEW |