Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(861)

Side by Side Diff: build/android/gyp/java_cpp_enum_tests.py

Issue 705093005: Add C++11 enum class support to the Java enum class generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/gyp/java_cpp_enum.py ('k') | build/android/pylib/constants.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Tests for enum_preprocess.py. 6 """Tests for enum_preprocess.py.
7 7
8 This test suite containss various tests for the C++ -> Java enum generator. 8 This test suite containss various tests for the C++ -> Java enum generator.
9 """ 9 """
10 10
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 def testParseThrowsOnUnknownDirective(self): 143 def testParseThrowsOnUnknownDirective(self):
144 test_data = """ 144 test_data = """
145 // GENERATED_JAVA_UNKNOWN: Value 145 // GENERATED_JAVA_UNKNOWN: Value
146 enum EnumName { 146 enum EnumName {
147 VALUE_ONE, 147 VALUE_ONE,
148 }; 148 };
149 """.split('\n') 149 """.split('\n')
150 with self.assertRaises(Exception): 150 with self.assertRaises(Exception):
151 HeaderParser(test_data).ParseDefinitions() 151 HeaderParser(test_data).ParseDefinitions()
152 152
153 def testParseEnumClass(self):
154 test_data = """
155 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
156 enum class Foo {
157 FOO_A,
158 };
159 """.split('\n')
160 definitions = HeaderParser(test_data).ParseDefinitions()
161 self.assertEqual(1, len(definitions))
162 definition = definitions[0]
163 self.assertEqual('Foo', definition.class_name)
164 self.assertEqual('test.namespace', definition.enum_package)
165 self.assertEqual(collections.OrderedDict([('A', 0)]),
166 definition.entries)
167
168 def testParseEnumStruct(self):
169 test_data = """
170 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
171 enum struct Foo {
172 FOO_A,
173 };
174 """.split('\n')
175 definitions = HeaderParser(test_data).ParseDefinitions()
176 self.assertEqual(1, len(definitions))
177 definition = definitions[0]
178 self.assertEqual('Foo', definition.class_name)
179 self.assertEqual('test.namespace', definition.enum_package)
180 self.assertEqual(collections.OrderedDict([('A', 0)]),
181 definition.entries)
182
183 def testParseFixedTypeEnum(self):
184 test_data = """
185 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
186 enum Foo : int {
187 FOO_A,
188 };
189 """.split('\n')
190 definitions = HeaderParser(test_data).ParseDefinitions()
191 self.assertEqual(1, len(definitions))
192 definition = definitions[0]
193 self.assertEqual('Foo', definition.class_name)
194 self.assertEqual('test.namespace', definition.enum_package)
195 self.assertEqual('int', definition.fixed_type)
196 self.assertEqual(collections.OrderedDict([('A', 0)]),
197 definition.entries)
198
199 def testParseFixedTypeEnumClass(self):
200 test_data = """
201 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
202 enum class Foo: unsigned short {
203 FOO_A,
204 };
205 """.split('\n')
206 definitions = HeaderParser(test_data).ParseDefinitions()
207 self.assertEqual(1, len(definitions))
208 definition = definitions[0]
209 self.assertEqual('Foo', definition.class_name)
210 self.assertEqual('test.namespace', definition.enum_package)
211 self.assertEqual('unsigned short', definition.fixed_type)
212 self.assertEqual(collections.OrderedDict([('A', 0)]),
213 definition.entries)
214
215 def testParseUnknownFixedTypeRaises(self):
216 test_data = """
217 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
218 enum class Foo: foo_type {
219 FOO_A,
220 };
221 """.split('\n')
222 with self.assertRaises(Exception):
223 HeaderParser(test_data).ParseDefinitions()
224
153 def testEnumValueAssignmentNoneDefined(self): 225 def testEnumValueAssignmentNoneDefined(self):
154 definition = EnumDefinition(original_enum_name='c', enum_package='p') 226 definition = EnumDefinition(original_enum_name='c', enum_package='p')
155 definition.AppendEntry('A', None) 227 definition.AppendEntry('A', None)
156 definition.AppendEntry('B', None) 228 definition.AppendEntry('B', None)
157 definition.AppendEntry('C', None) 229 definition.AppendEntry('C', None)
158 definition.Finalize() 230 definition.Finalize()
159 self.assertEqual(collections.OrderedDict([('A', 0), 231 self.assertEqual(collections.OrderedDict([('A', 0),
160 ('B', 1), 232 ('B', 1),
161 ('C', 2)]), 233 ('C', 2)]),
162 definition.entries) 234 definition.entries)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 options, _ = parser.parse_args(argv) 332 options, _ = parser.parse_args(argv)
261 333
262 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) 334 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess)
263 unittest.TextTestRunner(verbosity=0).run(suite) 335 unittest.TextTestRunner(verbosity=0).run(suite)
264 336
265 if options.stamp: 337 if options.stamp:
266 build_utils.Touch(options.stamp) 338 build_utils.Touch(options.stamp)
267 339
268 if __name__ == '__main__': 340 if __name__ == '__main__':
269 main(sys.argv[1:]) 341 main(sys.argv[1:])
OLDNEW
« no previous file with comments | « build/android/gyp/java_cpp_enum.py ('k') | build/android/pylib/constants.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698