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

Side by Side 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 unified diff | Download patch
« pubspec.yaml ('K') | « test/client_generator_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env dart
2 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file.
5
6 library service_generator_test;
7
8 import 'package:protoc_plugin/src/descriptor.pb.dart';
9 import 'package:protoc_plugin/src/plugin.pb.dart';
10 import 'package:protoc_plugin/protoc.dart';
11 import 'package:unittest/unittest.dart';
12
13 ServiceDescriptorProto buildServiceDescriptor() {
14 ServiceDescriptorProto sd = new ServiceDescriptorProto()
15 ..name = 'Test'
16 ..method.addAll([
17 new MethodDescriptorProto()
18 ..name = 'aMethod'
19 ..inputType = 'SomeRequest'
20 ..outputType = 'SomeReply',
21 new MethodDescriptorProto()
22 ..name = 'anotherMethod'
23 ..inputType = '.foo.bar.EmptyMessage'
24 ..outputType = '.foo.bar.AnotherReply',
25 ]);
26 return sd;
27 }
28
29 void main() {
30 test('testServiceGenerator', () {
31 // NOTE: Below > 80 cols because it is matching generated code > 80 cols.
32 String expected = r'''
33 abstract class TestServiceBase extends GeneratedService {
34 Future<SomeReply> aMethod(ServerContext ctx, SomeRequest request);
35 Future<AnotherReply> anotherMethod(ServerContext ctx, EmptyMessage request);
36
37 Future<List<int>> handleCall(ServerContext ctx, String method, List<int> reque stBytes) async {
38 if (method == 'aMethod') {
39 var request = new SomeRequest.fromBuffer(requestBytes);
40 var result = await aMethod(ctx, request);
41 return result.writeToBuffer();
42 } else if (method == 'anotherMethod') {
43 var request = new EmptyMessage.fromBuffer(requestBytes);
44 var result = await anotherMethod(ctx, request);
45 return result.writeToBuffer();
46 } else {
47 throw 'Unknown method: $method';
48 }
49 }
50 }
51
52 ''';
53 var options = parseGenerationOptions(
54 new CodeGeneratorRequest(), new CodeGeneratorResponse());
55 var context =
56 new GenerationContext(options, new DefaultOutputConfiguration());
57 var fd = new FileDescriptorProto();
58 var fg = new FileGenerator(fd, null, context);
59 ServiceDescriptorProto sd = buildServiceDescriptor();
60 MemoryWriter buffer = new MemoryWriter();
61 IndentingWriter writer = new IndentingWriter(' ', buffer);
62 var sg = new ServiceGenerator(sd, fg, context);
63 sg.generate(writer);
64 expect(buffer.toString(), expected);
65 });
66 }
OLDNEW
« 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