| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 test.instrumentation; | 5 library test.instrumentation; |
| 6 | 6 |
| 7 import 'package:analyzer/instrumentation/instrumentation.dart'; | 7 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 | 9 |
| 10 import '../reflective_tests.dart'; | 10 import '../reflective_tests.dart'; |
| 11 | 11 |
| 12 main() { | 12 main() { |
| 13 group('instrumentation', () { | 13 group('instrumentation', () { |
| 14 runReflectiveTests(InstrumentationServiceTest); | 14 runReflectiveTests(InstrumentationServiceTest); |
| 15 runReflectiveTests(MulticastInstrumentationServerTest); | 15 runReflectiveTests(MulticastInstrumentationServerTest); |
| 16 }); | 16 }); |
| 17 } | 17 } |
| 18 | 18 |
| 19 @reflectiveTest | 19 @reflectiveTest |
| 20 class InstrumentationServiceTest { | 20 class InstrumentationServiceTest { |
| 21 void assertNormal(TestInstrumentationServer server, String tag, | 21 void assertNormal( |
| 22 String message) { | 22 TestInstrumentationServer server, String tag, String message) { |
| 23 String sent = server.normalChannel.toString(); | 23 String sent = server.normalChannel.toString(); |
| 24 if (!sent.endsWith(':$tag:$message\n')) { | 24 if (!sent.endsWith(':$tag:$message\n')) { |
| 25 fail('Expected "...:$tag:$message", found "$sent"'); | 25 fail('Expected "...:$tag:$message", found "$sent"'); |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 void test_logError_withColon() { | 29 void test_logError_withColon() { |
| 30 TestInstrumentationServer server = new TestInstrumentationServer(); | 30 TestInstrumentationServer server = new TestInstrumentationServer(); |
| 31 InstrumentationService service = new InstrumentationService(server); | 31 InstrumentationService service = new InstrumentationService(server); |
| 32 service.logError('Error:message'); | 32 service.logError('Error:message'); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 57 } | 57 } |
| 58 | 58 |
| 59 void test_logFileRead() { | 59 void test_logFileRead() { |
| 60 TestInstrumentationServer server = new TestInstrumentationServer(); | 60 TestInstrumentationServer server = new TestInstrumentationServer(); |
| 61 InstrumentationService service = new InstrumentationService(server); | 61 InstrumentationService service = new InstrumentationService(server); |
| 62 String path = '/file/path'; | 62 String path = '/file/path'; |
| 63 int time = 978336000000; | 63 int time = 978336000000; |
| 64 String content = 'class C {\n}\n'; | 64 String content = 'class C {\n}\n'; |
| 65 service.logFileRead(path, time, content); | 65 service.logFileRead(path, time, content); |
| 66 assertNormal( | 66 assertNormal( |
| 67 server, | 67 server, InstrumentationService.TAG_FILE_READ, '$path:$time:$content'); |
| 68 InstrumentationService.TAG_FILE_READ, | |
| 69 '$path:$time:$content'); | |
| 70 } | 68 } |
| 71 | 69 |
| 72 void test_logLogEntry() { | 70 void test_logLogEntry() { |
| 73 TestInstrumentationServer server = new TestInstrumentationServer(); | 71 TestInstrumentationServer server = new TestInstrumentationServer(); |
| 74 InstrumentationService service = new InstrumentationService(server); | 72 InstrumentationService service = new InstrumentationService(server); |
| 75 String level = 'level'; | 73 String level = 'level'; |
| 76 DateTime time = new DateTime(2001); | 74 DateTime time = new DateTime(2001); |
| 77 String message = 'message'; | 75 String message = 'message'; |
| 78 service.logLogEntry(level, time, message); | 76 service.logLogEntry(level, time, message); |
| 79 assertNormal( | 77 assertNormal(server, InstrumentationService.TAG_LOG_ENTRY, |
| 80 server, | |
| 81 InstrumentationService.TAG_LOG_ENTRY, | |
| 82 '$level:${time.millisecondsSinceEpoch}:$message'); | 78 '$level:${time.millisecondsSinceEpoch}:$message'); |
| 83 } | 79 } |
| 84 | 80 |
| 85 void test_logNotification() { | 81 void test_logNotification() { |
| 86 TestInstrumentationServer server = new TestInstrumentationServer(); | 82 TestInstrumentationServer server = new TestInstrumentationServer(); |
| 87 InstrumentationService service = new InstrumentationService(server); | 83 InstrumentationService service = new InstrumentationService(server); |
| 88 String message = 'notificationText'; | 84 String message = 'notificationText'; |
| 89 service.logNotification(message); | 85 service.logNotification(message); |
| 90 assertNormal(server, InstrumentationService.TAG_NOTIFICATION, message); | 86 assertNormal(server, InstrumentationService.TAG_NOTIFICATION, message); |
| 91 } | 87 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 102 TestInstrumentationServer server = new TestInstrumentationServer(); | 98 TestInstrumentationServer server = new TestInstrumentationServer(); |
| 103 InstrumentationService service = new InstrumentationService(server); | 99 InstrumentationService service = new InstrumentationService(server); |
| 104 String message = 'responseText'; | 100 String message = 'responseText'; |
| 105 service.logResponse(message); | 101 service.logResponse(message); |
| 106 assertNormal(server, InstrumentationService.TAG_RESPONSE, message); | 102 assertNormal(server, InstrumentationService.TAG_RESPONSE, message); |
| 107 } | 103 } |
| 108 | 104 |
| 109 void test_logVersion() { | 105 void test_logVersion() { |
| 110 TestInstrumentationServer server = new TestInstrumentationServer(); | 106 TestInstrumentationServer server = new TestInstrumentationServer(); |
| 111 InstrumentationService service = new InstrumentationService(server); | 107 InstrumentationService service = new InstrumentationService(server); |
| 112 service.logVersion( | 108 service.logVersion('myUuid', 'someClientId', 'someClientVersion', |
| 113 'myUuid', | 109 'aServerVersion', 'anSdkVersion'); |
| 114 'someClientId', | |
| 115 'someClientVersion', | |
| 116 'aServerVersion', | |
| 117 'anSdkVersion'); | |
| 118 expect(server.normalChannel.toString(), ''); | 110 expect(server.normalChannel.toString(), ''); |
| 119 expect( | 111 expect(server.priorityChannel.toString(), endsWith( |
| 120 server.priorityChannel.toString(), | 112 ':myUuid:someClientId:someClientVersion:aServerVersion:anSdkVersion\n'))
; |
| 121 endsWith( | |
| 122 ':myUuid:someClientId:someClientVersion:aServerVersion:anSdkVersion\
n')); | |
| 123 } | 113 } |
| 124 } | 114 } |
| 125 | 115 |
| 126 @reflectiveTest | 116 @reflectiveTest |
| 127 class MulticastInstrumentationServerTest { | 117 class MulticastInstrumentationServerTest { |
| 128 TestInstrumentationServer serverA = new TestInstrumentationServer(); | 118 TestInstrumentationServer serverA = new TestInstrumentationServer(); |
| 129 TestInstrumentationServer serverB = new TestInstrumentationServer(); | 119 TestInstrumentationServer serverB = new TestInstrumentationServer(); |
| 130 MulticastInstrumentationServer server; | 120 MulticastInstrumentationServer server; |
| 131 | 121 |
| 132 void setUp() { | 122 void setUp() { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 @override | 166 @override |
| 177 void logWithPriority(String message) { | 167 void logWithPriority(String message) { |
| 178 priorityChannel.writeln(message); | 168 priorityChannel.writeln(message); |
| 179 } | 169 } |
| 180 | 170 |
| 181 @override | 171 @override |
| 182 void shutdown() { | 172 void shutdown() { |
| 183 // Ignored | 173 // Ignored |
| 184 } | 174 } |
| 185 } | 175 } |
| OLD | NEW |