Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
scripts.dartgenerator_test.DartGeneratorTestCase Class Reference
Inheritance diagram for scripts.dartgenerator_test.DartGeneratorTestCase:

Public Member Functions

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

Detailed Description

Definition at line 19 of file dartgenerator_test.py.

Member Function Documentation

◆ setUp()

def 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
Definition: create.py:1
int compare(const void *untyped_lhs, const void *untyped_rhs)
Definition: skdiff.h:161

◆ tearDown()

def 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()

def 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
void Flush(SkSurface *surface)
Definition: GpuTools.h:25

◆ testFilterByAnnotations()

def 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()

def 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()

def 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

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