Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Unified Diff: runtime/vm/handles_test.cc

Issue 2640573003: Resolution for issue #5092: Unit test handle checks consider dangling handles to be valid. (Closed)
Patch Set: Removed Dart API entry for IsValid. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/handles_test.cc
diff --git a/runtime/vm/handles_test.cc b/runtime/vm/handles_test.cc
index 8a05fb750af0db59d9dc811f43dd6739a6394f46..6c472b1d77b5a3fc6f96381203f51eabd7805e5d 100644
--- a/runtime/vm/handles_test.cc
+++ b/runtime/vm/handles_test.cc
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
#include "platform/assert.h"
+#include "vm/dart_api_state.h"
#include "vm/flags.h"
#include "vm/handles.h"
#include "vm/heap.h"
@@ -77,4 +78,57 @@ TEST_CASE(AllocateScopeHandle) {
EXPECT_EQ(handle_count, VMHandles::ScopedHandleCount());
}
+
+static void NoopCallback(void* isolate_callback_data,
+ Dart_WeakPersistentHandle handle,
+ void* peer) {}
+
+
+// Unit test for handle validity checks.
+TEST_CASE(CheckHandleValidity) {
+#if defined(DEBUG)
+ FLAG_trace_handles = true;
+#endif
+ Thread* current = Thread::Current();
+ Dart_Handle handle = NULL;
+ // Check validity using zone handles.
+ {
+ StackZone sz(current);
+ handle = reinterpret_cast<Dart_Handle>(&Smi::ZoneHandle(Smi::New(1)));
+ EXPECT_VALID(handle);
+ }
+ EXPECT(!Api::IsValid(handle));
+
+ // Check validity using scoped handles.
+ {
+ HANDLESCOPE(current);
+ Dart_EnterScope();
+ handle = reinterpret_cast<Dart_Handle>(&Smi::Handle(Smi::New(1)));
+ EXPECT_VALID(handle);
+ Dart_ExitScope();
+ }
+ EXPECT(!Api::IsValid(handle));
+
+ // Check validity using persistent handle.
+ Isolate* isolate = Isolate::Current();
+ Dart_PersistentHandle persistent_handle =
+ Dart_NewPersistentHandle(Api::NewHandle(thread, Smi::New(1)));
+ EXPECT_VALID(persistent_handle);
+
+ Dart_DeletePersistentHandle(persistent_handle);
+ EXPECT(!Api::IsValid(persistent_handle));
+
+ // Check validity using weak persistent handle.
+ handle = reinterpret_cast<Dart_Handle>(Dart_NewWeakPersistentHandle(
+ Dart_NewStringFromCString("foo"), NULL, 0, NoopCallback));
+
+ EXPECT_NOTNULL(handle);
+ EXPECT_VALID(handle);
+
+ Dart_DeleteWeakPersistentHandle(
+ reinterpret_cast<Dart_Isolate>(isolate),
+ reinterpret_cast<Dart_WeakPersistentHandle>(handle));
+ EXPECT(!Api::IsValid(handle));
+}
+
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698