Skip to content

Commit

Permalink
#1260: Added tests for Finalizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
iarkh committed Feb 9, 2022
1 parent d34fc84 commit 495119a
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 29 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2022, 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 The value and detach arguments ... Both must be objects supported
/// as an [Expando] key.
///
/// @description Checks that [value] must be supported as an [Expando] keys.
/// Test String.
/// @author [email protected]
import "../gc_utils_lib.dart";
import "../../../Utils/expect.dart";

final Finalizer finalizer = Finalizer((_) { throw "Should not reach here"; });
Object detachToken = Object;

main() {
Expect.throws(() {
finalizer.attach("Shouldn't work", "Finalization token", detach: detachToken);
});

String s = "Just a string";
Expect.throws(() {
finalizer.attach("Shouldn't work", "Finalization token");
});

dynamic d = s;
Expect.throws(() {
finalizer.attach("Shouldn't work", "Finalization token");
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2022, 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 The value and detach arguments ... Both must be objects supported
/// as an [Expando] key.
///
/// @description Checks that [value] must be supported as an [Expando] keys.
/// Test numbers.
/// @author [email protected]
import "../gc_utils_lib.dart";
import "../../../Utils/expect.dart";

final Finalizer finalizer = Finalizer((_) { throw "Should not reach here"; });
Object detachToken = Object;

main() {
Expect.throws(() {
finalizer.attach(12345, "Finalization token", detach: detachToken);
});

var i = 3.14;
Expect.throws(() {
finalizer.attach(i, "Finalization token");
});

int j = -12934;
Expect.throws(() {
finalizer.attach(j, "Finalization token");
});

dynamic d = -12.376;
Expect.throws(() {
finalizer.attach(d, "Finalization token");
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2022, 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 The value and detach arguments ... Both must be objects supported
/// as an [Expando] key.
///
/// @description Checks that [value] must be supported as an [Expando] keys.
/// Test booleans.
/// @author [email protected]
import "../gc_utils_lib.dart";
import "../../../Utils/expect.dart";

final Finalizer finalizer = Finalizer((_) { throw "Should not reach here"; });
Object detachToken = Object;

main() {
Expect.throws(() {
finalizer.attach(true, "Finalization token", detach: detachToken);
});

var b1 = false;
Expect.throws(() {
finalizer.attach(b1, "Finalization token");
});

bool? b2 = true;
Expect.throws(() {
finalizer.attach(b2, "Finalization token");
});

dynamic b3 = true;
Expect.throws(() {
finalizer.attach(b3, "Finalization token");
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2022, 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 The value and detach arguments ... Both must be objects supported
/// as an [Expando] key.
///
/// @description Checks that [value] must be supported as an [Expando] keys.
/// Test [Null].
/// @author [email protected]
import "../gc_utils_lib.dart";
import "../../../Utils/expect.dart";

final Finalizer finalizer = Finalizer((_) { throw "Should not reach here"; });

main() {
dynamic d = null;
Expect.throws(() {
finalizer.attach(d, "Finalization token");
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2022, 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 The value and detach arguments ... Both must be objects supported
/// as an [Expando] key.
///
/// @description Checks that [value] must be supported as an [Expando] keys.
/// Test Test dart:ffi pointers.
/// @author [email protected]
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

final Finalizer finalizer = Finalizer((_) { throw "Should not reach here"; });
Object detachToken = Object;

main() {
Pointer<Int8> p1 = calloc<Int8>();
try {
Expect.throws(() {
finalizer.attach(p1, "Finalization token");
});
} finally {
calloc.free(p1);
}

Pointer<Int16> p2 = calloc<Int16>();
try {
Expect.throws(() {
finalizer.attach(p2, "Finalization token");
});
} finally {
calloc.free(p2);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2022, 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 The value and detach arguments ... Both must be objects supported
/// as an [Expando] key.
///
/// @description Checks that [value] must be supported as an [Expando] keys.
/// Test Test dart:ffi struct.
/// @author [email protected]
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

final Finalizer finalizer = Finalizer((_) { throw "Should not reach here"; });

class S extends Struct {
@Int32()
external int x;
}

main() {
Pointer<S> p = calloc<S>();
try {
S s = p.ref;
Expect.throws(() {
finalizer.attach(p, "Finalization token");
});
} finally {
calloc.free(p);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2022, 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 The value and detach arguments ... Both must be objects supported
/// as an [Expando] key.
///
/// @description Checks that [value] must be supported as an [Expando] keys.
/// Test Test dart:ffi union.
/// @author [email protected]
import "dart:ffi";
import "package:ffi/ffi.dart";
import "../../../Utils/expect.dart";

final Finalizer finalizer = Finalizer((_) { throw "Should not reach here"; });

class U extends Union {
@Int32()
external int x;
@Int16()
external int y;
}

main() {
Pointer<U> p = calloc<U>();
try {
U u = p.ref;
Expect.throws(() {
finalizer.attach(u, "Finalization token");
});
} finally {
calloc.free(p);
}
}

0 comments on commit 495119a

Please sign in to comment.