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

Side by Side Diff: test/client_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
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 client_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('testClientGenerator', () {
31 // NOTE: Below > 80 cols because it is matching generated code > 80 cols.
32 String expected = r'''
33 class TestApi {
34 ProtobufClient _client;
35 TestApi(this._client);
36
37 Future<SomeReply> aMethod(ClientContext ctx, SomeRequest request) async {
38 var resultBytes = await _client.Invoke(ctx, '/Test.aMethod', request.writeTo Buffer());
39 return new SomeReply.fromBuffer(resultBytes);
40 }
41 Future<AnotherReply> anotherMethod(ClientContext ctx, EmptyMessage request) as ync {
42 var resultBytes = await _client.Invoke(ctx, '/Test.anotherMethod', request.w riteToBuffer());
43 return new AnotherReply.fromBuffer(resultBytes);
44 }
45 }
46
47 ''';
48 var options = parseGenerationOptions(
49 new CodeGeneratorRequest(), new CodeGeneratorResponse());
50 var context =
51 new GenerationContext(options, new DefaultOutputConfiguration());
52 var fd = new FileDescriptorProto();
53 var fg = new FileGenerator(fd, null, context);
54 ServiceDescriptorProto sd = buildServiceDescriptor();
55 MemoryWriter buffer = new MemoryWriter();
56 IndentingWriter writer = new IndentingWriter(' ', buffer);
57 ClientApiGenerator cag = new ClientApiGenerator(sd, fg, context);
58 cag.generate(writer);
59 expect(buffer.toString(), expected);
60 });
61 }
OLDNEW
« pubspec.yaml ('K') | « test/all_tests.dart ('k') | test/service_generator_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698