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

Side by Side Diff: mojo/public/dart/third_party/analyzer/test/instrumentation/instrumentation_test.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.instrumentation;
6
7 import 'package:analyzer/instrumentation/instrumentation.dart';
8 import 'package:unittest/unittest.dart';
9
10 import '../reflective_tests.dart';
11
12 main() {
13 group('instrumentation', () {
14 runReflectiveTests(InstrumentationServiceTest);
15 runReflectiveTests(MulticastInstrumentationServerTest);
16 });
17 }
18
19 @reflectiveTest
20 class InstrumentationServiceTest {
21 void assertNormal(
22 TestInstrumentationServer server, String tag, String message) {
23 String sent = server.normalChannel.toString();
24 if (!sent.endsWith(':$tag:$message\n')) {
25 fail('Expected "...:$tag:$message", found "$sent"');
26 }
27 }
28
29 void test_logError_withColon() {
30 TestInstrumentationServer server = new TestInstrumentationServer();
31 InstrumentationService service = new InstrumentationService(server);
32 service.logError('Error:message');
33 assertNormal(server, InstrumentationService.TAG_ERROR, 'Error::message');
34 }
35
36 void test_logError_withLeadingColon() {
37 TestInstrumentationServer server = new TestInstrumentationServer();
38 InstrumentationService service = new InstrumentationService(server);
39 service.logError(':a:bb');
40 assertNormal(server, InstrumentationService.TAG_ERROR, '::a::bb');
41 }
42
43 void test_logError_withoutColon() {
44 TestInstrumentationServer server = new TestInstrumentationServer();
45 InstrumentationService service = new InstrumentationService(server);
46 String message = 'Error message';
47 service.logError(message);
48 assertNormal(server, InstrumentationService.TAG_ERROR, message);
49 }
50
51 void test_logException_noTrace() {
52 TestInstrumentationServer server = new TestInstrumentationServer();
53 InstrumentationService service = new InstrumentationService(server);
54 String message = 'exceptionMessage';
55 service.logException(message, null);
56 assertNormal(server, InstrumentationService.TAG_EXCEPTION, '$message:null');
57 }
58
59 void test_logFileRead() {
60 TestInstrumentationServer server = new TestInstrumentationServer();
61 InstrumentationService service = new InstrumentationService(server);
62 String path = '/file/path';
63 int time = 978336000000;
64 String content = 'class C {\n}\n';
65 service.logFileRead(path, time, content);
66 assertNormal(
67 server, InstrumentationService.TAG_FILE_READ, '$path:$time:$content');
68 }
69
70 void test_logLogEntry() {
71 TestInstrumentationServer server = new TestInstrumentationServer();
72 InstrumentationService service = new InstrumentationService(server);
73 String level = 'level';
74 DateTime time = new DateTime(2001);
75 String message = 'message';
76 String exception = 'exception';
77 String stackTraceText = 'stackTrace';
78 StackTrace stackTrace = new StackTrace.fromString(stackTraceText);
79 service.logLogEntry(level, time, message, exception, stackTrace);
80 assertNormal(server, InstrumentationService.TAG_LOG_ENTRY,
81 '$level:${time.millisecondsSinceEpoch}:$message:$exception:$stackTraceTe xt');
82 }
83
84 void test_logNotification() {
85 TestInstrumentationServer server = new TestInstrumentationServer();
86 InstrumentationService service = new InstrumentationService(server);
87 String message = 'notificationText';
88 service.logNotification(message);
89 assertNormal(server, InstrumentationService.TAG_NOTIFICATION, message);
90 }
91
92 void test_logRequest() {
93 TestInstrumentationServer server = new TestInstrumentationServer();
94 InstrumentationService service = new InstrumentationService(server);
95 String message = 'requestText';
96 service.logRequest(message);
97 assertNormal(server, InstrumentationService.TAG_REQUEST, message);
98 }
99
100 void test_logResponse() {
101 TestInstrumentationServer server = new TestInstrumentationServer();
102 InstrumentationService service = new InstrumentationService(server);
103 String message = 'responseText';
104 service.logResponse(message);
105 assertNormal(server, InstrumentationService.TAG_RESPONSE, message);
106 }
107
108 void test_logVersion() {
109 TestInstrumentationServer server = new TestInstrumentationServer();
110 InstrumentationService service = new InstrumentationService(server);
111 service.logVersion('myUuid', 'someClientId', 'someClientVersion',
112 'aServerVersion', 'anSdkVersion');
113 expect(server.normalChannel.toString(), '');
114 expect(server.priorityChannel.toString(), endsWith(
115 ':myUuid:someClientId:someClientVersion:aServerVersion:anSdkVersion\n')) ;
116 }
117 }
118
119 @reflectiveTest
120 class MulticastInstrumentationServerTest {
121 TestInstrumentationServer serverA = new TestInstrumentationServer();
122 TestInstrumentationServer serverB = new TestInstrumentationServer();
123 MulticastInstrumentationServer server;
124
125 void setUp() {
126 server = new MulticastInstrumentationServer([serverA, serverB]);
127 }
128
129 void test_log() {
130 server.log('foo bar');
131 _assertNormal(serverA, 'foo bar');
132 _assertNormal(serverB, 'foo bar');
133 }
134
135 void test_logWithPriority() {
136 server.logWithPriority('foo bar');
137 _assertPriority(serverA, 'foo bar');
138 _assertPriority(serverB, 'foo bar');
139 }
140
141 void test_shutdown() {
142 server.shutdown();
143 }
144
145 void _assertNormal(TestInstrumentationServer server, String message) {
146 String sent = server.normalChannel.toString();
147 if (!sent.endsWith('$message\n')) {
148 fail('Expected "...$message", found "$sent"');
149 }
150 }
151
152 void _assertPriority(TestInstrumentationServer server, String message) {
153 String sent = server.priorityChannel.toString();
154 if (!sent.endsWith('$message\n')) {
155 fail('Expected "...$message", found "$sent"');
156 }
157 }
158 }
159
160 class TestInstrumentationServer implements InstrumentationServer {
161 StringBuffer normalChannel = new StringBuffer();
162 StringBuffer priorityChannel = new StringBuffer();
163
164 @override
165 void log(String message) {
166 normalChannel.writeln(message);
167 }
168
169 @override
170 void logWithPriority(String message) {
171 priorityChannel.writeln(message);
172 }
173
174 @override
175 void shutdown() {
176 // Ignored
177 }
178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698