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

Side by Side Diff: vm/snapshot_test.cc

Issue 11745022: - Make Boolean 'true' and 'false' singleton VM isolate objects. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 11 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
« no previous file with comments | « vm/snapshot.cc ('k') | vm/stub_code_ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "include/dart_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.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_api_message.h" 10 #include "vm/dart_api_message.h"
(...skipping 21 matching lines...) Expand all
32 Double& dbl1 = Double::Handle(); 32 Double& dbl1 = Double::Handle();
33 Double& dbl2 = Double::Handle(); 33 Double& dbl2 = Double::Handle();
34 dbl1 ^= expected.raw(); 34 dbl1 ^= expected.raw();
35 dbl2 ^= actual.raw(); 35 dbl2 ^= actual.raw();
36 return dbl1.value() == dbl2.value(); 36 return dbl1.value() == dbl2.value();
37 } 37 }
38 return false; 38 return false;
39 } 39 }
40 if (expected.IsBool()) { 40 if (expected.IsBool()) {
41 if (actual.IsBool()) { 41 if (actual.IsBool()) {
42 Bool& bl1 = Bool::Handle(); 42 return expected.raw() == actual.raw();
43 Bool& bl2 = Bool::Handle();
44 bl1 ^= expected.raw();
45 bl2 ^= actual.raw();
46 return bl1.value() == bl2.value();
47 } 43 }
48 return false; 44 return false;
49 } 45 }
50 return false; 46 return false;
51 } 47 }
52 48
53 49
54 static uint8_t* malloc_allocator( 50 static uint8_t* malloc_allocator(
55 uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 51 uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
56 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); 52 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size));
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 CheckEncodeDecodeMessage(root); 301 CheckEncodeDecodeMessage(root);
306 } 302 }
307 303
308 304
309 TEST_CASE(SerializeTrue) { 305 TEST_CASE(SerializeTrue) {
310 StackZone zone(Isolate::Current()); 306 StackZone zone(Isolate::Current());
311 307
312 // Write snapshot with true object. 308 // Write snapshot with true object.
313 uint8_t* buffer; 309 uint8_t* buffer;
314 MessageWriter writer(&buffer, &zone_allocator); 310 MessageWriter writer(&buffer, &zone_allocator);
315 const Bool& bl = Bool::Handle(Bool::True()); 311 const Bool& bl = Bool::True();
316 writer.WriteMessage(bl); 312 writer.WriteMessage(bl);
317 intptr_t buffer_len = writer.BytesWritten(); 313 intptr_t buffer_len = writer.BytesWritten();
318 314
319 // Read object back from the snapshot. 315 // Read object back from the snapshot.
320 SnapshotReader reader(buffer, buffer_len, 316 SnapshotReader reader(buffer, buffer_len,
321 Snapshot::kMessage, Isolate::Current()); 317 Snapshot::kMessage, Isolate::Current());
322 const Object& serialized_object = Object::Handle(reader.ReadObject()); 318 const Object& serialized_object = Object::Handle(reader.ReadObject());
323 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString()); 319 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString());
324 320
325 EXPECT(Equals(bl, serialized_object)); 321 EXPECT(Equals(bl, serialized_object));
326 322
327 // Read object back from the snapshot into a C structure. 323 // Read object back from the snapshot into a C structure.
328 ApiNativeScope scope; 324 ApiNativeScope scope;
329 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 325 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
330 Dart_CObject* root = api_reader.ReadMessage(); 326 Dart_CObject* root = api_reader.ReadMessage();
331 EXPECT_NOTNULL(root); 327 EXPECT_NOTNULL(root);
332 EXPECT_EQ(Dart_CObject::kBool, root->type); 328 EXPECT_EQ(Dart_CObject::kBool, root->type);
333 EXPECT_EQ(true, root->value.as_bool); 329 EXPECT_EQ(true, root->value.as_bool);
334 CheckEncodeDecodeMessage(root); 330 CheckEncodeDecodeMessage(root);
335 } 331 }
336 332
337 333
338 TEST_CASE(SerializeFalse) { 334 TEST_CASE(SerializeFalse) {
339 StackZone zone(Isolate::Current()); 335 StackZone zone(Isolate::Current());
340 336
341 // Write snapshot with false object. 337 // Write snapshot with false object.
342 uint8_t* buffer; 338 uint8_t* buffer;
343 MessageWriter writer(&buffer, &zone_allocator); 339 MessageWriter writer(&buffer, &zone_allocator);
344 const Bool& bl = Bool::Handle(Bool::False()); 340 const Bool& bl = Bool::False();
345 writer.WriteMessage(bl); 341 writer.WriteMessage(bl);
346 intptr_t buffer_len = writer.BytesWritten(); 342 intptr_t buffer_len = writer.BytesWritten();
347 343
348 // Read object back from the snapshot. 344 // Read object back from the snapshot.
349 SnapshotReader reader(buffer, buffer_len, 345 SnapshotReader reader(buffer, buffer_len,
350 Snapshot::kMessage, Isolate::Current()); 346 Snapshot::kMessage, Isolate::Current());
351 const Object& serialized_object = Object::Handle(reader.ReadObject()); 347 const Object& serialized_object = Object::Handle(reader.ReadObject());
352 EXPECT(Equals(bl, serialized_object)); 348 EXPECT(Equals(bl, serialized_object));
353 349
354 // Read object back from the snapshot into a C structure. 350 // Read object back from the snapshot into a C structure.
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 const Object& list = Object::Handle(Api::UnwrapHandle(result)); 1249 const Object& list = Object::Handle(Api::UnwrapHandle(result));
1254 writer.WriteMessage(list); 1250 writer.WriteMessage(list);
1255 intptr_t buffer_len = writer.BytesWritten(); 1251 intptr_t buffer_len = writer.BytesWritten();
1256 1252
1257 // Read object back from the snapshot into a C structure. 1253 // Read object back from the snapshot into a C structure.
1258 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 1254 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
1259 return api_reader.ReadMessage(); 1255 return api_reader.ReadMessage();
1260 } 1256 }
1261 1257
1262 1258
1263 static void CheckString(Dart_Handle string, const char* expected) { 1259 static void CheckString(Dart_Handle dart_string, const char* expected) {
1264 StackZone zone(Isolate::Current()); 1260 StackZone zone(Isolate::Current());
1265 uint8_t* buffer; 1261 uint8_t* buffer;
1266 MessageWriter writer(&buffer, &zone_allocator); 1262 MessageWriter writer(&buffer, &zone_allocator);
1267 String& str = String::Handle(); 1263 String& str = String::Handle();
1268 str ^= Api::UnwrapHandle(string); 1264 str ^= Api::UnwrapHandle(dart_string);
1269 writer.WriteMessage(str); 1265 writer.WriteMessage(str);
1270 intptr_t buffer_len = writer.BytesWritten(); 1266 intptr_t buffer_len = writer.BytesWritten();
1271 1267
1272 // Read object back from the snapshot into a C structure. 1268 // Read object back from the snapshot into a C structure.
1273 ApiNativeScope scope; 1269 ApiNativeScope scope;
1274 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 1270 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
1275 Dart_CObject* root = api_reader.ReadMessage(); 1271 Dart_CObject* root = api_reader.ReadMessage();
1276 EXPECT_NOTNULL(root); 1272 EXPECT_NOTNULL(root);
1277 EXPECT_EQ(Dart_CObject::kString, root->type); 1273 EXPECT_EQ(Dart_CObject::kString, root->type);
1278 EXPECT_STREQ(expected, root->value.as_string); 1274 EXPECT_STREQ(expected, root->value.as_string);
1279 CheckEncodeDecodeMessage(root); 1275 CheckEncodeDecodeMessage(root);
1280 } 1276 }
1281 1277
1282 1278
1283 static void CheckStringInvalid(Dart_Handle string) { 1279 static void CheckStringInvalid(Dart_Handle dart_string) {
1284 StackZone zone(Isolate::Current()); 1280 StackZone zone(Isolate::Current());
1285 uint8_t* buffer; 1281 uint8_t* buffer;
1286 MessageWriter writer(&buffer, &zone_allocator); 1282 MessageWriter writer(&buffer, &zone_allocator);
1287 String& str = String::Handle(); 1283 String& str = String::Handle();
1288 str ^= Api::UnwrapHandle(string); 1284 str ^= Api::UnwrapHandle(dart_string);
1289 writer.WriteMessage(str); 1285 writer.WriteMessage(str);
1290 intptr_t buffer_len = writer.BytesWritten(); 1286 intptr_t buffer_len = writer.BytesWritten();
1291 1287
1292 // Read object back from the snapshot into a C structure. 1288 // Read object back from the snapshot into a C structure.
1293 ApiNativeScope scope; 1289 ApiNativeScope scope;
1294 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 1290 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
1295 Dart_CObject* root = api_reader.ReadMessage(); 1291 Dart_CObject* root = api_reader.ReadMessage();
1296 EXPECT_NOTNULL(root); 1292 EXPECT_NOTNULL(root);
1297 EXPECT_EQ(Dart_CObject::kUnsupported, root->type); 1293 EXPECT_EQ(Dart_CObject::kUnsupported, root->type);
1298 } 1294 }
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 EXPECT(Dart_ErrorHasException(result)); 2196 EXPECT(Dart_ErrorHasException(result));
2201 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", 2197 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n",
2202 Dart_GetError(result)); 2198 Dart_GetError(result));
2203 2199
2204 Dart_ExitScope(); 2200 Dart_ExitScope();
2205 } 2201 }
2206 2202
2207 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 2203 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
2208 2204
2209 } // namespace dart 2205 } // namespace dart
OLDNEW
« no previous file with comments | « vm/snapshot.cc ('k') | vm/stub_code_ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698