michael@0: import WebIDL michael@0: michael@0: def WebIDLTest(parser, harness): michael@0: testData = [("::TestAttr%s::b", "b", "Byte%s", False), michael@0: ("::TestAttr%s::rb", "rb", "Byte%s", True), michael@0: ("::TestAttr%s::o", "o", "Octet%s", False), michael@0: ("::TestAttr%s::ro", "ro", "Octet%s", True), michael@0: ("::TestAttr%s::s", "s", "Short%s", False), michael@0: ("::TestAttr%s::rs", "rs", "Short%s", True), michael@0: ("::TestAttr%s::us", "us", "UnsignedShort%s", False), michael@0: ("::TestAttr%s::rus", "rus", "UnsignedShort%s", True), michael@0: ("::TestAttr%s::l", "l", "Long%s", False), michael@0: ("::TestAttr%s::rl", "rl", "Long%s", True), michael@0: ("::TestAttr%s::ul", "ul", "UnsignedLong%s", False), michael@0: ("::TestAttr%s::rul", "rul", "UnsignedLong%s", True), michael@0: ("::TestAttr%s::ll", "ll", "LongLong%s", False), michael@0: ("::TestAttr%s::rll", "rll", "LongLong%s", True), michael@0: ("::TestAttr%s::ull", "ull", "UnsignedLongLong%s", False), michael@0: ("::TestAttr%s::rull", "rull", "UnsignedLongLong%s", True), michael@0: ("::TestAttr%s::str", "str", "String%s", False), michael@0: ("::TestAttr%s::rstr", "rstr", "String%s", True), michael@0: ("::TestAttr%s::obj", "obj", "Object%s", False), michael@0: ("::TestAttr%s::robj", "robj", "Object%s", True), michael@0: ("::TestAttr%s::object", "object", "Object%s", False), michael@0: ("::TestAttr%s::f", "f", "Float%s", False), michael@0: ("::TestAttr%s::rf", "rf", "Float%s", True)] michael@0: michael@0: parser.parse(""" michael@0: interface TestAttr { michael@0: attribute byte b; michael@0: readonly attribute byte rb; michael@0: attribute octet o; michael@0: readonly attribute octet ro; michael@0: attribute short s; michael@0: readonly attribute short rs; michael@0: attribute unsigned short us; michael@0: readonly attribute unsigned short rus; michael@0: attribute long l; michael@0: readonly attribute long rl; michael@0: attribute unsigned long ul; michael@0: readonly attribute unsigned long rul; michael@0: attribute long long ll; michael@0: readonly attribute long long rll; michael@0: attribute unsigned long long ull; michael@0: readonly attribute unsigned long long rull; michael@0: attribute DOMString str; michael@0: readonly attribute DOMString rstr; michael@0: attribute object obj; michael@0: readonly attribute object robj; michael@0: attribute object _object; michael@0: attribute float f; michael@0: readonly attribute float rf; michael@0: }; michael@0: michael@0: interface TestAttrNullable { michael@0: attribute byte? b; michael@0: readonly attribute byte? rb; michael@0: attribute octet? o; michael@0: readonly attribute octet? ro; michael@0: attribute short? s; michael@0: readonly attribute short? rs; michael@0: attribute unsigned short? us; michael@0: readonly attribute unsigned short? rus; michael@0: attribute long? l; michael@0: readonly attribute long? rl; michael@0: attribute unsigned long? ul; michael@0: readonly attribute unsigned long? rul; michael@0: attribute long long? ll; michael@0: readonly attribute long long? rll; michael@0: attribute unsigned long long? ull; michael@0: readonly attribute unsigned long long? rull; michael@0: attribute DOMString? str; michael@0: readonly attribute DOMString? rstr; michael@0: attribute object? obj; michael@0: readonly attribute object? robj; michael@0: attribute object? _object; michael@0: attribute float? f; michael@0: readonly attribute float? rf; michael@0: }; michael@0: michael@0: interface TestAttrArray { michael@0: attribute byte[] b; michael@0: readonly attribute byte[] rb; michael@0: attribute octet[] o; michael@0: readonly attribute octet[] ro; michael@0: attribute short[] s; michael@0: readonly attribute short[] rs; michael@0: attribute unsigned short[] us; michael@0: readonly attribute unsigned short[] rus; michael@0: attribute long[] l; michael@0: readonly attribute long[] rl; michael@0: attribute unsigned long[] ul; michael@0: readonly attribute unsigned long[] rul; michael@0: attribute long long[] ll; michael@0: readonly attribute long long[] rll; michael@0: attribute unsigned long long[] ull; michael@0: readonly attribute unsigned long long[] rull; michael@0: attribute DOMString[] str; michael@0: readonly attribute DOMString[] rstr; michael@0: attribute object[] obj; michael@0: readonly attribute object[] robj; michael@0: attribute object[] _object; michael@0: attribute float[] f; michael@0: readonly attribute float[] rf; michael@0: }; michael@0: michael@0: interface TestAttrNullableArray { michael@0: attribute byte[]? b; michael@0: readonly attribute byte[]? rb; michael@0: attribute octet[]? o; michael@0: readonly attribute octet[]? ro; michael@0: attribute short[]? s; michael@0: readonly attribute short[]? rs; michael@0: attribute unsigned short[]? us; michael@0: readonly attribute unsigned short[]? rus; michael@0: attribute long[]? l; michael@0: readonly attribute long[]? rl; michael@0: attribute unsigned long[]? ul; michael@0: readonly attribute unsigned long[]? rul; michael@0: attribute long long[]? ll; michael@0: readonly attribute long long[]? rll; michael@0: attribute unsigned long long[]? ull; michael@0: readonly attribute unsigned long long[]? rull; michael@0: attribute DOMString[]? str; michael@0: readonly attribute DOMString[]? rstr; michael@0: attribute object[]? obj; michael@0: readonly attribute object[]? robj; michael@0: attribute object[]? _object; michael@0: attribute float[]? f; michael@0: readonly attribute float[]? rf; michael@0: }; michael@0: michael@0: interface TestAttrArrayOfNullableTypes { michael@0: attribute byte?[] b; michael@0: readonly attribute byte?[] rb; michael@0: attribute octet?[] o; michael@0: readonly attribute octet?[] ro; michael@0: attribute short?[] s; michael@0: readonly attribute short?[] rs; michael@0: attribute unsigned short?[] us; michael@0: readonly attribute unsigned short?[] rus; michael@0: attribute long?[] l; michael@0: readonly attribute long?[] rl; michael@0: attribute unsigned long?[] ul; michael@0: readonly attribute unsigned long?[] rul; michael@0: attribute long long?[] ll; michael@0: readonly attribute long long?[] rll; michael@0: attribute unsigned long long?[] ull; michael@0: readonly attribute unsigned long long?[] rull; michael@0: attribute DOMString?[] str; michael@0: readonly attribute DOMString?[] rstr; michael@0: attribute object?[] obj; michael@0: readonly attribute object?[] robj; michael@0: attribute object?[] _object; michael@0: attribute float?[] f; michael@0: readonly attribute float?[] rf; michael@0: }; michael@0: michael@0: interface TestAttrNullableArrayOfNullableTypes { michael@0: attribute byte?[]? b; michael@0: readonly attribute byte?[]? rb; michael@0: attribute octet?[]? o; michael@0: readonly attribute octet?[]? ro; michael@0: attribute short?[]? s; michael@0: readonly attribute short?[]? rs; michael@0: attribute unsigned short?[]? us; michael@0: readonly attribute unsigned short?[]? rus; michael@0: attribute long?[]? l; michael@0: readonly attribute long?[]? rl; michael@0: attribute unsigned long?[]? ul; michael@0: readonly attribute unsigned long?[]? rul; michael@0: attribute long long?[]? ll; michael@0: readonly attribute long long?[]? rll; michael@0: attribute unsigned long long?[]? ull; michael@0: readonly attribute unsigned long long?[]? rull; michael@0: attribute DOMString?[]? str; michael@0: readonly attribute DOMString?[]? rstr; michael@0: attribute object?[]? obj; michael@0: readonly attribute object?[]? robj; michael@0: attribute object?[]? _object; michael@0: attribute float?[]? f; michael@0: readonly attribute float?[]? rf; michael@0: }; michael@0: """) michael@0: michael@0: results = parser.finish() michael@0: michael@0: def checkAttr(attr, QName, name, type, readonly): michael@0: harness.ok(isinstance(attr, WebIDL.IDLAttribute), michael@0: "Should be an IDLAttribute") michael@0: harness.ok(attr.isAttr(), "Attr is an Attr") michael@0: harness.ok(not attr.isMethod(), "Attr is not an method") michael@0: harness.ok(not attr.isConst(), "Attr is not a const") michael@0: harness.check(attr.identifier.QName(), QName, "Attr has the right QName") michael@0: harness.check(attr.identifier.name, name, "Attr has the right name") michael@0: harness.check(str(attr.type), type, "Attr has the right type") michael@0: harness.check(attr.readonly, readonly, "Attr's readonly state is correct") michael@0: michael@0: harness.ok(True, "TestAttr interface parsed without error.") michael@0: harness.check(len(results), 6, "Should be six productions.") michael@0: iface = results[0] michael@0: harness.ok(isinstance(iface, WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: harness.check(iface.identifier.QName(), "::TestAttr", "Interface has the right QName") michael@0: harness.check(iface.identifier.name, "TestAttr", "Interface has the right name") michael@0: harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData)) michael@0: michael@0: attrs = iface.members michael@0: michael@0: for i in range(len(attrs)): michael@0: data = testData[i] michael@0: attr = attrs[i] michael@0: (QName, name, type, readonly) = data michael@0: checkAttr(attr, QName % "", name, type % "", readonly) michael@0: michael@0: iface = results[1] michael@0: harness.ok(isinstance(iface, WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: harness.check(iface.identifier.QName(), "::TestAttrNullable", "Interface has the right QName") michael@0: harness.check(iface.identifier.name, "TestAttrNullable", "Interface has the right name") michael@0: harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData)) michael@0: michael@0: attrs = iface.members michael@0: michael@0: for i in range(len(attrs)): michael@0: data = testData[i] michael@0: attr = attrs[i] michael@0: (QName, name, type, readonly) = data michael@0: checkAttr(attr, QName % "Nullable", name, type % "OrNull", readonly) michael@0: michael@0: iface = results[2] michael@0: harness.ok(isinstance(iface, WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: harness.check(iface.identifier.QName(), "::TestAttrArray", "Interface has the right QName") michael@0: harness.check(iface.identifier.name, "TestAttrArray", "Interface has the right name") michael@0: harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData)) michael@0: michael@0: attrs = iface.members michael@0: michael@0: for i in range(len(attrs)): michael@0: data = testData[i] michael@0: attr = attrs[i] michael@0: (QName, name, type, readonly) = data michael@0: checkAttr(attr, QName % "Array", name, type % "Array", readonly) michael@0: michael@0: iface = results[3] michael@0: harness.ok(isinstance(iface, WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: harness.check(iface.identifier.QName(), "::TestAttrNullableArray", "Interface has the right QName") michael@0: harness.check(iface.identifier.name, "TestAttrNullableArray", "Interface has the right name") michael@0: harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData)) michael@0: michael@0: attrs = iface.members michael@0: michael@0: for i in range(len(attrs)): michael@0: data = testData[i] michael@0: attr = attrs[i] michael@0: (QName, name, type, readonly) = data michael@0: checkAttr(attr, QName % "NullableArray", name, type % "ArrayOrNull", readonly) michael@0: michael@0: iface = results[4] michael@0: harness.ok(isinstance(iface, WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: harness.check(iface.identifier.QName(), "::TestAttrArrayOfNullableTypes", "Interface has the right QName") michael@0: harness.check(iface.identifier.name, "TestAttrArrayOfNullableTypes", "Interface has the right name") michael@0: harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData)) michael@0: michael@0: attrs = iface.members michael@0: michael@0: for i in range(len(attrs)): michael@0: data = testData[i] michael@0: attr = attrs[i] michael@0: (QName, name, type, readonly) = data michael@0: checkAttr(attr, QName % "ArrayOfNullableTypes", name, type % "OrNullArray", readonly) michael@0: michael@0: iface = results[5] michael@0: harness.ok(isinstance(iface, WebIDL.IDLInterface), michael@0: "Should be an IDLInterface") michael@0: harness.check(iface.identifier.QName(), "::TestAttrNullableArrayOfNullableTypes", "Interface has the right QName") michael@0: harness.check(iface.identifier.name, "TestAttrNullableArrayOfNullableTypes", "Interface has the right name") michael@0: harness.check(len(iface.members), len(testData), "Expect %s members" % len(testData)) michael@0: michael@0: attrs = iface.members michael@0: michael@0: for i in range(len(attrs)): michael@0: data = testData[i] michael@0: attr = attrs[i] michael@0: (QName, name, type, readonly) = data michael@0: checkAttr(attr, QName % "NullableArrayOfNullableTypes", name, type % "OrNullArrayOrNull", readonly) michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface A { michael@0: [SetterThrows] readonly attribute boolean foo; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except Exception, x: michael@0: threw = True michael@0: harness.ok(threw, "Should not allow [SetterThrows] on readonly attributes") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface A { michael@0: [Throw] readonly attribute boolean foo; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except Exception, x: michael@0: threw = True michael@0: harness.ok(threw, "Should spell [Throws] correctly") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface A { michael@0: [SameObject] readonly attribute boolean foo; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except Exception, x: michael@0: threw = True michael@0: harness.ok(threw, "Should not allow [SameObject] on attributes not of interface type") michael@0: michael@0: parser = parser.reset() michael@0: threw = False michael@0: try: michael@0: parser.parse(""" michael@0: interface A { michael@0: [SameObject] readonly attribute A foo; michael@0: }; michael@0: """) michael@0: results = parser.finish() michael@0: except Exception, x: michael@0: threw = True michael@0: harness.ok(not threw, "Should allow [SameObject] on attributes of interface type")