Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
scripts.dartgenerator_test.DartGeneratorTestCase Class Reference
Inheritance diagram for scripts.dartgenerator_test.DartGeneratorTestCase:

Public Member Functions

 setUp (self)
 
 tearDown (self)
 
 testBasicGeneration (self)
 
 testFilterByAnnotations (self)
 
 testTypeRenames (self)
 
 testQualifiedDartTypes (self)
 

Protected Member Functions

 _InDatabase (self, interface_name)
 
 _FilePathForDartInterface (self, interface_name)
 
 _InOutput (self, interface_name)
 
 _ReadOutputFile (self, interface_name)
 
 _AssertOutputSansHeaderEquals (self, interface_name, expected_content)
 
 _AssertOutputContains (self, interface_name, expected_content)
 
 _AssertOutputDoesNotContain (self, interface_name, expected_content)
 

Protected Attributes

 _database_dir
 
 _working_dir
 
 _output_dir
 
 _auxiliary_dir
 
 _database
 
 _generator
 

Detailed Description

Definition at line 19 of file dartgenerator_test.py.

Member Function Documentation

◆ _AssertOutputContains()

scripts.dartgenerator_test.DartGeneratorTestCase._AssertOutputContains (   self,
  interface_name,
  expected_content 
)
protected

Definition at line 55 of file dartgenerator_test.py.

55 def _AssertOutputContains(self, interface_name, expected_content):
56 actual_content, file_path = self._ReadOutputFile(interface_name)
57 if expected_content not in actual_content:
58 msg = """
59STRING: %s
60Was found not in output file: %s
61FILE CONTENT:
62%s
63""" % (expected_content, file_path, actual_content)
64 self.fail(msg)
65

◆ _AssertOutputDoesNotContain()

scripts.dartgenerator_test.DartGeneratorTestCase._AssertOutputDoesNotContain (   self,
  interface_name,
  expected_content 
)
protected

Definition at line 66 of file dartgenerator_test.py.

66 def _AssertOutputDoesNotContain(self, interface_name, expected_content):
67 actual_content, file_path = self._ReadOutputFile(interface_name)
68 if expected_content in actual_content:
69 msg = """
70STRING: %s
71Was found in output file: %s
72FILE CONTENT:
73%s
74""" % (expected_content, file_path, actual_content)
75 self.fail(msg)
76

◆ _AssertOutputSansHeaderEquals()

scripts.dartgenerator_test.DartGeneratorTestCase._AssertOutputSansHeaderEquals (   self,
  interface_name,
  expected_content 
)
protected

Definition at line 40 of file dartgenerator_test.py.

40 def _AssertOutputSansHeaderEquals(self, interface_name, expected_content):
41 full_actual_content, file_path = self._ReadOutputFile(interface_name)
42 # Remove file header comments in // or multiline /* ... */ syntax.
43 header_re = re.compile(r'^(\s*(//.*|/\*([^*]|\*[^/])*\*/)\s*)*')
44 actual_content = header_re.sub('', full_actual_content)
45 if expected_content != actual_content:
46 msg = """
47FILE: %s
48EXPECTED:
49%s
50ACTUAL:
51%s
52""" % (file_path, expected_content, actual_content)
53 self.fail(msg)
54

◆ _FilePathForDartInterface()

scripts.dartgenerator_test.DartGeneratorTestCase._FilePathForDartInterface (   self,
  interface_name 
)
protected

Definition at line 25 of file dartgenerator_test.py.

25 def _FilePathForDartInterface(self, interface_name):
26 return os.path.join(self._generator._output_dir, 'src', 'interface',
27 '%s.dart' % interface_name)
28

◆ _InDatabase()

scripts.dartgenerator_test.DartGeneratorTestCase._InDatabase (   self,
  interface_name 
)
protected

Definition at line 21 of file dartgenerator_test.py.

21 def _InDatabase(self, interface_name):
22 return os.path.exists(
23 os.path.join(self._database_dir, '%s.idl' % interface_name))
24

◆ _InOutput()

scripts.dartgenerator_test.DartGeneratorTestCase._InOutput (   self,
  interface_name 
)
protected

Definition at line 29 of file dartgenerator_test.py.

