| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import database | 6 import database |
| 7 import idlparser | 7 import idlparser |
| 8 import logging.config | 8 import logging.config |
| 9 import os | 9 import os |
| 10 import os.path | 10 import os.path |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 shutil.rmtree(self._database_dir) | 62 shutil.rmtree(self._database_dir) |
| 63 | 63 |
| 64 def test_basic_import(self): | 64 def test_basic_import(self): |
| 65 file_name = self._create_input('input.idl', ''' | 65 file_name = self._create_input('input.idl', ''' |
| 66 module M { | 66 module M { |
| 67 interface I { | 67 interface I { |
| 68 attribute int a; | 68 attribute int a; |
| 69 }; | 69 }; |
| 70 };''') | 70 };''') |
| 71 self._builder.import_idl_file(file_name) | 71 self._builder.import_idl_file(file_name) |
| 72 self._builder.merge_imported_interfaces() | 72 self._builder.merge_imported_interfaces([]) |
| 73 self._db.Save() | 73 self._db.Save() |
| 74 self._assert_interface_exists('I.idl') | 74 self._assert_interface_exists('I.idl') |
| 75 | 75 |
| 76 def test_splitting(self): | 76 def test_splitting(self): |
| 77 file_name = self._create_input('input.idl', ''' | 77 file_name = self._create_input('input.idl', ''' |
| 78 module M { | 78 module M { |
| 79 interface I { | 79 interface I { |
| 80 readonly attribute int a; | 80 readonly attribute int a; |
| 81 int o(in int x, in optional int y); | 81 int o(in int x, in optional int y); |
| 82 }; | 82 }; |
| 83 };''') | 83 };''') |
| 84 self._builder.import_idl_file(file_name) | 84 self._builder.import_idl_file(file_name) |
| 85 self._builder.merge_imported_interfaces() | 85 self._builder.merge_imported_interfaces([]) |
| 86 self._db.Save() | 86 self._db.Save() |
| 87 self._assert_content_equals('I.idl', ''' | 87 self._assert_content_equals('I.idl', ''' |
| 88 interface I { | 88 interface I { |
| 89 /* Attributes */ | 89 /* Attributes */ |
| 90 getter attribute int a; | 90 getter attribute int a; |
| 91 | 91 |
| 92 /* Operations */ | 92 /* Operations */ |
| 93 int o(in int x); | 93 int o(in int x); |
| 94 int o(in int x, in int y); | 94 int o(in int x, in int y); |
| 95 };''') | 95 };''') |
| 96 | 96 |
| 97 def test_renames(self): | 97 def test_renames(self): |
| 98 file_name = self._create_input('input.idl', ''' | 98 file_name = self._create_input('input.idl', ''' |
| 99 module M { | 99 module M { |
| 100 interface I { | 100 interface I { |
| 101 T op(T x); | 101 T op(T x); |
| 102 readonly attribute N::T attr; | 102 readonly attribute N::T attr; |
| 103 }; | 103 }; |
| 104 };''') | 104 };''') |
| 105 options = DatabaseBuilderOptions(type_rename_map={'I': 'i', 'T': 't'}) | 105 options = DatabaseBuilderOptions(type_rename_map={'I': 'i', 'T': 't'}) |
| 106 self._builder.import_idl_file(file_name, options) | 106 self._builder.import_idl_file(file_name, options) |
| 107 self._builder.merge_imported_interfaces() | 107 self._builder.merge_imported_interfaces([]) |
| 108 self._db.Save() | 108 self._db.Save() |
| 109 self._assert_content_equals('i.idl', ''' | 109 self._assert_content_equals('i.idl', ''' |
| 110 interface i { | 110 interface i { |
| 111 /* Attributes */ | 111 /* Attributes */ |
| 112 getter attribute t attr; | 112 getter attribute t attr; |
| 113 /* Operations */ | 113 /* Operations */ |
| 114 t op(in t x); | 114 t op(in t x); |
| 115 };''') | 115 };''') |
| 116 | 116 |
| 117 def test_type_defs(self): | 117 def test_type_defs(self): |
| 118 file_name = self._create_input('input.idl', ''' | 118 file_name = self._create_input('input.idl', ''' |
| 119 module M { | 119 module M { |
| 120 typedef T S; | 120 typedef T S; |
| 121 interface I : S { | 121 interface I : S { |
| 122 S op(S x); | 122 S op(S x); |
| 123 readonly attribute S attr; | 123 readonly attribute S attr; |
| 124 }; | 124 }; |
| 125 };''') | 125 };''') |
| 126 options = DatabaseBuilderOptions() | 126 options = DatabaseBuilderOptions() |
| 127 self._builder.import_idl_file(file_name, options) | 127 self._builder.import_idl_file(file_name, options) |
| 128 self._builder.merge_imported_interfaces() | 128 self._builder.merge_imported_interfaces([]) |
| 129 self._db.Save() | 129 self._db.Save() |
| 130 self._assert_content_equals('I.idl', ''' | 130 self._assert_content_equals('I.idl', ''' |
| 131 interface I : | 131 interface I : |
| 132 T { | 132 T { |
| 133 /* Attributes */ | 133 /* Attributes */ |
| 134 getter attribute T attr; | 134 getter attribute T attr; |
| 135 /* Operations */ | 135 /* Operations */ |
| 136 T op(in T x); | 136 T op(in T x); |
| 137 };''') | 137 };''') |
| 138 | 138 |
| 139 def test_merge(self): | 139 def test_merge(self): |
| 140 file_name1 = self._create_input('input1.idl', ''' | 140 file_name1 = self._create_input('input1.idl', ''' |
| 141 module M { | 141 module M { |
| 142 interface I { | 142 interface I { |
| 143 const int CONST_BOTH = 0; | 143 const int CONST_BOTH = 0; |
| 144 const int CONST_ONLY_FIRST = 0; | 144 const int CONST_ONLY_FIRST = 0; |
| 145 const int CONST_BOTH_DIFFERENT_VALUE = 0; | 145 const int CONST_BOTH_DIFFERENT_VALUE = 0; |
| 146 | 146 |
| 147 readonly attribute int attr_only_first; | 147 readonly attribute int attr_only_first; |
| 148 readonly attribute int attr_both; | 148 readonly attribute int attr_both; |
| 149 readonly attribute int attr_both_readonly_difference; | 149 readonly attribute int attr_both_readonly_difference; |
| 150 readonly attribute int attr_both_int_long_difference; | 150 readonly attribute int attr_both_int_long_difference; |
| 151 | 151 |
| 152 int op_only_first(); | 152 int op_only_first(); |
| 153 int op_both(int a); | 153 int op_both(int a); |
| 154 int op_both_optionals_difference(int a, | 154 int op_both_optionals_difference(int a, |
| 155 in optional int b); | 155 in optional int b); |
| 156 int op_both_arg_rename(int arg); | 156 int op_both_arg_rename(int arg); |
| 157 | |
| 158 snippet {FIRST SNIPPET}; | |
| 159 }; | 157 }; |
| 160 };''') | 158 };''') |
| 161 self._builder.import_idl_file(file_name1, | 159 self._builder.import_idl_file(file_name1, |
| 162 DatabaseBuilderOptions(source='1st', | 160 DatabaseBuilderOptions(source='1st', |
| 163 idl_syntax=idlparser.FREMONTCUT_SYNTAX)) | 161 idl_syntax=idlparser.FREMONTCUT_SYNTAX)) |
| 164 file_name2 = self._create_input('input2.idl', ''' | 162 file_name2 = self._create_input('input2.idl', ''' |
| 165 module M { | 163 module M { |
| 166 interface I { | 164 interface I { |
| 167 const int CONST_BOTH = 0; | 165 const int CONST_BOTH = 0; |
| 168 const int CONST_ONLY_SECOND = 0; | 166 const int CONST_ONLY_SECOND = 0; |
| 169 const int CONST_BOTH_DIFFERENT_VALUE = 1; | 167 const int CONST_BOTH_DIFFERENT_VALUE = 1; |
| 170 | 168 |
| 171 readonly attribute int attr_only_second; | 169 readonly attribute int attr_only_second; |
| 172 readonly attribute int attr_both; | 170 readonly attribute int attr_both; |
| 173 readonly attribute long attr_both_int_long_difference; | 171 readonly attribute long attr_both_int_long_difference; |
| 174 attribute int attr_both_readonly_difference; | 172 attribute int attr_both_readonly_difference; |
| 175 | 173 |
| 176 int op_only_second(); | 174 int op_only_second(); |
| 177 int op_both(int a); | 175 int op_both(int a); |
| 178 int op_both_optionals_difference(int a, | 176 int op_both_optionals_difference(int a, |
| 179 optional boolean b); | 177 optional boolean b); |
| 180 int op_both_arg_rename(int betterName); | 178 int op_both_arg_rename(int betterName); |
| 181 | |
| 182 snippet {SECOND SNIPPET}; | |
| 183 }; | 179 }; |
| 184 };''') | 180 };''') |
| 185 self._builder.import_idl_file(file_name2, | 181 self._builder.import_idl_file(file_name2, |
| 186 DatabaseBuilderOptions(source='2nd', | 182 DatabaseBuilderOptions(source='2nd', |
| 187 idl_syntax=idlparser.FREMONTCUT_SYNTAX)) | 183 idl_syntax=idlparser.FREMONTCUT_SYNTAX)) |
| 188 self._builder.set_same_signatures({'int': 'long'}) | 184 self._builder.set_same_signatures({'int': 'long'}) |
| 189 self._builder.merge_imported_interfaces() | 185 self._builder.merge_imported_interfaces([]) |
| 190 self._db.Save() | 186 self._db.Save() |
| 191 self._assert_content_equals('I.idl', ''' | 187 self._assert_content_equals('I.idl', ''' |
| 192 @1st(module=M) @2nd(module=M) interface I { | 188 @1st(module=M) @2nd(module=M) interface I { |
| 193 /* Constants */ | 189 /* Constants */ |
| 194 @1st @2nd const int CONST_BOTH = 0; | 190 @1st @2nd const int CONST_BOTH = 0; |
| 195 @1st const int CONST_BOTH_DIFFERENT_VALUE = 0; | 191 @1st const int CONST_BOTH_DIFFERENT_VALUE = 0; |
| 196 @2nd const int CONST_BOTH_DIFFERENT_VALUE = 1; | 192 @2nd const int CONST_BOTH_DIFFERENT_VALUE = 1; |
| 197 @1st const int CONST_ONLY_FIRST = 0; | 193 @1st const int CONST_ONLY_FIRST = 0; |
| 198 @2nd const int CONST_ONLY_SECOND = 0; | 194 @2nd const int CONST_ONLY_SECOND = 0; |
| 199 | 195 |
| 200 /* Attributes */ | 196 /* Attributes */ |
| 201 @1st @2nd getter attribute int attr_both; | 197 @1st @2nd getter attribute int attr_both; |
| 202 @1st @2nd getter attribute int attr_both_int_long_difference; | 198 @1st @2nd getter attribute int attr_both_int_long_difference; |
| 203 @1st @2nd getter attribute int attr_both_readonly_difference; | 199 @1st @2nd getter attribute int attr_both_readonly_difference; |
| 204 @2nd setter attribute int attr_both_readonly_difference; | 200 @2nd setter attribute int attr_both_readonly_difference; |
| 205 @1st getter attribute int attr_only_first; | 201 @1st getter attribute int attr_only_first; |
| 206 @2nd getter attribute int attr_only_second; | 202 @2nd getter attribute int attr_only_second; |
| 207 | 203 |
| 208 /* Operations */ | 204 /* Operations */ |
| 209 @1st @2nd int op_both(in t a); | 205 @1st @2nd int op_both(in t a); |
| 210 @1st @2nd int op_both_arg_rename(in t betterName); | 206 @1st @2nd int op_both_arg_rename(in t betterName); |
| 211 @1st @2nd int op_both_optionals_difference(in t a); | 207 @1st @2nd int op_both_optionals_difference(in t a); |
| 212 @1st int op_both_optionals_difference(in t a, in int b); | 208 @1st int op_both_optionals_difference(in t a, in int b); |
| 213 @2nd int op_both_optionals_difference(in t a, in boolean b); | 209 @2nd int op_both_optionals_difference(in t a, in boolean b); |
| 214 @1st int op_only_first(); | 210 @1st int op_only_first(); |
| 215 @2nd int op_only_second(); | 211 @2nd int op_only_second(); |
| 216 | |
| 217 /* Snippets */ | |
| 218 @1st snippet {FIRST SNIPPET}; | |
| 219 @2nd snippet {SECOND SNIPPET}; | |
| 220 };''') | 212 };''') |
| 221 | 213 |
| 222 def test_mergeDartName(self): | 214 def test_mergeDartName(self): |
| 223 file_name1 = self._create_input('input1.idl', ''' | 215 file_name1 = self._create_input('input1.idl', ''' |
| 224 module M { | 216 module M { |
| 225 interface I { | 217 interface I { |
| 226 [ImplementationFunction=foo] int member(in int a); | 218 [ImplementationFunction=foo] int member(in int a); |
| 227 }; | 219 }; |
| 228 };''') | 220 };''') |
| 229 self._builder.import_idl_file(file_name1, | 221 self._builder.import_idl_file(file_name1, |
| 230 DatabaseBuilderOptions(source='1st', | 222 DatabaseBuilderOptions(source='1st', |
| 231 idl_syntax=idlparser.FREMONTCUT_SYNTAX)) | 223 idl_syntax=idlparser.FREMONTCUT_SYNTAX)) |
| 232 file_name2 = self._create_input('input2.idl', ''' | 224 file_name2 = self._create_input('input2.idl', ''' |
| 233 module M { | 225 module M { |
| 234 interface I { | 226 interface I { |
| 235 [DartName=bar] int member(in int a); | 227 [DartName=bar] int member(in int a); |
| 236 }; | 228 }; |
| 237 };''') | 229 };''') |
| 238 self._builder.import_idl_file(file_name2, | 230 self._builder.import_idl_file(file_name2, |
| 239 DatabaseBuilderOptions(source='2nd', | 231 DatabaseBuilderOptions(source='2nd', |
| 240 idl_syntax=idlparser.FREMONTCUT_SYNTAX)) | 232 idl_syntax=idlparser.FREMONTCUT_SYNTAX)) |
| 241 self._builder.merge_imported_interfaces() | 233 self._builder.merge_imported_interfaces([]) |
| 242 self._db.Save() | 234 self._db.Save() |
| 243 self._assert_content_equals('I.idl', ''' | 235 self._assert_content_equals('I.idl', ''' |
| 244 @1st(module=M) @2nd(module=M) interface I { | 236 @1st(module=M) @2nd(module=M) interface I { |
| 245 /* Operations */ | 237 /* Operations */ |
| 246 @1st @2nd [DartName=bar, ImplementationFunction=foo] int member(in int a
); | 238 @1st @2nd [DartName=bar, ImplementationFunction=foo] int member(in int a
); |
| 247 };''') | 239 };''') |
| 248 | 240 |
| 249 def test_supplemental(self): | 241 def test_supplemental(self): |
| 250 file_name = self._create_input('input1.idl', ''' | 242 file_name = self._create_input('input1.idl', ''' |
| 251 module M { | 243 module M { |
| 252 interface I { | 244 interface I { |
| 253 readonly attribute int a; | 245 readonly attribute int a; |
| 254 }; | 246 }; |
| 255 [Supplemental] interface I { | 247 [Supplemental] interface I { |
| 256 readonly attribute int b; | 248 readonly attribute int b; |
| 257 }; | 249 }; |
| 258 };''') | 250 };''') |
| 259 self._builder.import_idl_file(file_name, | 251 self._builder.import_idl_file(file_name, |
| 260 DatabaseBuilderOptions(source='Src')) | 252 DatabaseBuilderOptions(source='Src')) |
| 261 self._builder.merge_imported_interfaces() | 253 self._builder.merge_imported_interfaces([]) |
| 262 self._db.Save() | 254 self._db.Save() |
| 263 self._assert_content_equals('I.idl', ''' | 255 self._assert_content_equals('I.idl', ''' |
| 264 @Src(module=M) interface I { | 256 @Src(module=M) [Supplemental] interface I { |
| 265 /* Attributes */ | 257 /* Attributes */ |
| 266 @Src getter attribute int a; | 258 @Src getter attribute int a; |
| 267 @Src getter attribute int b; | 259 @Src getter attribute int b; |
| 268 };''') | 260 };''') |
| 269 | 261 |
| 270 def test_impl_stmt(self): | 262 def test_impl_stmt(self): |
| 271 file_name = self._create_input('input.idl', ''' | 263 file_name = self._create_input('input.idl', ''' |
| 272 module M { | 264 module M { |
| 273 interface I {}; | 265 interface I {}; |
| 274 I implements J; | 266 I implements J; |
| 275 };''') | 267 };''') |
| 276 self._builder.import_idl_file(file_name, | 268 self._builder.import_idl_file(file_name, |
| 277 DatabaseBuilderOptions(source='Src')) | 269 DatabaseBuilderOptions(source='Src')) |
| 278 self._builder.merge_imported_interfaces() | 270 self._builder.merge_imported_interfaces([]) |
| 279 self._db.Save() | 271 self._db.Save() |
| 280 self._assert_content_equals('I.idl', ''' | 272 self._assert_content_equals('I.idl', ''' |
| 281 @Src(module=M) interface I : | 273 @Src(module=M) interface I : |
| 282 @Src J { | 274 @Src J { |
| 283 };''') | 275 };''') |
| 284 | 276 |
| 285 def test_obsolete(self): | 277 def test_obsolete(self): |
| 286 file_name1 = self._create_input('input1.idl', ''' | 278 file_name1 = self._create_input('input1.idl', ''' |
| 287 module M { | 279 module M { |
| 288 interface I { | 280 interface I { |
| 289 readonly attribute int keep; | 281 readonly attribute int keep; |
| 290 readonly attribute int obsolete; // Would be removed | 282 readonly attribute int obsolete; // Would be removed |
| 291 }; | 283 }; |
| 292 };''') | 284 };''') |
| 293 self._builder.import_idl_file(file_name1, | 285 self._builder.import_idl_file(file_name1, |
| 294 DatabaseBuilderOptions(source='src')) | 286 DatabaseBuilderOptions(source='src')) |
| 295 file_name2 = self._create_input('input2.idl', ''' | 287 file_name2 = self._create_input('input2.idl', ''' |
| 296 module M { | 288 module M { |
| 297 interface I { | 289 interface I { |
| 298 readonly attribute int keep; | 290 readonly attribute int keep; |
| 299 readonly attribute int new; | 291 readonly attribute int new; |
| 300 }; | 292 }; |
| 301 };''') | 293 };''') |
| 302 self._builder.import_idl_file(file_name2, | 294 self._builder.import_idl_file(file_name2, |
| 303 DatabaseBuilderOptions(source='src', | 295 DatabaseBuilderOptions(source='src', |
| 304 obsolete_old_declarations=True)) | 296 obsolete_old_declarations=True)) |
| 305 self._builder.merge_imported_interfaces() | 297 self._builder.merge_imported_interfaces([]) |
| 306 self._db.Save() | 298 self._db.Save() |
| 307 self._assert_content_equals('I.idl', ''' | 299 self._assert_content_equals('I.idl', ''' |
| 308 @src(module=M) interface I { | 300 @src(module=M) interface I { |
| 309 /* Attributes */ | 301 /* Attributes */ |
| 310 @src getter attribute int keep; | 302 @src getter attribute int keep; |
| 311 @src getter attribute int new; | 303 @src getter attribute int new; |
| 312 };''') | 304 };''') |
| 313 | 305 |
| 314 def test_annotation_normalization(self): | 306 def test_annotation_normalization(self): |
| 315 file_name = self._create_input('input.idl', ''' | 307 file_name = self._create_input('input.idl', ''' |
| 316 module M { | 308 module M { |
| 317 interface I : J{ | 309 interface I : J{ |
| 318 const int C = 0; | 310 const int C = 0; |
| 319 readonly attribute int a; | 311 readonly attribute int a; |
| 320 int op(); | 312 int op(); |
| 321 }; | 313 }; |
| 322 };''') | 314 };''') |
| 323 self._builder.import_idl_file(file_name, | 315 self._builder.import_idl_file(file_name, |
| 324 DatabaseBuilderOptions(source='Src', source_attributes={'x': 'y'})) | 316 DatabaseBuilderOptions(source='Src', source_attributes={'x': 'y'})) |
| 325 self._builder.merge_imported_interfaces() | 317 self._builder.merge_imported_interfaces([]) |
| 326 interface = self._db.GetInterface('I') | 318 interface = self._db.GetInterface('I') |
| 327 interface.parents[0].annotations['Src']['x'] = 'u' | 319 interface.parents[0].annotations['Src']['x'] = 'u' |
| 328 interface.constants[0].annotations['Src']['z'] = 'w' | 320 interface.constants[0].annotations['Src']['z'] = 'w' |
| 329 interface.attributes[0].annotations['Src']['x'] = 'u' | 321 interface.attributes[0].annotations['Src']['x'] = 'u' |
| 330 self._db.Save() | 322 self._db.Save() |
| 331 | 323 |
| 332 # Before normalization | 324 # Before normalization |
| 333 self._assert_content_equals('I.idl', ''' | 325 self._assert_content_equals('I.idl', ''' |
| 334 @Src(module=M, x=y) | 326 @Src(module=M, x=y) |
| 335 interface I : @Src(x=u) J { | 327 interface I : @Src(x=u) J { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 DatabaseBuilderOptions(source='1st')) | 361 DatabaseBuilderOptions(source='1st')) |
| 370 file_name2 = self._create_input('input2.idl', ''' | 362 file_name2 = self._create_input('input2.idl', ''' |
| 371 module M { | 363 module M { |
| 372 interface I { | 364 interface I { |
| 373 readonly attribute int attr; | 365 readonly attribute int attr; |
| 374 }; | 366 }; |
| 375 interface J : I {}; | 367 interface J : I {}; |
| 376 };''') | 368 };''') |
| 377 self._builder.import_idl_file(file_name2, | 369 self._builder.import_idl_file(file_name2, |
| 378 DatabaseBuilderOptions(source='2nd')) | 370 DatabaseBuilderOptions(source='2nd')) |
| 379 self._builder.merge_imported_interfaces() | 371 self._builder.merge_imported_interfaces([]) |
| 380 self._builder.fix_displacements('2nd') | 372 self._builder.fix_displacements('2nd') |
| 381 self._db.Save() | 373 self._db.Save() |
| 382 self._assert_content_equals('J.idl', ''' | 374 self._assert_content_equals('J.idl', ''' |
| 383 @1st(module=M) @2nd(module=M) interface J : | 375 @1st(module=M) @2nd(module=M) interface J : |
| 384 @1st @2nd I { | 376 @1st @2nd I { |
| 385 /* Attributes */ | 377 /* Attributes */ |
| 386 @1st | 378 @1st |
| 387 @2nd(via=I) | 379 @2nd(via=I) |
| 388 getter attribute int attr; | 380 getter attribute int attr; |
| 389 };''') | 381 };''') |
| 390 | 382 |
| 391 | 383 |
| 392 if __name__ == "__main__": | 384 if __name__ == "__main__": |
| 393 logging.config.fileConfig("logging.conf") | 385 logging.config.fileConfig("logging.conf") |
| 394 if __name__ == '__main__': | 386 if __name__ == '__main__': |
| 395 unittest.main() | 387 unittest.main() |
| OLD | NEW |