• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 
3 // Copyright 2015 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;
20 using Grpc.Core;
21 using Grpc.Core.Internal;
22 using Grpc.Core.Utils;
23 using NUnit.Framework;
24 
25 namespace Grpc.Core.Internal.Tests
26 {
27     public class MetadataArraySafeHandleTest
28     {
29         [Test]
CreateEmptyAndDestroy()30         public void CreateEmptyAndDestroy()
31         {
32             var nativeMetadata = MetadataArraySafeHandle.Create(new Metadata());
33             nativeMetadata.Dispose();
34         }
35 
36         [Test]
CreateAndDestroy()37         public void CreateAndDestroy()
38         {
39             var metadata = new Metadata
40             {
41                 { "host", "somehost" },
42                 { "header2", "header value" },
43             };
44             var nativeMetadata = MetadataArraySafeHandle.Create(metadata);
45             nativeMetadata.Dispose();
46         }
47 
48         [Test]
ReadMetadataFromPtrUnsafe()49         public void ReadMetadataFromPtrUnsafe()
50         {
51             var metadata = new Metadata
52             {
53                 { "host", "somehost" },
54                 { "header2", "header value" }
55             };
56             var nativeMetadata = MetadataArraySafeHandle.Create(metadata);
57 
58             var copy = MetadataArraySafeHandle.ReadMetadataFromPtrUnsafe(nativeMetadata.Handle);
59             Assert.AreEqual(2, copy.Count);
60 
61             Assert.AreEqual("host", copy[0].Key);
62             Assert.AreEqual("somehost", copy[0].Value);
63             Assert.AreEqual("header2", copy[1].Key);
64             Assert.AreEqual("header value", copy[1].Value);
65 
66             nativeMetadata.Dispose();
67         }
68     }
69 }
70