Skip to content

Commit

Permalink
#993. Pointer equality tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey G. Grekhov committed Mar 4, 2021
1 parent 84cad35 commit 7978676
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
30 changes: 30 additions & 0 deletions LibTest/ffi/Pointer/equals_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 bool operator == (Object other)
* override
* Equality for Pointers only depends on their address.
*
* @description Checks that equality for Pointers only depends on their address.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int8> p1 = calloc<Int8>();
Pointer<Int8> p2 = calloc<Int8>();
try {
Expect.isFalse(p1 == p2);
Expect.isTrue(p1 != p2);
Pointer<Int8> p3 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p3);
} finally {
calloc.free(p1);
calloc.free(p2);
}
}
48 changes: 48 additions & 0 deletions LibTest/ffi/Pointer/equals_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 bool operator == (Object other)
* override
* Equality for Pointers only depends on their address.
*
* @description Checks that equality for Pointers only depends on their address.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

main() {
Pointer<Int8> p1 = calloc();
try {
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p2);
Pointer<Int32> p3 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p3);
Pointer<Int64> p4 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p4);
Pointer<Uint8> p5 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p5);
Pointer<Uint16> p6 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p6);
Pointer<Uint32> p7 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p7);
Pointer<Uint64> p8 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p8);
Pointer<Float> p9 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p9);
Pointer<Double> p10 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p10);
Pointer<IntPtr> p11 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p11);
Pointer<Pointer<Int32>> p12 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p12);
Pointer<Array<Int32>> p13 = new Pointer.fromAddress(p1.address);
Expect.isTrue(p1 == p13);
} finally {
calloc.free(p1);
}
}

0 comments on commit 7978676

Please sign in to comment.