Skip to content

Commit

Permalink
#993. Int64Pointer tests added for FFI library
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Aug 2, 2021
1 parent bbb26d9 commit fea1468
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 0 deletions.
32 changes: 32 additions & 0 deletions LibTest/ffi/Pointer/Int64Pointer.asTypedList_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 Int64List 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 method returns a typed list view backed by
/// memory in the address space.
/// @author sgrekhov@unipro.ru
import "dart:ffi";
import 'dart:typed_data';
import "package:ffi/ffi.dart";
import '../../../Utils/expect.dart';

void main() {
Pointer<Int64> p = calloc<Int64>(3);
p[0] = 3;
p[1] = 42;
p[2] = -1;
Int64List l = p.asTypedList(3);
Expect.equals(3, l[0]);
Expect.equals(42, l[1]);
Expect.equals(-1, l[2]);
}
20 changes: 20 additions & 0 deletions LibTest/ffi/Pointer/Int64Pointer.value_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 int value
/// The 64-bit two's complement integer at address.
///
/// @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<Int64> p = calloc<Int64>();
Expect.equals(0, p.value);
p.value = 42;
Expect.equals(42, p.value);
}
20 changes: 20 additions & 0 deletions LibTest/ffi/Pointer/Int64Pointer.value_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 int value
/// The 64-bit two's complement integer at address.
///
/// @description Check that a Dart integer is not truncated before being stored
/// @author sgrekhov@unipro.ru
import "dart:ffi";
import "package:ffi/ffi.dart";
import '../../../Utils/expect.dart';

void main() {
Pointer<Int32> p = calloc<Int32>();
Expect.equals(0, p.value);
p.value = 0xFFFFFFFFFFFFFFFF;
Expect.equals(0xFFFFFFFFFFFFFFFF, p.value);
}
25 changes: 25 additions & 0 deletions LibTest/ffi/Pointer/Int64Pointer_A01_t01.dart
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 int operator [](int index)
/// The int at address + 8 * index.
///
/// The 32-bit two's complement integer at address + 8 * index.
///
/// @description Check that operator [](int index) returns int at
/// address + 8 * index.
/// @author sgrekhov@unipro.ru
import "dart:ffi";
import "package:ffi/ffi.dart";
import '../../../Utils/expect.dart';

void main() {
Pointer<Int64> p1 = calloc<Int64>(2);
Pointer<Int64> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int64>());
p1.value = 1;
p2.value = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
}
23 changes: 23 additions & 0 deletions LibTest/ffi/Pointer/Int64Pointer_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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 int operator [](int index)
///
/// The 64-bit two's complement integer at address + 8 * index.
///
/// @description Check that a Dart integer is not truncated before being stored
/// @author sgrekhov@unipro.ru
import "dart:ffi";
import "package:ffi/ffi.dart";
import '../../../Utils/expect.dart';

void main() {
Pointer<Int64> p1 = calloc<Int64>(2);
Pointer<Int64> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int64>());
p1.value = 0xFFFFFFFFFFFFFFFF;
p2.value = 0xFFFFFFFFFFFFFFFF;
Expect.equals(0xFFFFFFFFFFFFFFFF, p1[0]);
Expect.equals(0xFFFFFFFFFFFFFFFF, p1[1]);
}
24 changes: 24 additions & 0 deletions LibTest/ffi/Pointer/Int64Pointer_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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, int value)
/// The 64-bit two's complement integer at address + 8 * index.
///
/// @description Check that operator []=(int index) sets int at
/// address + 8 * index.
/// @author sgrekhov@unipro.ru
import "dart:ffi";
import "package:ffi/ffi.dart";
import '../../../Utils/expect.dart';

void main() {
Pointer<Int64> p1 = calloc<Int64>(2);
Pointer<Int64> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int64>());
p1[0] = 1;
p1[1] = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
Expect.equals(42, p2.value);
}
23 changes: 23 additions & 0 deletions LibTest/ffi/Pointer/Int64Pointer_A02_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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, int value)
/// The 64-bit two's complement integer at address + 8 * index.
///
/// @description Check that a Dart integer is not truncated before being stored
/// @author sgrekhov@unipro.ru
import "dart:ffi";
import "package:ffi/ffi.dart";
import '../../../Utils/expect.dart';

void main() {
Pointer<Int64> p1 = calloc<Int64>(2);
Pointer<Int64> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int64>());
p1[0] = 0xFFFFFFFFFFFFFFFF;
p1[1] = 0xFFFFFFFFFFFFFFFF;
Expect.equals(0xFFFFFFFFFFFFFFFF, p1[0]);
Expect.equals(0xFFFFFFFFFFFFFFFF, p1[1]);
Expect.equals(0xFFFFFFFFFFFFFFFF, p2.value);
}

0 comments on commit fea1468

Please sign in to comment.