blob: 7c39071001d76665135dae6bfb947f3348115ea2 [file] [log] [blame]
Treehugger Robot588aae72020-08-21 10:01:58 +00001// Copyright 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package rust
16
17import (
Ivan Lozano6a3d1e92020-11-02 15:06:26 -050018 "strings"
Treehugger Robot588aae72020-08-21 10:01:58 +000019 "testing"
Ivan Lozano6a3d1e92020-11-02 15:06:26 -050020
21 "android/soong/android"
Treehugger Robot588aae72020-08-21 10:01:58 +000022)
23
24func TestRustProtobuf(t *testing.T) {
25 ctx := testRust(t, `
26 rust_protobuf {
27 name: "librust_proto",
28 proto: "buf.proto",
29 crate_name: "rust_proto",
30 source_stem: "buf",
31 }
32 `)
Treehugger Robot588aae72020-08-21 10:01:58 +000033 // Check that libprotobuf is added as a dependency.
34 librust_proto := ctx.ModuleForTests("librust_proto", "android_arm64_armv8-a_dylib").Module().(*Module)
35 if !android.InList("libprotobuf", librust_proto.Properties.AndroidMkDylibs) {
36 t.Errorf("libprotobuf dependency missing for rust_protobuf (dependency missing from AndroidMkDylibs)")
37 }
Ivan Lozano6a3d1e92020-11-02 15:06:26 -050038
39 // Make sure the correct plugin is being used.
40 librust_proto_out := ctx.ModuleForTests("librust_proto", "android_arm64_armv8-a_source").Output("buf.rs")
41 cmd := librust_proto_out.RuleParams.Command
42 if w := "protoc-gen-rust"; !strings.Contains(cmd, w) {
43 t.Errorf("expected %q in %q", w, cmd)
44 }
45
46}
47
48func TestRustGrpcio(t *testing.T) {
49 ctx := testRust(t, `
50 rust_grpcio {
51 name: "librust_grpcio",
52 proto: "buf.proto",
53 crate_name: "rust_grpcio",
54 source_stem: "buf",
55 }
56 `)
57
58 // Check that libprotobuf is added as a dependency.
59 librust_grpcio_module := ctx.ModuleForTests("librust_grpcio", "android_arm64_armv8-a_dylib").Module().(*Module)
60 if !android.InList("libprotobuf", librust_grpcio_module.Properties.AndroidMkDylibs) {
61 t.Errorf("libprotobuf dependency missing for rust_grpcio (dependency missing from AndroidMkDylibs)")
62 }
63
64 // Make sure the correct plugin is being used.
65 librust_grpcio_out := ctx.ModuleForTests("librust_grpcio", "android_arm64_armv8-a_source").Output("buf.rs")
66 cmd := librust_grpcio_out.RuleParams.Command
67 if w := "protoc-gen-grpc"; !strings.Contains(cmd, w) {
68 t.Errorf("expected %q in %q", w, cmd)
69 }
Treehugger Robot588aae72020-08-21 10:01:58 +000070}