-
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.
- Loading branch information
Sergey G. Grekhov
committed
Feb 12, 2021
1 parent
8920358
commit d45cb88
Showing
5 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
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
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
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,25 @@ | ||
/* | ||
* 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 Struct() | ||
* Construct a reference to the nullptr. | ||
* | ||
* @description Checks that this constructor constructs a reference to the | ||
* nullptr. | ||
* @author sgrekhov@unipro.ru | ||
* @issue 44987 | ||
*/ | ||
import "dart:ffi"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class S1 extends Struct { | ||
S1() : super(); | ||
} | ||
|
||
void main() { | ||
S1 s1 = new S1(); | ||
Expect.equals(nullptr.address, s1.addressOf.address); | ||
} |
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,50 @@ | ||
/* | ||
* 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 Struct() | ||
* The supertype of all FFI struct types. | ||
* | ||
* FFI struct types should extend this class and declare fields corresponding | ||
* to the underlying native structure. | ||
* | ||
* @description Checks that FFI struct types should extend this class and | ||
* declare fields corresponding to the underlying native structure | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class Coord extends Struct { | ||
@Double() | ||
external double x; | ||
@Double() | ||
external double y; | ||
|
||
external Pointer<Coord> next; | ||
} | ||
|
||
// Native C function | ||
typedef TransposeCoordinateCFunc = Pointer<Coord> Function(Pointer<Coord>); | ||
// Dart function | ||
typedef TransposeCoordinateDartFunc = Pointer<Coord> Function(Pointer<Coord>); | ||
|
||
void main() { | ||
final dl = new DynamicLibrary.open(libPath(TEST_FUNCTIONS_LIB)); | ||
final TransposeCoordinateDartFunc f = dl | ||
.lookup<NativeFunction<TransposeCoordinateCFunc>>('TransposeCoordinate') | ||
.asFunction(); | ||
Pointer<Coord> c1 = calloc<Coord>(); | ||
try { | ||
c1.ref.x = 1; | ||
c1.ref.y = 2; | ||
f(c1); | ||
Expect.equals(11, c1.ref.x); | ||
Expect.equals(12, c1.ref.y); | ||
} finally { | ||
calloc.free(c1); | ||
} | ||
} |
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,54 @@ | ||
/* | ||
* 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 Struct() | ||
* The supertype of all FFI struct types. | ||
* | ||
* FFI struct types should extend this class and declare fields corresponding | ||
* to the underlying native structure. | ||
* | ||
* @description Checks that FFI struct types should extend this class and | ||
* declare fields corresponding to the underlying native structure. Test | ||
* nullable Struct subtype members | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class Coord extends Struct { | ||
Coord() : super(); | ||
|
||
@Double() | ||
external double? x; | ||
@Double() | ||
external double? y; | ||
|
||
external Pointer<Coord>? next; | ||
} | ||
|
||
// Native C function | ||
typedef TransposeCoordinateCFunc = Pointer<Coord> Function(Pointer<Coord>); | ||
// Dart function | ||
typedef TransposeCoordinateDartFunc = Pointer<Coord> Function(Pointer<Coord>); | ||
|
||
void main() { | ||
final dl = new DynamicLibrary.open(libPath(TEST_FUNCTIONS_LIB)); | ||
final TransposeCoordinateDartFunc f = dl | ||
.lookup<NativeFunction<TransposeCoordinateCFunc>>('TransposeCoordinate') | ||
.asFunction(); | ||
Coord c = new Coord(); | ||
Pointer<Coord> c1 = calloc<Coord>(); | ||
try { | ||
c1.ref.x = 1; | ||
c1.ref.y = 2; | ||
f(c1); | ||
Expect.equals(11, c1.ref.x); | ||
Expect.equals(12, c1.ref.y); | ||
} finally { | ||
calloc.free(c1); | ||
} | ||
} |