Skip to content

Commit

Permalink
#993. Array tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Mar 31, 2021
1 parent e5b0950 commit 1f471ad
Show file tree
Hide file tree
Showing 9 changed files with 440 additions and 2 deletions.
92 changes: 92 additions & 0 deletions LibTest/ffi/Array/Array.multi_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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>.multi(List<int> dimensions)
* Const constructor to specify Array dimensions in Structs.
*
* class MyStruct extends Struct {
* @Array.multi([2, 2, 2])
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
*
* @Array.multi([2, 2, 2, 2, 2, 2, 2, 2])
* external Array<Array<Array<Array<Array<Array<Array<Array<Uint8>>>>>>>> eightDimensionalInlineArray;
* }
* Do not invoke in normal code.
*
* @description Checks multidimentional array created by Array.multi()
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

class MyStruct extends Struct {
@Array.multi([1, 2, 3, 4, 5, 6])
external Array<Array<Array<Array<Array<Array<Uint8>>>>>> a0;
}

void main() {
final pointer = calloc<MyStruct>();
try {
final array = pointer.ref.a0;

for (int i1 = 0; i1 < 1; i1++) {
for (int i2 = 0; i2 < 2; i2++) {
for (int i3 = 0; i3 < 3; i3++) {
for (int i4 = 0; i4 < 4; i4++) {
for (int i5 = 0; i5 < 5; i5++) {
for (int i6 = 0; i6 < 5; i6++) {
Expect.equals(0, array[i1][i2][i3][i4][i5][i6]);
array[i1][i2][i3][i4][i5][i6] = i1 + i2 + i3 + i4 + i5 + i6;
Expect.equals(
i1 + i2 + i3 + i4 + i5 + i6, array[i1][i2][i3][i4][i5][i6]);
}
}
}
}
}
}
Expect.throws(() {
array[-1];
});
Expect.throws(() {
array[1];
});
Expect.throws(() {
array[0][-1];
});
Expect.throws(() {
array[0][2];
});
Expect.throws(() {
array[0][1][-1];
});
Expect.throws(() {
array[0][1][3];
});
Expect.throws(() {
array[0][0][0][-1];
});
Expect.throws(() {
array[0][1][2][4];
});
Expect.throws(() {
array[0][0][0][0][-1];
});
Expect.throws(() {
array[0][1][2][3][5];
});
Expect.throws(() {
array[0][0][0][0][0][-1];
});
Expect.throws(() {
array[0][1][2][3][4][6];
});
} finally {
calloc.free(pointer);
}
}
42 changes: 42 additions & 0 deletions LibTest/ffi/Array/Array.multi_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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>.multi(List<int> dimensions)
* Const constructor to specify Array dimensions in Structs.
*
* class MyStruct extends Struct {
* @Array.multi([2, 2, 2])
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
*
* @Array.multi([2, 2, 2, 2, 2, 2, 2, 2])
* external Array<Array<Array<Array<Array<Array<Array<Array<Uint8>>>>>>>> eightDimensionalInlineArray;
* }
* Do not invoke in normal code.
*
* @description Checks multidimentional array created by Array.multi(). Check
* wrong array size
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";

class MyStruct extends Struct {
@Array.multi([])
//^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe]
external Array<Int16> a0;

@Array.multi([1])
//^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe]
external Array<Array<Int16>> a1;
}

void main() {
MyStruct? ms = null;
}
51 changes: 51 additions & 0 deletions LibTest/ffi/Array/Array.multi_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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>.multi(List<int> dimensions)
* Const constructor to specify Array dimensions in Structs.
*
* class MyStruct extends Struct {
* @Array.multi([2, 2, 2])
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
*
* @Array.multi([2, 2, 2, 2, 2, 2, 2, 2])
* external Array<Array<Array<Array<Array<Array<Array<Array<Uint8>>>>>>>> eightDimensionalInlineArray;
* }
* Do not invoke in normal code.
*
* @description Checks multidimentional array created by Array.multi(). Check
* not literal argument
* @author sgrekhov@unipro.ru
* @issue 45537
*/
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

