Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
Update test expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Sep 29, 2023
1 parent 15ebe89 commit 2d984b5
Show file tree
Hide file tree
Showing 8 changed files with 492 additions and 28 deletions.
1 change: 1 addition & 0 deletions example/c_json/cjson_generated_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ final class cJSON_Hooks extends ffi.Struct {
}

typedef cJSON_bool = ffi.Int;
typedef cJSON_bool_dart = int;

const int CJSON_VERSION_MAJOR = 1;

Expand Down
465 changes: 465 additions & 0 deletions example/libclang-example/generated_bindings.dart

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/src/code_generator/typealias.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class Typealias extends BindingType {
final typeString =
_useFfiDartType ? type.getFfiDartType(w) : type.getCType(w);
final dartTypeString = type.getDartType(w);
if (_dartAliasName == null && typeString != dartTypeString) {
if (_dartAliasName == null && type is! Typealias &&
typeString != dartTypeString) {
_dartAliasName = w.topLevelUniqueNamer.makeUnique('${name}_dart');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class NativeLibrary {

typedef Typedef1 = ffi.Pointer<ffi.NativeFunction<Typedef1_function>>;
typedef Typedef1_function = ffi.Void Function(ffi.Handle);
typedef Typedef1_function_dart = void Function(Object);

final class Struct1 extends ffi.Opaque {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ typedef WithTypedefReturnType_function = InsideReturnType Function();
typedef InsideReturnType
= ffi.Pointer<ffi.NativeFunction<InsideReturnType_function>>;
typedef InsideReturnType_function = ffi.Void Function();
typedef InsideReturnType_function_dart = void Function();

final class Struct2 extends ffi.Struct {
external VoidFuncPointer constFuncPointer;
Expand All @@ -86,3 +87,4 @@ final class Struct2 extends ffi.Struct {
typedef VoidFuncPointer
= ffi.Pointer<ffi.NativeFunction<VoidFuncPointer_function>>;
typedef VoidFuncPointer_function = ffi.Void Function();
typedef VoidFuncPointer_function_dart = void Function();
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ final class S extends ffi.Struct {
typedef ArithmeticOperation
= ffi.Pointer<ffi.NativeFunction<ArithmeticOperation_function>>;
typedef ArithmeticOperation_function = ffi.Int Function(ffi.Int a, ffi.Int b);
typedef ArithmeticOperation_function_dart = int Function(int a, int b);
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ final class Struct1 extends ffi.Struct {
typedef NamedFunctionProto
= ffi.Pointer<ffi.NativeFunction<NamedFunctionProto_function>>;
typedef NamedFunctionProto_function = ffi.Void Function();
typedef NamedFunctionProto_function_dart = void Function();

final class AnonymousStructInTypedef extends ffi.Opaque {}

Expand All @@ -113,6 +114,7 @@ abstract class _NamedEnumInTypedef {
}

typedef NestingASpecifiedType = ffi.IntPtr;
typedef NestingASpecifiedType_dart = int;

final class Struct2 extends ffi.Opaque {}

Expand Down
45 changes: 18 additions & 27 deletions test/regen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:args/args.dart';
Expand All @@ -18,12 +19,15 @@ e.g. with this command:
$ dart run test/setup.dart && dart run test/regen.dart && dart test
''';

Future<void> _regenConfig(File yamlConfig, File bindingOutput) async {
yamlConfig = yamlConfig.absolute;
bindingOutput = bindingOutput.absolute;
final config = testConfigFromPath(yamlConfig.path);
final library = parse(config);
library.generateFile(bindingOutput);
Future<void> _regenConfig(
String yamlConfigPath, String bindingOutputPath) async {
final yamlConfig = File(yamlConfigPath).absolute;
final bindingOutput = File(bindingOutputPath).absolute;
await withChDir(yamlConfig.path, () {
final config = testConfigFromPath(yamlConfig.path);
final library = parse(config);
library.generateFile(bindingOutput);
});
}

Future<void> main(List<String> args) async {
Expand All @@ -50,25 +54,12 @@ Future<void> main(List<String> args) async {
print('${record.level.name}: ${record.time}: ${record.message}');
});

final nativeTestConfig = File('test/native_test/config.yaml').absolute;
final nativeTestOut =
File('test/native_test/_expected_native_test_bindings.dart').absolute;
await withChDir(nativeTestConfig.path,
() => _regenConfig(nativeTestConfig, nativeTestOut));

final libclangConfig = File('example/libclang-example/config.yaml').absolute;
final libclangOut =
File('example/libclang-example/generated_bindings.dart').absolute;
await withChDir(
libclangConfig.path, () => _regenConfig(libclangConfig, libclangOut));

final simpleConfig = File('example/simple/config.yaml').absolute;
final simpleOut = File('example/simple/generated_bindings.dart').absolute;
await withChDir(
simpleConfig.path, () => _regenConfig(simpleConfig, simpleOut));

final cJsonConfig = File('example/c_json/config.yaml').absolute;
final cJsonOut =
File('example/c_json/cjson_generated_bindings.dart').absolute;
await withChDir(cJsonConfig.path, () => _regenConfig(cJsonConfig, cJsonOut));
await _regenConfig('test/native_test/config.yaml',
'test/native_test/_expected_native_test_bindings.dart');
await _regenConfig('example/libclang-example/config.yaml',
'example/libclang-example/generated_bindings.dart');
await _regenConfig(
'example/simple/config.yaml', 'example/simple/generated_bindings.dart');
await _regenConfig('example/c_json/config.yaml',
'example/c_json/cjson_generated_bindings.dart');
}

0 comments on commit 2d984b5

Please sign in to comment.