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_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 EXPECT_VALID(null); | 514 EXPECT_VALID(null); |
515 EXPECT(Dart_IsNull(null)); | 515 EXPECT(Dart_IsNull(null)); |
516 | 516 |
517 Dart_Handle str = NewString("test"); | 517 Dart_Handle str = NewString("test"); |
518 EXPECT_VALID(str); | 518 EXPECT_VALID(str); |
519 EXPECT(!Dart_IsNull(str)); | 519 EXPECT(!Dart_IsNull(str)); |
520 } | 520 } |
521 | 521 |
522 | 522 |
523 TEST_CASE(IdentityEquals) { | 523 TEST_CASE(IdentityEquals) { |
524 Dart_Handle five = NewString("5"); | 524 Dart_Handle five = Dart_NewInteger(5); |
525 Dart_Handle five_again = NewString("5"); | 525 Dart_Handle five_again = Dart_NewInteger(5); |
526 Dart_Handle seven = NewString("7"); | 526 Dart_Handle mint = Dart_NewInteger(0xFFFFFFFF); |
| 527 Dart_Handle mint_again = Dart_NewInteger(0xFFFFFFFF); |
| 528 Dart_Handle abc = NewString("abc"); |
| 529 Dart_Handle abc_again = NewString("abc"); |
| 530 Dart_Handle xyz = NewString("abc"); |
527 Dart_Handle dart_core = NewString("dart:core"); | 531 Dart_Handle dart_core = NewString("dart:core"); |
528 Dart_Handle dart_mirrors = NewString("dart:mirrors"); | 532 Dart_Handle dart_mirrors = NewString("dart:mirrors"); |
529 | 533 |
530 // Same objects. | 534 // Same objects. |
531 EXPECT(Dart_IdentityEquals(five, five)); | 535 EXPECT(Dart_IdentityEquals(five, five)); |
| 536 EXPECT(Dart_IdentityEquals(mint, mint)); |
| 537 EXPECT(Dart_IdentityEquals(abc, abc)); |
| 538 EXPECT(Dart_IdentityEquals(xyz, xyz)); |
532 | 539 |
533 // Equal objects. | 540 // Equal objects with special spec rules. |
534 EXPECT(!Dart_IdentityEquals(five, five_again)); | 541 EXPECT(Dart_IdentityEquals(five, five_again)); |
| 542 EXPECT(Dart_IdentityEquals(mint, mint_again)); |
| 543 |
| 544 // Equal objects without special spec rules. |
| 545 EXPECT(!Dart_IdentityEquals(abc, abc_again)); |
535 | 546 |
536 // Different objects. | 547 // Different objects. |
537 EXPECT(!Dart_IdentityEquals(five, seven)); | 548 EXPECT(!Dart_IdentityEquals(five, mint)); |
| 549 EXPECT(!Dart_IdentityEquals(abc, xyz)); |
538 | 550 |
539 // Case where identical() is not the same as pointer equality. | 551 // Case where identical() is not the same as pointer equality. |
540 Dart_Handle nan1 = Dart_NewDouble(NAN); | 552 Dart_Handle nan1 = Dart_NewDouble(NAN); |
541 Dart_Handle nan2 = Dart_NewDouble(NAN); | 553 Dart_Handle nan2 = Dart_NewDouble(NAN); |
542 EXPECT(Dart_IdentityEquals(nan1, nan2)); | 554 EXPECT(Dart_IdentityEquals(nan1, nan2)); |
543 | 555 |
544 // Non-instance objects. | 556 // Non-instance objects. |
545 { | 557 { |
546 Isolate* isolate = Isolate::Current(); | 558 Isolate* isolate = Isolate::Current(); |
547 DARTSCOPE(isolate); | 559 DARTSCOPE(isolate); |
548 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); | 560 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
549 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); | 561 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
550 | 562 |
551 EXPECT(Dart_IdentityEquals(lib1, lib1)); | 563 EXPECT(Dart_IdentityEquals(lib1, lib1)); |
552 EXPECT(Dart_IdentityEquals(lib2, lib2)); | 564 EXPECT(Dart_IdentityEquals(lib2, lib2)); |
553 EXPECT(!Dart_IdentityEquals(lib1, lib2)); | 565 EXPECT(!Dart_IdentityEquals(lib1, lib2)); |
554 | 566 |
555 // Mix instance and non-instance. | 567 // Mix instance and non-instance. |
556 EXPECT(!Dart_IdentityEquals(lib1, nan1)); | 568 EXPECT(!Dart_IdentityEquals(lib1, nan1)); |
557 EXPECT(!Dart_IdentityEquals(nan1, lib1)); | 569 EXPECT(!Dart_IdentityEquals(nan1, lib1)); |
558 } | 570 } |
559 } | 571 } |
560 | 572 |
561 | 573 |
| 574 TEST_CASE(IdentityHash) { |
| 575 Dart_Handle five = Dart_NewInteger(5); |
| 576 Dart_Handle five_again = Dart_NewInteger(5); |
| 577 Dart_Handle mint = Dart_NewInteger(0xFFFFFFFF); |
| 578 Dart_Handle mint_again = Dart_NewInteger(0xFFFFFFFF); |
| 579 Dart_Handle abc = NewString("abc"); |
| 580 // Dart_Handle abc_again = NewString("abc"); |
| 581 Dart_Handle xyz = NewString("abc"); |
| 582 Dart_Handle dart_core = NewString("dart:core"); |
| 583 Dart_Handle dart_mirrors = NewString("dart:mirrors"); |
| 584 |
| 585 // Same objects. |
| 586 EXPECT_EQ(Dart_IdentityHash(five), Dart_IdentityHash(five)); |
| 587 EXPECT_EQ(Dart_IdentityHash(mint), Dart_IdentityHash(mint)); |
| 588 EXPECT_EQ(Dart_IdentityHash(abc), Dart_IdentityHash(abc)); |
| 589 EXPECT_EQ(Dart_IdentityHash(xyz), Dart_IdentityHash(xyz)); |
| 590 |
| 591 // Equal objects with special spec rules. |
| 592 EXPECT_EQ(Dart_IdentityHash(five), Dart_IdentityHash(five_again)); |
| 593 EXPECT_EQ(Dart_IdentityHash(mint), Dart_IdentityHash(mint_again)); |
| 594 |
| 595 // Note abc and abc_again are not required to have equal identity hashes. |
| 596 |
| 597 // Case where identical() is not the same as pointer equality. |
| 598 Dart_Handle nan1 = Dart_NewDouble(NAN); |
| 599 Dart_Handle nan2 = Dart_NewDouble(NAN); |
| 600 EXPECT_EQ(Dart_IdentityHash(nan1), Dart_IdentityHash(nan2)); |
| 601 |
| 602 // Non-instance objects. |
| 603 { |
| 604 Isolate* isolate = Isolate::Current(); |
| 605 DARTSCOPE(isolate); |
| 606 Dart_Handle lib1 = Dart_LookupLibrary(dart_core); |
| 607 Dart_Handle lib2 = Dart_LookupLibrary(dart_mirrors); |
| 608 |
| 609 EXPECT_EQ(Dart_IdentityHash(lib1), Dart_IdentityHash(lib1)); |
| 610 EXPECT_EQ(Dart_IdentityHash(lib2), Dart_IdentityHash(lib2)); |
| 611 } |
| 612 } |
| 613 |
| 614 |
562 TEST_CASE(ObjectEquals) { | 615 TEST_CASE(ObjectEquals) { |
563 bool equal = false; | 616 bool equal = false; |
564 Dart_Handle five = NewString("5"); | 617 Dart_Handle five = NewString("5"); |
565 Dart_Handle five_again = NewString("5"); | 618 Dart_Handle five_again = NewString("5"); |
566 Dart_Handle seven = NewString("7"); | 619 Dart_Handle seven = NewString("7"); |
567 | 620 |
568 // Same objects. | 621 // Same objects. |
569 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); | 622 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); |
570 EXPECT(equal); | 623 EXPECT(equal); |
571 | 624 |
(...skipping 7585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8157 NewString("main"), | 8210 NewString("main"), |
8158 1, | 8211 1, |
8159 dart_args); | 8212 dart_args); |
8160 int64_t value = 0; | 8213 int64_t value = 0; |
8161 result = Dart_IntegerToInt64(result, &value); | 8214 result = Dart_IntegerToInt64(result, &value); |
8162 EXPECT_VALID(result); | 8215 EXPECT_VALID(result); |
8163 EXPECT_EQ(6, value); | 8216 EXPECT_EQ(6, value); |
8164 } | 8217 } |
8165 | 8218 |
8166 } // namespace dart | 8219 } // namespace dart |
OLD | NEW |