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

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

Issue 542363003: Don't double-escape in strings in the VM Service, and don't use \u0000 to determine the string lengt (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months 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) 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/bigint_operations.h" 8 #include "vm/bigint_operations.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 4092 matching lines...) Expand 10 before | Expand all | Expand 10 after
4103 4103
4104 cls = Object::dynamic_class(); 4104 cls = Object::dynamic_class();
4105 array = cls.fields(); 4105 array = cls.fields();
4106 EXPECT(!array.IsNull()); 4106 EXPECT(!array.IsNull());
4107 EXPECT(array.IsArray()); 4107 EXPECT(array.IsArray());
4108 array = cls.functions(); 4108 array = cls.functions();
4109 EXPECT(!array.IsNull()); 4109 EXPECT(!array.IsNull());
4110 EXPECT(array.IsArray()); 4110 EXPECT(array.IsArray());
4111 } 4111 }
4112 4112
4113 4113
turnidge 2014/09/09 16:12:31 Could you add a direct unit test for ToCStringTrun
rmacnak 2014/09/09 21:00:23 Added.
4114 TEST_CASE(ToUserCString) {
4115 const char* kScriptChars =
4116 "var simple = 'simple';\n"
4117 "var escapes = 'stuff\\n\\r\\f\\b\\t\\v\\'\"\\$stuff';\n"
4118 "var uescapes = 'stuff\\u0001\\u0002stuff';\n"
4119 "var toolong = "
4120 "'01234567890123456789012345678901234567890123456789howdy';\n"
4121 "var toolong2 = "
4122 "'0123456789012345678901234567890123\\t567890123456789howdy';\n"
4123 "var toolong3 = "
4124 "'012345678901234567890123456789\\u0001567890123456789howdy';\n";
4125 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
4126 EXPECT_VALID(lib);
4127
4128 String& obj = String::Handle();
4129 Dart_Handle result;
4130
4131 // Simple string.
4132 result = Dart_GetField(lib, NewString("simple"));
4133 EXPECT_VALID(result);
4134 obj ^= Api::UnwrapHandle(result);
4135 EXPECT_STREQ("\"simple\"", obj.ToUserCString(40));
4136
4137 // Escaped chars.
4138 result = Dart_GetField(lib, NewString("escapes"));
4139 EXPECT_VALID(result);
4140 obj ^= Api::UnwrapHandle(result);
4141 EXPECT_STREQ("\"stuff\\n\\r\\f\\b\\t\\v'\\\"\\$stuff\"",
4142 obj.ToUserCString(40));
4143
4144 // U-escaped chars.
4145 result = Dart_GetField(lib, NewString("uescapes"));
4146 EXPECT_VALID(result);
4147 obj ^= Api::UnwrapHandle(result);
4148 EXPECT_STREQ("\"stuff\\u0001\\u0002stuff\"", obj.ToUserCString(40));
4149
4150 // Truncation.
4151 result = Dart_GetField(lib, NewString("toolong"));
4152 EXPECT_VALID(result);
4153 obj ^= Api::UnwrapHandle(result);
4154 EXPECT_STREQ("\"01234567890123456789012345678901234\"...",
4155 obj.ToUserCString(40));
4156
4157 // Truncation, shorter.
4158 result = Dart_GetField(lib, NewString("toolong"));
4159 EXPECT_VALID(result);
4160 obj ^= Api::UnwrapHandle(result);
4161 EXPECT_STREQ("\"01234\"...", obj.ToUserCString(10));
4162
4163 // Truncation, limit is in escape.
4164 result = Dart_GetField(lib, NewString("toolong2"));
4165 EXPECT_VALID(result);
4166 obj ^= Api::UnwrapHandle(result);
4167 EXPECT_STREQ("\"0123456789012345678901234567890123\"...",
4168 obj.ToUserCString(40));
4169
4170 // Truncation, limit is in u-escape
4171 result = Dart_GetField(lib, NewString("toolong3"));
4172 EXPECT_VALID(result);
4173 obj ^= Api::UnwrapHandle(result);
4174 EXPECT_STREQ("\"012345678901234567890123456789\"...",
4175 obj.ToUserCString(40));
4176 }
4177
4178
4179 class ObjectAccumulator : public ObjectVisitor { 4114 class ObjectAccumulator : public ObjectVisitor {
4180 public: 4115 public:
4181 explicit ObjectAccumulator(GrowableArray<Object*>* objects) 4116 explicit ObjectAccumulator(GrowableArray<Object*>* objects)
4182 : ObjectVisitor(Isolate::Current()), objects_(objects) {} 4117 : ObjectVisitor(Isolate::Current()), objects_(objects) {}
4183 virtual ~ObjectAccumulator() { } 4118 virtual ~ObjectAccumulator() { }
4184 virtual void VisitObject(RawObject* obj) { 4119 virtual void VisitObject(RawObject* obj) {
4185 // Free-list elements cannot even be wrapped in handles. 4120 // Free-list elements cannot even be wrapped in handles.
4186 if (obj->IsFreeListElement()) { 4121 if (obj->IsFreeListElement()) {
4187 return; 4122 return;
4188 } 4123 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
4364 JSONStream js; 4299 JSONStream js;
4365 const String& str = String::Handle(String::New("dw")); 4300 const String& str = String::Handle(String::New("dw"));
4366 str.PrintJSON(&js, true); 4301 str.PrintJSON(&js, true);
4367 elideSubstring("classes", js.ToCString(), buffer); 4302 elideSubstring("classes", js.ToCString(), buffer);
4368 elideSubstring("objects", buffer, buffer); 4303 elideSubstring("objects", buffer, buffer);
4369 elideSubstring("_OneByteString@", buffer, buffer); 4304 elideSubstring("_OneByteString@", buffer, buffer);
4370 EXPECT_STREQ( 4305 EXPECT_STREQ(
4371 "{\"type\":\"@String\"," 4306 "{\"type\":\"@String\","
4372 "\"class\":{\"type\":\"@Class\",\"id\":\"\"," 4307 "\"class\":{\"type\":\"@Class\",\"id\":\"\","
4373 "\"name\":\"_OneByteString\",\"vmName\":\"\"}," 4308 "\"name\":\"_OneByteString\",\"vmName\":\"\"},"
4374 "\"id\":\"\",\"valueAsString\":\"\\\"dw\\\"\"}", 4309 "\"id\":\"\",\"valueAsString\":\"dw\","
4310 "\"valueAsStringIsTruncated\":false}",
turnidge 2014/09/09 16:12:31 Omit if false
4375 buffer); 4311 buffer);
4376 } 4312 }
4377 // Array reference 4313 // Array reference
4378 { 4314 {
4379 JSONStream js; 4315 JSONStream js;
4380 const Array& array = Array::Handle(Array::New(0)); 4316 const Array& array = Array::Handle(Array::New(0));
4381 array.PrintJSON(&js, true); 4317 array.PrintJSON(&js, true);
4382 elideSubstring("classes", js.ToCString(), buffer); 4318 elideSubstring("classes", js.ToCString(), buffer);
4383 elideSubstring("objects", buffer, buffer); 4319 elideSubstring("objects", buffer, buffer);
4384 elideSubstring("_List@", buffer, buffer); 4320 elideSubstring("_List@", buffer, buffer);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
4537 EXPECT_VALID(h_result); 4473 EXPECT_VALID(h_result);
4538 Integer& result = Integer::Handle(); 4474 Integer& result = Integer::Handle();
4539 result ^= Api::UnwrapHandle(h_result); 4475 result ^= Api::UnwrapHandle(h_result);
4540 String& foo = String::Handle(String::New("foo")); 4476 String& foo = String::Handle(String::New("foo"));
4541 Integer& expected = Integer::Handle(); 4477 Integer& expected = Integer::Handle();
4542 expected ^= foo.HashCode(); 4478 expected ^= foo.HashCode();
4543 EXPECT(result.IsIdenticalTo(expected)); 4479 EXPECT(result.IsIdenticalTo(expected));
4544 } 4480 }
4545 4481
4546 } // namespace dart 4482 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698