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