コード例 #1
0
        public void CreateFromListTest()
        {
            var r = new[] { 5, 5, 5, 5 };
            var h = SafeHGlobalHandle.CreateFromList(r, r.Length);

            Assert.That(!h.IsClosed && !h.IsInvalid);
            Assert.That(h.Size, Is.EqualTo(Marshal.SizeOf <int>() * r.Length));
            Assert.That(h.ToStructure <int>(), Is.EqualTo(5));
            Assert.That(h.ToEnumerable <int>(4), Has.Exactly(4).EqualTo(5).And.Exactly(4).Items);

            var d = new[] { new RECT(1, 1, 1, 1), new RECT(2, 2, 2, 2) };

            h = SafeHGlobalHandle.CreateFromList(d, d.Length);
            Assert.That(!h.IsClosed && !h.IsInvalid);
            Assert.That(h.Size, Is.EqualTo(Marshal.SizeOf <RECT>() * d.Length));
            Assert.That(h.ToStructure <RECT>().X, Is.EqualTo(1));
            Assert.That(h.ToArray <RECT>(4), Has.Exactly(4).Items);

            var p = new[] { new PRECT(1, 1, 1, 1), new PRECT(2, 2, 2, 2) };

            h = SafeHGlobalHandle.CreateFromList(p);
            Assert.That(!h.IsClosed && !h.IsInvalid);
            Assert.That(h.Size, Is.EqualTo(Marshal.SizeOf <PRECT>() * p.Length));
            Assert.That(h.ToArray <RECT>(4), Has.Exactly(4).Items);

            Assert.That(() => SafeHGlobalHandle.CreateFromList(new[] { "X" }), Throws.ArgumentException);
        }
コード例 #2
0
        public void AddResourceAttributeAceTest()
        {
            using (var pNewSacl = new SafePACL(256))
            {
                using (var capId = new SafePSID("S-1-17-22"))
                    Assert.That(AddScopedPolicyIDAce(pNewSacl, ACL_REVISION, 0, 0, capId), ResultIs.Successful);

                var attrValues = new[] { 12L, 32L };
                using (var pattrValues = SafeHGlobalHandle.CreateFromList(attrValues))
                {
                    var csattr = new CLAIM_SECURITY_ATTRIBUTE_V1
                    {
                        Name       = "Int",
                        ValueType  = CLAIM_SECURITY_ATTRIBUTE_TYPE.CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64,
                        ValueCount = (uint)attrValues.Length,
                        Values     = new CLAIM_SECURITY_ATTRIBUTE_V1.VALUESUNION {
                            pInt64 = (IntPtr)pattrValues
                        }
                    };
                    var attr = new[] { csattr };
                    using (var pattr = SafeHGlobalHandle.CreateFromList(attr))
                    {
                        var csi = CLAIM_SECURITY_ATTRIBUTES_INFORMATION.Default;
                        csi.AttributeCount         = (uint)attr.Length;
                        csi.Attribute.pAttributeV1 = (IntPtr)pattr;
                        var len = 0U;
                        Assert.That(AddResourceAttributeAce(pNewSacl, ACL_REVISION, 0, 0, SafePSID.Everyone, csi, ref len), ResultIs.Successful);
                    }
                }
            }
        }
コード例 #3
0
        public void ToArrayTest()
        {
            var rs = new[] { 10, 11, 12, 13, 14 };
            var h  = SafeHGlobalHandle.CreateFromList(rs, rs.Length, i);
            var ro = ((IntPtr)h).ToArray <int>(4, i);

            Assert.That(ro.Length, Is.EqualTo(4));
            Assert.That(ro[2], Is.EqualTo(rs[2]));

            Assert.That(((IntPtr)h).ToArray <int>(0, i), Is.Empty);
            Assert.That(IntPtr.Zero.ToArray <int>(3, i), Is.Null);
        }
コード例 #4
0
        public void ToIEnumTest()
        {
            var rs = new[] { 10, 11, 12, 13, 14 };
            var h  = SafeHGlobalHandle.CreateFromList(rs, rs.Length, i);
            var ro = ((IntPtr)h).ToIEnum <int>(4, i);
            var v  = 10;

            foreach (var rv in ro)
            {
                Assert.That(rv, Is.EqualTo(v++));
            }
            Assert.That(v, Is.EqualTo(14));

            Assert.That(((IntPtr)h).ToIEnum <int>(0, i), Is.Empty);
            Assert.That(IntPtr.Zero.ToIEnum <int>(3, i), Is.Empty);
        }