summaryrefslogtreecommitdiff
path: root/utils/codegen/ipc/mojo/public/tools/mojom/feature_unittest.py
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-08-08 18:13:00 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-08-15 23:59:08 +0300
commit50c92cc7e2924009ecab3e4004448b01d687707c (patch)
treec22b49816a3c79dae4727780962aa0928df42b52 /utils/codegen/ipc/mojo/public/tools/mojom/feature_unittest.py
parentd3bf27180ef1d91b86b7b87a2378e559eaff5455 (diff)
meson: Move all code generation scripts to utils/codegen/
We have multiple code generation scripts in utils/, mixed with other miscellaneous utilities, as well as a larger code base based on mojom in utils/ipc/. To make code sharing easier between the generator scripts, without creating a mess in the utils/ directory, move all the code generation code to utils/codegen/. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'utils/codegen/ipc/mojo/public/tools/mojom/feature_unittest.py')
-rw-r--r--utils/codegen/ipc/mojo/public/tools/mojom/feature_unittest.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/utils/codegen/ipc/mojo/public/tools/mojom/feature_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/feature_unittest.py
new file mode 100644
index 00000000..5f014e1c
--- /dev/null
+++ b/utils/codegen/ipc/mojo/public/tools/mojom/feature_unittest.py
@@ -0,0 +1,84 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from mojom_parser_test_case import MojomParserTestCase
+
+
+class FeatureTest(MojomParserTestCase):
+ """Tests feature parsing behavior."""
+ def testFeatureOff(self):
+ """Verifies basic parsing of feature types."""
+ types = self.ExtractTypes("""
+ // e.g. BASE_DECLARE_FEATURE(kFeature);
+ [AttributeOne=ValueOne]
+ feature kFeature {
+ // BASE_FEATURE(kFeature,"MyFeature",
+ // base::FEATURE_DISABLED_BY_DEFAULT);
+ const string name = "MyFeature";
+ const bool default_state = false;
+ };
+ """)
+ self.assertEqual('name', types['kFeature'].constants[0].mojom_name)
+ self.assertEqual('"MyFeature"', types['kFeature'].constants[0].value)
+ self.assertEqual('default_state', types['kFeature'].constants[1].mojom_name)
+ self.assertEqual('false', types['kFeature'].constants[1].value)
+
+ def testFeatureOn(self):
+ """Verifies basic parsing of feature types."""
+ types = self.ExtractTypes("""
+ // e.g. BASE_DECLARE_FEATURE(kFeature);
+ feature kFeature {
+ // BASE_FEATURE(kFeature,"MyFeature",
+ // base::FEATURE_ENABLED_BY_DEFAULT);
+ const string name = "MyFeature";
+ const bool default_state = true;
+ };
+ """)
+ self.assertEqual('name', types['kFeature'].constants[0].mojom_name)
+ self.assertEqual('"MyFeature"', types['kFeature'].constants[0].value)
+ self.assertEqual('default_state', types['kFeature'].constants[1].mojom_name)
+ self.assertEqual('true', types['kFeature'].constants[1].value)
+
+ def testFeatureWeakKeyword(self):
+ """Verifies that `feature` is a weak keyword."""
+ types = self.ExtractTypes("""
+ // e.g. BASE_DECLARE_FEATURE(kFeature);
+ [AttributeOne=ValueOne]
+ feature kFeature {
+ // BASE_FEATURE(kFeature,"MyFeature",
+ // base::FEATURE_DISABLED_BY_DEFAULT);
+ const string name = "MyFeature";
+ const bool default_state = false;
+ };
+ struct MyStruct {
+ bool feature = true;
+ };
+ interface InterfaceName {
+ Method(string feature) => (int32 feature);
+ };
+ """)
+ self.assertEqual('name', types['kFeature'].constants[0].mojom_name)
+ self.assertEqual('"MyFeature"', types['kFeature'].constants[0].value)
+ self.assertEqual('default_state', types['kFeature'].constants[1].mojom_name)
+ self.assertEqual('false', types['kFeature'].constants[1].value)
+
+ def testFeatureAttributesAreFeatures(self):
+ """Verifies that feature values in attributes are really feature types."""
+ a_mojom = 'a.mojom'
+ self.WriteFile(
+ a_mojom, 'module a;'
+ 'feature F { const string name = "f";'
+ 'const bool default_state = false; };')
+ b_mojom = 'b.mojom'
+ self.WriteFile(
+ b_mojom, 'module b;'
+ 'import "a.mojom";'
+ 'feature G'
+ '{const string name = "g"; const bool default_state = false;};'
+ '[Attri=a.F] interface Foo { Foo(); };'
+ '[Boink=G] interface Bar {};')
+ self.ParseMojoms([a_mojom, b_mojom])
+ b = self.LoadModule(b_mojom)
+ self.assertEqual(b.interfaces[0].attributes['Attri'].mojom_name, 'F')
+ self.assertEqual(b.interfaces[1].attributes['Boink'].mojom_name, 'G')