-
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.
Fixes #993. DoublePointer tests added for FFI library
- Loading branch information
sgrekhov
committed
Jul 29, 2021
1 parent
99bb9f1
commit e3e7029
Showing
4 changed files
with
106 additions
and
0 deletions.
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
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 Float64List asTypedList(int length) | ||
/// Creates a typed list view backed by memory in the address space. | ||
/// | ||
/// The returned view will allow access to the memory range from address to | ||
/// address + 8 * length. | ||
/// | ||
/// The user has to ensure the memory range is accessible while using the | ||
/// returned list. | ||
/// | ||
/// @description Check that this getter/setter works as designed | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import 'dart:typed_data'; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Double> p = calloc<Double>(3); | ||
p[0] = 3.14; | ||
p[1] = 42.42; | ||
p[2] = 1.1; | ||
Float64List l = p.asTypedList(3); | ||
Expect.equals(3.14, l[0]); | ||
Expect.equals(42.42, l[1]); | ||
Expect.equals(1.1, l[2]); | ||
} |
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,22 @@ | ||
// 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 double value | ||
/// The double at address. | ||
/// | ||
/// The address must be 8-byte aligned. | ||
/// | ||
/// @description Check that this getter/setter works as designed | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Double> p = calloc<Double>(); | ||
Expect.equals(0, p.value); | ||
p.value = 3.14; | ||
Expect.equals(3.14, p.value); | ||
} |
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,26 @@ | ||
// 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 double operator [](int index) | ||
/// The double at address + 8 * index. | ||
/// | ||
/// The address must be 8-byte aligned. | ||
/// | ||
/// @description Check that operator [](int index) returns double at | ||
/// address + 8 * index. | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import 'dart:typed_data'; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Double> p1 = calloc<Double>(2); | ||
Pointer<Double> p2 = new Pointer.fromAddress(p1.address + sizeOf<Double>()); | ||
p1.value = 1.1; | ||
p2.value = 3.14; | ||
Expect.equals(1.1, p1[0]); | ||
Expect.equals(3.14, p1[1]); | ||
} |
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,27 @@ | ||
// 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 void operator []=(int index, double value) | ||
/// The double at address + 8 * index. | ||
/// | ||
/// The address must be 8-byte aligned. | ||
/// | ||
/// @description Check that operator [](int index) returns double at | ||
/// address + 8 * index. | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import 'dart:typed_data'; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Double> p1 = calloc<Double>(2); | ||
Pointer<Double> p2 = new Pointer.fromAddress(p1.address + sizeOf<Double>()); | ||
p1[0] = 1.1; | ||
p1[1] = 3.14; | ||
Expect.equals(1.1, p1[0]); | ||
Expect.equals(3.14, p1[1]); | ||
Expect.equals(3.14, p2.value); | ||
} |