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

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

Issue 8429027: Add an external array type to support typed arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments from patch set 1 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 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 1585
1586 other_array = Array::New(kArrayLen - 1); 1586 other_array = Array::New(kArrayLen - 1);
1587 other_array.SetAt(0, array); 1587 other_array.SetAt(0, array);
1588 other_array.SetAt(2, array); 1588 other_array.SetAt(2, array);
1589 EXPECT(!array.Equals(other_array)); 1589 EXPECT(!array.Equals(other_array));
1590 1590
1591 EXPECT_EQ(0, Array::Handle(Array::Empty()).Length()); 1591 EXPECT_EQ(0, Array::Handle(Array::Empty()).Length());
1592 } 1592 }
1593 1593
1594 1594
1595 TEST_CASE(ByteBuffer) {
1596 uint8_t data[] = { 253, 254, 255, 0, 1, 2, 3, 4 };
1597 intptr_t data_length = ARRAY_SIZE(data);
1598
1599 const ByteBuffer& array1 =
1600 ByteBuffer::Handle(ByteBuffer::New(data, data_length));
1601 EXPECT(!array1.IsNull());
1602 EXPECT_EQ(data_length, array1.Length());
1603 EXPECT_EQ(-3, array1.At<int8_t>(0));
1604 EXPECT_EQ(253, array1.At<uint8_t>(0));
1605 EXPECT_EQ(-2, array1.At<int8_t>(1));
1606 EXPECT_EQ(254, array1.At<uint8_t>(1));
1607 EXPECT_EQ(-1, array1.At<int8_t>(2));
1608 EXPECT_EQ(255, array1.At<uint8_t>(2));
1609 EXPECT_EQ(0, array1.At<int8_t>(3));
1610 EXPECT_EQ(0, array1.At<uint8_t>(3));
1611 EXPECT_EQ(1, array1.At<int8_t>(4));
1612 EXPECT_EQ(1, array1.At<uint8_t>(4));
1613 EXPECT_EQ(2, array1.At<int8_t>(5));
1614 EXPECT_EQ(2, array1.At<uint8_t>(5));
1615
1616 const ByteBuffer& array2 =
1617 ByteBuffer::Handle(ByteBuffer::New(data, data_length));
1618 EXPECT(!array1.IsNull());
1619 EXPECT_EQ(data_length, array2.Length());
1620 EXPECT(array1.Equals(array2));
1621 EXPECT(array2.Equals(array1));
1622 array1.SetAt<uint8_t>(0, 123);
1623 array2.SetAt<int8_t>(2, -123);
1624 EXPECT(array1.Equals(array2));
1625 EXPECT(array2.Equals(array1));
1626
1627 memset(data, 0, ARRAY_SIZE(data));
1628 array1.SetAt<float>(0, FLT_MIN);
1629 array1.SetAt<float>(1, FLT_MAX);
1630 EXPECT_EQ(FLT_MIN, array2.At<float>(0));
1631 EXPECT_EQ(FLT_MAX, array2.At<float>(1));
1632
1633 array1.SetAt<float>(0, 0.0f);
1634 EXPECT_EQ(0.0f, array2.At<float>(0));
1635 array1.SetAt<float>(1, 1.0f);
1636 EXPECT_EQ(1.0f, array2.At<float>(1));
1637
1638 array1.SetAt<double>(0, DBL_MIN);
1639 EXPECT_EQ(DBL_MIN, array2.At<double>(0));
1640 array1.SetAt<double>(0, DBL_MAX);
1641 EXPECT_EQ(DBL_MAX, array2.At<double>(0));
1642
1643 array1.SetAt<double>(0, 0.0);
1644 EXPECT_EQ(0.0, array2.At<double>(0));
1645 array1.SetAt<double>(0, 1.0);
1646 EXPECT_EQ(1.0, array2.At<double>(0));
1647 }
1648
1649
1595 TEST_CASE(Script) { 1650 TEST_CASE(Script) {
1596 const char* url_chars = "builtin:test-case"; 1651 const char* url_chars = "builtin:test-case";
1597 const char* source_chars = "This will not compile."; 1652 const char* source_chars = "This will not compile.";
1598 const String& url = String::Handle(String::New(url_chars)); 1653 const String& url = String::Handle(String::New(url_chars));
1599 const String& source = String::Handle(String::New(source_chars)); 1654 const String& source = String::Handle(String::New(source_chars));
1600 const Script& script = Script::Handle(Script::New(url, 1655 const Script& script = Script::Handle(Script::New(url,
1601 source, 1656 source,
1602 RawScript::kSource)); 1657 RawScript::kSource));
1603 EXPECT(!script.IsNull()); 1658 EXPECT(!script.IsNull());
1604 EXPECT(script.IsScript()); 1659 EXPECT(script.IsScript());
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 cls = iterator.GetNextClass(); 2004 cls = iterator.GetNextClass();
1950 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); 2005 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw()));
1951 count++; 2006 count++;
1952 } 2007 }
1953 ASSERT(count == 2); 2008 ASSERT(count == 2);
1954 } 2009 }
1955 2010
1956 #endif // TARGET_ARCH_IA32. 2011 #endif // TARGET_ARCH_IA32.
1957 2012
1958 } // namespace dart 2013 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698