Skip to content

Commit 1f471ad

Browse files
author
sgrekhov
committed
#993. Array tests added
1 parent e5b0950 commit 1f471ad

9 files changed

+440
-2
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion
8+
* const Array<T extends NativeType>.multi(List<int> dimensions)
9+
* Const constructor to specify Array dimensions in Structs.
10+
*
11+
* class MyStruct extends Struct {
12+
* @Array.multi([2, 2, 2])
13+
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
14+
*
15+
* @Array.multi([2, 2, 2, 2, 2, 2, 2, 2])
16+
* external Array<Array<Array<Array<Array<Array<Array<Array<Uint8>>>>>>>> eightDimensionalInlineArray;
17+
* }
18+
* Do not invoke in normal code.
19+
*
20+
* @description Checks multidimentional array created by Array.multi()
21+
22+
*/
23+
import "dart:ffi";
24+
import "package:ffi/ffi.dart";
25+
import "../../../Utils/expect.dart";
26+
27+
class MyStruct extends Struct {
28+
@Array.multi([1, 2, 3, 4, 5, 6])
29+
external Array<Array<Array<Array<Array<Array<Uint8>>>>>> a0;
30+
}
31+
32+
void main() {
33+
final pointer = calloc<MyStruct>();
34+
try {
35+
final array = pointer.ref.a0;
36+
37+
for (int i1 = 0; i1 < 1; i1++) {
38+
for (int i2 = 0; i2 < 2; i2++) {
39+
for (int i3 = 0; i3 < 3; i3++) {
40+
for (int i4 = 0; i4 < 4; i4++) {
41+
for (int i5 = 0; i5 < 5; i5++) {
42+
for (int i6 = 0; i6 < 5; i6++) {
43+
Expect.equals(0, array[i1][i2][i3][i4][i5][i6]);
44+
array[i1][i2][i3][i4][i5][i6] = i1 + i2 + i3 + i4 + i5 + i6;
45+
Expect.equals(
46+
i1 + i2 + i3 + i4 + i5 + i6, array[i1][i2][i3][i4][i5][i6]);
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
Expect.throws(() {
54+
array[-1];
55+
});
56+
Expect.throws(() {
57+
array[1];
58+
});
59+
Expect.throws(() {
60+
array[0][-1];
61+
});
62+
Expect.throws(() {
63+
array[0][2];
64+
});
65+
Expect.throws(() {
66+
array[0][1][-1];
67+
});
68+
Expect.throws(() {
69+
array[0][1][3];
70+
});
71+
Expect.throws(() {
72+
array[0][0][0][-1];
73+
});
74+
Expect.throws(() {
75+
array[0][1][2][4];
76+
});
77+
Expect.throws(() {
78+
array[0][0][0][0][-1];
79+
});
80+
Expect.throws(() {
81+
array[0][1][2][3][5];
82+
});
83+
Expect.throws(() {
84+
array[0][0][0][0][0][-1];
85+
});
86+
Expect.throws(() {
87+
array[0][1][2][3][4][6];
88+
});
89+
} finally {
90+
calloc.free(pointer);
91+
}
92+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion
8+
* const Array<T extends NativeType>.multi(List<int> dimensions)
9+
* Const constructor to specify Array dimensions in Structs.
10+
*
11+
* class MyStruct extends Struct {
12+
* @Array.multi([2, 2, 2])
13+
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
14+
*
15+
* @Array.multi([2, 2, 2, 2, 2, 2, 2, 2])
16+
* external Array<Array<Array<Array<Array<Array<Array<Array<Uint8>>>>>>>> eightDimensionalInlineArray;
17+
* }
18+
* Do not invoke in normal code.
19+
*
20+
* @description Checks multidimentional array created by Array.multi(). Check
21+
* wrong array size
22+
23+
*/
24+
import "dart:ffi";
25+
26+
class MyStruct extends Struct {
27+
@Array.multi([])
28+
//^^^^^^^^^^^^^^^^
29+
// [analyzer] unspecified
30+
// [cfe]
31+
external Array<Int16> a0;
32+
33+
@Array.multi([1])
34+
//^^^^^^^^^^^^^^^^
35+
// [analyzer] unspecified
36+
// [cfe]
37+
external Array<Array<Int16>> a1;
38+
}
39+
40+
void main() {
41+
MyStruct? ms = null;
42+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion
8+
* const Array<T extends NativeType>.multi(List<int> dimensions)
9+
* Const constructor to specify Array dimensions in Structs.
10+
*
11+
* class MyStruct extends Struct {
12+
* @Array.multi([2, 2, 2])
13+
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
14+
*
15+
* @Array.multi([2, 2, 2, 2, 2, 2, 2, 2])
16+
* external Array<Array<Array<Array<Array<Array<Array<Array<Uint8>>>>>>>> eightDimensionalInlineArray;
17+
* }
18+
* Do not invoke in normal code.
19+
*
20+
* @description Checks multidimentional array created by Array.multi(). Check
21+
* not literal argument
22+
23+
* @issue 45537
24+
*/
25+
import "dart:ffi";
26+
import "package:ffi/ffi.dart";
27+
import "../../../Utils/expect.dart";
28+
29+
const arr = [3, 1];
30+
31+
class MyStruct extends Struct {
32+
@Array.multi(arr)
33+
external Array<Array<Int8>> a0;
34+
}
35+
36+
void main() {
37+
final pointer = calloc<MyStruct>();
38+
try {
39+
final array = pointer.ref.a0;
40+
41+
for (int i1 = 0; i1 < 3; i1++) {
42+
for (int i2 = 0; i2 < 1; i2++) {
43+
Expect.equals(0, array[i1][i2]);
44+
array[i1][i2] = i1 + i2;
45+
Expect.equals(i1 + i2, array[i1][i2]);
46+
}
47+
}
48+
} finally {
49+
calloc.free(pointer);
50+
}
51+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion
8+
* const Array<T extends NativeType>.multi(List<int> dimensions)
9+
* Const constructor to specify Array dimensions in Structs.
10+
*
11+
* class MyStruct extends Struct {
12+
* @Array.multi([2, 2, 2])
13+
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
14+
*
15+
* @Array.multi([2, 2, 2, 2, 2, 2, 2, 2])
16+
* external Array<Array<Array<Array<Array<Array<Array<Array<Uint8>>>>>>>> eightDimensionalInlineArray;
17+
* }
18+
* Do not invoke in normal code.
19+
*
20+
* @description Checks multidimentional array created by Array.multi(). Check
21+
* negative array size
22+
23+
* @issue 45538
24+
*/
25+
import "dart:ffi";
26+
27+
class MyStruct extends Struct {
28+
@Array.multi([-1])
29+
//^^^^^^^^^^^^^^^^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
external Array<Uint8> a0;
33+
}
34+
35+
void main() {
36+
MyStruct? ms = null;
37+
}

LibTest/ffi/Array/Array_A01_t01.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@
55
*/
66
/**
77
* @assertion
8-
* const Array<T extends NativeType>(int dimension1)
8+
* const Array<T extends NativeType>(
9+
* int dimension1,
10+
* [int dimension2,
11+
* int dimension3,
12+
* int dimension4,
13+
* int dimension5]
14+
* )
915
* Const constructor to specify Array dimensions in Structs.
1016
*
17+
* class MyStruct extends Struct {
18+
* @Array(8)
19+
* external Array<Uint8> inlineArray;
20+
*
21+
* @Array(2, 2, 2)
22+
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
23+
* }
24+
* Do not invoke in normal code.
25+
*
1126
* @description Checks that this class represents a fixed-size array of T
1227
1328
*/

LibTest/ffi/Array/Array_A02_t01.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@
55
*/
66
/**
77
* @assertion
8-
* const Array<T extends NativeType>(int dimension1)
8+
* const Array<T extends NativeType>(
9+
* int dimension1,
10+
* [int dimension2,
11+
* int dimension3,
12+
* int dimension4,
13+
* int dimension5]
14+
* )
915
* Const constructor to specify Array dimensions in Structs.
1016
*
17+
* class MyStruct extends Struct {
18+
* @Array(8)
19+
* external Array<Uint8> inlineArray;
20+
*
21+
* @Array(2, 2, 2)
22+
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
23+
* }
24+
* Do not invoke in normal code.
25+
*
1126
* @description Checks that this class controls array boundaries
1227
1328
*/

LibTest/ffi/Array/Array_A03_t01.dart

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion
8+
* const Array<T extends NativeType>(
9+
* int dimension1,
10+
* [int dimension2,
11+
* int dimension3,
12+
* int dimension4,
13+
* int dimension5]
14+
* )
15+
* Const constructor to specify Array dimensions in Structs.
16+
*
17+
* class MyStruct extends Struct {
18+
* @Array(8)
19+
* external Array<Uint8> inlineArray;
20+
*
21+
* @Array(2, 2, 2)
22+
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
23+
* }
24+
* Do not invoke in normal code.
25+
*
26+
* @description Checks multidimentional array
27+
28+
*/
29+
import "dart:ffi";
30+
import "package:ffi/ffi.dart";
31+
import "../../../Utils/expect.dart";
32+
33+
class MyStruct extends Struct {
34+
@Array(1, 2, 3, 4, 5)
35+
external Array<Array<Array<Array<Array<Uint8>>>>> a0;
36+
}
37+
38+
void main() {
39+
final pointer = calloc<MyStruct>();
40+
try {
41+
final array = pointer.ref.a0;
42+
43+
for (int i1 = 0; i1 < 1; i1++) {
44+
for (int i2 = 0; i2 < 2; i2++) {
45+
for (int i3 = 0; i3 < 3; i3++) {
46+
for (int i4 = 0; i4 < 4; i4++) {
47+
for (int i5 = 0; i5 < 5; i5++) {
48+
Expect.equals(0, array[i1][i2][i3][i4][i5]);
49+
array[i1][i2][i3][i4][i5] = i1 + i2 + i3 + i4 + i5;
50+
Expect.equals(i1 + i2 + i3 + i4 + i5, array[i1][i2][i3][i4][i5]);
51+
}
52+
}
53+
}
54+
}
55+
}
56+
Expect.throws(() {
57+
array[-1];
58+
});
59+
Expect.throws(() {
60+
array[1];
61+
});
62+
Expect.throws(() {
63+
array[0][-1];
64+
});
65+
Expect.throws(() {
66+
array[0][2];
67+
});
68+
Expect.throws(() {
69+
array[0][1][-1];
70+
});
71+
Expect.throws(() {
72+
array[0][1][3];
73+
});
74+
Expect.throws(() {
75+
array[0][0][0][-1];
76+
});
77+
Expect.throws(() {
78+
array[0][1][2][4];
79+
});
80+
Expect.throws(() {
81+
array[0][0][0][0][-1];
82+
});
83+
Expect.throws(() {
84+
array[0][1][2][3][5];
85+
});
86+
} finally {
87+
calloc.free(pointer);
88+
}
89+
}

0 commit comments

Comments
 (0)