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

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

Issue 8492015: Allow printf-style arguments for Dart_Error and Api::Error. (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"
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(Dart_Error) {
17 Dart_CreateIsolate(NULL, NULL);
18 Dart_EnterScope();
19
20 Dart_Handle error = Dart_Error("An %s", "error");
21 EXPECT(!Dart_IsValid(error));
22 EXPECT_STREQ("An error", Dart_GetError(error));
23
24 Dart_ExitScope();
25 Dart_ShutdownIsolate();
26 }
27
28
16 UNIT_TEST_CASE(Null) { 29 UNIT_TEST_CASE(Null) {
17 Dart_CreateIsolate(NULL, NULL); 30 Dart_CreateIsolate(NULL, NULL);
18 Dart_EnterScope(); // Enter a Dart API scope for the unit test. 31 Dart_EnterScope(); // Enter a Dart API scope for the unit test.
19 32
20 Dart_Handle null = Dart_Null(); 33 Dart_Handle null = Dart_Null();
21 EXPECT_VALID(null); 34 EXPECT_VALID(null);
22 EXPECT(Dart_IsNull(null)); 35 EXPECT(Dart_IsNull(null));
23 36
24 Dart_Handle str = Dart_NewString("test"); 37 Dart_Handle str = Dart_NewString("test");
25 EXPECT_VALID(str); 38 EXPECT_VALID(str);
(...skipping 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 result = Dart_IntegerValue(result, &value); 1557 result = Dart_IntegerValue(result, &value);
1545 EXPECT_VALID(result); 1558 EXPECT_VALID(result);
1546 EXPECT_EQ(3, value); 1559 EXPECT_EQ(3, value);
1547 1560
1548 Dart_ExitScope(); 1561 Dart_ExitScope();
1549 } 1562 }
1550 Dart_ShutdownIsolate(); 1563 Dart_ShutdownIsolate();
1551 } 1564 }
1552 1565
1553 1566
1567 UNIT_TEST_CASE(GetClass) {
1568 const char* kScriptChars =
1569 "class DoesExist {"
1570 "}";
1571
1572 Dart_CreateIsolate(NULL, NULL);
1573 Dart_EnterScope();
1574 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1575
1576 // Lookup a class that does exist.
1577 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("DoesExist"));
1578 EXPECT_VALID(cls);
1579
1580 // Lookup a class that does not exist.
1581 cls = Dart_GetClass(lib, Dart_NewString("DoesNotExist"));
1582 EXPECT(!Dart_IsValid(cls));
1583 EXPECT_STREQ("Class 'DoesNotExist' not found in library 'dart:test-lib'.",
1584 Dart_GetError(cls));
1585
1586 Dart_ExitScope();
1587 Dart_ShutdownIsolate();
1588 }
1589
1590
1554 UNIT_TEST_CASE(InstanceOf) { 1591 UNIT_TEST_CASE(InstanceOf) {
1555 const char* kScriptChars = 1592 const char* kScriptChars =
1556 "class OtherClass {\n" 1593 "class OtherClass {\n"
1557 " static returnNull() { return null; }\n" 1594 " static returnNull() { return null; }\n"
1558 "}\n" 1595 "}\n"
1559 "class InstanceOfTest {\n" 1596 "class InstanceOfTest {\n"
1560 " InstanceOfTest() {}\n" 1597 " InstanceOfTest() {}\n"
1561 " static InstanceOfTest testMain() {\n" 1598 " static InstanceOfTest testMain() {\n"
1562 " return new InstanceOfTest();\n" 1599 " return new InstanceOfTest();\n"
1563 " }\n" 1600 " }\n"
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 NULL); 1974 NULL);
1938 EXPECT_VALID(result); 1975 EXPECT_VALID(result);
1939 1976
1940 Dart_ExitScope(); // Exit the Dart API scope. 1977 Dart_ExitScope(); // Exit the Dart API scope.
1941 } 1978 }
1942 Dart_ShutdownIsolate(); 1979 Dart_ShutdownIsolate();
1943 } 1980 }
1944 #endif // TARGET_ARCH_IA32. 1981 #endif // TARGET_ARCH_IA32.
1945 1982
1946 } // namespace dart 1983 } // 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