29 def _InOutput(self, interface_name):
30 return os.path.exists(self._FilePathForDartInterface(interface_name))
31

◆ _ReadOutputFile()

scripts.dartgenerator_test.DartGeneratorTestCase._ReadOutputFile (   self,
  interface_name 
)
protected

Definition at line 32 of file dartgenerator_test.py.

32 def _ReadOutputFile(self, interface_name):
33 self.assertTrue(self._InOutput(interface_name))
34 file_path = self._FilePathForDartInterface(interface_name)
35 f = open(file_path, 'r')
36 content = f.read()
37 f.close()
38 return content, file_path
39

◆ setUp()

scripts.dartgenerator_test.DartGeneratorTestCase.setUp (   self)

Definition at line 77 of file dartgenerator_test.py.

77 def setUp(self):
78 self._working_dir = tempfile.mkdtemp()
79 self._output_dir = os.path.join(self._working_dir, 'output')
80 self._database_dir = os.path.join(self._working_dir, 'database')
81 self._auxiliary_dir = os.path.join(self._working_dir, 'auxiliary')
82 self.assertFalse(os.path.exists(self._database_dir))
83
84 # Create database and add one interface.
85 db = database.Database(self._database_dir)
86 os.mkdir(self._auxiliary_dir)
87 self.assertTrue(os.path.exists(self._database_dir))
88
89 content = """
90 module shapes {
91 @A1 @A2
92 interface Shape {
93 @A1 @A2 getter attribute int attr;
94 @A1 setter attribute int attr;
95 @A3 boolean op();
96 const long CONSTANT = 1;
97 getter attribute DOMString strAttr;
98 Shape create();
99 boolean compare(Shape s);
100 Rectangle createRectangle();
101 void addLine(lines::Line line);
102 void someDartType(File file);
103 void someUnidentifiedType(UnidentifiableType t);
104 };
105 };
106
107 module rectangles {
108 @A3
109 interface Rectangle : @A3 shapes::Shape {
110 void someTemplatedType(List<Shape> list);
111 };
112 };
113
114 module lines {
115 @A1
116 interface Line : shapes::Shape {
117 };
118 };
119 """
120
121 parser = idlparser.IDLParser(idlparser.FREMONTCUT_SYNTAX)
122 ast = parser.parse(content)
123 idl_file = idlnode.IDLFile(ast)
124 for interface in idl_file.interfaces:
125 db.AddInterface(interface)
126 db.Save()
127
128 self.assertTrue(self._InDatabase('Shape'))
129 self.assertTrue(self._InDatabase('Rectangle'))
130 self.assertTrue(self._InDatabase('Line'))
131
132 self._database = database.Database(self._database_dir)
133 self._generator = dartgenerator.DartGenerator(self._auxiliary_dir,
134 '../templates', 'test')
135

◆ tearDown()

scripts.dartgenerator_test.DartGeneratorTestCase.tearDown (   self)

Definition at line 136 of file dartgenerator_test.py.

136 def tearDown(self):
137 shutil.rmtree(self._database_dir)
138 shutil.rmtree(self._auxiliary_dir)
139

◆ testBasicGeneration()

scripts.dartgenerator_test.DartGeneratorTestCase.testBasicGeneration (   self)

Definition at line 140 of file dartgenerator_test.py.

140 def testBasicGeneration(self):
141 # Generate all interfaces:
142 self._database.Load()
143 self._generator.Generate(self._database, self._output_dir)
144 self._generator.Flush()
145
146 self.assertTrue(self._InOutput('Shape'))
147 self.assertTrue(self._InOutput('Rectangle'))
148 self.assertTrue(self._InOutput('Line'))
149

◆ testFilterByAnnotations()

scripts.dartgenerator_test.DartGeneratorTestCase.testFilterByAnnotations (   self)

Definition at line 150 of file dartgenerator_test.py.

