| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../../../resources/js-test.js"></script> | |
| 4 <script src="resources/webgl-test.js"></script> | |
| 5 </head> | |
| 6 <body> | |
| 7 <div id="description"></div> | |
| 8 <div id="console"></div> | |
| 9 | |
| 10 <script> | |
| 11 | |
| 12 description("Verifies that out-of-range parameters for creation, slicing and set
ting of WebGL arrays are caught"); | |
| 13 | |
| 14 function testConstructionWithNullBuffer(type, name) { | |
| 15 var array; | |
| 16 try { | |
| 17 array = new type(null, 0, 0); | |
| 18 testPassed("Construction of " + name + " with null buffer should not thr
ow exception"); | |
| 19 } catch (e) { | |
| 20 testFailed("Construction of " + name + " with null buffer threw exceptio
n"); | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 | |
| 25 function testConstructionWithOutOfRangeValues(type, name) { | |
| 26 var buffer = new ArrayBuffer(4); | |
| 27 var array; | |
| 28 try { | |
| 29 array = new type(buffer, 4, 0x3FFFFFFF); | |
| 30 testFailed("Construction of " + name + " with out-of-range values should
throw exception"); | |
| 31 } catch (e) { | |
| 32 testPassed("Construction of " + name + " with out-of-range values threw
exception"); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 function testConstructionWithNegativeOutOfRangeValues(type, name) { | |
| 37 var buffer = new ArrayBuffer(4); | |
| 38 var array; | |
| 39 try { | |
| 40 array = new type(buffer, 4, -2147483648); | |
| 41 testFailed("Construction of " + name + " with negative out-of-range valu
es should throw exception"); | |
| 42 } catch (e) { | |
| 43 testPassed("Construction of " + name + " with negative out-of-range valu
es threw exception"); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 // These need to be global for shouldBe to see them | |
| 48 var array; | |
| 49 var typeSize; | |
| 50 | |
| 51 function testSubarrayWithOutOfRangeValues(type, name, sz) { | |
| 52 debug("Testing subarray of " + name); | |
| 53 try { | |
| 54 var buffer = new ArrayBuffer(32); | |
| 55 array = new type(buffer); | |
| 56 typeSize = sz; | |
| 57 shouldBe("array.length", "32 / typeSize"); | |
| 58 try { | |
| 59 shouldBe("array.subarray(4, 0x3FFFFFFF).length", "(32 / typeSize) -
4"); | |
| 60 shouldBe("array.subarray(4, -2147483648).length", "0"); | |
| 61 } catch (e) { | |
| 62 testFailed("Subarray of " + name + " threw exception"); | |
| 63 } | |
| 64 } catch (e) { | |
| 65 testFailed("Exception: " + e); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 function testSettingFromArrayWithOutOfRangeOffset(type, name) { | |
| 70 var webglArray = new type(32); | |
| 71 var array = []; | |
| 72 for (var i = 0; i < 16; i++) { | |
| 73 array.push(i); | |
| 74 } | |
| 75 try { | |
| 76 webglArray.set(array, 0x7FFFFFF8); | |
| 77 testFailed("Setting " + name + " from array with out-of-range offset was
not caught"); | |
| 78 } catch (e) { | |
| 79 testPassed("Setting " + name + " from array with out-of-range offset was
caught"); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 function testSettingFromFakeArrayWithOutOfRangeLength(type, name) { | |
| 84 var webglArray = new type(32); | |
| 85 var array = {}; | |
| 86 array.length = 0x80000000; | |
| 87 try { | |
| 88 webglArray.set(array, 8); | |
| 89 testFailed("Setting " + name + " from fake array with invalid length was
not caught"); | |
| 90 } catch (e) { | |
| 91 testPassed("Setting " + name + " from fake array with invalid length was
caught"); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 function testSettingFromWebGLArrayWithOutOfRangeOffset(type, name) { | |
| 96 var webglArray = new type(32); | |
| 97 var srcArray = new type(16); | |
| 98 for (var i = 0; i < 16; i++) { | |
| 99 srcArray[i] = i; | |
| 100 } | |
| 101 try { | |
| 102 webglArray.set(srcArray, 0x7FFFFFF8); | |
| 103 testFailed("Setting " + name + " from " + name + " with out-of-range off
set was not caught"); | |
| 104 } catch (e) { | |
| 105 testPassed("Setting " + name + " from " + name + " with out-of-range off
set was caught"); | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 var typeNames = [ "Int8Array", | |
| 110 "Uint8Array", | |
| 111 "Int16Array", | |
| 112 "Uint16Array", | |
| 113 "Int32Array", | |
| 114 "Uint32Array", | |
| 115 "Float32Array" ]; | |
| 116 | |
| 117 var typeSizes = [ 1, 1, 2, 2, 4, 4, 4 ]; | |
| 118 | |
| 119 for (var i = 0; i < typeNames.length; i++) { | |
| 120 var name = typeNames[i]; | |
| 121 var type = window[name]; | |
| 122 if (!type) { | |
| 123 testFailed("Could not find array type " + name); | |
| 124 } else { | |
| 125 testConstructionWithNullBuffer(type, name); | |
| 126 testConstructionWithOutOfRangeValues(type, name); | |
| 127 testConstructionWithNegativeOutOfRangeValues(type, name); | |
| 128 testSubarrayWithOutOfRangeValues(type, name, typeSizes[i]); | |
| 129 testSettingFromArrayWithOutOfRangeOffset(type, name); | |
| 130 testSettingFromFakeArrayWithOutOfRangeLength(type, name); | |
| 131 testSettingFromWebGLArrayWithOutOfRangeOffset(type, name); | |
| 132 } | |
| 133 } | |
| 134 | |
| 135 buffer = new ArrayBuffer(40); | |
| 136 ints = new Int32Array(buffer, 0, 10); | |
| 137 floats = new Float32Array(buffer, 0, 10); | |
| 138 // Plant a NaN into the buffer | |
| 139 ints[0]=-0x7ffff; | |
| 140 // Read the NaN out as a float | |
| 141 shouldBeTrue("isNaN(floats[0])"); | |
| 142 | |
| 143 </script> | |
| 144 | |
| 145 </body> | |
| 146 </html> | |
| OLD | NEW |