Skip to content

Commit

Permalink
#993. DynamicLibrary constructors tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey G. Grekhov committed Feb 4, 2021
1 parent 06ef7ae commit 7473e25
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* 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.
Expand All @@ -21,4 +21,3 @@ void main() {
Expect.isTrue(o2 is DartRepresentationOf);
Expect.equals("DartRepresentationOf", o2.runtimeType.toString());
}

3 changes: 1 addition & 2 deletions LibTest/ffi/Dart_CObject/Dart_CObject_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* 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.
Expand All @@ -17,4 +17,3 @@ void main() {
Expect.isTrue(o is Dart_CObject);
Expect.isTrue(o is Opaque);
}

21 changes: 21 additions & 0 deletions LibTest/ffi/DynamicLibrary/DynamicLibrary.executable_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.executable()
* Creates a dynamic library representing the running executable.
*
* @description Checks that this constructor creates a dynamic library
* representing the running executable
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../../../Utils/expect.dart";

void main() {
DynamicLibrary dl = new DynamicLibrary.executable();
Expect.isNotNull(dl);
Expect.isNotNull(dl.lookup("Dart_Invoke"));
}
5 changes: 2 additions & 3 deletions LibTest/ffi/DynamicLibrary/DynamicLibrary.open_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* 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.
Expand All @@ -22,8 +22,7 @@ import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

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

28 changes: 28 additions & 0 deletions LibTest/ffi/DynamicLibrary/DynamicLibrary.open_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 an ArgumentError if loading the dynamic library
* fails
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Expect.throws(() {
new DynamicLibrary.open("Wrong path");
}, (e) => e is ArgumentError);
}
31 changes: 31 additions & 0 deletions LibTest/ffi/DynamicLibrary/DynamicLibrary.open_A03_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 calling this function multiple times, even in
* different isolates, returns objects which are equal but not identical
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
final path = libPath("ffi_test_dynamic_library");
DynamicLibrary dl1 = new DynamicLibrary.open(path);
DynamicLibrary dl2 = new DynamicLibrary.open(path);
Expect.equals(dl1, dl2);
Expect.isTrue(dl1 == dl2);
Expect.isFalse(identical(dl1, dl2));
}
30 changes: 30 additions & 0 deletions LibTest/ffi/DynamicLibrary/DynamicLibrary.process_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.process()
* Creates a dynamic library holding all global symbols.
*
* Any symbol in a library currently loaded with global visibility (including
* the executable itself) may be resolved in this library.
*
* This feature is not available on Windows, instead an exception is thrown.
*
* @description Checks that this constructor creates a dynamic library
* holding all global symbol
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import 'dart:io' show Platform;
import "../../../Utils/expect.dart";

void main() {
if (!Platform.isWindows) {
DynamicLibrary dl = new DynamicLibrary.process();
Expect.isNotNull(dl);
Expect.isNotNull(dl.lookup("Dart_Invoke"));
Expect.isNotNull(dl.lookup("printf"));
}
}
28 changes: 28 additions & 0 deletions LibTest/ffi/DynamicLibrary/DynamicLibrary.process_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.process()
* Creates a dynamic library holding all global symbols.
*
* Any symbol in a library currently loaded with global visibility (including
* the executable itself) may be resolved in this library.
*
* This feature is not available on Windows, instead an exception is thrown.
*
* @description Checks that this throws an exception on Windows
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import 'dart:io' show Platform;
import "../../../Utils/expect.dart";

void main() {
if (Platform.isWindows) {
Expect.throws(() {
new DynamicLibrary.process();
});
}
}

0 comments on commit 7473e25

Please sign in to comment.