-
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. Array class extensions tests added
- Loading branch information
sgrekhov
committed
Jun 2, 2021
1 parent
ac0b73a
commit 47bae86
Showing
22 changed files
with
538 additions
and
515 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,43 @@ | ||
// 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 ArrayArray<T extends NativeType> extension Null safety | ||
//. Bounds checking indexing methods on Arrays of Array. | ||
/// | ||
/// @description Checks that this extension contains bounds checking indexing | ||
/// methods on Arrays of Array | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class MyStruct extends Struct { | ||
@Array(2, 3) | ||
external Array<Array<Int16>> a0; | ||
@Array.multi([2, 3]) | ||
external Array<Array<Int16>> a1; | ||
} | ||
|
||
void main() { | ||
final pointer = calloc<MyStruct>(); | ||
try { | ||
final array = pointer.ref.a0; | ||
for (int i = 0; i < 2; i++) { | ||
for (int j = 0; j < 2; j++) { | ||
array[i][j] = 42; | ||
Expect.equals(42, array[i][j]); | ||
} | ||
} | ||
final array2 = pointer.ref.a1; | ||
for (int i = 0; i < 2; i++) { | ||
for (int j = 0; j < 2; j++) { | ||
array2[i][j] = 42; | ||
Expect.equals(42, array2[i][j]); | ||
} | ||
} | ||
} finally { | ||
calloc.free(pointer); | ||
} | ||
} |
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,40 @@ | ||
// 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 ArrayArray<T extends NativeType> extension Null safety | ||
//. Bounds checking indexing methods on Arrays of Array. | ||
/// | ||
/// @description Checks that this extension contains bounds checking indexing | ||
/// methods on Arrays of Array | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class MyStruct extends Struct { | ||
@Array(2, 3) | ||
external Array<Array<Int16>> a0; | ||
@Array.multi([2, 3]) | ||
external Array<Array<Int16>> a1; | ||
} | ||
|
||
void main() { | ||
final pointer = calloc<MyStruct>(); | ||
try { | ||
final array1 = pointer.ref.a0; | ||
Expect.throws(() {array1[3][0];}); | ||
Expect.throws(() {array1[3][0] = 42;}); | ||
Expect.throws(() {array1[0][3];}); | ||
Expect.throws(() {array1[0][3] = 42;}); | ||
|
||
final array2 = pointer.ref.a1; | ||
Expect.throws(() {array2[3][0];}); | ||
Expect.throws(() {array2[3][0] = 42;}); | ||
Expect.throws(() {array2[0][3];}); | ||
Expect.throws(() {array2[0][3] = 42;}); | ||
} finally { | ||
calloc.free(pointer); | ||
} | ||
} |
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,41 @@ | ||
// 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 | ||
/// const Array<T extends NativeType>( | ||
/// int dimension1, | ||
/// [int dimension2, | ||
/// int dimension3, | ||
/// int dimension4, | ||
/// int dimension5] | ||
/// ) | ||
/// Const constructor to specify Array dimensions in Structs. | ||
/// | ||
/// class MyStruct extends Struct { | ||
/// @Array(8) | ||
/// external Array<Uint8> inlineArray; | ||
/// | ||
/// @Array(2, 2, 2) | ||
/// external Array<Array<Array<Uint8>>> threeDimensionalInlineArray; | ||
/// } | ||
/// Do not invoke in normal code. | ||
/// | ||
/// @description Checks that it is a compile error if Array annotation has a | ||
/// wrong dimension | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
|
||
class MyStruct extends Struct { | ||
@Array(2) | ||
//^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
external Array<Array<Int16>> a0; | ||
} | ||
|
||
void main() { | ||
MyStruct ms; | ||
} |
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
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
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
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
Oops, something went wrong.