本文整理汇总了C#中System.IO.UnmanagedMemoryStream.SetLength方法的典型用法代码示例。如果您正苦于以下问题:C# UnmanagedMemoryStream.SetLength方法的具体用法?C# UnmanagedMemoryStream.SetLength怎么用?C# UnmanagedMemoryStream.SetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.UnmanagedMemoryStream
的用法示例。
在下文中一共展示了UnmanagedMemoryStream.SetLength方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetLength_Negative
public void SetLength_Negative ()
{
UnmanagedMemoryStream ums = new UnmanagedMemoryStream(mem_byteptr,
length, capacity, FileAccess.ReadWrite);
try {
ums.SetLength(-1);
Assert.Fail ("#1");
} catch (ArgumentOutOfRangeException ex) {
// Non-negative number required
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNotNull (ex.ParamName, "#5");
Assert.AreEqual ("length", ex.ParamName, "#6");
}
ums.Close();
}
示例2: SetLength
public void SetLength ()
{
UnmanagedMemoryStream ums = new UnmanagedMemoryStream(mem_byteptr,
length, capacity, FileAccess.ReadWrite);
ums.Write (testStreamData, 0, testStreamData.Length);
ums.SetLength (length - 1);
Assert.AreEqual (capacity, ums.Capacity, "#A1");
Assert.AreEqual (length - 1, ums.Length, "#A2");
Assert.AreEqual (length - 1, ums.Position, "#A3");
ums.SetLength (length + 1);
Assert.AreEqual (capacity, ums.Capacity, "#B1");
Assert.AreEqual (length + 1, ums.Length, "#B2");
Assert.AreEqual (length - 1, ums.Position, "#B3");
ums.SetLength (length);
Assert.AreEqual (capacity, ums.Capacity, "#C1");
Assert.AreEqual (length, ums.Length, "#C2");
Assert.AreEqual (length - 1, ums.Position, "#C3");
ums.SetLength (0);
Assert.AreEqual (capacity, ums.Capacity, "#D1");
Assert.AreEqual (0, ums.Length, "#D2");
Assert.AreEqual (0, ums.Position, "#D3");
ums.SetLength (capacity);
Assert.AreEqual (capacity, ums.Capacity, "#E1");
Assert.AreEqual (capacity, ums.Length, "#E2");
Assert.AreEqual (0, ums.Position, "#E3");
ums.Close();
}
示例3: SetLength_Capacity_Exceeded
public void SetLength_Capacity_Exceeded ()
{
UnmanagedMemoryStream ums = new UnmanagedMemoryStream(mem_byteptr,
length, capacity, FileAccess.ReadWrite);
try {
ums.SetLength (capacity + 1);
Assert.Fail ("#1");
} catch (IOException ex) {
// Unable to expand length of this stream beyond its capacity
Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
ums.Close();
}
示例4: SetLength_Stream_ReadOnly
public void SetLength_Stream_ReadOnly ()
{
UnmanagedMemoryStream ums = new UnmanagedMemoryStream(mem_byteptr,
length);
try {
ums.SetLength (length);
Assert.Fail ("#1");
} catch (NotSupportedException ex) {
// Stream does not support writing
Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
}
ums.Close();
}