| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 | 6 |
| 7 #include "vm/assert.h" | 7 #include "vm/assert.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
| 10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
| 11 #include "vm/utils.h" | 11 #include "vm/utils.h" |
| 12 #include "vm/verifier.h" | 12 #include "vm/verifier.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 UNIT_TEST_CASE(Null) { |
| 17 Dart_CreateIsolate(NULL, NULL); |
| 18 Dart_EnterScope(); // Enter a Dart API scope for the unit test. |
| 19 |
| 20 Dart_Handle null = Dart_Null(); |
| 21 EXPECT_VALID(null); |
| 22 EXPECT(Dart_IsNull(null)); |
| 23 |
| 24 Dart_Handle str = Dart_NewString("test"); |
| 25 EXPECT_VALID(str); |
| 26 EXPECT(!Dart_IsNull(str)); |
| 27 |
| 28 Dart_ExitScope(); // Exit the Dart API scope. |
| 29 Dart_ShutdownIsolate(); |
| 30 } |
| 31 |
| 32 |
| 16 UNIT_TEST_CASE(BooleanValues) { | 33 UNIT_TEST_CASE(BooleanValues) { |
| 17 Dart_CreateIsolate(NULL, NULL); | 34 Dart_CreateIsolate(NULL, NULL); |
| 18 Dart_EnterScope(); // Enter a Dart API scope for the unit test. | 35 Dart_EnterScope(); // Enter a Dart API scope for the unit test. |
| 19 | 36 |
| 20 Dart_Handle str = Dart_NewString("test"); | 37 Dart_Handle str = Dart_NewString("test"); |
| 21 EXPECT(!Dart_IsBoolean(str)); | 38 EXPECT(!Dart_IsBoolean(str)); |
| 39 |
| 40 bool value = false; |
| 41 Dart_Handle result = Dart_BooleanValue(str, &value); |
| 42 EXPECT(!Dart_IsValid(result)); |
| 43 |
| 22 Dart_Handle val1 = Dart_NewBoolean(true); | 44 Dart_Handle val1 = Dart_NewBoolean(true); |
| 23 EXPECT(Dart_IsBoolean(val1)); | 45 EXPECT(Dart_IsBoolean(val1)); |
| 46 |
| 47 result = Dart_BooleanValue(val1, &value); |
| 48 EXPECT_VALID(result); |
| 49 EXPECT(value); |
| 50 |
| 24 Dart_Handle val2 = Dart_NewBoolean(false); | 51 Dart_Handle val2 = Dart_NewBoolean(false); |
| 25 EXPECT(Dart_IsBoolean(val2)); | 52 EXPECT(Dart_IsBoolean(val2)); |
| 26 bool value = false; | 53 |
| 27 Dart_Handle result = Dart_BooleanValue(val1, &value); | |
| 28 EXPECT_VALID(result); | |
| 29 EXPECT(value); | |
| 30 result = Dart_BooleanValue(val2, &value); | 54 result = Dart_BooleanValue(val2, &value); |
| 31 EXPECT_VALID(result); | 55 EXPECT_VALID(result); |
| 32 EXPECT(!value); | 56 EXPECT(!value); |
| 33 | 57 |
| 58 Dart_ExitScope(); // Exit the Dart API scope. |
| 59 Dart_ShutdownIsolate(); |
| 60 } |
| 61 |
| 62 |
| 63 UNIT_TEST_CASE(BooleanConstants) { |
| 64 Dart_CreateIsolate(NULL, NULL); |
| 65 Dart_EnterScope(); // Enter a Dart API scope for the unit test. |
| 66 |
| 67 Dart_Handle true_handle = Dart_True(); |
| 68 EXPECT_VALID(true_handle); |
| 69 EXPECT(Dart_IsBoolean(true_handle)); |
| 70 |
| 71 bool value = false; |
| 72 Dart_Handle result = Dart_BooleanValue(true_handle, &value); |
| 73 EXPECT_VALID(result); |
| 74 EXPECT(value); |
| 75 |
| 76 Dart_Handle false_handle = Dart_False(); |
| 77 EXPECT_VALID(false_handle); |
| 78 EXPECT(Dart_IsBoolean(false_handle)); |
| 79 |
| 80 result = Dart_BooleanValue(false_handle, &value); |
| 81 EXPECT_VALID(result); |
| 82 EXPECT(!value); |
| 83 |
| 34 Dart_ExitScope(); // Exit the Dart API scope. | 84 Dart_ExitScope(); // Exit the Dart API scope. |
| 35 Dart_ShutdownIsolate(); | 85 Dart_ShutdownIsolate(); |
| 36 } | 86 } |
| 37 | 87 |
| 38 | 88 |
| 39 UNIT_TEST_CASE(DoubleValues) { | 89 UNIT_TEST_CASE(DoubleValues) { |
| 40 Dart_CreateIsolate(NULL, NULL); | 90 Dart_CreateIsolate(NULL, NULL); |
| 41 Dart_EnterScope(); // Enter a Dart API scope for the unit test. | 91 Dart_EnterScope(); // Enter a Dart API scope for the unit test. |
| 42 | 92 |
| 43 const double kDoubleVal1 = 201.29; | 93 const double kDoubleVal1 = 201.29; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 str ^= Api::UnwrapHandle(handles[i]); | 485 str ^= Api::UnwrapHandle(handles[i]); |
| 436 EXPECT(str.Equals(kTestString2)); | 486 EXPECT(str.Equals(kTestString2)); |
| 437 } | 487 } |
| 438 } | 488 } |
| 439 EXPECT(scope == state->top_scope()); | 489 EXPECT(scope == state->top_scope()); |
| 440 EXPECT_EQ(2000, state->CountPersistentHandles()); | 490 EXPECT_EQ(2000, state->CountPersistentHandles()); |
| 441 Dart_ShutdownIsolate(); | 491 Dart_ShutdownIsolate(); |
| 442 } | 492 } |
| 443 | 493 |
| 444 | 494 |
| 495 // Test that we are able to create a persistent handle from a |
| 496 // persistent handle. |
| 497 UNIT_TEST_CASE(NewPersistentHandle_FromPersistentHandle) { |
| 498 Dart_CreateIsolate(NULL, NULL); |
| 499 |
| 500 Isolate* isolate = Isolate::Current(); |
| 501 EXPECT(isolate != NULL); |
| 502 ApiState* state = isolate->api_state(); |
| 503 EXPECT(state != NULL); |
| 504 |
| 505 // Start with a known persistent handle. |
| 506 Dart_Handle obj1 = Dart_True(); |
| 507 EXPECT(state->IsValidPersistentHandle(obj1)); |
| 508 |
| 509 // And use it to allocate a second persistent handle. |
| 510 Dart_Handle obj2 = Dart_NewPersistentHandle(obj1); |
| 511 EXPECT(state->IsValidPersistentHandle(obj2)); |
| 512 |
| 513 // Make sure that the value transferred. |
| 514 EXPECT(Dart_IsBoolean(obj2)); |
| 515 bool value = false; |
| 516 Dart_Handle result = Dart_BooleanValue(obj2, &value); |
| 517 EXPECT_VALID(result); |
| 518 EXPECT(value); |
| 519 |
| 520 Dart_ShutdownIsolate(); |
| 521 } |
| 522 |
| 523 |
| 445 // Unit test for creating multiple scopes and local handles within them. | 524 // Unit test for creating multiple scopes and local handles within them. |
| 446 // Ensure that the local handles get all cleaned out when exiting the | 525 // Ensure that the local handles get all cleaned out when exiting the |
| 447 // scope. | 526 // scope. |
| 448 UNIT_TEST_CASE(LocalHandles) { | 527 UNIT_TEST_CASE(LocalHandles) { |
| 449 Dart_CreateIsolate(NULL, NULL); | 528 Dart_CreateIsolate(NULL, NULL); |
| 450 Isolate* isolate = Isolate::Current(); | 529 Isolate* isolate = Isolate::Current(); |
| 451 EXPECT(isolate != NULL); | 530 EXPECT(isolate != NULL); |
| 452 ApiState* state = isolate->api_state(); | 531 ApiState* state = isolate->api_state(); |
| 453 EXPECT(state != NULL); | 532 EXPECT(state != NULL); |
| 454 ApiLocalScope* scope = state->top_scope(); | 533 ApiLocalScope* scope = state->top_scope(); |
| (...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 NULL); | 1937 NULL); |
| 1859 EXPECT_VALID(result); | 1938 EXPECT_VALID(result); |
| 1860 | 1939 |
| 1861 Dart_ExitScope(); // Exit the Dart API scope. | 1940 Dart_ExitScope(); // Exit the Dart API scope. |
| 1862 } | 1941 } |
| 1863 Dart_ShutdownIsolate(); | 1942 Dart_ShutdownIsolate(); |
| 1864 } | 1943 } |
| 1865 #endif // TARGET_ARCH_IA32. | 1944 #endif // TARGET_ARCH_IA32. |
| 1866 | 1945 |
| 1867 } // namespace dart | 1946 } // namespace dart |
| OLD | NEW |