• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 
3 // Copyright 2018 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #endregion
18 
19 using System.IO;
20 using NUnit.Framework;
21 
22 namespace Grpc.Tools.Tests
23 {
24     public class CppGeneratorTest : GeneratorTest
25     {
26         GeneratorServices _generator;
27 
28         [SetUp]
SetUp()29         public new void SetUp()
30         {
31             _generator = GeneratorServices.GetForLanguage("Cpp", _log);
32         }
33 
34         [TestCase("foo.proto", "", "foo")]
35         [TestCase("foo.proto", ".", "foo")]
36         [TestCase("foo.proto", "./", "foo")]
37         [TestCase("sub/foo.proto", "", "sub/foo")]
38         [TestCase("root/sub/foo.proto", "root", "sub/foo")]
39         [TestCase("root/sub/foo.proto", "root", "sub/foo")]
40         [TestCase("/root/sub/foo.proto", "/root", "sub/foo")]
RelativeDirectoryCompute(string proto, string root, string expectStem)41         public void RelativeDirectoryCompute(string proto, string root, string expectStem)
42         {
43             if (Path.DirectorySeparatorChar == '\\')
44                 expectStem = expectStem.Replace('/', '\\');
45             var poss = _generator.GetPossibleOutputs(Utils.MakeItem(proto, "ProtoRoot", root));
46             Assert.AreEqual(2, poss.Length);
47             Assert.Contains(expectStem + ".pb.cc", poss);
48             Assert.Contains(expectStem + ".pb.h", poss);
49         }
50 
51         [Test]
NoGrpcTwoOutputs()52         public void NoGrpcTwoOutputs()
53         {
54             var poss = _generator.GetPossibleOutputs(Utils.MakeItem("foo.proto"));
55             Assert.AreEqual(2, poss.Length);
56         }
57 
58         [TestCase("false")]
59         [TestCase("")]
GrpcDisabledTwoOutput(string grpc)60         public void GrpcDisabledTwoOutput(string grpc)
61         {
62             var item = Utils.MakeItem("foo.proto", "grpcservices", grpc);
63             var poss = _generator.GetPossibleOutputs(item);
64             Assert.AreEqual(2, poss.Length);
65         }
66 
67         [TestCase("true")]
GrpcEnabledFourOutputs(string grpc)68         public void GrpcEnabledFourOutputs(string grpc)
69         {
70             var item = Utils.MakeItem("foo.proto", "grpcservices", grpc);
71             var poss = _generator.GetPossibleOutputs(item);
72             Assert.AreEqual(4, poss.Length);
73             Assert.Contains("foo.pb.cc", poss);
74             Assert.Contains("foo.pb.h", poss);
75             Assert.Contains("foo.grpc.pb.cc", poss);
76             Assert.Contains("foo.grpc.pb.h", poss);
77         }
78 
79         [Test]
OutputDirMetadataRecognized()80         public void OutputDirMetadataRecognized()
81         {
82             var item = Utils.MakeItem("foo.proto", "OutputDir", "out");
83             var poss = _generator.GetPossibleOutputs(item);
84             Assert.AreEqual(2, poss.Length);
85             Assert.That(Path.GetDirectoryName(poss[0]), Is.EqualTo("out"));
86         }
87     };
88 }
89