public static unsafe void GetAsciiSpanFromSBytePointerTest() { Assert.That(() => MarshalUtilities.GetAsciiSpan(null, -1).ToArray(), Is.EqualTo(Array.Empty <sbyte>()) ); fixed(sbyte *source = Array.Empty <sbyte>()) { var pSource = source; Assert.That(() => MarshalUtilities.GetAsciiSpan(pSource, -1).ToArray(), Is.EqualTo(Array.Empty <sbyte>()) ); } fixed(sbyte *source = new sbyte[] { (sbyte)'A', (sbyte)'B', (sbyte)'C' }) { var pSource = source; Assert.That(() => MarshalUtilities.GetAsciiSpan(pSource, -1).ToArray(), Is.EqualTo(new sbyte[] { (sbyte)'A', (sbyte)'B', (sbyte)'C' }) ); Assert.That(() => MarshalUtilities.GetAsciiSpan(pSource, 2).ToArray(), Is.EqualTo(new sbyte[] { (sbyte)'A', (sbyte)'B' }) ); } }
public static void GetAsciiSpanFromStringTest() { Assert.That(() => MarshalUtilities.GetAsciiSpan(null).ToArray(), Is.EqualTo(Array.Empty <sbyte>()) ); Assert.That(() => MarshalUtilities.GetAsciiSpan(string.Empty).ToArray(), Is.EqualTo(Array.Empty <sbyte>()) ); Assert.That(() => MarshalUtilities.GetAsciiSpan("ABC").ToArray(), Is.EqualTo(new sbyte[] { (sbyte)'A', (sbyte)'B', (sbyte)'C' }) ); }
public static unsafe void GetAsciiSpanFromSByteReferenceTest() { Assert.That(() => MarshalUtilities.GetAsciiSpan(UnsafeUtilities.NullRef <sbyte>(), -1).ToArray(), Is.EqualTo(Array.Empty <sbyte>()) ); var source = new sbyte[] { (sbyte)'A', (sbyte)'B', (sbyte)'C' }; Assert.That(() => MarshalUtilities.GetAsciiSpan(in source[0], -1).ToArray(), Is.EqualTo(new sbyte[] { (sbyte)'A', (sbyte)'B', (sbyte)'C' }) ); Assert.That(() => MarshalUtilities.GetAsciiSpan(in source[0], 2).ToArray(), Is.EqualTo(new sbyte[] { (sbyte)'A', (sbyte)'B' }) ); }