150 def testFilterByAnnotations(self):
151 self._database.Load()
152 self._generator.FilterInterfaces(self._database, ['A1', 'A2'], ['A3'])
153 self._generator.Generate(self._database, self._output_dir)
154 self._generator.Flush()
155
156 # Only interfaces with (@A1 and @A2) or @A3 should be generated:
157 self.assertTrue(self._InOutput('Shape'))
158 self.assertTrue(self._InOutput('Rectangle'))
159 self.assertFalse(self._InOutput('Line'))
160
161 # Only members with (@A1 and @A2) or @A3 should be generated:
162 # TODO(sra): make th
163 self._AssertOutputSansHeaderEquals(
164 'Shape', """interface Shape {
165
166 final int attr;
167
168 bool op();
169}
170""")
171
172 self._AssertOutputContains('Rectangle',
173 'interface Rectangle extends shapes::Shape')
174

◆ testQualifiedDartTypes()

scripts.dartgenerator_test.DartGeneratorTestCase.testQualifiedDartTypes (   self)

Definition at line 189 of file dartgenerator_test.py.

189 def testQualifiedDartTypes(self):
190 self._database.Load()
191 self._generator.FilterMembersWithUnidentifiedTypes(self._database)
192 self._generator.Generate(self._database, self._output_dir)
193 self._generator.Flush()
194
195 # Verify primitive conversions are working:
196 self._AssertOutputContains('Shape', 'static const int CONSTANT = 1')
197 self._AssertOutputContains('Shape', 'final String strAttr;')
198
199 # Verify interface names are converted:
200 self._AssertOutputContains('Shape', 'interface Shape {')
201 self._AssertOutputContains('Shape', ' Shape create();')
202 # TODO(sra): Why is this broken? Output contains qualified type.
203 #self._AssertOutputContains('Shape',
204 # 'void addLine(Line line);')
205 self._AssertOutputContains('Shape', 'Rectangle createRectangle();')
206 # TODO(sra): Why is this broken? Output contains qualified type.
207 #self._AssertOutputContains('Rectangle',
208 # 'interface Rectangle extends Shape')
209 # Verify dart names are preserved:
210 # TODO(vsm): Re-enable when package / namespaces are enabled.
211 # self._AssertOutputContains('shapes', 'Shape',
212 # 'void someDartType(File file);')
213
214 # Verify that unidentified types are not removed:
215 self._AssertOutputDoesNotContain('Shape', 'someUnidentifiedType')
216
217 # Verify template conversion:
218 # TODO(vsm): Re-enable when core collections are supported.
219 # self._AssertOutputContains('rectangles', 'Rectangle',
220 # 'void someTemplatedType(List<Shape> list)')
221
222

◆ testTypeRenames()

scripts.dartgenerator_test.DartGeneratorTestCase.testTypeRenames (   self)

Definition at line 175 of file dartgenerator_test.py.

175 def testTypeRenames(self):
176 self._database.Load()
177 # Translate 'Shape' to spanish:
178 self._generator.RenameTypes(self._database, {'Shape': 'Forma'}, False)
179 self._generator.Generate(self._database, self._output_dir)
180 self._generator.Flush()
181
182 # Validate that all references to Shape have been converted:
183 self._AssertOutputContains('Forma', 'interface Forma')
184 self._AssertOutputContains('Forma', 'Forma create();')
185 self._AssertOutputContains('Forma', 'bool compare(Forma s);')
186 self._AssertOutputContains('Rectangle',
187 'interface Rectangle extends Forma')
188

Member Data Documentation

◆ _auxiliary_dir

scripts.dartgenerator_test.DartGeneratorTestCase._auxiliary_dir
protected

Definition at line 81 of file dartgenerator_test.py.

◆ _database

scripts.dartgenerator_test.DartGeneratorTestCase._database
protected

Definition at line 132 of file dartgenerator_test.py.

◆ _database_dir

scripts.dartgenerator_test.DartGeneratorTestCase._database_dir
protected

Definition at line 23 of file dartgenerator_test.py.

◆ _generator

scripts.dartgenerator_test.DartGeneratorTestCase._generator
protected

Definition at line 133 of file dartgenerator_test.py.

◆ _output_dir

scripts.dartgenerator_test.DartGeneratorTestCase._output_dir
protected

Definition at line 79 of file dartgenerator_test.py.

◆ _working_dir

scripts.dartgenerator_test.DartGeneratorTestCase._working_dir
protected

Definition at line 78 of file dartgenerator_test.py.


The documentation for this class was generated from the following file: