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

Unified Diff: runtime/bin/vmservice/observatory/test/graph_test.dart

Issue 773573005: vmservice: basic object graph serialization. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/vmservice/observatory/test/graph_test.dart
===================================================================
--- runtime/bin/vmservice/observatory/test/graph_test.dart (revision 0)
+++ runtime/bin/vmservice/observatory/test/graph_test.dart (working copy)
@@ -0,0 +1,58 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'package:observatory/object_graph.dart';
+import 'package:observatory/service_io.dart';
+import 'package:unittest/unittest.dart';
+import 'test_helper.dart';
+
+class Foo {
+ Object left;
+ Object right;
+}
+Foo root;
+
+void script() {
+ // Create 3 instances of Foo, with out-degrees 0 (for b), 1 (for a), and 2 (for root).
+ root = new Foo();
+ var a = new Foo();
+ var b = new Foo();
+ root.left = a;
+ root.right = b;
+ a.left = b;
+}
+
+int fooId;
+
+var tests = [
+
+(Isolate isolate) {
+ Completer completer = new Completer();
+ isolate.vm.events.stream.listen((ServiceEvent event) {
+ if (event.eventType == '_Graph') {
+ ReadStream reader = new ReadStream(event.data);
+ ObjectGraph graph = new ObjectGraph(reader);
+ List<ObjectVertex> foos = graph.vertices.where((ObjectVertex obj) => obj.classId == fooId);
Cutch 2014/12/02 16:46:26 assert that fooId != null before?
koda 2014/12/02 18:47:12 Done.
+ expect(foos.length, equals(3));
+ expect(foos.where((ObjectVertex obj) => obj.succ.length == 0).length, equals(1));
+ expect(foos.where((ObjectVertex obj) => obj.succ.length == 1).length, equals(1));
+ expect(foos.where((ObjectVertex obj) => obj.succ.length == 2).length, equals(1));
+ completer.complete();
+ }
+ });
+ return isolate.rootLib.load().then((Library lib) {
+ expect(lib.classes.length, equals(1));
+ // Extract the numerical class id of 'Foo', used in the event listener above.
+ Class fooClass = lib.classes.first;
+ String prefix = "classes/";
+ fooId = int.parse(fooClass.id.substring(prefix.length));
Cutch 2014/12/02 16:46:26 Not necessarily for your change- it might make sen
koda 2014/12/02 18:47:12 Agreed, I've added a TODO.
+ isolate.get('graph');
+ return completer.future;
+ });
+},
+
+];
+
+main(args) => runIsolateTests(args, tests, testeeBefore: script);

Powered by Google App Engine
This is Rietveld 408576698