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

Unified Diff: pkg/analysis_server/test/protocol_test.dart

Issue 137853026: Basic communication protocol for server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« pkg/analysis_server/test/mocks.dart ('K') | « pkg/analysis_server/test/mocks.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/protocol_test.dart
diff --git a/pkg/analysis_server/test/protocol_test.dart b/pkg/analysis_server/test/protocol_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e5d3b5c02656a9574b46f21bba8c2549bca43f45
--- /dev/null
+++ b/pkg/analysis_server/test/protocol_test.dart
@@ -0,0 +1,112 @@
+// 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.
+
+library test.protocol;
+
+import '../lib/src/protocol.dart';
devoncarew 2014/01/20 22:35:01 Can use a self-reference, or not. nit: I generall
Brian Wilkerson 2014/01/21 03:21:20 Done.
+
+import 'package:unittest/matcher.dart';
+import 'package:unittest/unittest.dart';
+
+main() {
+ group('Request', () {
+ test('getParameter_defined', RequestTest.getParameter_defined);
+ test('getParameter_undefined', RequestTest.getParameter_undefined);
+ test('getRequiredParameter_defined', RequestTest.getRequiredParameter_defined);
+ test('getRequiredParameter_undefined', RequestTest.getRequiredParameter_undefined);
+ });
+ group('Response', () {
+ test('create_contextDoesNotExist', ResponseTest.create_contextDoesNotExist);
+ test('create_invalidRequestFormat', ResponseTest.create_invalidRequestFormat);
+ test('create_missingRequiredParameter', ResponseTest.create_missingRequiredParameter);
+ test('create_unknownRequest', ResponseTest.create_unknownRequest);
+ test('setResult', ResponseTest.setResult);
+ });
+}
+
+class RequestTest {
+ static void getParameter_defined() {
+ String name = 'name';
+ String value = 'value';
+ Request request = new Request('0', '');
+ request.setParameter(name, value);
+ expect(request.getParameter(name), equals(value));
+ }
+
+ static void getParameter_undefined() {
+ String name = 'name';
+ Request request = new Request('0', '');
+ expect(request.getParameter(name), isNull);
+ }
+
+ static void getRequiredParameter_defined() {
+ String name = 'name';
+ String value = 'value';
+ Request request = new Request('0', '');
+ request.setParameter(name, value);
+ expect(request.getRequiredParameter(name), equals(value));
+ }
+
+ static void getRequiredParameter_undefined() {
+ String name = 'name';
+ Request request = new Request('0', '');
+ expect(() => request.getRequiredParameter(name), throwsA(new isInstanceOf<RequestFailure>()));
+ }
+}
+
+class ResponseTest {
+ static void create_contextDoesNotExist() {
+ Response response = new Response.contextDoesNotExist(new Request('0', ''));
+ expect(response.id, equals('0'));
+ expect(response.error, isNotNull);
+ expect(response.toJson(), equals({
+ Response.ID: '0',
+ Response.ERROR: 'Context does not exist'
+ }));
+ }
+
+ static void create_invalidRequestFormat() {
+ Response response = new Response.invalidRequestFormat();
+ expect(response.id, equals(''));
+ expect(response.error, isNotNull);
+ expect(response.toJson(), equals({
+ Response.ID: '',
+ Response.ERROR: 'Invalid request'
+ }));
+ }
+
+ static void create_missingRequiredParameter() {
+ Response response = new Response.missingRequiredParameter(new Request('0', ''), 'x');
+ expect(response.id, equals('0'));
+ expect(response.error, isNotNull);
+ expect(response.toJson(), equals({
+ Response.ID: '0',
+ Response.ERROR: 'Missing required parameter: x'
+ }));
+ }
+
+ static void create_unknownRequest() {
+ Response response = new Response.unknownRequest(new Request('0', ''));
+ expect(response.id, equals('0'));
+ expect(response.error, isNotNull);
+ expect(response.toJson(), equals({
+ Response.ID: '0',
+ Response.ERROR: 'Unknown request'
+ }));
+ }
+
+ static void setResult() {
+ String resultName = 'name';
+ String resultValue = 'value';
+ Response response = new Response('0');
+ response.setResult(resultName, resultValue);
+ expect(response.toJson(), equals({
+ Response.ID: '0',
+ Response.ERROR: null,
+ Response.RESULT: {
+ resultName: resultValue
+ }
+ }));
+ }
+}
« pkg/analysis_server/test/mocks.dart ('K') | « pkg/analysis_server/test/mocks.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698