Skip to content

Commit

Permalink
#993. Pointer.cast() tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Mar 2, 2021
1 parent c3ffd4d commit ff1eb19
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 0 deletions.
28 changes: 28 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>();
try {
Pointer<Int8> p2 = new Pointer.fromAddress(p1.address);
p1.value = 256;
Expect.equals(0, p2.value);
var p3 = p2.cast<Int16>();
Expect.equals(256, p3.value);
} finally {
calloc.free(p1);
}
}
28 changes: 28 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int8> p1 = calloc<Int8>();
try {
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address);
p2.value = 256;
Expect.equals(0, p1.value);
var p3 = p2.cast<Int8>();
Expect.equals(0, p3.value);
} finally {
calloc.free(p1);
}
}
27 changes: 27 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>();
try {
Pointer<Void> p2 = new Pointer.fromAddress(p1.address);
p1.value = 256;
var p3 = p2.cast<Int8>();
Expect.equals(0, p3.value);
} finally {
calloc.free(p1);
}
}
28 changes: 28 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
* @issue 45149
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>();
try {
Pointer<Opaque> p2 = new Pointer.fromAddress(p1.address);
p1.value = 256;
var p3 = p2.cast<Int8>();
Expect.equals(0, p3.value);
} finally {
calloc.free(p1);
}
}
28 changes: 28 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t05.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
* @issue 45149
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>();
try {
Pointer<Handle> p2 = new Pointer.fromAddress(p1.address);
p1.value = 256;
var p3 = p2.cast<Int8>();
Expect.equals(0, p3.value);
} finally {
calloc.free(p1);
}
}
27 changes: 27 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t06.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>();
try {
Pointer<Array<Int16>> p2 = new Pointer.fromAddress(p1.address);
p1.value = 256;
var p3 = p2.cast<Int8>();
Expect.equals(0, p3.value);
} finally {
calloc.free(p1);
}
}
27 changes: 27 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t07.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>();
try {
Pointer<Double> p2 = new Pointer.fromAddress(p1.address);
p1.value = 256;
var p3 = p2.cast<Int8>();
Expect.equals(0, p3.value);
} finally {
calloc.free(p1);
}
}
27 changes: 27 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t08.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>();
try {
Pointer<NativeType> p2 = new Pointer.fromAddress(p1.address);
p1.value = 256;
var p3 = p2.cast<Int8>();
Expect.equals(0, p3.value);
} finally {
calloc.free(p1);
}
}
27 changes: 27 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t09.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>();
try {
Pointer<NativeFunction> p2 = new Pointer.fromAddress(p1.address);
p1.value = 256;
var p3 = p2.cast<Int8>();
Expect.equals(0, p3.value);
} finally {
calloc.free(p1);
}
}
27 changes: 27 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t10.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>();
try {
Pointer<Pointer> p2 = new Pointer.fromAddress(p1.address);
p1.value = 256;
var p3 = p2.cast<Int8>();
Expect.equals(0, p3.value);
} finally {
calloc.free(p1);
}
}
27 changes: 27 additions & 0 deletions LibTest/ffi/Pointer/cast_A01_t11.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 Pointer<U> cast <U extends NativeType>()
* Cast Pointer to a Pointer.
*
* @description Checks that this method casts Pointer to a Pointer
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../ffi_utils.dart';
import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>();
try {
Pointer<Struct> p2 = new Pointer.fromAddress(p1.address);
p1.value = 256;
var p3 = p2.cast<Int8>();
Expect.equals(0, p3.value);
} finally {
calloc.free(p1);
}
}

0 comments on commit ff1eb19

Please sign in to comment.