Back to index

enigmail  1.4.3
runtests.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Any copyright is dedicated to the public domain.
00004 #
00005 # Unit tests for xpidl.py
00006 
00007 import unittest
00008 import xpidl
00009 
00010 class TestParser(unittest.TestCase):
00011     def setUp(self):
00012         self.p = xpidl.IDLParser()
00013     
00014     def testEmpty(self):
00015         i = self.p.parse("", filename='f')
00016         self.assertTrue(isinstance(i, xpidl.IDL))
00017         self.assertEqual([], i.productions)
00018 
00019     def testForwardInterface(self):
00020         i = self.p.parse("interface foo;", filename='f')
00021         self.assertTrue(isinstance(i, xpidl.IDL))
00022         self.assertTrue(isinstance(i.productions[0], xpidl.Forward))
00023         self.assertEqual("foo", i.productions[0].name)
00024 
00025     def testInterface(self):
00026         i = self.p.parse("[uuid(abc)] interface foo {};", filename='f')
00027         self.assertTrue(isinstance(i, xpidl.IDL))
00028         self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
00029         self.assertEqual("foo", i.productions[0].name)
00030 
00031     def testAttributes(self):
00032         i = self.p.parse("[scriptable, builtinclass, function, deprecated, uuid(abc)] interface foo {};", filename='f')
00033         self.assertTrue(isinstance(i, xpidl.IDL))
00034         self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
00035         iface = i.productions[0]
00036         self.assertEqual("foo", iface.name)
00037         self.assertTrue(iface.attributes.scriptable)
00038         self.assertTrue(iface.attributes.builtinclass)
00039         self.assertTrue(iface.attributes.function)
00040         self.assertTrue(iface.attributes.deprecated)
00041 
00042         i = self.p.parse("[noscript, uuid(abc)] interface foo {};", filename='f')
00043         self.assertTrue(isinstance(i, xpidl.IDL))
00044         self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
00045         iface = i.productions[0]
00046         self.assertEqual("foo", iface.name)
00047         self.assertTrue(iface.attributes.noscript)
00048 
00049     def testMethod(self):
00050         i = self.p.parse("""[uuid(abc)] interface foo {
00051 void bar();
00052 };""", filename='f')
00053         self.assertTrue(isinstance(i, xpidl.IDL))
00054         self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
00055         iface = i.productions[0]
00056         m = iface.members[0]
00057         self.assertTrue(isinstance(m, xpidl.Method))
00058         self.assertEqual("bar", m.name)
00059         self.assertEqual("void", m.type)
00060 
00061     def testMethodParams(self):
00062         i = self.p.parse("""[uuid(abc)] interface foo {
00063 long bar(in long a, in float b, [array] in long c);
00064 };""", filename='f')
00065         i.resolve([], self.p)
00066         self.assertTrue(isinstance(i, xpidl.IDL))
00067         self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
00068         iface = i.productions[0]
00069         m = iface.members[0]
00070         self.assertTrue(isinstance(m, xpidl.Method))
00071         self.assertEqual("bar", m.name)
00072         self.assertEqual("long", m.type)
00073         self.assertEqual(3, len(m.params))
00074         self.assertEqual("long", m.params[0].type)
00075         self.assertEqual("in", m.params[0].paramtype)
00076         self.assertEqual("float", m.params[1].type)
00077         self.assertEqual("in", m.params[1].paramtype)
00078         self.assertEqual("long", m.params[2].type)
00079         self.assertEqual("in", m.params[2].paramtype)
00080         self.assertTrue(isinstance(m.params[2].realtype, xpidl.Array))
00081         self.assertEqual("long", m.params[2].realtype.type.name)
00082 
00083     def testAttribute(self):
00084         i = self.p.parse("""[uuid(abc)] interface foo {
00085 attribute long bar;
00086 };""", filename='f')
00087         self.assertTrue(isinstance(i, xpidl.IDL))
00088         self.assertTrue(isinstance(i.productions[0], xpidl.Interface))
00089         iface = i.productions[0]
00090         a = iface.members[0]
00091         self.assertTrue(isinstance(a, xpidl.Attribute))
00092         self.assertEqual("bar", a.name)
00093         self.assertEqual("long", a.type)
00094 
00095 if __name__ == '__main__':
00096     unittest.main()