bug 677671 - Add unit tests for xpidl.py. r=khuey
authorTed Mielczarek <ted.mielczarek@gmail.com>
Wed, 17 Aug 2011 13:26:26 -0400
changeset 77293 20e301ec28a0569379c03f42bfeb375a2638a014
parent 77188 e136897709967e43e35ce4678db19a6204ee94ec
child 77294 844bfd249e6a42b860c7cbf2c48c41cf356ce928
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs677671
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 677671 - Add unit tests for xpidl.py. r=khuey
xpcom/Makefile.in
xpcom/idl-parser/runtests.py
--- a/xpcom/Makefile.in
+++ b/xpcom/Makefile.in
@@ -91,8 +91,13 @@ endif
 include $(topsrcdir)/config/rules.mk
 
 regenerate-idl-parser:
 	$(PYTHON_PATH) \
 	  -I$(topsrcdir)/other-licenses/ply \
 	  -I$(topsrcdir)/xpcom/idl-parser \
 	  $(topsrcdir)/xpcom/idl-parser/header.py --cachedir=$(topsrcdir)/xpcom/idl-parser --regen
 
+check::
+	$(PYTHON_PATH) \
+	  -I$(topsrcdir)/other-licenses/ply \
+	  -I$(topsrcdir)/xpcom/idl-parser \
+	  $(topsrcdir)/xpcom/idl-parser/runtests.py
new file mode 100644
--- /dev/null
+++ b/xpcom/idl-parser/runtests.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+#
+# Any copyright is dedicated to the public domain.
+#
+# Unit tests for xpidl.py
+
+import unittest
+import xpidl
+
+class TestParser(unittest.TestCase):
+    def setUp(self):
+        self.p = xpidl.IDLParser()
+    
+    def testEmpty(self):
+        i = self.p.parse("", filename='f')
+        self.assertTrue(isinstance(i, xpidl.IDL))
+        self.assertEqual([], i.productions)
+
+    def testForwardInterface(self):
+        i = self.p.parse("interface foo;", filename='f')
+        self.assertTrue(isinstance(i, xpidl.IDL))
+        self.assertTrue(isinstance(i.productions[0], xpidl.Forward))
+        self.assertEqual("foo", i.productions[0].name)
+
+    def testInterface(self):
+        i = self.p.parse("[uuid(abc)] interface foo {};", filename='f')
+        self.assertTrue(isinstance(i, xpidl.IDL))
+        self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
+        self.assertEqual("foo", i.productions[0].name)
+
+    def testAttributes(self):
+        i = self.p.parse("[scriptable, builtinclass, function, deprecated, uuid(abc)] interface foo {};", filename='f')
+        self.assertTrue(isinstance(i, xpidl.IDL))
+        self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
+        iface = i.productions[0]
+        self.assertEqual("foo", iface.name)
+        self.assertTrue(iface.attributes.scriptable)
+        self.assertTrue(iface.attributes.builtinclass)
+        self.assertTrue(iface.attributes.function)
+        self.assertTrue(iface.attributes.deprecated)
+
+        i = self.p.parse("[noscript, uuid(abc)] interface foo {};", filename='f')
+        self.assertTrue(isinstance(i, xpidl.IDL))
+        self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
+        iface = i.productions[0]
+        self.assertEqual("foo", iface.name)
+        self.assertTrue(iface.attributes.noscript)
+
+    def testMethod(self):
+        i = self.p.parse("""[uuid(abc)] interface foo {
+void bar();
+};""", filename='f')
+        self.assertTrue(isinstance(i, xpidl.IDL))
+        self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
+        iface = i.productions[0]
+        m = iface.members[0]
+        self.assertTrue(isinstance(m, xpidl.Method))
+        self.assertEqual("bar", m.name)
+        self.assertEqual("void", m.type)
+
+    def testMethodParams(self):
+        i = self.p.parse("""[uuid(abc)] interface foo {
+long bar(in long a, in float b, [array] in long c);
+};""", filename='f')
+        i.resolve([], self.p)
+        self.assertTrue(isinstance(i, xpidl.IDL))
+        self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
+        iface = i.productions[0]
+        m = iface.members[0]
+        self.assertTrue(isinstance(m, xpidl.Method))
+        self.assertEqual("bar", m.name)
+        self.assertEqual("long", m.type)
+        self.assertEqual(3, len(m.params))
+        self.assertEqual("long", m.params[0].type)
+        self.assertEqual("in", m.params[0].paramtype)
+        self.assertEqual("float", m.params[1].type)
+        self.assertEqual("in", m.params[1].paramtype)
+        self.assertEqual("long", m.params[2].type)
+        self.assertEqual("in", m.params[2].paramtype)
+        self.assertTrue(isinstance(m.params[2].realtype, xpidl.Array))
+        self.assertEqual("long", m.params[2].realtype.type.name)
+
+    def testAttribute(self):
+        i = self.p.parse("""[uuid(abc)] interface foo {
+attribute long bar;
+};""", filename='f')
+        self.assertTrue(isinstance(i, xpidl.IDL))
+        self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
+        iface = i.productions[0]
+        a = iface.members[0]
+        self.assertTrue(isinstance(a, xpidl.Attribute))
+        self.assertEqual("bar", a.name)
+        self.assertEqual("long", a.type)
+
+if __name__ == '__main__':
+    unittest.main()