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 4091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4102 cls = Object::dynamic_class(); | 4102 cls = Object::dynamic_class(); |
4103 array = cls.fields(); | 4103 array = cls.fields(); |
4104 EXPECT(!array.IsNull()); | 4104 EXPECT(!array.IsNull()); |
4105 EXPECT(array.IsArray()); | 4105 EXPECT(array.IsArray()); |
4106 array = cls.functions(); | 4106 array = cls.functions(); |
4107 EXPECT(!array.IsNull()); | 4107 EXPECT(!array.IsNull()); |
4108 EXPECT(array.IsArray()); | 4108 EXPECT(array.IsArray()); |
4109 } | 4109 } |
4110 | 4110 |
4111 | 4111 |
4112 TEST_CASE(ToCStringTruncated) { | |
4113 const char* kScriptChars = | |
4114 "var ascii = 'Hello, World!';\n" | |
4115 "var unicode = '\\u00CE\\u00F1\\u0163\\u00E9r\\u00F1\\u00E5\\u0163" | |
4116 "\\u00EE\\u00F6\\u00F1\\u00E5\\u013C\\u00EE\\u017E\\u00E5\\u0163" | |
4117 "\\u00EE\\u1EDD\\u00F1';\n" | |
4118 "var surrogates ='\\u{1D11E}\\u{1D11E}\\u{1D11E}\\u{1D11E}"\ | |
4119 "\\u{1D11E}';\n"; | |
4120 | |
4121 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
4122 EXPECT_VALID(lib); | |
4123 | |
4124 String& obj = String::Handle(); | |
4125 Dart_Handle result; | |
4126 bool did_truncate; | |
4127 intptr_t length; | |
4128 | |
4129 result = Dart_GetField(lib, NewString("ascii")); | |
4130 EXPECT_VALID(result); | |
4131 obj ^= Api::UnwrapHandle(result); | |
4132 EXPECT_STREQ("Hello, World!", | |
4133 obj.ToCStringTruncated(100, &did_truncate, &length)); | |
4134 EXPECT(!did_truncate); | |
4135 EXPECT_EQ(13, length); | |
4136 EXPECT_STREQ("Hel", obj.ToCStringTruncated(3, &did_truncate, &length)); | |
4137 EXPECT(did_truncate); | |
4138 EXPECT_EQ(3, length); | |
4139 | |
4140 result = Dart_GetField(lib, NewString("unicode")); | |
4141 EXPECT_VALID(result); | |
4142 obj ^= Api::UnwrapHandle(result); | |
4143 EXPECT_STREQ("\u00CE\u00F1\u0163\u00E9r\u00F1\u00E5\u0163" | |
4144 "\u00EE\u00F6\u00F1\u00E5\u013C\u00EE\u017E\u00E5\u0163" | |
4145 "\u00EE\u1EDD\u00F1", | |
4146 obj.ToCStringTruncated(100, &did_truncate, &length)); | |
4147 EXPECT(!did_truncate); | |
4148 EXPECT_EQ(40, length); | |
4149 EXPECT_STREQ("\u00CE\u00F1\u0163", | |
4150 obj.ToCStringTruncated(3, &did_truncate, &length)); | |
4151 EXPECT(did_truncate); | |
4152 EXPECT_EQ(6, length); | |
4153 | |
4154 result = Dart_GetField(lib, NewString("surrogates")); | |
4155 EXPECT_VALID(result); | |
4156 obj ^= Api::UnwrapHandle(result); | |
4157 EXPECT_STREQ("\U0001D11E\U0001D11E\U0001D11E\U0001D11E\U0001D11E", | |
4158 obj.ToCStringTruncated(100, &did_truncate, &length)); | |
4159 EXPECT(!did_truncate); | |
4160 EXPECT_EQ(20, length); | |
4161 EXPECT_STREQ("\U0001D11E", | |
4162 obj.ToCStringTruncated(3, &did_truncate, &length)); | |
4163 EXPECT(did_truncate); | |
4164 EXPECT_EQ(4, length); // 3 code units would be in the middle of a surrogate | |
4165 // pair, so it gets rounded down 2 code units. | |
4166 EXPECT_STREQ("\U0001D11E\U0001D11E", | |
4167 obj.ToCStringTruncated(4, &did_truncate, &length)); | |
4168 EXPECT(did_truncate); | |
4169 EXPECT_EQ(8, length); | |
4170 } | |
4171 | |
4172 class ObjectAccumulator : public ObjectVisitor { | 4112 class ObjectAccumulator : public ObjectVisitor { |
4173 public: | 4113 public: |
4174 explicit ObjectAccumulator(GrowableArray<Object*>* objects) | 4114 explicit ObjectAccumulator(GrowableArray<Object*>* objects) |
4175 : ObjectVisitor(Isolate::Current()), objects_(objects) {} | 4115 : ObjectVisitor(Isolate::Current()), objects_(objects) {} |
4176 virtual ~ObjectAccumulator() { } | 4116 virtual ~ObjectAccumulator() { } |
4177 virtual void VisitObject(RawObject* obj) { | 4117 virtual void VisitObject(RawObject* obj) { |
4178 // Free-list elements cannot even be wrapped in handles. | 4118 // Free-list elements cannot even be wrapped in handles. |
4179 if (obj->IsFreeListElement()) { | 4119 if (obj->IsFreeListElement()) { |
4180 return; | 4120 return; |
4181 } | 4121 } |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4531 EXPECT_VALID(h_result); | 4471 EXPECT_VALID(h_result); |
4532 Integer& result = Integer::Handle(); | 4472 Integer& result = Integer::Handle(); |
4533 result ^= Api::UnwrapHandle(h_result); | 4473 result ^= Api::UnwrapHandle(h_result); |
4534 String& foo = String::Handle(String::New("foo")); | 4474 String& foo = String::Handle(String::New("foo")); |
4535 Integer& expected = Integer::Handle(); | 4475 Integer& expected = Integer::Handle(); |
4536 expected ^= foo.HashCode(); | 4476 expected ^= foo.HashCode(); |
4537 EXPECT(result.IsIdenticalTo(expected)); | 4477 EXPECT(result.IsIdenticalTo(expected)); |
4538 } | 4478 } |
4539 | 4479 |
4540 } // namespace dart | 4480 } // namespace dart |
OLD | NEW |