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

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

Issue 8383029: Implement external strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fully displace external string metadata 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
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 "vm/assert.h" 5 #include "vm/assert.h"
6 #include "vm/assembler.h" 6 #include "vm/assembler.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 EXPECT(str.IsFourByteString()); 1483 EXPECT(str.IsFourByteString());
1484 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); 1484 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
1485 EXPECT_EQ(expected_size, str.Length()); 1485 EXPECT_EQ(expected_size, str.Length());
1486 for (int i = 0; i < str.Length(); ++i) { 1486 for (int i = 0; i < str.Length(); ++i) {
1487 EXPECT_EQ(expected[i], str.CharAt(i)); 1487 EXPECT_EQ(expected[i], str.CharAt(i));
1488 } 1488 }
1489 } 1489 }
1490 } 1490 }
1491 1491
1492 1492
1493 TEST_CASE(ExternalOneByteString) {
1494 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 };
1495 intptr_t len = ARRAY_SIZE(characters);
1496
1497 const String& str =
1498 String::Handle(
1499 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew));
1500 EXPECT(!str.IsOneByteString());
1501 EXPECT(str.IsExternalOneByteString());
1502 EXPECT_EQ(str.Length(), len);
1503 EXPECT(str.Equals("\xC3\xB6\xC3\xB1\xC3\xA9"));
1504
1505 const String& copy = String::Handle(String::SubString(str, 0, len));
1506 EXPECT(!copy.IsExternalOneByteString());
1507 EXPECT(copy.IsOneByteString());
1508 EXPECT_EQ(len, copy.Length());
1509 EXPECT(copy.Equals(str));
1510
1511 const String& concat = String::Handle(String::Concat(str, str));
1512 EXPECT(!concat.IsExternalOneByteString());
1513 EXPECT(concat.IsOneByteString());
1514 EXPECT_EQ(len * 2, concat.Length());
1515 EXPECT(concat.Equals("\xC3\xB6\xC3\xB1\xC3\xA9\xC3\xB6\xC3\xB1\xC3\xA9"));
1516
1517 const String& substr = String::Handle(String::SubString(str, 1, 1));
1518 EXPECT(!substr.IsExternalOneByteString());
1519 EXPECT(substr.IsOneByteString());
1520 EXPECT_EQ(1, substr.Length());
1521 EXPECT(substr.Equals("\xC3\xB1"));
1522 }
1523
1524
1525 TEST_CASE(ExternalTwoByteString) {
1526 uint16_t characters[] = { 0x1E6B, 0x1E85, 0x1E53 };
1527 intptr_t len = ARRAY_SIZE(characters);
1528
1529 const String& str =
1530 String::Handle(
1531 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew));
1532 EXPECT(!str.IsTwoByteString());
1533 EXPECT(str.IsExternalTwoByteString());
1534 EXPECT_EQ(str.Length(), len);
1535 EXPECT(str.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"));
1536
1537 const String& copy = String::Handle(String::SubString(str, 0, len));
1538 EXPECT(!copy.IsExternalTwoByteString());
1539 EXPECT(copy.IsTwoByteString());
1540 EXPECT_EQ(len, copy.Length());
1541 EXPECT(copy.Equals(str));
1542
1543 const String& concat = String::Handle(String::Concat(str, str));
1544 EXPECT(!concat.IsExternalTwoByteString());
1545 EXPECT(concat.IsTwoByteString());
1546 EXPECT_EQ(len * 2, concat.Length());
1547 EXPECT(concat.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"
1548 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"));
1549
1550 const String& substr = String::Handle(String::SubString(str, 1, 1));
1551 EXPECT(!substr.IsExternalTwoByteString());
1552 EXPECT(substr.IsTwoByteString());
1553 EXPECT_EQ(1, substr.Length());
1554 EXPECT(substr.Equals("\xE1\xBA\x85"));
1555 }
1556
1557
1558 TEST_CASE(ExternalFourByteString) {
1559 uint32_t characters[] = { 0x1D5BF, 0x1D5C8, 0x1D5CE, 0x1D5CB };
1560 intptr_t len = ARRAY_SIZE(characters);
1561
1562 const String& str =
1563 String::Handle(
1564 ExternalFourByteString::New(characters, len, NULL, NULL, Heap::kNew));
1565 EXPECT(!str.IsFourByteString());
1566 EXPECT(str.IsExternalFourByteString());
1567 EXPECT_EQ(str.Length(), len);
1568 EXPECT(str.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1569 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
1570
1571 const String& copy = String::Handle(String::SubString(str, 0, len));
1572 EXPECT(!copy.IsExternalFourByteString());
1573 EXPECT(copy.IsFourByteString());
1574 EXPECT_EQ(len, copy.Length());
1575 EXPECT(copy.Equals(str));
1576
1577 const String& concat = String::Handle(String::Concat(str, str));
1578 EXPECT(!concat.IsExternalFourByteString());
1579 EXPECT(concat.IsFourByteString());
1580 EXPECT_EQ(len * 2, concat.Length());
1581 EXPECT(concat.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1582 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"
1583 "\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1584 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
1585
1586 const String& substr = String::Handle(String::SubString(str, 1, 2));
1587 EXPECT(!substr.IsExternalFourByteString());
1588 EXPECT(substr.IsFourByteString());
1589 EXPECT_EQ(2, substr.Length());
1590 EXPECT(substr.Equals("\xF0\x9D\x97\x88\xF0\x9D\x97\x8E"));
1591 }
1592
1593
1493 TEST_CASE(Symbol) { 1594 TEST_CASE(Symbol) {
1494 const String& one = String::Handle(String::NewSymbol("Eins")); 1595 const String& one = String::Handle(String::NewSymbol("Eins"));
1495 EXPECT(one.IsSymbol()); 1596 EXPECT(one.IsSymbol());
1496 const String& two = String::Handle(String::NewSymbol("Zwei")); 1597 const String& two = String::Handle(String::NewSymbol("Zwei"));
1497 const String& three = String::Handle(String::NewSymbol("Drei")); 1598 const String& three = String::Handle(String::NewSymbol("Drei"));
1498 const String& four = String::Handle(String::NewSymbol("Vier")); 1599 const String& four = String::Handle(String::NewSymbol("Vier"));
1499 const String& five = String::Handle(String::NewSymbol("Fuenf")); 1600 const String& five = String::Handle(String::NewSymbol("Fuenf"));
1500 const String& six = String::Handle(String::NewSymbol("Sechs")); 1601 const String& six = String::Handle(String::NewSymbol("Sechs"));
1501 const String& seven = String::Handle(String::NewSymbol("Sieben")); 1602 const String& seven = String::Handle(String::NewSymbol("Sieben"));
1502 const String& eight = String::Handle(String::NewSymbol("Acht")); 1603 const String& eight = String::Handle(String::NewSymbol("Acht"));
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 cls = iterator.GetNextClass(); 2050 cls = iterator.GetNextClass();
1950 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); 2051 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw()));
1951 count++; 2052 count++;
1952 } 2053 }
1953 ASSERT(count == 2); 2054 ASSERT(count == 2);
1954 } 2055 }
1955 2056
1956 #endif // TARGET_ARCH_IA32. 2057 #endif // TARGET_ARCH_IA32.
1957 2058
1958 } // namespace dart 2059 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698