dart-sdk/tests/ffi/extension_methods_test.dart
Daco Harkes ec66deec26 [vm/ffi] Split out tests which use nulls
Issue: https://github.com/dart-lang/sdk/issues/40233
Change-Id: If4e79995f13ed2870f4663ceac5500ceacbe04df
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132602
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-01-20 16:01:08 +00:00

65 lines
1.4 KiB
Dart

// Copyright (c) 2019, 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.
import 'dart:ffi';
import "package:expect/expect.dart";
import "package:ffi/ffi.dart";
main(List<String> arguments) {
for (int i = 0; i < 100; i++) {
testStoreLoad();
testReifiedGeneric();
}
}
testStoreLoad() {
final p = allocate<Int8>(count: 2);
p.value = 10;
Expect.equals(10, p.value);
p[1] = 20;
Expect.equals(20, p[1]);
if (sizeOf<IntPtr>() == 4) {
// Test round tripping.
Expect.equals(20, p.elementAt(0x100000001).value);
Expect.equals(20, p[0x100000001]);
}
// Test negative index.
final pUseNegative = p.elementAt(1);
Expect.equals(10, pUseNegative[-1]);
final p1 = allocate<Double>(count: 2);
p1.value = 10.0;
Expect.approxEquals(10.0, p1.value);
p1[1] = 20.0;
Expect.approxEquals(20.0, p1[1]);
free(p1);
final p2 = allocate<Pointer<Int8>>(count: 2);
p2.value = p;
Expect.equals(p, p2.value);
p2[1] = p;
Expect.equals(p, p2[1]);
free(p2);
free(p);
final p3 = allocate<Foo>();
Foo foo = p3.ref;
foo.a = 1;
Expect.equals(1, foo.a);
free(p3);
}
testReifiedGeneric() {
final p = allocate<Pointer<Int8>>();
Pointer<Pointer<NativeType>> p2 = p;
Expect.isTrue(p2.value is Pointer<Int8>);
free(p);
}
class Foo extends Struct {
@Int8()
int a;
}