content/canvas/test/webgl-conformance/conformance/textures/tex-image-with-invalid-data.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/test/webgl-conformance/conformance/textures/tex-image-with-invalid-data.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<head>
     1.7 +<meta charset="utf-8">
     1.8 +    <title>texImage2D and texSubImage2D tests with invalid data</title>
     1.9 +  <link rel="stylesheet" href="../../resources/js-test-style.css"/>
    1.10 +  <script src="../../resources/js-test-pre.js"></script>
    1.11 +  <script src="../resources/webgl-test.js"></script>
    1.12 +</head>
    1.13 +<body>
    1.14 +<div id="description"></div>
    1.15 +<div id="console"></div>
    1.16 +<canvas id="canvas" width="2" height="2"> </canvas>
    1.17 +<script type="text/javascript">
    1.18 +description("texImage2D and texSubImage2D tests with invalid data");
    1.19 +
    1.20 +var canvas = document.getElementById("canvas");
    1.21 +var gl = create3DContext(canvas);
    1.22 +if (!gl)
    1.23 +  testFailed("Context created.");
    1.24 +else
    1.25 +  testPassed("Context created.");
    1.26 +
    1.27 +var tex;
    1.28 +
    1.29 +function setup() {
    1.30 +    tex = gl.createTexture();
    1.31 +    gl.bindTexture(gl.TEXTURE_2D, bug32619_tests.tex);
    1.32 +    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    1.33 +}
    1.34 +
    1.35 +function teardown() {
    1.36 +    gl.deleteTexture(tex);
    1.37 +}
    1.38 +
    1.39 +function test(desc, func, expected) {
    1.40 +    debug(desc);
    1.41 +
    1.42 +    var exc = null;
    1.43 +    try {
    1.44 +	func();
    1.45 +    } catch (x) {
    1.46 +	exc = x;
    1.47 +    }
    1.48 +
    1.49 +    if (expected == gl.INVALID_OPERATION) {
    1.50 +	glErrorShouldBe(gl, expected);
    1.51 +    } else if (expected == "exception") {
    1.52 +        if (exc) {
    1.53 +	    testPassed("threw exception");
    1.54 +	} else {
    1.55 +	    testFailed("did not throw exception");
    1.56 +	}
    1.57 +    }
    1.58 +}
    1.59 +
    1.60 +test("Passing a buffer not large enough to texImage2D should generate an INVALID_OPERATION",
    1.61 +     function () {
    1.62 +	 var tooSmall = new Uint8Array(64);
    1.63 +	 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
    1.64 +     },
    1.65 +     gl.INVALID_OPERATION);
    1.66 +
    1.67 +test("Passing texImage2D parameter data of Number type should throw an exception",
    1.68 +     function () {
    1.69 +      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, 42);
    1.70 +     },
    1.71 +     "exception");
    1.72 +
    1.73 +test("Passing texImage2D parameter data of String type should throw a TypeError",
    1.74 +     function () {
    1.75 +      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 64, 64, 0, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
    1.76 +     },
    1.77 +     "exception");
    1.78 +test("Passing a buffer not large enough to texSubImage2D should generate an INVALID_OPERATION",
    1.79 +     function () {
    1.80 +	 var tooSmall = new Uint8Array(64);
    1.81 +	 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
    1.82 +     },
    1.83 +     gl.INVALID_OPERATION);
    1.84 +
    1.85 +test("Passing texSubImage2D parameter data of Number type should throw a TypeError",
    1.86 +     function () {
    1.87 +	 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, 42);
    1.88 +     },
    1.89 +     "exception");
    1.90 +
    1.91 +test("Passing texSubImage2D parameter data of String type should throw a TypeError",
    1.92 +     function () {
    1.93 +      gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 64, 64, gl.RGBA, gl.UNSIGNED_BYTE, "not a buffer");
    1.94 +     },
    1.95 +     "exception");
    1.96 +
    1.97 +debug("");
    1.98 +successfullyParsed = true;
    1.99 +</script>
   1.100 +<script>finishTest();</script>
   1.101 +
   1.102 +</body>
   1.103 +</html>
   1.104 +

mercurial