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

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: don't import dart:async if no services 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
« pubspec.yaml ('K') | « test/client_generator_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e81abae98350d7e13326e0152819c82d3c27bf22
--- /dev/null
+++ b/test/service_generator_test.dart
@@ -0,0 +1,66 @@
+#!/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);
+
+ Future<List<int>> handleCall(ServerContext ctx, String method, List<int> requestBytes) async {
+ if (method == 'aMethod') {
+ var request = new SomeRequest.fromBuffer(requestBytes);
+ var result = await aMethod(ctx, request);
+ return result.writeToBuffer();
+ } else if (method == 'anotherMethod') {
+ var request = new EmptyMessage.fromBuffer(requestBytes);
+ var result = await anotherMethod(ctx, request);
+ return result.writeToBuffer();
+ } else {
+ throw '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);
+ });
+}
« pubspec.yaml ('K') | « test/client_generator_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698