summaryrefslogtreecommitdiff
path: root/include
ModeNameSize
d---------android142logplain
d---------libcamera815logplain
d---------linux643logplain
-rw-r--r--meson.build121logplain
' href='#n29'>29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
# 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.

from mojom_parser_test_case import MojomParserTestCase


class MojomParserTest(MojomParserTestCase):
  """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 testBasicParse(self):
    """Basic test to verify that we can parse a mojom file and get a module."""
    mojom = 'foo/bar.mojom'
    self.WriteFile(
        mojom, """\
        module test;
        enum TestEnum { kFoo };
        """)
    self.ParseMojoms([mojom])

    m = self.LoadModule(mojom)
    self.assertEqual('foo/bar.mojom', m.path)
    self.assertEqual('test', m.mojom_namespace)
    self.assertEqual(1, len(m.enums))

  def testBasicParseWithAbsolutePaths(self):
    """Verifies that we can parse a mojom file given an absolute path input."""
    mojom = 'foo/bar.mojom'
    self.WriteFile(
        mojom, """\
        module test;
        enum TestEnum { kFoo };
        """)
    self.ParseMojoms([self.GetPath(mojom)])

    m = self.LoadModule(mojom)
    self.assertEqual('foo/bar.mojom', m.path)
    self.assertEqual('test', m.mojom_namespace)
    self.assertEqual(1, len(m.enums))

  def testImport(self):
    """Verify imports within the same set of mojom inputs."""
    a = 'a.mojom'
    b = 'b.mojom'
    self.WriteFile(
        a, """\
        module a;
        import "b.mojom";
        struct Foo { b.Bar bar; };""")
    self.WriteFile(b, """\
        module b;
        struct Bar {};""")
    self.ParseMojoms([a, b])

    ma = self.LoadModule(a)
    mb = self.LoadModule(b)
    self.assertEqual('a.mojom', ma.path)
    self.assertEqual('b.mojom', mb.path)
    self.assertEqual(1, len(ma.imports))
    self.assertEqual(mb, ma.imports[0])

  def testPreProcessedImport(self):
    """Verify imports processed by a previous parser execution can be loaded
    properly when parsing a dependent mojom."""
    a = 'a.mojom'
    self.WriteFile(a, """\
        module a;
        struct Bar {};""")
    self.ParseMojoms([a])

    b = 'b.mojom'
    self.WriteFile(
        b, """\
        module b;
        import "a.mojom";
        struct Foo { a.Bar bar; };""")
    self.ParseMojoms([b])

  def testMissingImport(self):
    """Verify that an import fails if the imported mojom does not exist."""
    a = 'a.mojom'
    self.WriteFile(
        a, """\
        module a;
        import "non-existent.mojom";
        struct Bar {};""")
    with self.assertRaisesRegexp(ValueError, "does not exist"):
      self.ParseMojoms([a])

  def testUnparsedImport(self):
    """Verify that an import fails if the imported mojom is not in the set of
    mojoms provided to the parser on this execution AND there is no pre-existing
    parsed output module already on disk for it."""
    a = 'a.mojom'
    b = 'b.mojom'
    self.WriteFile(a, """\
        module a;
        struct Bar {};""")
    self.WriteFile(
        b, """\
        module b;
        import "a.mojom";
        struct Foo { a.Bar bar; };""")

    # a.mojom has not been parsed yet, so its import will fail when processing
    # b.mojom here.
    with self.assertRaisesRegexp(ValueError, "does not exist"):
      self.ParseMojoms([b])

  def testCheckImportsBasic(self):