test_arraybuffer.py (4420B)
1 import WebIDL 2 3 4 def WebIDLTest(parser, harness): 5 parser.parse( 6 """ 7 interface TestArrayBuffer { 8 attribute ArrayBuffer bufferAttr; 9 undefined bufferMethod(ArrayBuffer arg1, ArrayBuffer? arg2, sequence<ArrayBuffer> arg3); 10 11 attribute ArrayBufferView viewAttr; 12 undefined viewMethod(ArrayBufferView arg1, ArrayBufferView? arg2, sequence<ArrayBufferView> arg3); 13 14 attribute Int8Array int8ArrayAttr; 15 undefined int8ArrayMethod(Int8Array arg1, Int8Array? arg2, sequence<Int8Array> arg3); 16 17 attribute Uint8Array uint8ArrayAttr; 18 undefined uint8ArrayMethod(Uint8Array arg1, Uint8Array? arg2, sequence<Uint8Array> arg3); 19 20 attribute Uint8ClampedArray uint8ClampedArrayAttr; 21 undefined uint8ClampedArrayMethod(Uint8ClampedArray arg1, Uint8ClampedArray? arg2, sequence<Uint8ClampedArray> arg3); 22 23 attribute Int16Array int16ArrayAttr; 24 undefined int16ArrayMethod(Int16Array arg1, Int16Array? arg2, sequence<Int16Array> arg3); 25 26 attribute Uint16Array uint16ArrayAttr; 27 undefined uint16ArrayMethod(Uint16Array arg1, Uint16Array? arg2, sequence<Uint16Array> arg3); 28 29 attribute Int32Array int32ArrayAttr; 30 undefined int32ArrayMethod(Int32Array arg1, Int32Array? arg2, sequence<Int32Array> arg3); 31 32 attribute Uint32Array uint32ArrayAttr; 33 undefined uint32ArrayMethod(Uint32Array arg1, Uint32Array? arg2, sequence<Uint32Array> arg3); 34 35 attribute Float32Array float32ArrayAttr; 36 undefined float32ArrayMethod(Float32Array arg1, Float32Array? arg2, sequence<Float32Array> arg3); 37 38 attribute Float64Array float64ArrayAttr; 39 undefined float64ArrayMethod(Float64Array arg1, Float64Array? arg2, sequence<Float64Array> arg3); 40 41 attribute BigInt64Array bigInt64ArrayAttr; 42 undefined BigInt64ArrayMethod(BigInt64Array arg1, BigInt64Array? arg2, sequence<BigInt64Array> arg3); 43 44 attribute BigUint64Array bigUint64ArrayAttr; 45 undefined BigUint64ArrayMethod(BigUint64Array arg1, BigUint64Array? arg2, sequence<BigUint64Array> arg3); 46 }; 47 """ 48 ) 49 50 results = parser.finish() 51 52 iface = results[0] 53 54 harness.ok(True, "TestArrayBuffer interface parsed without error") 55 harness.check(len(iface.members), 26, "Interface should have twenty two members") 56 57 members = iface.members 58 59 def checkStuff(attr, method, t): 60 harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Expect an IDLAttribute") 61 harness.ok(isinstance(method, WebIDL.IDLMethod), "Expect an IDLMethod") 62 63 harness.check(str(attr.type), t, "Expect an ArrayBuffer type") 64 harness.ok(attr.type.isSpiderMonkeyInterface(), "Should test as a js interface") 65 66 (retType, arguments) = method.signatures()[0] 67 harness.ok(retType.isUndefined(), "Should have an undefined return type") 68 harness.check(len(arguments), 3, "Expect 3 arguments") 69 70 harness.check(str(arguments[0].type), t, "Expect an ArrayBuffer type") 71 harness.ok( 72 arguments[0].type.isSpiderMonkeyInterface(), "Should test as a js interface" 73 ) 74 75 harness.check( 76 str(arguments[1].type), t + "OrNull", "Expect an ArrayBuffer type" 77 ) 78 harness.ok( 79 arguments[1].type.inner.isSpiderMonkeyInterface(), 80 "Should test as a js interface", 81 ) 82 83 harness.check( 84 str(arguments[2].type), t + "Sequence", "Expect an ArrayBuffer type" 85 ) 86 harness.ok( 87 arguments[2].type.inner.isSpiderMonkeyInterface(), 88 "Should test as a js interface", 89 ) 90 91 checkStuff(members[0], members[1], "ArrayBuffer") 92 checkStuff(members[2], members[3], "ArrayBufferView") 93 checkStuff(members[4], members[5], "Int8Array") 94 checkStuff(members[6], members[7], "Uint8Array") 95 checkStuff(members[8], members[9], "Uint8ClampedArray") 96 checkStuff(members[10], members[11], "Int16Array") 97 checkStuff(members[12], members[13], "Uint16Array") 98 checkStuff(members[14], members[15], "Int32Array") 99 checkStuff(members[16], members[17], "Uint32Array") 100 checkStuff(members[18], members[19], "Float32Array") 101 checkStuff(members[20], members[21], "Float64Array") 102 checkStuff(members[22], members[23], "BigInt64Array") 103 checkStuff(members[24], members[25], "BigUint64Array")