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

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/vm/dart_api_impl.cc ('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 12 matching lines...) Expand all
23 23
24 Dart_Handle str = Dart_NewString("test"); 24 Dart_Handle str = Dart_NewString("test");
25 EXPECT_VALID(str); 25 EXPECT_VALID(str);
26 EXPECT(!Dart_IsNull(str)); 26 EXPECT(!Dart_IsNull(str));
27 27
28 Dart_ExitScope(); // Exit the Dart API scope. 28 Dart_ExitScope(); // Exit the Dart API scope.
29 Dart_ShutdownIsolate(); 29 Dart_ShutdownIsolate();
30 } 30 }
31 31
32 32
33 UNIT_TEST_CASE(IsSame) {
34 Dart_CreateIsolate(NULL, NULL);
35 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
36
37 bool identical = false;
38 Dart_Handle five = Dart_NewString("5");
39 Dart_Handle five_again = Dart_NewString("5");
40 Dart_Handle seven = Dart_NewString("7");
41
42 // Identical objects.
43 EXPECT_VALID(Dart_IsSame(five, five, &identical));
44 EXPECT(identical);
45
46 // Equal objects.
47 EXPECT_VALID(Dart_IsSame(five, five_again, &identical));
48 EXPECT(!identical);
49
50 // Different objects.
51 EXPECT_VALID(Dart_IsSame(five, seven, &identical));
52 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.
53
54 Dart_ExitScope(); // Exit the Dart API scope.
55 Dart_ShutdownIsolate();
56 }
57
58
59 UNIT_TEST_CASE(ObjectEquals) {
60 Dart_CreateIsolate(NULL, NULL);
61 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
62
63 bool equal = false;
64 Dart_Handle five = Dart_NewString("5");
65 Dart_Handle five_again = Dart_NewString("5");
66 Dart_Handle seven = Dart_NewString("7");
67
68 // Identical objects.
69 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal));
70 EXPECT(equal);
71
72 // Equal objects.
73 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal));
74 EXPECT(equal);
75
76 // Different objects.
77 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal));
78 EXPECT(!equal);
79
80 Dart_ExitScope(); // Exit the Dart API scope.
81 Dart_ShutdownIsolate();
82 }
83
84
33 UNIT_TEST_CASE(BooleanValues) { 85 UNIT_TEST_CASE(BooleanValues) {
34 Dart_CreateIsolate(NULL, NULL); 86 Dart_CreateIsolate(NULL, NULL);
35 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 87 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
36 88
37 Dart_Handle str = Dart_NewString("test"); 89 Dart_Handle str = Dart_NewString("test");
38 EXPECT(!Dart_IsBoolean(str)); 90 EXPECT(!Dart_IsBoolean(str));
39 91
40 bool value = false; 92 bool value = false;
41 Dart_Handle result = Dart_BooleanValue(str, &value); 93 Dart_Handle result = Dart_BooleanValue(str, &value);
42 EXPECT(!Dart_IsValid(result)); 94 EXPECT(!Dart_IsValid(result));
(...skipping 1539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 EXPECT(!Dart_ExceptionOccurred(instanceOfTestObj)); 1634 EXPECT(!Dart_ExceptionOccurred(instanceOfTestObj));
1583 1635
1584 // Fetch InstanceOfTest class. 1636 // Fetch InstanceOfTest class.
1585 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("InstanceOfTest")); 1637 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("InstanceOfTest"));
1586 EXPECT_VALID(cls); 1638 EXPECT_VALID(cls);
1587 EXPECT(!Dart_ExceptionOccurred(cls)); 1639 EXPECT(!Dart_ExceptionOccurred(cls));
1588 1640
1589 // Now check instanceOfTestObj reported as an instance of 1641 // Now check instanceOfTestObj reported as an instance of
1590 // InstanceOfTest class. 1642 // InstanceOfTest class.
1591 bool is_instance = false; 1643 bool is_instance = false;
1592 result = Dart_IsInstanceOf(instanceOfTestObj, cls, &is_instance); 1644 result = Dart_ObjectIsType(instanceOfTestObj, cls, &is_instance);
1593 EXPECT_VALID(result); 1645 EXPECT_VALID(result);
1594 EXPECT(is_instance); 1646 EXPECT(is_instance);
1595 1647
1596 // Fetch OtherClass and check if instanceOfTestObj is instance of it. 1648 // Fetch OtherClass and check if instanceOfTestObj is instance of it.
1597 Dart_Handle otherClass = Dart_GetClass(lib, Dart_NewString("OtherClass")); 1649 Dart_Handle otherClass = Dart_GetClass(lib, Dart_NewString("OtherClass"));
1598 EXPECT_VALID(otherClass); 1650 EXPECT_VALID(otherClass);
1599 EXPECT(!Dart_ExceptionOccurred(otherClass)); 1651 EXPECT(!Dart_ExceptionOccurred(otherClass));
1600 1652
1601 result = Dart_IsInstanceOf(instanceOfTestObj, otherClass, &is_instance); 1653 result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance);
1602 EXPECT_VALID(result); 1654 EXPECT_VALID(result);
1603 EXPECT(!is_instance); 1655 EXPECT(!is_instance);
1604 1656
1605 // Check that primitives are not instances of InstanceOfTest class. 1657 // Check that primitives are not instances of InstanceOfTest class.
1606 result = Dart_IsInstanceOf(Dart_NewString("a string"), otherClass, 1658 result = Dart_ObjectIsType(Dart_NewString("a string"), otherClass,
1607 &is_instance); 1659 &is_instance);
1608 EXPECT_VALID(result); 1660 EXPECT_VALID(result);
1609 EXPECT(!is_instance); 1661 EXPECT(!is_instance);
1610 1662
1611 result = Dart_IsInstanceOf(Dart_NewInteger(42), otherClass, &is_instance); 1663 result = Dart_ObjectIsType(Dart_NewInteger(42), otherClass, &is_instance);
1612 EXPECT_VALID(result); 1664 EXPECT_VALID(result);
1613 EXPECT(!is_instance); 1665 EXPECT(!is_instance);
1614 1666
1615 result = Dart_IsInstanceOf(Dart_NewBoolean(true), otherClass, &is_instance); 1667 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherClass, &is_instance);
1616 EXPECT_VALID(result); 1668 EXPECT_VALID(result);
1617 EXPECT(!is_instance); 1669 EXPECT(!is_instance);
1618 1670
1619 // Check that null is not an instance of InstanceOfTest class. 1671 // Check that null is not an instance of InstanceOfTest class.
1620 Dart_Handle null = Dart_InvokeStatic(lib, 1672 Dart_Handle null = Dart_InvokeStatic(lib,
1621 Dart_NewString("OtherClass"), 1673 Dart_NewString("OtherClass"),
1622 Dart_NewString("returnNull"), 1674 Dart_NewString("returnNull"),
1623 0, 1675 0,
1624 NULL); 1676 NULL);
1625 EXPECT_VALID(null); 1677 EXPECT_VALID(null);
1626 EXPECT(!Dart_ExceptionOccurred(null)); 1678 EXPECT(!Dart_ExceptionOccurred(null));
1627 1679
1628 result = Dart_IsInstanceOf(null, otherClass, &is_instance); 1680 result = Dart_ObjectIsType(null, otherClass, &is_instance);
1629 EXPECT_VALID(result); 1681 EXPECT_VALID(result);
1630 EXPECT(!is_instance); 1682 EXPECT(!is_instance);
1631 1683
1632 // Check that error is returned if null is passed as a class argument. 1684 // Check that error is returned if null is passed as a class argument.
1633 result = Dart_IsInstanceOf(null, null, &is_instance); 1685 result = Dart_ObjectIsType(null, null, &is_instance);
1634 EXPECT(!Dart_IsValid(result)); 1686 EXPECT(!Dart_IsValid(result));
1635 1687
1636 Dart_ExitScope(); // Exit the Dart API scope. 1688 Dart_ExitScope(); // Exit the Dart API scope.
1637 } 1689 }
1638 Dart_ShutdownIsolate(); 1690 Dart_ShutdownIsolate();
1639 } 1691 }
1640 1692
1641 1693
1642 UNIT_TEST_CASE(NullReceiver) { 1694 UNIT_TEST_CASE(NullReceiver) {
1643 Dart_CreateIsolate(NULL, NULL); 1695 Dart_CreateIsolate(NULL, NULL);
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 NULL); 1989 NULL);
1938 EXPECT_VALID(result); 1990 EXPECT_VALID(result);
1939 1991
1940 Dart_ExitScope(); // Exit the Dart API scope. 1992 Dart_ExitScope(); // Exit the Dart API scope.
1941 } 1993 }
1942 Dart_ShutdownIsolate(); 1994 Dart_ShutdownIsolate();
1943 } 1995 }
1944 #endif // TARGET_ARCH_IA32. 1996 #endif // TARGET_ARCH_IA32.
1945 1997
1946 } // namespace dart 1998 } // namespace dart
OLDNEW
« runtime/vm/dart_api_impl.cc ('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