1 | #region Copyright notice and license
|
---|
2 | // Protocol Buffers - Google's data interchange format
|
---|
3 | // Copyright 2008 Google Inc. All rights reserved.
|
---|
4 | // http://github.com/jskeet/dotnet-protobufs/
|
---|
5 | // Original C++/Java/Python code:
|
---|
6 | // http://code.google.com/p/protobuf/
|
---|
7 | //
|
---|
8 | // Redistribution and use in source and binary forms, with or without
|
---|
9 | // modification, are permitted provided that the following conditions are
|
---|
10 | // met:
|
---|
11 | //
|
---|
12 | // * Redistributions of source code must retain the above copyright
|
---|
13 | // notice, this list of conditions and the following disclaimer.
|
---|
14 | // * Redistributions in binary form must reproduce the above
|
---|
15 | // copyright notice, this list of conditions and the following disclaimer
|
---|
16 | // in the documentation and/or other materials provided with the
|
---|
17 | // distribution.
|
---|
18 | // * Neither the name of Google Inc. nor the names of its
|
---|
19 | // contributors may be used to endorse or promote products derived from
|
---|
20 | // this software without specific prior written permission.
|
---|
21 | //
|
---|
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
33 | #endregion
|
---|
34 |
|
---|
35 | using Google.ProtocolBuffers.DescriptorProtos;
|
---|
36 | using Google.ProtocolBuffers.Descriptors;
|
---|
37 | using NUnit.Framework;
|
---|
38 |
|
---|
39 | namespace Google.ProtocolBuffers {
|
---|
40 | [TestFixture]
|
---|
41 | public class DescriptorUtilTest {
|
---|
42 | [Test]
|
---|
43 | public void ExplicitNamespace() {
|
---|
44 | FileDescriptorProto proto = new FileDescriptorProto.Builder {
|
---|
45 | Name = "x", Package = "pack", Options = new FileOptions.Builder().SetExtension(CSharpOptions.CSharpFileOptions,
|
---|
46 | new CSharpFileOptions.Builder { Namespace = "Foo.Bar" }.Build()).Build()
|
---|
47 | }.Build();
|
---|
48 | FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
|
---|
49 | Assert.AreEqual("Foo.Bar", descriptor.CSharpOptions.Namespace);
|
---|
50 | }
|
---|
51 |
|
---|
52 | [Test]
|
---|
53 | public void NoNamespaceFallsBackToPackage() {
|
---|
54 | FileDescriptorProto proto = new FileDescriptorProto.Builder { Name = "x", Package = "pack" }.Build();
|
---|
55 | FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
|
---|
56 | Assert.AreEqual("pack", descriptor.CSharpOptions.Namespace);
|
---|
57 | }
|
---|
58 |
|
---|
59 | [Test]
|
---|
60 | public void NoNamespaceOrPackageFallsBackToEmptyString() {
|
---|
61 | FileDescriptorProto proto = new FileDescriptorProto.Builder { Name = "x" }.Build();
|
---|
62 | FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
|
---|
63 | Assert.AreEqual("", descriptor.CSharpOptions.Namespace);
|
---|
64 | }
|
---|
65 |
|
---|
66 | [Test]
|
---|
67 | public void ExplicitlyNamedFileClass() {
|
---|
68 | FileDescriptorProto proto = new FileDescriptorProto.Builder {
|
---|
69 | Name = "x", Options = new FileOptions.Builder().SetExtension(CSharpOptions.CSharpFileOptions,
|
---|
70 | new CSharpFileOptions.Builder { UmbrellaClassname = "Foo" }.Build()).Build()
|
---|
71 | }.Build();
|
---|
72 | FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
|
---|
73 | Assert.AreEqual("Foo", descriptor.CSharpOptions.UmbrellaClassname);
|
---|
74 | }
|
---|
75 |
|
---|
76 | [Test]
|
---|
77 | public void ImplicitFileClassWithProtoSuffix() {
|
---|
78 | FileDescriptorProto proto = new FileDescriptorProto.Builder { Name = "foo_bar.proto" }.Build();
|
---|
79 | FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
|
---|
80 | Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
|
---|
81 | }
|
---|
82 |
|
---|
83 | [Test]
|
---|
84 | public void ImplicitFileClassWithProtoDevelSuffix() {
|
---|
85 | FileDescriptorProto proto = new FileDescriptorProto.Builder { Name = "foo_bar.protodevel" }.Build();
|
---|
86 | FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
|
---|
87 | Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
|
---|
88 | }
|
---|
89 |
|
---|
90 | [Test]
|
---|
91 | public void ImplicitFileClassWithNoSuffix() {
|
---|
92 | FileDescriptorProto proto = new FileDescriptorProto.Builder { Name = "foo_bar" }.Build();
|
---|
93 | FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
|
---|
94 | Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
|
---|
95 | }
|
---|
96 |
|
---|
97 | [Test]
|
---|
98 | public void ImplicitFileClassWithDirectoryStructure() {
|
---|
99 | FileDescriptorProto proto = new FileDescriptorProto.Builder { Name = "x/y/foo_bar" }.Build();
|
---|
100 | FileDescriptor descriptor = FileDescriptor.BuildFrom(proto, null);
|
---|
101 | Assert.AreEqual("FooBar", descriptor.CSharpOptions.UmbrellaClassname);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|