blob: 46469113c591ac0f50086ea4c0f138f6c96096c6 [file] [log] [blame]
Jan Tattermuschc0b37212015-03-13 08:35:41 -07001#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
34using System;
35using Grpc.Core;
36using Grpc.Core.Internal;
37using Grpc.Core.Utils;
38using NUnit.Framework;
39
40namespace Grpc.Core.Internal.Tests
41{
42 public class MetadataArraySafeHandleTest
43 {
44 [Test]
45 public void CreateEmptyAndDestroy()
46 {
Jan Tattermuschb5332812015-07-14 19:29:35 -070047 var nativeMetadata = MetadataArraySafeHandle.Create(new Metadata());
Jan Tattermuschc0b37212015-03-13 08:35:41 -070048 nativeMetadata.Dispose();
49 }
50
51 [Test]
52 public void CreateAndDestroy()
53 {
Jan Tattermusch7b4a31f2015-07-20 17:08:13 -070054 var metadata = new Metadata
55 {
Jan Tattermuschb5332812015-07-14 19:29:35 -070056 new Metadata.Entry("host", "somehost"),
57 new Metadata.Entry("header2", "header value"),
58 };
Jan Tattermuschc0b37212015-03-13 08:35:41 -070059 var nativeMetadata = MetadataArraySafeHandle.Create(metadata);
60 nativeMetadata.Dispose();
61 }
Jan Tattermusch7f23a752015-07-20 20:28:28 -070062
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 Tattermuschc0b37212015-03-13 08:35:41 -070083 }
84}