OLD | NEW |
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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/json.h" | 10 #include "platform/json.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 Dart_Handle str = NewString("test"); | 182 Dart_Handle str = NewString("test"); |
183 EXPECT_VALID(str); | 183 EXPECT_VALID(str); |
184 EXPECT(!Dart_IsNull(str)); | 184 EXPECT(!Dart_IsNull(str)); |
185 } | 185 } |
186 | 186 |
187 | 187 |
188 TEST_CASE(IdentityEquals) { | 188 TEST_CASE(IdentityEquals) { |
189 Dart_Handle five = NewString("5"); | 189 Dart_Handle five = NewString("5"); |
190 Dart_Handle five_again = NewString("5"); | 190 Dart_Handle five_again = NewString("5"); |
191 Dart_Handle seven = NewString("7"); | 191 Dart_Handle seven = NewString("7"); |
| 192 Dart_Handle dart_core = NewString("dart:core"); |
| 193 Dart_Handle dart_mirrors = NewString("dart:mirrors"); |
192 | 194 |
193 // Same objects. | 195 // Same objects. |
194 EXPECT(Dart_IdentityEquals(five, five)); | 196 EXPECT(Dart_IdentityEquals(five, five)); |
195 | 197 |
196 // Equal objects. | 198 // Equal objects. |
197 EXPECT(!Dart_IdentityEquals(five, five_again)); | 199 EXPECT(!Dart_IdentityEquals(five, five_again)); |
198 | 200 |
199 // Different objects. | 201 // Different objects. |
200 EXPECT(!Dart_IdentityEquals(five, seven)); | 202 EXPECT(!Dart_IdentityEquals(five, seven)); |
201 | 203 |
202 // Non-instance objects. | 204 // Non-instance objects. |
203 { | 205 { |
204 Isolate* isolate = Isolate::Current(); | 206 Isolate* isolate = Isolate::Current(); |
205 DARTSCOPE(isolate); | 207 DARTSCOPE(isolate); |
206 Dart_Handle class1 = Api::NewHandle(isolate, Object::void_class()); | 208 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
207 Dart_Handle class2 = Api::NewHandle(isolate, Object::class_class()); | 209 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
208 | 210 |
209 EXPECT(Dart_IdentityEquals(class1, class1)); | 211 EXPECT(Dart_IdentityEquals(lib1, lib1)); |
210 | 212 EXPECT(Dart_IdentityEquals(lib2, lib2)); |
211 EXPECT(!Dart_IdentityEquals(class1, class2)); | 213 EXPECT(!Dart_IdentityEquals(lib1, lib2)); |
212 } | 214 } |
213 } | 215 } |
214 | 216 |
215 | 217 |
216 TEST_CASE(ObjectEquals) { | 218 TEST_CASE(ObjectEquals) { |
217 bool equal = false; | 219 bool equal = false; |
218 Dart_Handle five = NewString("5"); | 220 Dart_Handle five = NewString("5"); |
219 Dart_Handle five_again = NewString("5"); | 221 Dart_Handle five_again = NewString("5"); |
220 Dart_Handle seven = NewString("7"); | 222 Dart_Handle seven = NewString("7"); |
221 | 223 |
(...skipping 29 matching lines...) Expand all Loading... |
251 const Type& null_type_obj = Api::UnwrapTypeHandle(isolate, type); | 253 const Type& null_type_obj = Api::UnwrapTypeHandle(isolate, type); |
252 EXPECT(null_type_obj.raw() == Type::NullType()); | 254 EXPECT(null_type_obj.raw() == Type::NullType()); |
253 | 255 |
254 Dart_Handle instance = Dart_True(); | 256 Dart_Handle instance = Dart_True(); |
255 type = Dart_InstanceGetType(instance); | 257 type = Dart_InstanceGetType(instance); |
256 EXPECT_VALID(type); | 258 EXPECT_VALID(type); |
257 EXPECT(Dart_IsType(type)); | 259 EXPECT(Dart_IsType(type)); |
258 const Type& bool_type_obj = Api::UnwrapTypeHandle(isolate, type); | 260 const Type& bool_type_obj = Api::UnwrapTypeHandle(isolate, type); |
259 EXPECT(bool_type_obj.raw() == Type::BoolType()); | 261 EXPECT(bool_type_obj.raw() == Type::BoolType()); |
260 | 262 |
261 // Errors propagate. | 263 Dart_Handle cls_name = Dart_ClassName(type); |
262 Dart_Handle error = Dart_NewApiError("MyError"); | |
263 Dart_Handle error_type = Dart_InstanceGetType(error); | |
264 EXPECT_ERROR(error_type, "MyError"); | |
265 | |
266 // Get the handle from a non-instance handle | |
267 Dart_Handle obj = Api::NewHandle(isolate, | |
268 isolate->object_store()->type_class()); | |
269 Dart_Handle type_type = Dart_InstanceGetType(obj); | |
270 EXPECT_ERROR(type_type, | |
271 "Dart_InstanceGetType expects argument 'instance' to be of " | |
272 "type Instance."); | |
273 } | |
274 | |
275 | |
276 TEST_CASE(InstanceGetClass) { | |
277 // Get the handle from a valid instance handle. | |
278 Dart_Handle instance = Dart_True(); | |
279 Dart_Handle cls = Dart_InstanceGetClass(instance); | |
280 EXPECT_VALID(cls); | |
281 EXPECT(Dart_IsClass(cls)); | |
282 Dart_Handle cls_name = Dart_ClassName(cls); | |
283 EXPECT_VALID(cls_name); | 264 EXPECT_VALID(cls_name); |
284 const char* cls_name_cstr = ""; | 265 const char* cls_name_cstr = ""; |
285 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); | 266 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); |
286 EXPECT_STREQ("bool", cls_name_cstr); | 267 EXPECT_STREQ("bool", cls_name_cstr); |
287 | 268 |
288 Dart_Handle qual_cls_name = Dart_QualifiedClassName(cls); | 269 Dart_Handle qual_cls_name = Dart_QualifiedClassName(type); |
289 EXPECT_VALID(qual_cls_name); | 270 EXPECT_VALID(qual_cls_name); |
290 const char* qual_cls_name_cstr = ""; | 271 const char* qual_cls_name_cstr = ""; |
291 EXPECT_VALID(Dart_StringToCString(qual_cls_name, &qual_cls_name_cstr)); | 272 EXPECT_VALID(Dart_StringToCString(qual_cls_name, &qual_cls_name_cstr)); |
292 EXPECT_STREQ("Library:'dart:core' Class: bool", qual_cls_name_cstr); | 273 EXPECT_STREQ("Library:'dart:core' Class: bool", qual_cls_name_cstr); |
293 | 274 |
294 // Errors propagate. | 275 // Errors propagate. |
295 Dart_Handle error = Dart_NewApiError("MyError"); | 276 Dart_Handle error = Dart_NewApiError("MyError"); |
296 Dart_Handle error_cls = Dart_InstanceGetClass(error); | 277 Dart_Handle error_type = Dart_InstanceGetType(error); |
297 EXPECT_ERROR(error_cls, "MyError"); | 278 EXPECT_ERROR(error_type, "MyError"); |
298 | 279 |
299 // Get the handle from a non-instance handle | 280 // Get the handle from a non-instance handle. |
300 ASSERT(Dart_IsClass(cls)); | 281 Dart_Handle dart_core = NewString("dart:core"); |
301 Dart_Handle cls_cls = Dart_InstanceGetClass(cls); | 282 Dart_Handle obj = Dart_LookupLibrary(dart_core); |
302 EXPECT_ERROR(cls_cls, | 283 Dart_Handle type_type = Dart_InstanceGetType(obj); |
303 "Dart_InstanceGetClass expects argument 'instance' to be of " | 284 EXPECT_ERROR(type_type, |
| 285 "Dart_InstanceGetType expects argument 'instance' to be of " |
304 "type Instance."); | 286 "type Instance."); |
305 } | 287 } |
306 | 288 |
307 | 289 |
308 TEST_CASE(BooleanValues) { | 290 TEST_CASE(BooleanValues) { |
309 Dart_Handle str = NewString("test"); | 291 Dart_Handle str = NewString("test"); |
310 EXPECT(!Dart_IsBoolean(str)); | 292 EXPECT(!Dart_IsBoolean(str)); |
311 | 293 |
312 bool value = false; | 294 bool value = false; |
313 Dart_Handle result = Dart_BooleanValue(str, &value); | 295 Dart_Handle result = Dart_BooleanValue(str, &value); |
(...skipping 7009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7323 NewString("main"), | 7305 NewString("main"), |
7324 0, | 7306 0, |
7325 NULL); | 7307 NULL); |
7326 int64_t value = 0; | 7308 int64_t value = 0; |
7327 result = Dart_IntegerToInt64(result, &value); | 7309 result = Dart_IntegerToInt64(result, &value); |
7328 EXPECT_VALID(result); | 7310 EXPECT_VALID(result); |
7329 EXPECT_EQ(8, value); | 7311 EXPECT_EQ(8, value); |
7330 } | 7312 } |
7331 | 7313 |
7332 } // namespace dart | 7314 } // namespace dart |
OLD | NEW |