Chromium Code Reviews| Index: runtime/vm/dart_api_impl_test.cc |
| =================================================================== |
| --- runtime/vm/dart_api_impl_test.cc (revision 1230) |
| +++ runtime/vm/dart_api_impl_test.cc (working copy) |
| @@ -30,6 +30,58 @@ |
| } |
| +UNIT_TEST_CASE(IsSame) { |
| + Dart_CreateIsolate(NULL, NULL); |
| + Dart_EnterScope(); // Enter a Dart API scope for the unit test. |
| + |
| + bool identical = false; |
| + Dart_Handle five = Dart_NewString("5"); |
| + Dart_Handle five_again = Dart_NewString("5"); |
| + Dart_Handle seven = Dart_NewString("7"); |
| + |
| + // Identical objects. |
| + EXPECT_VALID(Dart_IsSame(five, five, &identical)); |
| + EXPECT(identical); |
| + |
| + // Equal objects. |
| + EXPECT_VALID(Dart_IsSame(five, five_again, &identical)); |
| + EXPECT(!identical); |
| + |
| + // Different objects. |
| + EXPECT_VALID(Dart_IsSame(five, seven, &identical)); |
| + EXPECT(!identical); |
|
Ivan Posva
2011/11/07 23:48:30
Can you also test with objects that are not subcla
turnidge
2011/11/10 20:30:58
Ok.
|
| + |
| + Dart_ExitScope(); // Exit the Dart API scope. |
| + Dart_ShutdownIsolate(); |
| +} |
| + |
| + |
| +UNIT_TEST_CASE(ObjectEquals) { |
| + Dart_CreateIsolate(NULL, NULL); |
| + Dart_EnterScope(); // Enter a Dart API scope for the unit test. |
| + |
| + bool equal = false; |
| + Dart_Handle five = Dart_NewString("5"); |
| + Dart_Handle five_again = Dart_NewString("5"); |
| + Dart_Handle seven = Dart_NewString("7"); |
| + |
| + // Identical objects. |
| + EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); |
| + EXPECT(equal); |
| + |
| + // Equal objects. |
| + EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal)); |
| + EXPECT(equal); |
| + |
| + // Different objects. |
| + EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); |
| + EXPECT(!equal); |
| + |
| + Dart_ExitScope(); // Exit the Dart API scope. |
| + Dart_ShutdownIsolate(); |
| +} |
| + |
| + |
| UNIT_TEST_CASE(BooleanValues) { |
| Dart_CreateIsolate(NULL, NULL); |
| Dart_EnterScope(); // Enter a Dart API scope for the unit test. |
| @@ -1589,7 +1641,7 @@ |
| // Now check instanceOfTestObj reported as an instance of |
| // InstanceOfTest class. |
| bool is_instance = false; |
| - result = Dart_IsInstanceOf(instanceOfTestObj, cls, &is_instance); |
| + result = Dart_ObjectIsType(instanceOfTestObj, cls, &is_instance); |
| EXPECT_VALID(result); |
| EXPECT(is_instance); |
| @@ -1598,21 +1650,21 @@ |
| EXPECT_VALID(otherClass); |
| EXPECT(!Dart_ExceptionOccurred(otherClass)); |
| - result = Dart_IsInstanceOf(instanceOfTestObj, otherClass, &is_instance); |
| + result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance); |
| EXPECT_VALID(result); |
| EXPECT(!is_instance); |
| // Check that primitives are not instances of InstanceOfTest class. |
| - result = Dart_IsInstanceOf(Dart_NewString("a string"), otherClass, |
| + result = Dart_ObjectIsType(Dart_NewString("a string"), otherClass, |
| &is_instance); |
| EXPECT_VALID(result); |
| EXPECT(!is_instance); |
| - result = Dart_IsInstanceOf(Dart_NewInteger(42), otherClass, &is_instance); |
| + result = Dart_ObjectIsType(Dart_NewInteger(42), otherClass, &is_instance); |
| EXPECT_VALID(result); |
| EXPECT(!is_instance); |
| - result = Dart_IsInstanceOf(Dart_NewBoolean(true), otherClass, &is_instance); |
| + result = Dart_ObjectIsType(Dart_NewBoolean(true), otherClass, &is_instance); |
| EXPECT_VALID(result); |
| EXPECT(!is_instance); |
| @@ -1625,12 +1677,12 @@ |
| EXPECT_VALID(null); |
| EXPECT(!Dart_ExceptionOccurred(null)); |
| - result = Dart_IsInstanceOf(null, otherClass, &is_instance); |
| + result = Dart_ObjectIsType(null, otherClass, &is_instance); |
| EXPECT_VALID(result); |
| EXPECT(!is_instance); |
| // Check that error is returned if null is passed as a class argument. |
| - result = Dart_IsInstanceOf(null, null, &is_instance); |
| + result = Dart_ObjectIsType(null, null, &is_instance); |
| EXPECT(!Dart_IsValid(result)); |
| Dart_ExitScope(); // Exit the Dart API scope. |