const arr = [3, 1];

class MyStruct extends Struct {
@Array.multi(arr)
external Array<Array<Int8>> a0;
}

void main() {
final pointer = calloc<MyStruct>();
try {
final array = pointer.ref.a0;

for (int i1 = 0; i1 < 3; i1++) {
for (int i2 = 0; i2 < 1; i2++) {
Expect.equals(0, array[i1][i2]);
array[i1][i2] = i1 + i2;
Expect.equals(i1 + i2, array[i1][i2]);
}
}
} finally {
calloc.free(pointer);
}
}
37 changes: 37 additions & 0 deletions LibTest/ffi/Array/Array.multi_A01_t05.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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>.multi(List<int> dimensions)
* Const constructor to specify Array dimensions in Structs.
*
* class MyStruct extends Struct {
* @Array.multi([2, 2, 2])
* external Array<Array<Array<Uint8>>> threeDimensionalInlineArray;
*
* @Array.multi([2, 2, 2, 2, 2, 2, 2, 2])
* external Array<Array<Array<Array<Array<Array<Array<Array<Uint8>>>>>>>> eightDimensionalInlineArray;
* }
* Do not invoke in normal code.
*
* @description Checks multidimentional array created by Array.multi(). Check
* negative array size
* @author sgrekhov@unipro.ru
* @issue 45538
*/
import "dart:ffi";

class MyStruct extends Struct {
@Array.multi([-1])
//^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
external Array<Uint8> a0;
}

void main() {
MyStruct? ms = null;
}
17 changes: 16 additions & 1 deletion LibTest/ffi/Array/Array_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@
*/
/**
* @assertion
* const Array<T extends NativeType>(int dimension1)
* 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 this class represents a fixed-size array of T
* @author sgrekhov@unipro.ru
*/
Expand Down
17 changes: 16 additions & 1 deletion LibTest/ffi/Array/Array_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,24 @@
*/
/**
* @assertion
* const Array<T extends NativeType>(int dimension1)
* 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 this class controls array boundaries
* @author sgrekhov@unipro.ru
*/
Expand Down
89 changes: 89 additions & 0 deletions LibTest/ffi/Array/Array_A03_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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 multidimentional array
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

class MyStruct extends Struct {
@Array(1, 2, 3, 4, 5)
external Array<Array<Array<Array<Array<Uint8>>>>> a0;
}

void main() {
final pointer = calloc<MyStruct>();
try {
final array = pointer.ref.a0;

for (int i1 = 0; i1 < 1; i1++) {
for (int i2 = 0; i2 < 2; i2++) {
for (int i3 = 0; i3 < 3; i3++) {
for (int i4 = 0; i4 < 4; i4++) {
for (int i5 = 0; i5 < 5; i5++) {
Expect.equals(0, array[i1][i2][i3][i4][i5]);
array[i1][i2][i3][i4][i5] = i1 + i2 + i3 + i4 + i5;
Expect.equals(i1 + i2 + i3 + i4 + i5, array[i1][i2][i3][i4][i5]);
}
}
}
}
}
Expect.throws(() {
array[-1];
});
Expect.throws(() {
array[1];
});
Expect.throws(() {
array[0][-1];
});
Expect.throws(() {
array[0][2];
});
Expect.throws(() {
array[0][1][-1];
});
Expect.throws(() {
array[0][1][3];
});
Expect.throws(() {
array[0][0][0][-1];
});
Expect.throws(() {
array[0][1][2][4];
});
Expect.throws(() {
array[0][0][0][0][-1];
});
Expect.throws(() {
array[0][1][2][3][5];
});
} finally {
calloc.free(pointer);
}
}

0 comments on commit 1f471ad

Please sign in to comment.