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

Unified 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: 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/client_generator_test.dart
diff --git a/test/client_generator_test.dart b/test/client_generator_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..db5fa38fffe182035af1f5028bb0702f553a78c3
--- /dev/null
+++ b/test/client_generator_test.dart
@@ -0,0 +1,63 @@
+#!/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 client_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('testClientGenerator', () {
+ // NOTE: Below > 80 cols because it is matching generated code > 80 cols.
+ String expected = r'''
+class TestApi {
+ RpcClient _client;
+ TestApi(this._client);
+
+ Future<SomeReply> aMethod(ClientContext ctx, SomeRequest request) async {
+ var emptyResponse = new SomeReply();
+ var result = await _client.invoke(ctx, 'Test', 'AMethod', request, emptyResponse);
+ return result;
+ }
+ Future<AnotherReply> anotherMethod(ClientContext ctx, EmptyMessage request) async {
+ var emptyResponse = new AnotherReply();
+ var result = await _client.invoke(ctx, 'Test', 'AnotherMethod', request, emptyResponse);
+ return result;
+ }
+}
+
+''';
+ 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);
+ ClientApiGenerator cag = new ClientApiGenerator(sd, fg, context);
+ cag.generate(writer);
+ expect(buffer.toString(), expected);
+ });
+}
« no previous file with comments | « test/all_tests.dart ('k') | test/protos/service.proto » ('j') | test/service_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698