Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 1 | #region Copyright notice and license |
| 2 | |
| 3 | // Copyright 2015, Google Inc. |
| 4 | // All rights reserved. |
| 5 | // |
| 6 | // Redistribution and use in source and binary forms, with or without |
| 7 | // modification, are permitted provided that the following conditions are |
| 8 | // met: |
| 9 | // |
| 10 | // * Redistributions of source code must retain the above copyright |
| 11 | // notice, this list of conditions and the following disclaimer. |
| 12 | // * Redistributions in binary form must reproduce the above |
| 13 | // copyright notice, this list of conditions and the following disclaimer |
| 14 | // in the documentation and/or other materials provided with the |
| 15 | // distribution. |
| 16 | // * Neither the name of Google Inc. nor the names of its |
| 17 | // contributors may be used to endorse or promote products derived from |
| 18 | // this software without specific prior written permission. |
| 19 | // |
| 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | #endregion |
| 33 | |
| 34 | using System; |
| 35 | using Grpc.Core; |
| 36 | using Grpc.Core.Internal; |
| 37 | using Grpc.Core.Utils; |
| 38 | using NUnit.Framework; |
| 39 | |
| 40 | namespace Grpc.Core.Internal.Tests |
| 41 | { |
| 42 | public class MetadataArraySafeHandleTest |
| 43 | { |
| 44 | [Test] |
| 45 | public void CreateEmptyAndDestroy() |
| 46 | { |
Jan Tattermusch | b533281 | 2015-07-14 19:29:35 -0700 | [diff] [blame] | 47 | var nativeMetadata = MetadataArraySafeHandle.Create(new Metadata()); |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 48 | nativeMetadata.Dispose(); |
| 49 | } |
| 50 | |
| 51 | [Test] |
| 52 | public void CreateAndDestroy() |
| 53 | { |
Jan Tattermusch | 7b4a31f | 2015-07-20 17:08:13 -0700 | [diff] [blame] | 54 | var metadata = new Metadata |
| 55 | { |
Jan Tattermusch | b533281 | 2015-07-14 19:29:35 -0700 | [diff] [blame] | 56 | new Metadata.Entry("host", "somehost"), |
| 57 | new Metadata.Entry("header2", "header value"), |
| 58 | }; |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 59 | var nativeMetadata = MetadataArraySafeHandle.Create(metadata); |
| 60 | nativeMetadata.Dispose(); |
| 61 | } |
Jan Tattermusch | 7f23a75 | 2015-07-20 20:28:28 -0700 | [diff] [blame] | 62 | |
| 63 | [Test] |
| 64 | public void ReadMetadataFromPtrUnsafe() |
| 65 | { |
| 66 | var metadata = new Metadata |
| 67 | { |
| 68 | new Metadata.Entry("host", "somehost"), |
| 69 | new Metadata.Entry("header2", "header value"), |
| 70 | }; |
| 71 | var nativeMetadata = MetadataArraySafeHandle.Create(metadata); |
| 72 | |
| 73 | var copy = MetadataArraySafeHandle.ReadMetadataFromPtrUnsafe(nativeMetadata.Handle); |
| 74 | Assert.AreEqual(2, copy.Count); |
| 75 | |
| 76 | Assert.AreEqual("host", copy[0].Key); |
| 77 | Assert.AreEqual("somehost", copy[0].Value); |
| 78 | Assert.AreEqual("header2", copy[1].Key); |
| 79 | Assert.AreEqual("header value", copy[1].Value); |
| 80 | |
| 81 | nativeMetadata.Dispose(); |
| 82 | } |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 83 | } |
| 84 | } |