| 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 }); | 16 }); |
| 16 } | 17 } |
| 17 | 18 |
| 18 @ReflectiveTestCase() | 19 @ReflectiveTestCase() |
| 19 class InstrumentationServiceTest extends ReflectiveTestCase { | 20 class InstrumentationServiceTest extends ReflectiveTestCase { |
| 20 void assertNormal(TestInstrumentationServer server, String tag, | 21 void assertNormal(TestInstrumentationServer server, String tag, |
| 21 String message) { | 22 String message) { |
| 22 String sent = server.normalChannel.toString(); | 23 String sent = server.normalChannel.toString(); |
| 23 if (!sent.endsWith(':$tag:$message\n')) { | 24 if (!sent.endsWith(':$tag:$message\n')) { |
| 24 fail('Expected "...:$tag:$message", found "$sent"'); | 25 fail('Expected "...:$tag:$message", found "$sent"'); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 74 |
| 74 void test_logResponse() { | 75 void test_logResponse() { |
| 75 TestInstrumentationServer server = new TestInstrumentationServer(); | 76 TestInstrumentationServer server = new TestInstrumentationServer(); |
| 76 InstrumentationService service = new InstrumentationService(server); | 77 InstrumentationService service = new InstrumentationService(server); |
| 77 String message = 'responseText'; | 78 String message = 'responseText'; |
| 78 service.logResponse(message); | 79 service.logResponse(message); |
| 79 assertNormal(server, InstrumentationService.TAG_RESPONSE, message); | 80 assertNormal(server, InstrumentationService.TAG_RESPONSE, message); |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 | 83 |
| 84 @ReflectiveTestCase() |
| 85 class MulticastInstrumentationServerTest extends ReflectiveTestCase { |
| 86 TestInstrumentationServer serverA = new TestInstrumentationServer(); |
| 87 TestInstrumentationServer serverB = new TestInstrumentationServer(); |
| 88 MulticastInstrumentationServer server; |
| 89 |
| 90 void setUp() { |
| 91 server = new MulticastInstrumentationServer([serverA, serverB]); |
| 92 } |
| 93 |
| 94 void test_log() { |
| 95 server.log('foo bar'); |
| 96 _assertNormal(serverA, 'foo bar'); |
| 97 _assertNormal(serverB, 'foo bar'); |
| 98 } |
| 99 |
| 100 void test_logWithPriority() { |
| 101 server.logWithPriority('foo bar'); |
| 102 _assertPriority(serverA, 'foo bar'); |
| 103 _assertPriority(serverB, 'foo bar'); |
| 104 } |
| 105 |
| 106 void test_shutdown() { |
| 107 server.shutdown(); |
| 108 } |
| 109 |
| 110 void _assertNormal(TestInstrumentationServer server, String message) { |
| 111 String sent = server.normalChannel.toString(); |
| 112 if (!sent.endsWith('$message\n')) { |
| 113 fail('Expected "...$message", found "$sent"'); |
| 114 } |
| 115 } |
| 116 |
| 117 void _assertPriority(TestInstrumentationServer server, String message) { |
| 118 String sent = server.priorityChannel.toString(); |
| 119 if (!sent.endsWith('$message\n')) { |
| 120 fail('Expected "...$message", found "$sent"'); |
| 121 } |
| 122 } |
| 123 } |
| 124 |
| 83 class TestInstrumentationServer implements InstrumentationServer { | 125 class TestInstrumentationServer implements InstrumentationServer { |
| 84 StringBuffer normalChannel = new StringBuffer(); | 126 StringBuffer normalChannel = new StringBuffer(); |
| 85 StringBuffer priorityChannel = new StringBuffer(); | 127 StringBuffer priorityChannel = new StringBuffer(); |
| 86 | 128 |
| 87 @override | 129 @override |
| 88 void log(String message) { | 130 void log(String message) { |
| 89 normalChannel.writeln(message); | 131 normalChannel.writeln(message); |
| 90 } | 132 } |
| 91 | 133 |
| 92 @override | 134 @override |
| 93 void logWithPriority(String message) { | 135 void logWithPriority(String message) { |
| 94 priorityChannel.writeln(message); | 136 priorityChannel.writeln(message); |
| 95 } | 137 } |
| 96 | 138 |
| 97 @override | 139 @override |
| 98 void shutdown() { | 140 void shutdown() { |
| 99 // Ignored | 141 // Ignored |
| 100 } | 142 } |
| 101 } | 143 } |
| OLD | NEW |