-
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. Int64Pointer tests added for FFI library
- Loading branch information
sgrekhov
committed
Aug 2, 2021
1 parent
bbb26d9
commit fea1468
Showing
7 changed files
with
167 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,32 @@ | ||
// 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 Int64List asTypedList(int length) | ||
/// Creates a typed list view backed by memory in the address space. | ||
/// | ||
/// The returned view will allow access to the memory range from address to | ||
/// address + 8 * length. | ||
/// | ||
/// The user has to ensure the memory range is accessible while using the | ||
/// returned list. | ||
/// | ||
/// @description Check that this method returns a typed list view backed by | ||
/// memory in the address space. | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import 'dart:typed_data'; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Int64> p = calloc<Int64>(3); | ||
p[0] = 3; | ||
p[1] = 42; | ||
p[2] = -1; | ||
Int64List l = p.asTypedList(3); | ||
Expect.equals(3, l[0]); | ||
Expect.equals(42, l[1]); | ||
Expect.equals(-1, l[2]); | ||
} |
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,20 @@ | ||
// 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 int value | ||
/// The 64-bit two's complement integer at address. | ||
/// | ||
/// @description Check that this getter/setter works as designed | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Int64> p = calloc<Int64>(); | ||
Expect.equals(0, p.value); | ||
p.value = 42; | ||
Expect.equals(42, p.value); | ||
} |
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,20 @@ | ||
// 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 int value | ||
/// The 64-bit two's complement integer at address. | ||
/// | ||
/// @description Check that a Dart integer is not truncated before being stored | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Int32> p = calloc<Int32>(); | ||
Expect.equals(0, p.value); | ||
p.value = 0xFFFFFFFFFFFFFFFF; | ||
Expect.equals(0xFFFFFFFFFFFFFFFF, p.value); | ||
} |
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 int operator [](int index) | ||
/// The int at address + 8 * index. | ||
/// | ||
/// The 32-bit two's complement integer at address + 8 * index. | ||
/// | ||
/// @description Check that operator [](int index) returns int at | ||
/// address + 8 * index. | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Int64> p1 = calloc<Int64>(2); | ||
Pointer<Int64> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int64>()); | ||
p1.value = 1; | ||
p2.value = 42; | ||
Expect.equals(1, p1[0]); | ||
Expect.equals(42, p1[1]); | ||
} |
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,23 @@ | ||
// 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 int operator [](int index) | ||
/// | ||
/// The 64-bit two's complement integer at address + 8 * index. | ||
/// | ||
/// @description Check that a Dart integer is not truncated before being stored | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Int64> p1 = calloc<Int64>(2); | ||
Pointer<Int64> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int64>()); | ||
p1.value = 0xFFFFFFFFFFFFFFFF; | ||
p2.value = 0xFFFFFFFFFFFFFFFF; | ||
Expect.equals(0xFFFFFFFFFFFFFFFF, p1[0]); | ||
Expect.equals(0xFFFFFFFFFFFFFFFF, p1[1]); | ||
} |
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,24 @@ | ||
// 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 void operator []=(int index, int value) | ||
/// The 64-bit two's complement integer at address + 8 * index. | ||
/// | ||
/// @description Check that operator []=(int index) sets int at | ||
/// address + 8 * index. | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Int64> p1 = calloc<Int64>(2); | ||
Pointer<Int64> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int64>()); | ||
p1[0] = 1; | ||
p1[1] = 42; | ||
Expect.equals(1, p1[0]); | ||
Expect.equals(42, p1[1]); | ||
Expect.equals(42, p2.value); | ||
} |
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,23 @@ | ||
// 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 void operator []=(int index, int value) | ||
/// The 64-bit two's complement integer at address + 8 * index. | ||
/// | ||
/// @description Check that a Dart integer is not truncated before being stored | ||
/// @author sgrekhov@unipro.ru | ||
import "dart:ffi"; | ||
import "package:ffi/ffi.dart"; | ||
import '../../../Utils/expect.dart'; | ||
|
||
void main() { | ||
Pointer<Int64> p1 = calloc<Int64>(2); | ||
Pointer<Int64> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int64>()); | ||
p1[0] = 0xFFFFFFFFFFFFFFFF; | ||
p1[1] = 0xFFFFFFFFFFFFFFFF; | ||
Expect.equals(0xFFFFFFFFFFFFFFFF, p1[0]); | ||
Expect.equals(0xFFFFFFFFFFFFFFFF, p1[1]); | ||
Expect.equals(0xFFFFFFFFFFFFFFFF, p2.value); | ||
} |