-
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.
#993. Pointer.elementAt() tests added
- Loading branch information
sgrekhov
committed
Mar 3, 2021
1 parent
ff1eb19
commit 84cad35
Showing
8 changed files
with
247 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,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); | ||
} | ||
} |
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,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); | ||
} | ||
} |
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,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); | ||
} | ||
} |
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,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); | ||
} | ||
} |
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,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); | ||
} | ||
} |
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 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); | ||
} | ||
} |
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 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); | ||
} | ||
} |
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 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); | ||
} | ||
} |