-
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.
#993. 32 and 64-bit integer tests added
- Loading branch information
Sergey G. Grekhov
committed
Feb 19, 2021
1 parent
3bfbaa7
commit 01d84d3
Showing
11 changed files
with
326 additions
and
1 deletion.
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
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,38 @@ | ||
/* | ||
* 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 Represents a native signed 32 bit integer in C. | ||
* | ||
* @description Checks that this type represents a native signed 32 bit integer | ||
* in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Int32> p1 = calloc<Int32>(); | ||
try { | ||
Expect.equals(0, p1.value); | ||
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 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,38 @@ | ||
/* | ||
* 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 Represents a native signed 32 bit integer in C. | ||
* | ||
* @description Checks that this type represents a native signed 32 bit integer | ||
* in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Int32> p1 = calloc<Int32>(); | ||
Pointer<Int64> p2 = new Pointer<Int64>.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 = 2147483647; | ||
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 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,25 @@ | ||
/* | ||
* 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 Represents a native signed 32 bit integer in C. | ||
* | ||
* @description Checks that this type represents a native signed 16 bit integer | ||
* in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Int32> p1 = calloc<Int32>(3); | ||
try { | ||
Expect.equals(4, p1.elementAt(1).address - p1.address); | ||
Expect.equals(4, p1.elementAt(2).address - p1.elementAt(1).address); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
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 Represents a native signed 64 bit integer in C. | ||
* | ||
* @description Checks that this type represents a native signed 64 bit integer | ||
* in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Int64> p1 = calloc<Int64>(); | ||
try { | ||
Expect.equals(0, p1.value); | ||
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 = 2147483648; | ||
Expect.equals(2147483648, p1.value); | ||
p1.value = -2147483649; | ||
Expect.equals(-2147483649, p1.value); | ||
p1.value = 0x7FFFFFFFFFFFFFFF; | ||
Expect.equals(9223372036854775807, p1.value); | ||
p1.value = 0xFFFFFFFFFFFFFFFF; | ||
Expect.equals(-1, p1.value); | ||
p1.value = -9223372036854775808; | ||
Expect.equals(-9223372036854775808, p1.value); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
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,25 @@ | ||
/* | ||
* 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 Represents a native signed 32 bit integer in C. | ||
* | ||
* @description Checks that this type represents a native signed 16 bit integer | ||
* in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Int64> p1 = calloc<Int64>(3); | ||
try { | ||
Expect.equals(8, p1.elementAt(1).address - p1.address); | ||
Expect.equals(8, p1.elementAt(2).address - p1.elementAt(1).address); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
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 Represents a native unsigned 32 bit integer in C. | ||
* | ||
* @description Checks that this type represents a native unsigned 32 bit | ||
* integer in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Uint32> p1 = calloc<Uint32>(); | ||
try { | ||
Expect.equals(0, p1.value); | ||
p1.value = 256; | ||
Expect.equals(256, p1.value); | ||
p1.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p1.value = 65536; | ||
Expect.equals(65536, p1.value); | ||
p1.value = 4294967295; | ||
Expect.equals(4294967295, p1.value); | ||
p1.value = 4294967296; | ||
Expect.equals(0, p1.value); | ||
p1.value = -1; | ||
Expect.equals(4294967295, p1.value); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
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 Represents a native unsigned 32 bit integer in C. | ||
* | ||
* @description Checks that this type represents a native unsigned 32 bit | ||
* integer in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Uint32> p1 = calloc<Uint32>(); | ||
Pointer<Uint64> p2 = new Pointer<Uint64>.fromAddress(p1.address); | ||
try { | ||
p2.value = 256; | ||
Expect.equals(256, p1.value); | ||
p2.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p2.value = 65536; | ||
Expect.equals(65536, p1.value); | ||
p2.value = 4294967295; | ||
Expect.equals(4294967295, p1.value); | ||
p2.value = 4294967296; | ||
Expect.equals(0, p1.value); | ||
p2.value = -1; | ||
Expect.equals(4294967295, p1.value); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
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,25 @@ | ||
/* | ||
* 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 Represents a native unsigned 32 bit integer in C. | ||
* | ||
* @description Checks that this type represents a native unsigned 32 bit | ||
* integer in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Uint32> p1 = calloc<Uint32>(3); | ||
try { | ||
Expect.equals(4, p1.elementAt(1).address - p1.address); | ||
Expect.equals(4, p1.elementAt(2).address - p1.elementAt(1).address); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
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 Represents a native unsigned 64 bit integer in C. | ||
* | ||
* @description Checks that this type represents a native unsigned 64 bit | ||
* integer in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Uint64> p1 = calloc<Uint64>(); | ||
try { | ||
Expect.equals(0, p1.value); | ||
p1.value = 42; | ||
Expect.equals(42, p1.value); | ||
p1.value = 32768; | ||
Expect.equals(32768, p1.value); | ||
p1.value = 2147483648; | ||
Expect.equals(2147483648, p1.value); | ||
p1.value = 0x7FFFFFFFFFFFFFFF; | ||
Expect.equals(0x7FFFFFFFFFFFFFFF, p1.value); | ||
p1.value = 0xFFFFFFFFFFFFFFFF; | ||
Expect.equals(-1, p1.value); | ||
p1.value = -9223372036854775808; | ||
Expect.equals(-9223372036854775808, p1.value); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |
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,25 @@ | ||
/* | ||
* 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 Represents a native unsigned 64 bit integer in C. | ||
* | ||
* @description Checks that this type represents a native unsigned 64 bit | ||
* integer in C. | ||
* @author sgrekhov@unipro.ru | ||
*/ | ||
import "dart:ffi"; | ||
import "../ffi_utils.dart"; | ||
import "../../../Utils/expect.dart"; | ||
|
||
void main() { | ||
Pointer<Uint64> p1 = calloc<Uint64>(3); | ||
try { | ||
Expect.equals(8, p1.elementAt(1).address - p1.address); | ||
Expect.equals(8, p1.elementAt(2).address - p1.elementAt(1).address); | ||
} finally { | ||
calloc.free(p1); | ||
} | ||
} |