-
Notifications
You must be signed in to change notification settings - Fork 28
#993. [FFI] Missed tests added for some new types #1386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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) 2022, 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 The C int type. | ||
/// | ||
/// Typically a signed 32-bit integer. For a guaranteed 32-bit integer, use | ||
/// [Int32] with the C int32_t type. For an unsigned int, use [UnsignedInt]. | ||
/// | ||
/// The [Int] type is a native type, and should not be constructed in Dart code. | ||
/// It occurs only in native type signatures and as annotation on [Struct] and | ||
/// [Union] fields. | ||
/// | ||
/// @description Checks that this type represents C int type. | ||
/// @author [email protected] | ||
|
||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Int> p1 = calloc<Int>(); | ||
try { | ||
p1.value = 42; | ||
Expect.equals(42, p1.value); | ||
p1.value = -42; | ||
Expect.equals(-42, p1.value); | ||
p1.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p1.value = -32768; | ||
Expect.equals(-32768, p1.value); | ||
p1.value = 2147483647; | ||
Expect.equals(2147483647, p1.value); | ||
p1.value = 2147483648; | ||
Expect.equals(-2147483648, p1.value); | ||
p1.value = -2147483649; | ||
Expect.equals(2147483647, p1.value); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains hidden or 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) 2022, 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 The C int type. | ||
/// | ||
/// Typically a signed 32-bit integer. For a guaranteed 32-bit integer, use | ||
/// [Int32] with the C int32_t type. For an unsigned int, use [UnsignedInt]. | ||
/// | ||
/// The [Int] type is a native type, and should not be constructed in Dart code. | ||
/// It occurs only in native type signatures and as annotation on [Struct] and | ||
/// [Union] fields. | ||
/// | ||
/// @description Checks that this type represents C int type. | ||
/// @author [email protected] | ||
|
||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Int> p1 = calloc<Int>(); | ||
Pointer<Uint32> p2 = new Pointer<Uint32>.fromAddress(p1.address); | ||
try { | ||
p2.value = 42; | ||
Expect.equals(42, p1.value); | ||
p2.value = -42; | ||
Expect.equals(-42, p1.value); | ||
p2.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p2.value = -32768; | ||
Expect.equals(-32768, p1.value); | ||
p2.value = 0x7FFFFFFF; | ||
Expect.equals(2147483647, p1.value); | ||
p2.value = 2147483648; | ||
Expect.equals(-2147483648, p1.value); | ||
p2.value = -2147483649; | ||
Expect.equals(2147483647, p1.value); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains hidden or 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,29 @@ | ||
// Copyright (c) 2022, 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 The C int type. | ||
/// | ||
/// Typically a signed 32-bit integer. For a guaranteed 32-bit integer, use | ||
/// [Int32] with the C int32_t type. For an unsigned int, use [UnsignedInt]. | ||
/// | ||
/// The [Int] type is a native type, and should not be constructed in Dart code. | ||
/// It occurs only in native type signatures and as annotation on [Struct] and | ||
/// [Union] fields. | ||
/// | ||
/// @description Checks that this type represents a signed 32-bit integer | ||
/// @author [email protected] | ||
|
||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Int> p1 = calloc<Int>(2); | ||
try { | ||
Expect.equals(4, p1.elementAt(1).address - p1.address); | ||
Expect.equals(4, sizeOf<Int>()); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains hidden or 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,35 @@ | ||
// Copyright (c) 2022, 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 The C size_t type. | ||
/// | ||
/// The [Size] type is a native type, and should not be constructed in Dart | ||
/// code. It occurs only in native type signatures and as annotation on [Struct] | ||
/// and [Union] fields. | ||
/// | ||
/// @description Checks that this type represents C size_t type and is big | ||
/// enough to contain the size of the biggest object the host system can handle | ||
/// @author [email protected] | ||
|
||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Size> p1 = calloc<Size>(); | ||
try { | ||
p1.value = 42; | ||
Expect.equals(42, p1.value); | ||
p1.value = -42; | ||
Expect.equals(-42, p1.value); | ||
p1.value = 0xFFFFFFFF; // max 32-bit | ||
Expect.equals(0xFFFFFFFF, p1.value); | ||
if (sizeOf<IntPtr>() == 8) { // 64-bit system | ||
p1.value = 0xFFFFFFFFFFFFFFFF; | ||
Expect.equals(0xFFFFFFFFFFFFFFFF, p1.value); | ||
} | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains hidden or 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,21 @@ | ||
// Copyright (c) 2022, 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 The C size_t type. | ||
/// | ||
/// The [Size] type is a native type, and should not be constructed in Dart | ||
/// code. It occurs only in native type signatures and as annotation on [Struct] | ||
/// and [Union] fields. | ||
/// | ||
/// @description Checks that this type represents C size_t type and is big | ||
/// enough to contain the size of the biggest object the host system can handle | ||
/// @author [email protected] | ||
|
||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Expect.equals(sizeOf<IntPtr>(), sizeOf<Size>()); | ||
} |
This file contains hidden or 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) 2022, 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 The C uintptr_t type. | ||
/// | ||
/// The [UintPtr] type is a native type, and should not be constructed in Dart | ||
/// code. It occurs only in native type signatures and as annotation on [Struct] | ||
/// and [Union] fields. | ||
/// | ||
/// @description Checks that this represents C uintptr_t type | ||
/// @author [email protected] | ||
|
||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<UintPtr> p1 = calloc<UintPtr>(); | ||
try { | ||
p1.value = 42; | ||
Expect.equals(42, p1.value); | ||
p1.value = 256; | ||
Expect.equals(256, p1.value); | ||
p1.value = 32767; | ||
Expect.equals(32767, p1.value); | ||
p1.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p1.value = 0x7FFFFFFF; | ||
Expect.equals(2147483647, p1.value); | ||
p1.value = 0x80000000; // 2147483648 | ||
Expect.equals(2147483648, p1.value); | ||
if (sizeOf<UintPtr>() == 4) { | ||
p1.value = -42; | ||
Expect.equals(4294967254, p1.value); | ||
p1.value = -32769; | ||
Expect.equals(4294934527, p1.value); | ||
p1.value = -2147483649; | ||
Expect.equals(2147483647, p1.value); | ||
} else { | ||
p1.value = -42; | ||
Expect.equals(-42, p1.value); | ||
p1.value = -32769; | ||
Expect.equals(-32769, p1.value); | ||
p1.value = -2147483649; // 0xFFFFFFFF7FFFFFFF | ||
Expect.equals(-2147483649, p1.value); | ||
} | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains hidden or 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,62 @@ | ||
// Copyright (c) 2022, 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 The C uintptr_t type. | ||
/// | ||
/// The [UintPtr] type is a native type, and should not be constructed in Dart | ||
/// code. It occurs only in native type signatures and as annotation on [Struct] | ||
/// and [Union] fields. | ||
/// | ||
/// @description Checks that this represents C uintptr_t type | ||
/// @author [email protected] | ||
|
||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<UintPtr> p1 = calloc<UintPtr>(); | ||
try { | ||
if (sizeOf<UintPtr>() == 4) { | ||
Pointer<IntPtr> p2 = new Pointer<IntPtr>.fromAddress(p1.address); | ||
p2.value = 42; | ||
Expect.equals(42, p1.value); | ||
p2.value = -42; | ||
Expect.equals(-42, p1.value); | ||
p2.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p2.value = -32768; | ||
Expect.equals(-32768, p1.value); | ||
p2.value = 0x7FFFFFFF; | ||
Expect.equals(2147483647, p1.value); | ||
p2.value = 2147483648; | ||
Expect.equals(-2147483648, p1.value); | ||
p2.value = -2147483649; | ||
Expect.equals(2147483647, p1.value); | ||
} else { | ||
Pointer<Int64> p2 = new Pointer<Int64>.fromAddress(p1.address); | ||
Expect.equals(0, p1.value); | ||
p2.value = 42; | ||
Expect.equals(42, p1.value); | ||
p2.value = -42; | ||
Expect.equals(-42, p1.value); | ||
p2.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p2.value = -32768; | ||
Expect.equals(-32768, p1.value); | ||
p2.value = 2147483648; | ||
Expect.equals(2147483648, p1.value); | ||
p2.value = -2147483649; | ||
Expect.equals(-2147483649, p1.value); | ||
p2.value = 0x7FFFFFFFFFFFFFFF; | ||
Expect.equals(9223372036854775807, p1.value); | ||
p2.value = 0xFFFFFFFFFFFFFFFF; | ||
Expect.equals(-1, p1.value); | ||
p2.value = -9223372036854775808; | ||
Expect.equals(-9223372036854775808, p1.value); | ||
} | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains hidden or 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,30 @@ | ||
// Copyright (c) 2022, 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 The C uintptr_t type. | ||
/// | ||
/// The [UintPtr] type is a native type, and should not be constructed in Dart | ||
/// code. It occurs only in native type signatures and as annotation on [Struct] | ||
/// and [Union] fields. | ||
/// | ||
/// @description Checks that this represents C uintptr_t type | ||
/// @author [email protected] | ||
|
||
import "dart:ffi"; | ||
import 'package:ffi/ffi.dart'; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<UintPtr> p1 = calloc<UintPtr>(2); | ||
try { | ||
if (sizeOf<UintPtr>() == 4) { | ||
Expect.equals(4, p1.elementAt(1).address - p1.address); | ||
} else { | ||
Expect.equals(8, p1.elementAt(1).address - p1.address); | ||
Expect.equals(8, sizeOf<UintPtr>()); | ||
} | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains hidden or 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,31 @@ | ||
// Copyright (c) 2022, 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 The C unsigned char type. | ||
/// | ||
/// Typically an unsigned 8-bit integer. For a guaranteed 8-bit integer, use | ||
/// [Uint8] with the C uint8_t type. For a signed char, use [SignedChar]. | ||
/// | ||
/// The [UnsignedChar] type is a native type, and should not be constructed in | ||
/// Dart code. It occurs only in native type signatures and as annotation on | ||
/// [Struct] and [Union] fields. | ||
/// | ||
/// @description Checks that this type represents C unsigned char type. | ||
/// @author [email protected] | ||
|
||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<UnsignedChar> p1 = calloc<UnsignedChar>(); | ||
try { | ||
p1.value = 42; | ||
Expect.equals(42, p1.value); | ||
p1.value = -42; | ||
Expect.equals(214, p1.value); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
This file contains hidden or 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) 2022, 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 The C unsigned char type. | ||
/// | ||
/// Typically an unsigned 8-bit integer. For a guaranteed 8-bit integer, use | ||
/// [Uint8] with the C uint8_t type. For a signed char, use [SignedChar]. | ||
/// | ||
/// The [UnsignedChar] type is a native type, and should not be constructed in | ||
/// Dart code. It occurs only in native type signatures and as annotation on | ||
/// [Struct] and [Union] fields. | ||
/// | ||
/// @description Checks that this type represents C unsigned char type. | ||
/// @author [email protected] | ||
|
||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<UnsignedChar> p1 = calloc<UnsignedChar>(); | ||
Pointer<Int8> p2 = new Pointer<Int8>.fromAddress(p1.address); | ||
try { | ||
p2.value = 0; | ||
Expect.equals(0, p1.value); | ||
p2.value = 1; | ||
Expect.equals(1, p1.value); | ||
p2.value = 127; | ||
Expect.equals(127, p1.value); | ||
p2.value = 128; | ||
Expect.equals(128, p1.value); | ||
p2.value = 255; | ||
Expect.equals(255, p1.value); | ||
p2.value = 256; | ||
Expect.equals(0, p1.value); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.