summaryrefslogtreecommitdiff
path: root/utils/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2020-09-08 20:47:19 +0900
committerPaul Elder <paul.elder@ideasonboard.com>2020-11-11 19:22:37 +0900
commit82ba73535c0966e8ae8fb50db1ea23534d827717 (patch)
treef75b0d7f3933369872157105f1e467b71430e8cf /utils/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py
parent3d624b745b31383dbcd94d96246fab865820085f (diff)
utils: ipc: import mojo
Import mojo from the Chromium repository, so that we can use it for generating code for the IPC mechanism. The commit from which this was taken is: a079161ec8c6907b883f9cb84fc8c4e7896cb1d0 "Add PPAPI constructs for sending focus object to PdfAccessibilityTree" This tree has been pruned to remove directories that didn't have any necessary code: - mojo/* except for mojo/public - mojo core, docs, and misc files - mojo/public/* except for mojo/public/{tools,LICENSE} - language bindings for IPC, tests, and some mojo internals - mojo/public/tools/{fuzzers,chrome_ipc} - mojo/public/tools/bindings/generators - code generation for other languages No files were modified. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'utils/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py')
-rw-r--r--utils/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py b/utils/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py
new file mode 100644
index 00000000..19905c8a
--- /dev/null
+++ b/utils/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py
@@ -0,0 +1,73 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import imp
+import os.path
+import sys
+import unittest
+
+from mojom.generate import module as mojom
+from mojom.generate import translate
+from mojom.parse import ast
+
+
+class TranslateTest(unittest.TestCase):
+ """Tests |parser.Parse()|."""
+
+ def testSimpleArray(self):
+ """Tests a simple int32[]."""
+ # pylint: disable=W0212
+ self.assertEquals(translate._MapKind("int32[]"), "a:i32")
+
+ def testAssociativeArray(self):
+ """Tests a simple uint8{string}."""
+ # pylint: disable=W0212
+ self.assertEquals(translate._MapKind("uint8{string}"), "m[s][u8]")
+
+ def testLeftToRightAssociativeArray(self):
+ """Makes sure that parsing is done from right to left on the internal kinds
+ in the presence of an associative array."""
+ # pylint: disable=W0212
+ self.assertEquals(translate._MapKind("uint8[]{string}"), "m[s][a:u8]")
+
+ def testTranslateSimpleUnions(self):
+ """Makes sure that a simple union is translated correctly."""
+ tree = ast.Mojom(None, ast.ImportList(), [
+ ast.Union(
+ "SomeUnion", None,
+ ast.UnionBody([
+ ast.UnionField("a", None, None, "int32"),
+ ast.UnionField("b", None, None, "string")
+ ]))
+ ])
+
+ translation = translate.OrderedModule(tree, "mojom_tree", [])
+ self.assertEqual(1, len(translation.unions))
+
+ union = translation.unions[0]
+ self.assertTrue(isinstance(union, mojom.Union))
+ self.assertEqual("SomeUnion", union.mojom_name)
+ self.assertEqual(2, len(union.fields))
+ self.assertEqual("a", union.fields[0].mojom_name)
+ self.assertEqual(mojom.INT32.spec, union.fields[0].kind.spec)
+ self.assertEqual("b", union.fields[1].mojom_name)
+ self.assertEqual(mojom.STRING.spec, union.fields[1].kind.spec)
+
+ def testMapKindRaisesWithDuplicate(self):
+ """Verifies _MapTreeForType() raises when passed two values with the same
+ name."""
+ methods = [
+ ast.Method('dup', None, None, ast.ParameterList(), None),
+ ast.Method('dup', None, None, ast.ParameterList(), None)
+ ]
+ with self.assertRaises(Exception):
+ translate._ElemsOfType(methods, ast.Method, 'scope')
+
+ def testAssociatedKinds(self):
+ """Tests type spec translation of associated interfaces and requests."""
+ # pylint: disable=W0212
+ self.assertEquals(
+ translate._MapKind("asso<SomeInterface>?"), "?asso:x:SomeInterface")
+ self.assertEquals(
+ translate._MapKind("asso<SomeInterface&>?"), "?asso:r:x:SomeInterface")