Skip to content

Commit

Permalink
#993. More Array tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Apr 1, 2021
1 parent 459bf70 commit 6e40133
Show file tree
Hide file tree
Showing 26 changed files with 664 additions and 28 deletions.
44 changes: 44 additions & 0 deletions LibTest/ffi/Array/Array.multi_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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
* zero array size
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "package:ffi/ffi.dart";

class MyStruct extends Struct {
@Array.multi([0, 1])
external Array<Array<Int8>> a0;

@Array(0, 1, 0, 1)
external Array<Array<Array<Array<Int8>>>> a1;
}

void main() {
final pointer = calloc<MyStruct>();
try {
pointer.ref.a0;
pointer.ref.a1;
} finally {
calloc.free(pointer);
}
}

File renamed without changes.
56 changes: 56 additions & 0 deletions LibTest/ffi/Array/Array_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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 this class controls array boundaries
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

class MyStruct extends Struct {
@Array(8)
external Array<Uint8> a0;
}

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

for (int i = 0; i < 8; i++) {
array[i] = i + 1;
Expect.equals(i + 1, array[i]);
}
Expect.throws(() {
array[-1];
});
Expect.throws(() {
array[8];
});
} finally {
calloc.free(pointer);
}
}
File renamed without changes.
File renamed without changes.
18 changes: 3 additions & 15 deletions LibTest/ffi/Array/Array_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,21 @@
* }
* Do not invoke in normal code.
*
* @description Checks that this class controls array boundaries
* @description Checks that it is allowed to create array with zero size
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

class MyStruct extends Struct {
@Array(8)
@Array(0)
external Array<Uint8> a0;
}

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

for (int i = 0; i < 8; i++) {
array[i] = i + 1;
Expect.equals(i + 1, array[i]);
}
Expect.throws(() {
array[-1];
});
Expect.throws(() {
array[8];
});
pointer.ref.a0;
} finally {
calloc.free(pointer);
}
Expand Down
File renamed without changes.
17 changes: 16 additions & 1 deletion LibTest/ffi/Array/DoubleArray_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 Double
* @author sgrekhov@unipro.ru
*/
Expand Down
53 changes: 53 additions & 0 deletions LibTest/ffi/Array/DoubleArray_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 this class represents a fixed-size array of Double
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

class MyStruct extends Struct {
@Array.multi([2, 3])
external Array<Array<Double>> a0;
}

void main() {
final pointer = calloc<MyStruct>();
try {
final array = pointer.ref.a0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
array[i][j] = 3.14;
Expect.approxEquals(3.14, array[i][j]);
array[i][j] = -3.14;
Expect.approxEquals(-3.14, array[i][j]);
}
}
} finally {
calloc.free(pointer);
}
}
17 changes: 16 additions & 1 deletion LibTest/ffi/Array/FloatArray_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 Float
* @author sgrekhov@unipro.ru
*/
Expand Down
53 changes: 53 additions & 0 deletions LibTest/ffi/Array/FloatArray_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 this class represents a fixed-size array of Float
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

class MyStruct extends Struct {
@Array.multi([2, 3])
external Array<Array<Float>> a0;
}

void main() {
final pointer = calloc<MyStruct>();
try {
final array = pointer.ref.a0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
array[i][j] = 3.14;
Expect.approxEquals(3.14, array[i][j]);
array[i][j] = -3.14;
Expect.approxEquals(-3.14, array[i][j]);
}
}
} finally {
calloc.free(pointer);
}
}
17 changes: 16 additions & 1 deletion LibTest/ffi/Array/Int16Array_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 Int16
* @author sgrekhov@unipro.ru
*/
Expand Down
59 changes: 59 additions & 0 deletions LibTest/ffi/Array/Int16Array_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 this class represents a fixed-size array of Int16
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

class MyStruct extends Struct {
@Array.multi([1, 2])
external Array<Array<Int16>> a0;
}

void main() {
final pointer = calloc<MyStruct>();
try {
final array = pointer.ref.a0;
for (int i = 0; i < 1; i++) {
for (int j = 0; j < 2; j++) {
array[i][j] = i + j + 1;
Expect.equals(i + j + 1, array[i][j]);
array[i][j] = 32767;
Expect.equals(32767, array[i][j]);
array[i][j] = 32768;
Expect.equals(-32768, array[i][j]);
array[i][j] = -32768;
Expect.equals(-32768, array[i][j]);
array[i][j] = -32769;
Expect.equals(32767, array[i][j]);
}
}
} finally {
calloc.free(pointer);
}
}

0 comments on commit 6e40133

Please sign in to comment.