| OLD | NEW |
| 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 "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1944 EXPECT_EQ(1, Object::zero_array().Length()); | 1944 EXPECT_EQ(1, Object::zero_array().Length()); |
| 1945 element = Object::zero_array().At(0); | 1945 element = Object::zero_array().At(0); |
| 1946 EXPECT(Smi::Cast(element).IsZero()); | 1946 EXPECT(Smi::Cast(element).IsZero()); |
| 1947 | 1947 |
| 1948 array.MakeImmutable(); | 1948 array.MakeImmutable(); |
| 1949 Object& obj = Object::Handle(array.raw()); | 1949 Object& obj = Object::Handle(array.raw()); |
| 1950 EXPECT(obj.IsArray()); | 1950 EXPECT(obj.IsArray()); |
| 1951 } | 1951 } |
| 1952 | 1952 |
| 1953 | 1953 |
| 1954 TEST_CASE(ArrayLength) { | 1954 static void TestIllegalArrayLength(intptr_t length) { |
| 1955 const intptr_t kLength = Array::kMaxElements + 1; | |
| 1956 ASSERT(kLength >= 0); | |
| 1957 char buffer[1024]; | 1955 char buffer[1024]; |
| 1958 OS::SNPrint(buffer, sizeof(buffer), | 1956 OS::SNPrint(buffer, sizeof(buffer), |
| 1959 "main() {\n" | 1957 "main() {\n" |
| 1960 " new List(%" Pd ");\n" | 1958 " new List(%" Pd ");\n" |
| 1961 "}\n", | 1959 "}\n", |
| 1962 kLength); | 1960 length); |
| 1963 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); | 1961 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); |
| 1964 EXPECT_VALID(lib); | 1962 EXPECT_VALID(lib); |
| 1965 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1963 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 1966 OS::SNPrint(buffer, sizeof(buffer), | 1964 OS::SNPrint(buffer, sizeof(buffer), |
| 1967 "Unhandled exception:\n" | 1965 "Unhandled exception:\n" |
| 1968 "Invalid argument(s): Length (%" Pd ") must be an integer " | 1966 "Invalid argument(s): Length (%" Pd ") must be an integer " |
| 1969 "in the range [0..%" Pd "].", | 1967 "in the range [0..%" Pd "].", |
| 1970 kLength, Array::kMaxElements); | 1968 length, Array::kMaxElements); |
| 1971 EXPECT_ERROR(result, buffer); | 1969 EXPECT_ERROR(result, buffer); |
| 1972 } | 1970 } |
| 1973 | 1971 |
| 1974 | 1972 |
| 1973 TEST_CASE(ArrayLengthNegativeOne) { TestIllegalArrayLength(-1); } |
| 1974 TEST_CASE(ArrayLengthSmiMin) { TestIllegalArrayLength(kSmiMin); } |
| 1975 TEST_CASE(ArrayLengthOneTooMany) { |
| 1976 const intptr_t kOneTooMany = Array::kMaxElements + 1; |
| 1977 ASSERT(kOneTooMany >= 0); |
| 1978 TestIllegalArrayLength(kOneTooMany); |
| 1979 } |
| 1980 |
| 1981 |
| 1982 TEST_CASE(ArrayLengthMaxElements) { |
| 1983 char buffer[1024]; |
| 1984 OS::SNPrint(buffer, sizeof(buffer), |
| 1985 "main() {\n" |
| 1986 " return new List(%" Pd ");\n" |
| 1987 "}\n", |
| 1988 Array::kMaxElements); |
| 1989 Dart_Handle lib = TestCase::LoadTestScript(buffer, NULL); |
| 1990 EXPECT_VALID(lib); |
| 1991 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 1992 if (Dart_IsError(result)) { |
| 1993 EXPECT_ERROR(result, "Out of Memory"); |
| 1994 } else { |
| 1995 const intptr_t kExpected = Array::kMaxElements; |
| 1996 intptr_t actual = 0; |
| 1997 EXPECT_VALID(Dart_ListLength(result, &actual)); |
| 1998 EXPECT_EQ(kExpected, actual); |
| 1999 } |
| 2000 } |
| 2001 |
| 2002 |
| 1975 TEST_CASE(StringCodePointIterator) { | 2003 TEST_CASE(StringCodePointIterator) { |
| 1976 const String& str0 = String::Handle(String::New("")); | 2004 const String& str0 = String::Handle(String::New("")); |
| 1977 String::CodePointIterator it0(str0); | 2005 String::CodePointIterator it0(str0); |
| 1978 EXPECT(!it0.Next()); | 2006 EXPECT(!it0.Next()); |
| 1979 | 2007 |
| 1980 const String& str1 = String::Handle(String::New(" \xc3\xa7 ")); | 2008 const String& str1 = String::Handle(String::New(" \xc3\xa7 ")); |
| 1981 String::CodePointIterator it1(str1); | 2009 String::CodePointIterator it1(str1); |
| 1982 EXPECT(it1.Next()); | 2010 EXPECT(it1.Next()); |
| 1983 EXPECT_EQ(' ', it1.Current()); | 2011 EXPECT_EQ(' ', it1.Current()); |
| 1984 EXPECT(it1.Next()); | 2012 EXPECT(it1.Next()); |
| (...skipping 2511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4496 EXPECT_VALID(h_result); | 4524 EXPECT_VALID(h_result); |
| 4497 Integer& result = Integer::Handle(); | 4525 Integer& result = Integer::Handle(); |
| 4498 result ^= Api::UnwrapHandle(h_result); | 4526 result ^= Api::UnwrapHandle(h_result); |
| 4499 String& foo = String::Handle(String::New("foo")); | 4527 String& foo = String::Handle(String::New("foo")); |
| 4500 Integer& expected = Integer::Handle(); | 4528 Integer& expected = Integer::Handle(); |
| 4501 expected ^= foo.HashCode(); | 4529 expected ^= foo.HashCode(); |
| 4502 EXPECT(result.IsIdenticalTo(expected)); | 4530 EXPECT(result.IsIdenticalTo(expected)); |
| 4503 } | 4531 } |
| 4504 | 4532 |
| 4505 } // namespace dart | 4533 } // namespace dart |
| OLD | NEW |