-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#993. co19 ffi tests. Initial commit
- Loading branch information
sgrekhov
committed
Feb 3, 2021
1 parent
d65b0fc
commit 06ef7ae
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
LibTest/ffi/DartRepresentationOf/DartRepresentationOf_A01_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
LibTest/ffi/DynamicLibrary/DynamicLibrary.open_A01_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |