Skip to content

Commit

Permalink
#993. co19 ffi tests. Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Feb 3, 2021
1 parent d65b0fc commit 06ef7ae
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
24 changes: 24 additions & 0 deletions LibTest/ffi/DartRepresentationOf/DartRepresentationOf_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
* for details. All rights reserved. Use of this source code is governed by a
* BSD-style license that can be found in the LICENSE file.
*/
/**
* @assertion const DartRepresentationOf(String nativeType)
* Represents the Dart type corresponding to a NativeType.
*
* @description Checks that DartRepresentationOf can be created
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../../../Utils/expect.dart";

void main() {
DartRepresentationOf o1 = new DartRepresentationOf("");
Expect.isTrue(o1 is DartRepresentationOf);

DartRepresentationOf o2 = new DartRepresentationOf("double");
Expect.isTrue(o2 is DartRepresentationOf);
Expect.equals("DartRepresentationOf", o2.runtimeType.toString());
}

20 changes: 20 additions & 0 deletions LibTest/ffi/Dart_CObject/Dart_CObject_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
* for details. All rights reserved. Use of this source code is governed by a
* BSD-style license that can be found in the LICENSE file.
*/
/**
* @assertion Dart_CObject()
*
* @description Checks that Dart_CObject can be created
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../../../Utils/expect.dart";

void main() {
Dart_CObject o = new Dart_CObject();
Expect.isTrue(o is Dart_CObject);
Expect.isTrue(o is Opaque);
}

29 changes: 29 additions & 0 deletions LibTest/ffi/DynamicLibrary/DynamicLibrary.open_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
* for details. All rights reserved. Use of this source code is governed by a
* BSD-style license that can be found in the LICENSE file.
*/
/**
* @assertion DynamicLibrary.open(String name)
* Loads a dynamic library file with local visibility.
*
* Throws an ArgumentError if loading the dynamic library fails.
*
* Calling this function multiple times, even in different isolates, returns
* objects which are equal but not identical. The underlying library is only
* loaded once into the DartVM by the OS.
*
* @description Checks that this constructor loads a dynamic library file with
* local visibility
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
String path = libPath("ffi_test_dynamic_library");
DynamicLibrary dl = new DynamicLibrary.open(path);
Expect.isNotNull(dl);
}

24 changes: 24 additions & 0 deletions LibTest/ffi/ffi_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
* for details. All rights reserved. Use of this source code is governed by a
* BSD-style license that can be found in the LICENSE file.
*/
/**
* @description Utils for co19 ffi tests
* @author sgrekhov@unipro.ru
*/
import 'dart:ffi' as ffi;
import 'dart:io' show Platform;

String libPath(String libName, {String path = ""}) {
if (Platform.isLinux || Platform.isAndroid || Platform.isFuchsia)
return path + "lib" + libName + ".so";
if (Platform.isMacOS) return path + "lib" + libName + ".dylib";
if (Platform.isWindows) return path + libName + ".dll";
throw Exception("Platform not implemented");
}

ffi.DynamicLibrary openLibrary(String name, {String path = ""}) {
String fullPath = libPath(name, path: path);
return ffi.DynamicLibrary.open(fullPath);
}

0 comments on commit 06ef7ae

Please sign in to comment.