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

Side by Side Diff: vm/dart_api_impl_test.cc

Issue 11580003: Changes per discussion with Anton (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years 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
« no previous file with comments | « 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) 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/json.h" 7 #include "platform/json.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 EXPECT_EQ(4, len); 525 EXPECT_EQ(4, len);
526 526
527 uint8_t data8[] = { 'o', 'n', 'e', 0x7F }; 527 uint8_t data8[] = { 'o', 'n', 'e', 0x7F };
528 528
529 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8)); 529 Dart_Handle str8 = Dart_NewStringFromUTF8(data8, ARRAY_SIZE(data8));
530 EXPECT_VALID(str8); 530 EXPECT_VALID(str8);
531 EXPECT(Dart_IsString(str8)); 531 EXPECT(Dart_IsString(str8));
532 EXPECT(Dart_IsStringLatin1(str8)); 532 EXPECT(Dart_IsStringLatin1(str8));
533 EXPECT(!Dart_IsExternalString(str8)); 533 EXPECT(!Dart_IsExternalString(str8));
534 534
535 uint8_t latin1_array[] = {0, 0, 0, 0, 0};
536 len = 5;
537 Dart_Handle result = Dart_StringToLatin1(str8, latin1_array, &len);
538 EXPECT_VALID(result);
539 EXPECT_EQ(4, len);
540 EXPECT(latin1_array != NULL);
541 for (intptr_t i = 0; i < len; i++) {
542 EXPECT_EQ(data8[i], latin1_array[i]);
543 }
544
535 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), 545 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8),
536 NULL, NULL); 546 NULL, NULL);
537 EXPECT_VALID(ext8); 547 EXPECT_VALID(ext8);
538 EXPECT(Dart_IsString(ext8)); 548 EXPECT(Dart_IsString(ext8));
539 EXPECT(Dart_IsExternalString(ext8)); 549 EXPECT(Dart_IsExternalString(ext8));
540 550
541 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF }; 551 uint16_t data16[] = { 't', 'w', 'o', 0xFFFF };
542 552
543 Dart_Handle str16 = Dart_NewStringFromUTF16(data16, ARRAY_SIZE(data16)); 553 Dart_Handle str16 = Dart_NewStringFromUTF16(data16, ARRAY_SIZE(data16));
544 EXPECT_VALID(str16); 554 EXPECT_VALID(str16);
(...skipping 6763 matching lines...) Expand 10 before | Expand all | Expand 10 after
7308 Dart_ExitScope(); 7318 Dart_ExitScope();
7309 } 7319 }
7310 EXPECT_EQ(40, peer8); 7320 EXPECT_EQ(40, peer8);
7311 EXPECT_EQ(41, peer16); 7321 EXPECT_EQ(41, peer16);
7312 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); 7322 Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
7313 EXPECT_EQ(80, peer8); 7323 EXPECT_EQ(80, peer8);
7314 EXPECT_EQ(82, peer16); 7324 EXPECT_EQ(82, peer16);
7315 } 7325 }
7316 7326
7317 7327
7328 TEST_CASE(ExternalizeConstantStrings) {
7329 const char* kScriptChars =
7330 "void testMain() {\n"
7331 " return 'constant string';\n"
7332 "}\n";
7333
7334 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
7335 Dart_Handle result = Dart_Invoke(lib,
7336 NewString("testMain"),
7337 0,
7338 NULL);
7339 const char* expected_str = "constant string";
7340 const intptr_t kExpectedLen = 15;
7341 int peer = 40;
7342 uint8_t ext_str[kExpectedLen];
7343 Dart_Handle str = Dart_MakeExternalString(result,
7344 ext_str,
7345 kExpectedLen,
7346 &peer,
7347 MakeExternalCback);
7348
7349 EXPECT(Dart_IsNull(str));
7350 for (intptr_t i = 0; i < kExpectedLen; i++) {
7351 EXPECT_EQ(expected_str[i], ext_str[i]);
7352 }
7353 }
7354
7355
7318 TEST_CASE(LazyLoadDeoptimizes) { 7356 TEST_CASE(LazyLoadDeoptimizes) {
7319 const char* kLoadFirst = 7357 const char* kLoadFirst =
7320 "start(a) {\n" 7358 "start(a) {\n"
7321 " var obj = (a == 1) ? createB() : new A();\n" 7359 " var obj = (a == 1) ? createB() : new A();\n"
7322 " for (int i = 0; i < 4000; i++) {\n" 7360 " for (int i = 0; i < 4000; i++) {\n"
7323 " var res = obj.foo();\n" 7361 " var res = obj.foo();\n"
7324 " if (a == 1) { if (res != 1) throw 'Error'; }\n" 7362 " if (a == 1) { if (res != 1) throw 'Error'; }\n"
7325 " else if (res != 2) throw 'Error'; \n" 7363 " else if (res != 2) throw 'Error'; \n"
7326 " }\n" 7364 " }\n"
7327 "}\n" 7365 "}\n"
(...skipping 21 matching lines...) Expand all
7349 Dart_LoadSource(TestCase::lib(), url, source); 7387 Dart_LoadSource(TestCase::lib(), url, source);
7350 7388
7351 dart_args[0] = Dart_NewInteger(1); 7389 dart_args[0] = Dart_NewInteger(1);
7352 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); 7390 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args);
7353 EXPECT_VALID(result); 7391 EXPECT_VALID(result);
7354 } 7392 }
7355 7393
7356 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 7394 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
7357 7395
7358 } // namespace dart 7396 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698