Skip to content

Commit e3e7029

Browse files
author
sgrekhov
committed
Fixes #993. DoublePointer tests added for FFI library
1 parent 99bb9f1 commit e3e7029

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Float64List asTypedList(int length)
6+
/// Creates a typed list view backed by memory in the address space.
7+
///
8+
/// The returned view will allow access to the memory range from address to
9+
/// address + 8 * length.
10+
///
11+
/// The user has to ensure the memory range is accessible while using the
12+
/// returned list.
13+
///
14+
/// @description Check that this getter/setter works as designed
15+
/// @author [email protected]
16+
17+
import "dart:ffi";
18+
import 'dart:typed_data';
19+
import "package:ffi/ffi.dart";
20+
import '../../../Utils/expect.dart';
21+
22+
void main() {
23+
Pointer<Double> p = calloc<Double>(3);
24+
p[0] = 3.14;
25+
p[1] = 42.42;
26+
p[2] = 1.1;
27+
Float64List l = p.asTypedList(3);
28+
Expect.equals(3.14, l[0]);
29+
Expect.equals(42.42, l[1]);
30+
Expect.equals(1.1, l[2]);
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion double value
6+
/// The double at address.
7+
///
8+
/// The address must be 8-byte aligned.
9+
///
10+
/// @description Check that this getter/setter works as designed
11+
/// @author [email protected]
12+
13+
import "dart:ffi";
14+
import "package:ffi/ffi.dart";
15+
import '../../../Utils/expect.dart';
16+
17+
void main() {
18+
Pointer<Double> p = calloc<Double>();
19+
Expect.equals(0, p.value);
20+
p.value = 3.14;
21+
Expect.equals(3.14, p.value);
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion double operator [](int index)
6+
/// The double at address + 8 * index.
7+
///
8+
/// The address must be 8-byte aligned.
9+
///
10+
/// @description Check that operator [](int index) returns double at
11+
/// address + 8 * index.
12+
/// @author [email protected]
13+
14+
import "dart:ffi";
15+
import 'dart:typed_data';
16+
import "package:ffi/ffi.dart";
17+
import '../../../Utils/expect.dart';
18+
19+
void main() {
20+
Pointer<Double> p1 = calloc<Double>(2);
21+
Pointer<Double> p2 = new Pointer.fromAddress(p1.address + sizeOf<Double>());
22+
p1.value = 1.1;
23+
p2.value = 3.14;
24+
Expect.equals(1.1, p1[0]);
25+
Expect.equals(3.14, p1[1]);
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion void operator []=(int index, double value)
6+
/// The double at address + 8 * index.
7+
///
8+
/// The address must be 8-byte aligned.
9+
///
10+
/// @description Check that operator [](int index) returns double at
11+
/// address + 8 * index.
12+
/// @author [email protected]
13+
14+
import "dart:ffi";
15+
import 'dart:typed_data';
16+
import "package:ffi/ffi.dart";
17+
import '../../../Utils/expect.dart';
18+
19+
void main() {
20+
Pointer<Double> p1 = calloc<Double>(2);
21+
Pointer<Double> p2 = new Pointer.fromAddress(p1.address + sizeOf<Double>());
22+
p1[0] = 1.1;
23+
p1[1] = 3.14;
24+
Expect.equals(1.1, p1[0]);
25+
Expect.equals(3.14, p1[1]);
26+
Expect.equals(3.14, p2.value);
27+
}

0 commit comments

Comments
 (0)