summaryrefslogtreecommitdiff
path: root/utils/ipc/mojo/public/tools/mojom/mojom_parser_test_case.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_parser_test_case.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_parser_test_case.py')
-rw-r--r--utils/ipc/mojo/public/tools/mojom/mojom_parser_test_case.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/utils/ipc/mojo/public/tools/mojom/mojom_parser_test_case.py b/utils/ipc/mojo/public/tools/mojom/mojom_parser_test_case.py
new file mode 100644
index 00000000..e213fbfa
--- /dev/null
+++ b/utils/ipc/mojo/public/tools/mojom/mojom_parser_test_case.py
@@ -0,0 +1,73 @@
+# Copyright 2020 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 json
+import os
+import os.path
+import shutil
+import tempfile
+import unittest
+
+import mojom_parser
+
+from mojom.generate import module
+
+
+class MojomParserTestCase(unittest.TestCase):
+ """Tests covering the behavior defined by the main mojom_parser.py script.
+ This includes behavior around input and output path manipulation, dependency
+ resolution, and module serialization and deserialization."""
+
+ def __init__(self, method_name):
+ super(MojomParserTestCase, self).__init__(method_name)
+ self._temp_dir = None
+
+ def setUp(self):
+ self._temp_dir = tempfile.mkdtemp()
+
+ def tearDown(self):
+ shutil.rmtree(self._temp_dir)
+ self._temp_dir = None
+
+ def GetPath(self, path):
+ assert not os.path.isabs(path)
+ return os.path.join(self._temp_dir, path)
+
+ def GetModulePath(self, path):
+ assert not os.path.isabs(path)
+ return os.path.join(self.GetPath('out'), path) + '-module'
+
+ def WriteFile(self, path, contents):
+ full_path = self.GetPath(path)
+ dirname = os.path.dirname(full_path)
+ if not os.path.exists(dirname):
+ os.makedirs(dirname)
+ with open(full_path, 'w') as f:
+ f.write(contents)
+
+ def LoadModule(self, mojom_path):
+ with open(self.GetModulePath(mojom_path), 'rb') as f:
+ return module.Module.Load(f)
+
+ def ParseMojoms(self, mojoms, metadata=None):
+ """Parse all input mojoms relative the temp dir."""
+ out_dir = self.GetPath('out')
+ args = [
+ '--input-root', self._temp_dir, '--input-root', out_dir,
+ '--output-root', out_dir, '--mojoms'
+ ] + list(map(lambda mojom: os.path.join(self._temp_dir, mojom), mojoms))
+ if metadata:
+ args.extend(['--check-imports', self.GetPath(metadata)])
+ mojom_parser.Run(args)
+
+ def ExtractTypes(self, mojom):
+ filename = 'test.mojom'
+ self.WriteFile(filename, mojom)
+ self.ParseMojoms([filename])
+ m = self.LoadModule(filename)
+ definitions = {}
+ for kinds in (m.enums, m.structs, m.unions, m.interfaces):
+ for kind in kinds:
+ definitions[kind.mojom_name] = kind
+ return definitions