|
| 1 | +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:ffigen/ffigen.dart'; |
| 6 | +import 'package:ffigen/src/code_generator.dart'; |
| 7 | +import 'package:ffigen/src/strings.dart' as strings; |
| 8 | +import 'package:yaml/yaml.dart' as yaml; |
| 9 | +import 'package:test/test.dart'; |
| 10 | + |
| 11 | +import '../test_utils.dart'; |
| 12 | + |
| 13 | +late Library actual, expected; |
| 14 | + |
| 15 | +void main() { |
| 16 | + group('packed_struct_override_test', () { |
| 17 | + test('Invalid Packed Config values', () { |
| 18 | + const baseYaml = '''${strings.name}: 'NativeLibrary' |
| 19 | +${strings.description}: 'Compiler Opts Test' |
| 20 | +${strings.output}: 'unused' |
| 21 | +${strings.headers}: |
| 22 | + ${strings.entryPoints}: |
| 23 | + - 'test/header_parser_tests/packed_structs.h' |
| 24 | +${strings.structs}: |
| 25 | + ${strings.structPacking}: |
| 26 | + '''; |
| 27 | + expect( |
| 28 | + () => Config.fromYaml( |
| 29 | + yaml.loadYaml(baseYaml + "'.*': null") as yaml.YamlMap), |
| 30 | + throwsA(TypeMatcher<FormatException>())); |
| 31 | + expect( |
| 32 | + () => Config.fromYaml( |
| 33 | + yaml.loadYaml(baseYaml + "'.*': 3") as yaml.YamlMap), |
| 34 | + throwsA(TypeMatcher<FormatException>())); |
| 35 | + expect( |
| 36 | + () => Config.fromYaml( |
| 37 | + yaml.loadYaml(baseYaml + "'.*': 32") as yaml.YamlMap), |
| 38 | + throwsA(TypeMatcher<FormatException>())); |
| 39 | + }); |
| 40 | + test('Override values', () { |
| 41 | + final config = Config.fromYaml(yaml.loadYaml(''' |
| 42 | +${strings.name}: 'NativeLibrary' |
| 43 | +${strings.description}: 'Compiler Opts Test' |
| 44 | +${strings.output}: 'unused' |
| 45 | +${strings.headers}: |
| 46 | + ${strings.entryPoints}: |
| 47 | + - 'test/header_parser_tests/packed_structs.h' |
| 48 | +${strings.structs}: |
| 49 | + ${strings.structPacking}: |
| 50 | + 'Normal.*': 1 |
| 51 | + 'StructWithAttr': 2 |
| 52 | + 'PackedAttr': none |
| 53 | + ''') as yaml.YamlMap); |
| 54 | + |
| 55 | + final library = parse(config); |
| 56 | + |
| 57 | + expect((library.getBinding('NormalStruct1') as Struc).pack, 1); |
| 58 | + expect((library.getBinding('StructWithAttr') as Struc).pack, 2); |
| 59 | + expect((library.getBinding('PackedAttr') as Struc).pack, null); |
| 60 | + }); |
| 61 | + }); |
| 62 | +} |
0 commit comments