| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library vmservice_test_helper; | 5 library vmservice_test_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 try { | 79 try { |
| 80 replyAsString = UTF8.decode(data); | 80 replyAsString = UTF8.decode(data); |
| 81 } catch (e) { | 81 } catch (e) { |
| 82 onRequestFailed(e); | 82 onRequestFailed(e); |
| 83 return null; | 83 return null; |
| 84 } | 84 } |
| 85 print('** Response: $replyAsString'); | 85 print('** Response: $replyAsString'); |
| 86 var reply; | 86 var reply; |
| 87 try { | 87 try { |
| 88 reply = JSON.decode(replyAsString); | 88 reply = JSON.decode(replyAsString); |
| 89 } catch (e) { | 89 } catch (e, trace) { |
| 90 onRequestFailed(e); | 90 onRequestFailed(e); |
| 91 return null; | 91 return null; |
| 92 } | 92 } |
| 93 if (reply is! Map) { | 93 if (reply is! Map) { |
| 94 onRequestFailed('Reply was not a map: $reply'); | 94 onRequestFailed('Reply was not a map: $reply'); |
| 95 return null; | 95 return null; |
| 96 } | 96 } |
| 97 if (reply['type'] == null) { | 97 if (reply['type'] == null) { |
| 98 onRequestFailed('Reply does not contain a type key: $reply'); | 98 onRequestFailed('Reply does not contain a type key: $reply'); |
| 99 return null; | 99 return null; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return completer.future; | 167 return completer.future; |
| 168 }); | 168 }); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void requestExit() { | 171 void requestExit() { |
| 172 print('** Requesting script to exit.'); | 172 print('** Requesting script to exit.'); |
| 173 process.stdin.add([32, 13, 10]); | 173 process.stdin.add([32, 13, 10]); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 class IsolateListTester { | 177 class VMTester { |
| 178 final Map isolateList; | 178 final Map vm; |
| 179 | 179 |
| 180 IsolateListTester(this.isolateList) { | 180 VMTester(this.vm) { |
| 181 // The reply is an IsolateList. | 181 // The reply is a VM. |
| 182 Expect.equals('IsolateList', isolateList['type'], 'Not an IsolateList.'); | 182 Expect.equals('VM', vm['type'], 'Not an VM.'); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void checkIsolateCount(int n) { | 185 void checkIsolateCount(int n) { |
| 186 Expect.equals(n, isolateList['members'].length, 'Isolate count not $n'); | 186 Expect.equals(n, vm['isolates'].length, 'Isolate count not $n'); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void checkIsolateIdExists(String id) { | 189 void checkIsolateIdExists(String id) { |
| 190 var exists = false; | 190 var exists = false; |
| 191 isolateList['members'].forEach((isolate) { | 191 vm['isolates'].forEach((isolate) { |
| 192 if (isolate['id'] == id) { | 192 if (isolate['id'] == id) { |
| 193 exists = true; | 193 exists = true; |
| 194 } | 194 } |
| 195 }); | 195 }); |
| 196 Expect.isTrue(exists, 'No isolate with id: $id'); | 196 Expect.isTrue(exists, 'No isolate with id: $id'); |
| 197 } | 197 } |
| 198 | 198 |
| 199 String getIsolateId(int index) { | 199 String getIsolateId(int index) { |
| 200 return isolateList['members'][index]['id']; | 200 return vm['isolates'][index]['id']; |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 class ClassTableHelper { | 204 class ClassTableHelper { |
| 205 final Map classTable; | 205 final Map classTable; |
| 206 | 206 |
| 207 ClassTableHelper(this.classTable) { | 207 ClassTableHelper(this.classTable) { |
| 208 Expect.equals('ClassList', classTable['type'], 'Not a ClassTable.'); | 208 Expect.equals('ClassList', classTable['type'], 'Not a ClassTable.'); |
| 209 } | 209 } |
| 210 | 210 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 }); | 266 }); |
| 267 }); | 267 }); |
| 268 return Future.wait(requests).then((a) { | 268 return Future.wait(requests).then((a) { |
| 269 a.forEach((FieldRequestHelper field) { | 269 a.forEach((FieldRequestHelper field) { |
| 270 fields[field.field['user_name']] = field.field; | 270 fields[field.field['user_name']] = field.field; |
| 271 }); | 271 }); |
| 272 return this; | 272 return this; |
| 273 }); | 273 }); |
| 274 } | 274 } |
| 275 } | 275 } |
| OLD | NEW |