Skip to content

Commit

Permalink
#993. Pointer.elementAt() tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Mar 3, 2021
1 parent ff1eb19 commit 84cad35
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 0 deletions.
28 changes: 28 additions & 0 deletions LibTest/ffi/Pointer/elementAt_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 Pointer<T> elementAt(int index)
* Pointer arithmetic (takes element size into account).
* This method must be invoked with a compile-time constant T.
* Does not accept dynamic invocations -- where the type of the receiver is
* dynamic.
*
* @description Checks that this method implements pointer arithmetic
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<IntPtr> p1 = calloc<IntPtr>(3);
try {
Expect.isTrue(p1.elementAt(1).address - p1.address == 4 ||
p1.elementAt(2).address - p1.elementAt(1).address == 8);
} finally {
calloc.free(p1);
}
}
28 changes: 28 additions & 0 deletions LibTest/ffi/Pointer/elementAt_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 Pointer<T> elementAt(int index)
* Pointer arithmetic (takes element size into account).
* This method must be invoked with a compile-time constant T.
* Does not accept dynamic invocations -- where the type of the receiver is
* dynamic.
*
* @description Checks that this method implements pointer arithmetic
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Pointer<Int8>> p1 = calloc<Pointer<Int8>>(3);
try {
Expect.isTrue(p1.elementAt(1).address - p1.address == 4 ||
p1.elementAt(2).address - p1.elementAt(1).address == 8);
} finally {
calloc.free(p1);
}
}
34 changes: 34 additions & 0 deletions LibTest/ffi/Pointer/elementAt_A01_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 Pointer<T> elementAt(int index)
* Pointer arithmetic (takes element size into account).
* This method must be invoked with a compile-time constant T.
* Does not accept dynamic invocations -- where the type of the receiver is
* dynamic.
*
* @description Checks that this method implements pointer arithmetic
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

class MyStruct extends Struct {
@Int8()
external int x;
@Float()
external double y;
}

void main() {
Pointer<MyStruct> p1 = calloc<MyStruct>(2);
try {
Expect.isTrue(p1.elementAt(1).address - p1.elementAt(0).address > 0);
} finally {
calloc.free(p1);
}
}
32 changes: 32 additions & 0 deletions LibTest/ffi/Pointer/elementAt_A02_t02.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 Pointer<T> elementAt(int index)
* Pointer arithmetic (takes element size into account).
* This method must be invoked with a compile-time constant T.
* Does not accept dynamic invocations -- where the type of the receiver is
* dynamic.
*
* @description Checks that this method must be invoked with a compile-time
* constant T
* @author sgrekhov@unipro.ru
* @issue 45149
*/
import "dart:ffi";
import '../ffi_utils.dart';

void main() {
Pointer<Int64> p1 = calloc<Int64>(3);
try {
Pointer<Opaque> p2 = new Pointer.fromAddress(p1.address);
p2.elementAt(1);
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
} finally {
calloc.free(p1);
}
}
32 changes: 32 additions & 0 deletions LibTest/ffi/Pointer/elementAt_A02_t03.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 Pointer<T> elementAt(int index)
* Pointer arithmetic (takes element size into account).
* This method must be invoked with a compile-time constant T.
* Does not accept dynamic invocations -- where the type of the receiver is
* dynamic.
*
* @description Checks that this method must be invoked with a compile-time
* constant T
* @author sgrekhov@unipro.ru
* @issue 45150
*/
import "dart:ffi";
import '../ffi_utils.dart';

void main() {
Pointer<Int64> p1 = calloc<Int64>(3);
try {
Pointer<Handle> p2 = new Pointer.fromAddress(p1.address);
p2.elementAt(1);
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
} finally {
calloc.free(p1);
}
}
31 changes: 31 additions & 0 deletions LibTest/ffi/Pointer/elementAt_A02_t04.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 Pointer<T> elementAt(int index)
* Pointer arithmetic (takes element size into account).
* This method must be invoked with a compile-time constant T.
* Does not accept dynamic invocations -- where the type of the receiver is
* dynamic.
*
* @description Checks that this method must be invoked with a compile-time
* constant T
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';

void main() {
Pointer<Int64> p1 = calloc<Int64>(3);
try {
Pointer<Array<Int8>> p2 = new Pointer.fromAddress(p1.address);
p2.elementAt(1);
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
} finally {
calloc.free(p1);
}
}
31 changes: 31 additions & 0 deletions LibTest/ffi/Pointer/elementAt_A02_t05.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 Pointer<T> elementAt(int index)
* Pointer arithmetic (takes element size into account).
* This method must be invoked with a compile-time constant T.
* Does not accept dynamic invocations -- where the type of the receiver is
* dynamic.
*
* @description Checks that this method must be invoked with a compile-time
* constant T
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';

void main() {
Pointer<Int64> p1 = calloc<Int64>(3);
try {
Pointer<NativeType> p2 = new Pointer.fromAddress(p1.address);
p2.elementAt(1);
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
} finally {
calloc.free(p1);
}
}
31 changes: 31 additions & 0 deletions LibTest/ffi/Pointer/elementAt_A02_t06.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 Pointer<T> elementAt(int index)
* Pointer arithmetic (takes element size into account).
* This method must be invoked with a compile-time constant T.
* Does not accept dynamic invocations -- where the type of the receiver is
* dynamic.
*
* @description Checks that this method must be invoked with a compile-time
* constant T
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';

void main() {
Pointer<Int64> p1 = calloc<Int64>(3);
try {
Pointer<NativeFunction> p2 = new Pointer.fromAddress(p1.address);
p2.elementAt(1);
// ^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
} finally {
calloc.free(p1);
}
}

0 comments on commit 84cad35

Please sign in to comment.