Skip to content

Commit

Permalink
Fixes #993. DoublePointer tests added for FFI library
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Jul 29, 2021
1 parent 99bb9f1 commit e3e7029
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
31 changes: 31 additions & 0 deletions LibTest/ffi/Pointer/DoublePointer.asTypedList_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 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]);
}
22 changes: 22 additions & 0 deletions LibTest/ffi/Pointer/DoublePointer.value_t01.dart
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);
}
26 changes: 26 additions & 0 deletions LibTest/ffi/Pointer/DoublePointer_A01_t01.dart
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]);
}
27 changes: 27 additions & 0 deletions LibTest/ffi/Pointer/DoublePointer_A02_t01.dart
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);
}

0 comments on commit e3e7029

Please sign in to comment.