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

Unified Diff: test/service_generator_test.dart

Issue 1196293003: Initial support for generating client and server stubs for Dart. (Closed) Base URL: https://github.com/dart-lang/dart-protoc-plugin.git@master
Patch Set: adddressing nits Created 5 years, 6 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
Index: test/service_generator_test.dart
diff --git a/test/service_generator_test.dart b/test/service_generator_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..67c735ee8dc1ffa640c56c4b1e31c2a44019ba92
--- /dev/null
+++ b/test/service_generator_test.dart
@@ -0,0 +1,68 @@
+#!/usr/bin/env dart
+// Copyright (c) 2015, 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 service_generator_test;
+
+import 'package:protoc_plugin/src/descriptor.pb.dart';
+import 'package:protoc_plugin/src/plugin.pb.dart';
+import 'package:protoc_plugin/protoc.dart';
+import 'package:unittest/unittest.dart';
+
+ServiceDescriptorProto buildServiceDescriptor() {
+ ServiceDescriptorProto sd = new ServiceDescriptorProto()
+ ..name = 'Test'
+ ..method.addAll([
+ new MethodDescriptorProto()
+ ..name = 'AMethod'
+ ..inputType = 'SomeRequest'
+ ..outputType = 'SomeReply',
+ new MethodDescriptorProto()
+ ..name = 'AnotherMethod'
+ ..inputType = '.foo.bar.EmptyMessage'
+ ..outputType = '.foo.bar.AnotherReply',
+ ]);
+ return sd;
+}
+
+void main() {
+ test('testServiceGenerator', () {
+ // NOTE: Below > 80 cols because it is matching generated code > 80 cols.
+ String expected = r'''
+abstract class TestServiceBase extends GeneratedService {
+ Future<SomeReply> aMethod(ServerContext ctx, SomeRequest request);
+ Future<AnotherReply> anotherMethod(ServerContext ctx, EmptyMessage request);
+
+ GeneratedMessage createRequest(String method) {
+ switch (method) {
+ case 'AMethod': return new SomeRequest();
+ case 'AnotherMethod': return new EmptyMessage();
+ default: throw new ArgumentError('Unknown method: $method');
+ }
+ }
+
+ Future<GeneratedMessage> handleCall(ServerContext ctx, String method, GeneratedMessage request) async {
+ switch (method) {
+ case 'AMethod': return await aMethod(ctx, request);
+ case 'AnotherMethod': return await anotherMethod(ctx, request);
+ default: throw new ArgumentError('Unknown method: $method');
+ }
+ }
+}
+
+''';
+ var options = parseGenerationOptions(
+ new CodeGeneratorRequest(), new CodeGeneratorResponse());
+ var context =
+ new GenerationContext(options, new DefaultOutputConfiguration());
+ var fd = new FileDescriptorProto();
+ var fg = new FileGenerator(fd, null, context);
+ ServiceDescriptorProto sd = buildServiceDescriptor();
+ MemoryWriter buffer = new MemoryWriter();
+ IndentingWriter writer = new IndentingWriter(' ', buffer);
+ var sg = new ServiceGenerator(sd, fg, context);
+ sg.generate(writer);
+ expect(buffer.toString(), expected);
+ });
+}
« no previous file with comments | « test/protos/service.proto ('k') | test/service_test.dart » ('j') | test/service_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698