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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 8490016: Renaming: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
« runtime/include/dart_api.h ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 27 matching lines...) Expand all
38 38
39 Dart_Handle str = Dart_NewString("test"); 39 Dart_Handle str = Dart_NewString("test");
40 EXPECT_VALID(str); 40 EXPECT_VALID(str);
41 EXPECT(!Dart_IsNull(str)); 41 EXPECT(!Dart_IsNull(str));
42 42
43 Dart_ExitScope(); // Exit the Dart API scope. 43 Dart_ExitScope(); // Exit the Dart API scope.
44 Dart_ShutdownIsolate(); 44 Dart_ShutdownIsolate();
45 } 45 }
46 46
47 47
48 UNIT_TEST_CASE(IsSame) {
49 Dart_CreateIsolate(NULL, NULL);
50 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
51
52 bool same = false;
53 Dart_Handle five = Dart_NewString("5");
54 Dart_Handle five_again = Dart_NewString("5");
55 Dart_Handle seven = Dart_NewString("7");
56
57 // Same objects.
58 EXPECT_VALID(Dart_IsSame(five, five, &same));
59 EXPECT(same);
60
61 // Equal objects.
62 EXPECT_VALID(Dart_IsSame(five, five_again, &same));
63 EXPECT(!same);
64
65 // Different objects.
66 EXPECT_VALID(Dart_IsSame(five, seven, &same));
67 EXPECT(!same);
68
69 // Non-instance objects.
70 {
71 Zone zone;
72 HandleScope hs;
73 const Object& cls1 = Object::Handle(Object::null_class());
74 const Object& cls2 = Object::Handle(Object::class_class());
75 Dart_Handle class1 = Api::NewLocalHandle(cls1);
76 Dart_Handle class2 = Api::NewLocalHandle(cls2);
77
78 EXPECT_VALID(Dart_IsSame(class1, class1, &same));
79 EXPECT(same);
80
81 EXPECT_VALID(Dart_IsSame(class1, class2, &same));
82 EXPECT(!same);
83 }
84
85 Dart_ExitScope(); // Exit the Dart API scope.
86 Dart_ShutdownIsolate();
87 }
88
89
90 UNIT_TEST_CASE(ObjectEquals) {
91 Dart_CreateIsolate(NULL, NULL);
92 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
93
94 bool equal = false;
95 Dart_Handle five = Dart_NewString("5");
96 Dart_Handle five_again = Dart_NewString("5");
97 Dart_Handle seven = Dart_NewString("7");
98
99 // Same objects.
100 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal));
101 EXPECT(equal);
102
103 // Equal objects.
104 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal));
105 EXPECT(equal);
106
107 // Different objects.
108 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal));
109 EXPECT(!equal);
110
111 Dart_ExitScope(); // Exit the Dart API scope.
112 Dart_ShutdownIsolate();
113 }
114
115
48 UNIT_TEST_CASE(BooleanValues) { 116 UNIT_TEST_CASE(BooleanValues) {
49 Dart_CreateIsolate(NULL, NULL); 117 Dart_CreateIsolate(NULL, NULL);
50 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 118 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
51 119
52 Dart_Handle str = Dart_NewString("test"); 120 Dart_Handle str = Dart_NewString("test");
53 EXPECT(!Dart_IsBoolean(str)); 121 EXPECT(!Dart_IsBoolean(str));
54 122
55 bool value = false; 123 bool value = false;
56 Dart_Handle result = Dart_BooleanValue(str, &value); 124 Dart_Handle result = Dart_BooleanValue(str, &value);
57 EXPECT(!Dart_IsValid(result)); 125 EXPECT(!Dart_IsValid(result));
(...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 EXPECT(!Dart_ExceptionOccurred(instanceOfTestObj)); 1689 EXPECT(!Dart_ExceptionOccurred(instanceOfTestObj));
1622 1690
1623 // Fetch InstanceOfTest class. 1691 // Fetch InstanceOfTest class.
1624 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("InstanceOfTest")); 1692 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("InstanceOfTest"));
1625 EXPECT_VALID(cls); 1693 EXPECT_VALID(cls);
1626 EXPECT(!Dart_ExceptionOccurred(cls)); 1694 EXPECT(!Dart_ExceptionOccurred(cls));
1627 1695
1628 // Now check instanceOfTestObj reported as an instance of 1696 // Now check instanceOfTestObj reported as an instance of
1629 // InstanceOfTest class. 1697 // InstanceOfTest class.
1630 bool is_instance = false; 1698 bool is_instance = false;
1631 result = Dart_IsInstanceOf(instanceOfTestObj, cls, &is_instance); 1699 result = Dart_ObjectIsType(instanceOfTestObj, cls, &is_instance);
1632 EXPECT_VALID(result); 1700 EXPECT_VALID(result);
1633 EXPECT(is_instance); 1701 EXPECT(is_instance);
1634 1702
1635 // Fetch OtherClass and check if instanceOfTestObj is instance of it. 1703 // Fetch OtherClass and check if instanceOfTestObj is instance of it.
1636 Dart_Handle otherClass = Dart_GetClass(lib, Dart_NewString("OtherClass")); 1704 Dart_Handle otherClass = Dart_GetClass(lib, Dart_NewString("OtherClass"));
1637 EXPECT_VALID(otherClass); 1705 EXPECT_VALID(otherClass);
1638 EXPECT(!Dart_ExceptionOccurred(otherClass)); 1706 EXPECT(!Dart_ExceptionOccurred(otherClass));
1639 1707
1640 result = Dart_IsInstanceOf(instanceOfTestObj, otherClass, &is_instance); 1708 result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance);
1641 EXPECT_VALID(result); 1709 EXPECT_VALID(result);
1642 EXPECT(!is_instance); 1710 EXPECT(!is_instance);
1643 1711
1644 // Check that primitives are not instances of InstanceOfTest class. 1712 // Check that primitives are not instances of InstanceOfTest class.
1645 result = Dart_IsInstanceOf(Dart_NewString("a string"), otherClass, 1713 result = Dart_ObjectIsType(Dart_NewString("a string"), otherClass,
1646 &is_instance); 1714 &is_instance);
1647 EXPECT_VALID(result); 1715 EXPECT_VALID(result);
1648 EXPECT(!is_instance); 1716 EXPECT(!is_instance);
1649 1717
1650 result = Dart_IsInstanceOf(Dart_NewInteger(42), otherClass, &is_instance); 1718 result = Dart_ObjectIsType(Dart_NewInteger(42), otherClass, &is_instance);
1651 EXPECT_VALID(result); 1719 EXPECT_VALID(result);
1652 EXPECT(!is_instance); 1720 EXPECT(!is_instance);
1653 1721
1654 result = Dart_IsInstanceOf(Dart_NewBoolean(true), otherClass, &is_instance); 1722 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherClass, &is_instance);
1655 EXPECT_VALID(result); 1723 EXPECT_VALID(result);
1656 EXPECT(!is_instance); 1724 EXPECT(!is_instance);
1657 1725
1658 // Check that null is not an instance of InstanceOfTest class. 1726 // Check that null is not an instance of InstanceOfTest class.
1659 Dart_Handle null = Dart_InvokeStatic(lib, 1727 Dart_Handle null = Dart_InvokeStatic(lib,
1660 Dart_NewString("OtherClass"), 1728 Dart_NewString("OtherClass"),
1661 Dart_NewString("returnNull"), 1729 Dart_NewString("returnNull"),
1662 0, 1730 0,
1663 NULL); 1731 NULL);
1664 EXPECT_VALID(null); 1732 EXPECT_VALID(null);
1665 EXPECT(!Dart_ExceptionOccurred(null)); 1733 EXPECT(!Dart_ExceptionOccurred(null));
1666 1734
1667 result = Dart_IsInstanceOf(null, otherClass, &is_instance); 1735 result = Dart_ObjectIsType(null, otherClass, &is_instance);
1668 EXPECT_VALID(result); 1736 EXPECT_VALID(result);
1669 EXPECT(!is_instance); 1737 EXPECT(!is_instance);
1670 1738
1671 // Check that error is returned if null is passed as a class argument. 1739 // Check that error is returned if null is passed as a class argument.
1672 result = Dart_IsInstanceOf(null, null, &is_instance); 1740 result = Dart_ObjectIsType(null, null, &is_instance);
1673 EXPECT(!Dart_IsValid(result)); 1741 EXPECT(!Dart_IsValid(result));
1674 1742
1675 Dart_ExitScope(); // Exit the Dart API scope. 1743 Dart_ExitScope(); // Exit the Dart API scope.
1676 } 1744 }
1677 Dart_ShutdownIsolate(); 1745 Dart_ShutdownIsolate();
1678 } 1746 }
1679 1747
1680 1748
1681 UNIT_TEST_CASE(NullReceiver) { 1749 UNIT_TEST_CASE(NullReceiver) {
1682 Dart_CreateIsolate(NULL, NULL); 1750 Dart_CreateIsolate(NULL, NULL);
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1976 NULL); 2044 NULL);
1977 EXPECT_VALID(result); 2045 EXPECT_VALID(result);
1978 2046
1979 Dart_ExitScope(); // Exit the Dart API scope. 2047 Dart_ExitScope(); // Exit the Dart API scope.
1980 } 2048 }
1981 Dart_ShutdownIsolate(); 2049 Dart_ShutdownIsolate();
1982 } 2050 }
1983 #endif // TARGET_ARCH_IA32. 2051 #endif // TARGET_ARCH_IA32.
1984 2052
1985 } // namespace dart 2053 } // namespace dart
OLDNEW
« runtime/include/dart_api.h ('K') | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698