-
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
Sergey G. Grekhov
committed
Mar 4, 2021
1 parent
7978676
commit 07d91ec
Showing
15 changed files
with
635 additions
and
0 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,33 @@ | ||
/* | ||
* 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) | ||
* Const constructor to specify Array dimensions in Structs. | ||
* | ||
* @description Checks that this class represents a fixed-size array of T | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.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++) { | ||
Expect.equals(0, array[i]); | ||
} | ||
} 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) | ||
* Const constructor to specify Array dimensions in Structs. | ||
* | ||
* @description Checks that this class controls array boundaries | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.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); | ||
} | ||
} |
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,36 @@ | ||
/* | ||
* 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) | ||
* Const constructor to specify Array dimensions in Structs. | ||
* | ||
* @description Checks that this class represents a fixed-size array of Double | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class MyStruct extends Struct { | ||
@Array(2) | ||
external Array<Double> a0; | ||
} | ||
|
||
void main() { | ||
final pointer = calloc<MyStruct>(); | ||
try { | ||
final array = pointer.ref.a0; | ||
for (int i = 0; i < 2; i++) { | ||
array[i] = 3.14; | ||
Expect.approxEquals(3.14, array[i]); | ||
array[i] = -3.14; | ||
Expect.approxEquals(-3.14, array[i]); | ||
} | ||
} 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,36 @@ | ||
/* | ||
* 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) | ||
* Const constructor to specify Array dimensions in Structs. | ||
* | ||
* @description Checks that this class represents a fixed-size array of Float | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class MyStruct extends Struct { | ||
@Array(2) | ||
external Array<Float> a0; | ||
} | ||
|
||
void main() { | ||
final pointer = calloc<MyStruct>(); | ||
try { | ||
final array = pointer.ref.a0; | ||
for (int i = 0; i < 2; i++) { | ||
array[i] = 3.14; | ||
Expect.approxEquals(3.14, array[i]); | ||
array[i] = -3.14; | ||
Expect.approxEquals(-3.14, array[i]); | ||
} | ||
} 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,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>(int dimension1) | ||
* Const constructor to specify Array dimensions in Structs. | ||
* | ||
* @description Checks that this class represents a fixed-size array of Int16 | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class MyStruct extends Struct { | ||
@Array(2) | ||
external Array<Int16> a0; | ||
} | ||
|
||
void main() { | ||
final pointer = calloc<MyStruct>(); | ||
try { | ||
final array = pointer.ref.a0; | ||
for (int i = 0; i < 2; i++) { | ||
array[i] = i + 1; | ||
Expect.equals(i + 1, array[i]); | ||
array[i] = 32767; | ||
Expect.equals(32767, array[i]); | ||
array[i] = 32768; | ||
Expect.equals(-32768, array[i]); | ||
array[i] = -32768; | ||
Expect.equals(-32768, array[i]); | ||
array[i] = -32769; | ||
Expect.equals(32767, array[i]); | ||
} | ||
} 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,46 @@ | ||
/* | ||
* 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) | ||
* Const constructor to specify Array dimensions in Structs. | ||
* | ||
* @description Checks that this class represents a fixed-size array of Int32 | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class MyStruct extends Struct { | ||
@Array(2) | ||
external Array<Int32> a0; | ||
} | ||
|
||
void main() { | ||
final pointer = calloc<MyStruct>(); | ||
try { | ||
final array = pointer.ref.a0; | ||
for (int i = 0; i < 2; i++) { | ||
array[i] = 42; | ||
Expect.equals(42, array[i]); | ||
array[i] = -42; | ||
Expect.equals(-42, array[i]); | ||
array[i] = 32768; | ||
Expect.equals(32768, array[i]); | ||
array[i] = -32768; | ||
Expect.equals(-32768, array[i]); | ||
array[i] = 2147483647; | ||
Expect.equals(2147483647, array[i]); | ||
array[i] = 2147483648; | ||
Expect.equals(-2147483648, array[i]); | ||
array[i] = -2147483649; | ||
Expect.equals(2147483647, array[i]); | ||
} | ||
} 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,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>(int dimension1) | ||
* Const constructor to specify Array dimensions in Structs. | ||
* | ||
* @description Checks that this class represents a fixed-size array of Int64 | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class MyStruct extends Struct { | ||
@Array(2) | ||
external Array<Int64> a0; | ||
} | ||
|
||
void main() { | ||
final pointer = calloc<MyStruct>(); | ||
try { | ||
final array = pointer.ref.a0; | ||
for (int i = 0; i < 2; i++) { | ||
Expect.equals(0, array[i]); | ||
array[i] = 42; | ||
Expect.equals(42, array[i]); | ||
array[i] = -42; | ||
Expect.equals(-42, array[i]); | ||
array[i] = 32768; | ||
Expect.equals(32768, array[i]); | ||
array[i] = -32768; | ||
Expect.equals(-32768, array[i]); | ||
array[i] = 2147483648; | ||
Expect.equals(2147483648, array[i]); | ||
array[i] = -2147483649; | ||
Expect.equals(-2147483649, array[i]); | ||
array[i] = 0x7FFFFFFFFFFFFFFF; | ||
Expect.equals(9223372036854775807, array[i]); | ||
array[i] = 0xFFFFFFFFFFFFFFFF; | ||
Expect.equals(-1, array[i]); | ||
array[i] = -9223372036854775808; | ||
Expect.equals(-9223372036854775808, array[i]); | ||
} | ||
} 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 | ||
* const Array<T extends NativeType>(int dimension1) | ||
* Const constructor to specify Array dimensions in Structs. | ||
* | ||
* @description Checks that this class represents a fixed-size array of Int8 | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class MyStruct extends Struct { | ||
@Array(2) | ||
external Array<Int8> a0; | ||
} | ||
|
||
void main() { | ||
final pointer = calloc<MyStruct>(); | ||
try { | ||
final array = pointer.ref.a0; | ||
for (int i = 0; i < 2; i++) { | ||
array[i] = i + 1; | ||
Expect.equals(i + 1, array[i]); | ||
array[i] = 127; | ||
Expect.equals(127, array[i]); | ||
array[i] = 128; | ||
Expect.equals(-128, array[i]); | ||
array[i] = -129; | ||
Expect.equals(127, array[i]); | ||
} | ||
} 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,54 @@ | ||
/* | ||
* 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) | ||
* Const constructor to specify Array dimensions in Structs. | ||
* | ||
* @description Checks that this class represents a fixed-size array of IntPtr | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
class MyStruct extends Struct { | ||
@Array(2) | ||
external Array<IntPtr> a0; | ||
} | ||
|
||
void main() { | ||
final pointer = calloc<MyStruct>(); | ||
try { | ||
final array = pointer.ref.a0; | ||
for (int i = 0; i < 2; i++) { | ||
Expect.equals(0, array[i]); | ||
array[i] = 42; | ||
Expect.equals(42, array[i]); | ||
array[i] = -42; | ||
Expect.equals(-42, array[i]); | ||
array[i] = 256; | ||
Expect.equals(256, array[i]); | ||
array[i] = 32767; | ||
Expect.equals(32767, array[i]); | ||
if (sizeOf<IntPtr>() == 4) { | ||
array[i] = 32768; | ||
Expect.equals(-32768, array[i]); | ||
array[i] = -32768; | ||
Expect.equals(-32768, array[i]); | ||
array[i] = -32769; | ||
Expect.equals(32767, array[i]); | ||
} else { | ||
array[i] = 32768; | ||
Expect.equals(32768, array[i]); | ||
array[i] = -32769; | ||
Expect.equals(-32769, array[i]); | ||
} | ||
} | ||
} finally { | ||
calloc.free(pointer); | ||
} | ||
} |
Oops, something went wrong.