-
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.
- Loading branch information
sgrekhov
committed
Apr 1, 2021
1 parent
459bf70
commit 6e40133
Showing
26 changed files
with
664 additions
and
28 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,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.
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,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.
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
File renamed without changes.
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
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); | ||
} | ||
} |
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
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); | ||
} | ||
} |
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
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); | ||
} | ||
} |
Oops, something went wrong.