4 def WebIDLTest(parser
, harness
):
6 ("::TestAttr%s::b", "b", "Byte%s", False),
7 ("::TestAttr%s::rb", "rb", "Byte%s", True),
8 ("::TestAttr%s::o", "o", "Octet%s", False),
9 ("::TestAttr%s::ro", "ro", "Octet%s", True),
10 ("::TestAttr%s::s", "s", "Short%s", False),
11 ("::TestAttr%s::rs", "rs", "Short%s", True),
12 ("::TestAttr%s::us", "us", "UnsignedShort%s", False),
13 ("::TestAttr%s::rus", "rus", "UnsignedShort%s", True),
14 ("::TestAttr%s::l", "l", "Long%s", False),
15 ("::TestAttr%s::rl", "rl", "Long%s", True),
16 ("::TestAttr%s::ul", "ul", "UnsignedLong%s", False),
17 ("::TestAttr%s::rul", "rul", "UnsignedLong%s", True),
18 ("::TestAttr%s::ll", "ll", "LongLong%s", False),
19 ("::TestAttr%s::rll", "rll", "LongLong%s", True),
20 ("::TestAttr%s::ull", "ull", "UnsignedLongLong%s", False),
21 ("::TestAttr%s::rull", "rull", "UnsignedLongLong%s", True),
22 ("::TestAttr%s::str", "str", "String%s", False),
23 ("::TestAttr%s::rstr", "rstr", "String%s", True),
24 ("::TestAttr%s::obj", "obj", "Object%s", False),
25 ("::TestAttr%s::robj", "robj", "Object%s", True),
26 ("::TestAttr%s::object", "object", "Object%s", False),
27 ("::TestAttr%s::f", "f", "Float%s", False),
28 ("::TestAttr%s::rf", "rf", "Float%s", True),
35 readonly attribute byte rb;
37 readonly attribute octet ro;
39 readonly attribute short rs;
40 attribute unsigned short us;
41 readonly attribute unsigned short rus;
43 readonly attribute long rl;
44 attribute unsigned long ul;
45 readonly attribute unsigned long rul;
46 attribute long long ll;
47 readonly attribute long long rll;
48 attribute unsigned long long ull;
49 readonly attribute unsigned long long rull;
50 attribute DOMString str;
51 readonly attribute DOMString rstr;
53 readonly attribute object robj;
54 attribute object _object;
56 readonly attribute float rf;
59 interface TestAttrNullable {
61 readonly attribute byte? rb;
63 readonly attribute octet? ro;
65 readonly attribute short? rs;
66 attribute unsigned short? us;
67 readonly attribute unsigned short? rus;
69 readonly attribute long? rl;
70 attribute unsigned long? ul;
71 readonly attribute unsigned long? rul;
72 attribute long long? ll;
73 readonly attribute long long? rll;
74 attribute unsigned long long? ull;
75 readonly attribute unsigned long long? rull;
76 attribute DOMString? str;
77 readonly attribute DOMString? rstr;
78 attribute object? obj;
79 readonly attribute object? robj;
80 attribute object? _object;
82 readonly attribute float? rf;
87 results
= parser
.finish()
89 def checkAttr(attr
, QName
, name
, type, readonly
):
90 harness
.ok(isinstance(attr
, WebIDL
.IDLAttribute
), "Should be an IDLAttribute")
91 harness
.ok(attr
.isAttr(), "Attr is an Attr")
92 harness
.ok(not attr
.isMethod(), "Attr is not an method")
93 harness
.ok(not attr
.isConst(), "Attr is not a const")
94 harness
.check(attr
.identifier
.QName(), QName
, "Attr has the right QName")
95 harness
.check(attr
.identifier
.name
, name
, "Attr has the right name")
96 harness
.check(str(attr
.type), type, "Attr has the right type")
97 harness
.check(attr
.readonly
, readonly
, "Attr's readonly state is correct")
99 harness
.ok(True, "TestAttr interface parsed without error.")
100 harness
.check(len(results
), 2, "Should be two productions.")
102 harness
.ok(isinstance(iface
, WebIDL
.IDLInterface
), "Should be an IDLInterface")
104 iface
.identifier
.QName(), "::TestAttr", "Interface has the right QName"
106 harness
.check(iface
.identifier
.name
, "TestAttr", "Interface has the right name")
108 len(iface
.members
), len(testData
), "Expect %s members" % len(testData
)
111 attrs
= iface
.members
113 for i
in range(len(attrs
)):
116 (QName
, name
, type, readonly
) = data
117 checkAttr(attr
, QName
% "", name
, type % "", readonly
)
120 harness
.ok(isinstance(iface
, WebIDL
.IDLInterface
), "Should be an IDLInterface")
122 iface
.identifier
.QName(), "::TestAttrNullable", "Interface has the right QName"
125 iface
.identifier
.name
, "TestAttrNullable", "Interface has the right name"
128 len(iface
.members
), len(testData
), "Expect %s members" % len(testData
)
131 attrs
= iface
.members
133 for i
in range(len(attrs
)):
136 (QName
, name
, type, readonly
) = data
137 checkAttr(attr
, QName
% "Nullable", name
, type % "OrNull", readonly
)
139 parser
= parser
.reset()
145 [SetterThrows] readonly attribute boolean foo;
149 results
= parser
.finish()
150 except WebIDL
.WebIDLError
:
152 harness
.ok(threw
, "Should not allow [SetterThrows] on readonly attributes")
154 parser
= parser
.reset()
160 [Throw] readonly attribute boolean foo;
164 results
= parser
.finish()
165 except WebIDL
.WebIDLError
:
167 harness
.ok(threw
, "Should spell [Throws] correctly")
169 parser
= parser
.reset()
175 [SameObject] readonly attribute boolean foo;
179 results
= parser
.finish()
180 except WebIDL
.WebIDLError
:
183 threw
, "Should not allow [SameObject] on attributes not of interface type"
186 parser
= parser
.reset()
192 [SameObject] readonly attribute A foo;
196 results
= parser
.finish()
197 except WebIDL
.WebIDLError
:
199 harness
.ok(not threw
, "Should allow [SameObject] on attributes of interface type")