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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/dart_api_state.h"
6 #include "vm/flags.h" 7 #include "vm/flags.h"
7 #include "vm/handles.h" 8 #include "vm/handles.h"
8 #include "vm/heap.h" 9 #include "vm/heap.h"
9 #include "vm/object.h" 10 #include "vm/object.h"
10 #include "vm/unit_test.h" 11 #include "vm/unit_test.h"
11 #include "vm/zone.h" 12 #include "vm/zone.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 // Unit test for Zone handle allocation. 16 // Unit test for Zone handle allocation.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 const Smi& handle = Smi::Handle(Smi::New(i)); 71 const Smi& handle = Smi::Handle(Smi::New(i));
71 EXPECT(handle.IsSmi()); 72 EXPECT(handle.IsSmi());
72 EXPECT_EQ(i, handle.Value()); 73 EXPECT_EQ(i, handle.Value());
73 } 74 }
74 EXPECT_EQ((handle_count + (2 * kNumHandles)), 75 EXPECT_EQ((handle_count + (2 * kNumHandles)),
75 VMHandles::ScopedHandleCount()); 76 VMHandles::ScopedHandleCount());
76 } 77 }
77 EXPECT_EQ(handle_count, VMHandles::ScopedHandleCount()); 78 EXPECT_EQ(handle_count, VMHandles::ScopedHandleCount());
78 } 79 }
79 80
81
82 static void NoopCallback(void* isolate_callback_data,
83 Dart_WeakPersistentHandle handle,
84 void* peer) {}
85
86
87 // Unit test for handle validity checks.
88 TEST_CASE(CheckHandleValidity) {
89 #if defined(DEBUG)
90 FLAG_trace_handles = true;
91 #endif
92 Thread* current = Thread::Current();
93 Dart_Handle handle = NULL;
94 // Check validity using zone handles.
95 {
96 StackZone sz(current);
97 handle = reinterpret_cast<Dart_Handle>(&Smi::ZoneHandle(Smi::New(1)));
98 EXPECT_VALID(handle);
99 }
100 EXPECT(!Api::IsValid(handle));
101
102 // Check validity using scoped handles.
103 {
104 HANDLESCOPE(current);
105 Dart_EnterScope();
106 handle = reinterpret_cast<Dart_Handle>(&Smi::Handle(Smi::New(1)));
107 EXPECT_VALID(handle);
108 Dart_ExitScope();
109 }
110 EXPECT(!Api::IsValid(handle));
111
112 // Check validity using persistent handle.
113 Isolate* isolate = Isolate::Current();
114 Dart_PersistentHandle persistent_handle =
115 Dart_NewPersistentHandle(Api::NewHandle(thread, Smi::New(1)));
116 EXPECT_VALID(persistent_handle);
117
118 Dart_DeletePersistentHandle(persistent_handle);
119 EXPECT(!Api::IsValid(persistent_handle));
120
121 // Check validity using weak persistent handle.
122 handle = reinterpret_cast<Dart_Handle>(Dart_NewWeakPersistentHandle(
123 Dart_NewStringFromCString("foo"), NULL, 0, NoopCallback));
124
125 EXPECT_NOTNULL(handle);
126 EXPECT_VALID(handle);
127
128 Dart_DeleteWeakPersistentHandle(
129 reinterpret_cast<Dart_Isolate>(isolate),
130 reinterpret_cast<Dart_WeakPersistentHandle>(handle));
131 EXPECT(!Api::IsValid(handle));
132 }
133
80 } // namespace dart 134 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698