Exemple #1
0
 static extern Boolean WriteFile(
     IntPtr hFile,
     [In, Out] ArrayWithOffset lpBuffer,
     UInt32 nNumberOfBytesToWrite,
     out UInt32 lpNumberOfBytesWritten,
     IntPtr lpOverlapped
 );
Exemple #2
0
 static extern Boolean ReadFile(
     IntPtr hFile,
     [In, Out] ArrayWithOffset lpBuffer,
     UInt32 nNumberOfBytesToRead,
     out UInt32 lpNumberOfBytesRead,
     IntPtr lpOverlapped
 );
Exemple #3
0
        public void Ctor_Array_Offset(object array, int offset, int expectedHashCode)
        {
            var arrayWithOffset = new ArrayWithOffset(array, offset);

            Assert.Equal(array, arrayWithOffset.GetArray());
            Assert.Equal(offset, arrayWithOffset.GetOffset());
            Assert.Equal(expectedHashCode, arrayWithOffset.GetHashCode());
        }
Exemple #4
0
 public void Equals_Object_ReturnsExpected(ArrayWithOffset arrayWithOffset, object other, bool expected)
 {
     Assert.Equal(expected, arrayWithOffset.Equals(other));
     if (other is ArrayWithOffset otherArrayWithOffset)
     {
         Assert.Equal(expected, arrayWithOffset == otherArrayWithOffset);
         Assert.Equal(!expected, arrayWithOffset != otherArrayWithOffset);
     }
 }
Exemple #5
0
    static void testCharArrayWithOffset()
    {
        char[]          c         = GetInvalidArray();
        ArrayWithOffset arrWOff_0 = new ArrayWithOffset(c, 0);

        Assert.True(Char_InOut_ArrayWithOffset(arrWOff_0));

        c = GetValidArray();
        ArrayWithOffset arrWOff_1 = new ArrayWithOffset(c, 1);

        Assert.True(Char_InOut_ArrayWithOffset(arrWOff_1));
    }
Exemple #6
0
    static void testCharArrayWithOffset()
    {
        char[]          c         = GetInvalidArray();
        ArrayWithOffset arrWOff_0 = new ArrayWithOffset(c, 0);

        Assert.IsTrue(Char_InOut_ArrayWithOffset(arrWOff_0), "[Error] Location ctlpsawo11");

        c = GetValidArray();
        ArrayWithOffset arrWOff_1 = new ArrayWithOffset(c, 1);

        Assert.IsTrue(Char_InOut_ArrayWithOffset(arrWOff_1), "[Error] Location ctlpsawo22");
    }
Exemple #7
0
 // Determine if two objects are equal.
 public override bool Equals(Object obj)
 {
     if (obj is ArrayWithOffset)
     {
         ArrayWithOffset other = (ArrayWithOffset)obj;
         return(array == other.array && offset == other.offset);
     }
     else
     {
         return(false);
     }
 }
Exemple #8
0
    public void Read(Byte[] outBuffer, int index, int count)
    {
        UInt32 bytesRead;

        while (0 < count)
        {
            ArrayWithOffset arr = new ArrayWithOffset(outBuffer, index);

            if (!ReadFile(m_ReadPipe, arr, (UInt32)count, out bytesRead, IntPtr.Zero))
                throw new System.ApplicationException();

            index += (int)bytesRead;
            count -= (int)bytesRead;
        }
    }
Exemple #9
0
    public void Write(Byte[] buffer, int index, int count)
    {
	    UInt32 bytesWritten = 0;

	    while(0 < count)
	    {
            ArrayWithOffset arr = new ArrayWithOffset(buffer, index);

		    if(!WriteFile(m_WritePipe, arr, (uint)count, out bytesWritten, IntPtr.Zero))
                throw new System.ApplicationException();

            index += (int)bytesWritten;
            count -= (int)bytesWritten;
	    }
    }
Exemple #10
0
    public static int Main()
    {
        try
        {
            Span <int> expected = new int[] { 1, 2, 3, 4, 5, 6 };
            Span <int> newValue = new int[] { 7, 8, 9, 10, 11, 12 };

            for (int i = 0; i < expected.Length; i++)
            {
                int[]           array  = new int[] { 1, 2, 3, 4, 5, 6 };
                ArrayWithOffset offset = new ArrayWithOffset(array, i * 4); // The offset parameter in ArrayWithOffset is a byte-offset, not an element offset.

                fixed(int *expectedSubArray = expected.Slice(i))
                fixed(int *newValueSubArray = newValue.Slice(i))
                {
                    Assert.True(ArrayWithOffsetNative.Marshal_InOut(expectedSubArray, offset, expected.Length - i, newValueSubArray), $"Native call failed with element offset {i}.");
                }

                for (int j = 0; j < i; j++)
                {
                    Assert.Equal(expected[j], array[j]);
                }

                for (int j = i; j < array.Length; j++)
                {
                    Assert.Equal(newValue[j], array[j]);
                }
            }

            ArrayWithOffset arrayWithOffset = new ArrayWithOffset(new int[] { 1 }, 0);

            Assert.Throws <MarshalDirectiveException>(() => ArrayWithOffsetNative.Marshal_Invalid(arrayWithOffset));
            Assert.Throws <MarshalDirectiveException>(() => ArrayWithOffsetNative.Marshal_Invalid(ref arrayWithOffset));
            Assert.Throws <MarshalDirectiveException>(() => ArrayWithOffsetNative.Marshal_Invalid_Return());
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            return(101);
        }

        return(100);
    }
Exemple #11
0
 public static extern bool Marshal_InOut(int *expected, [In, Out] ArrayWithOffset actual, int numElements, int *newValue);
Exemple #12
0
 public static extern bool Char_InOut_ArrayWithOffset([In, Out] ArrayWithOffset charArrayWithOffset);
	public static bool op_Inequality(ArrayWithOffset a, ArrayWithOffset b) {}
 public static bool op_Inequality(ArrayWithOffset a, ArrayWithOffset b)
 {
 }
 public bool Equals(ArrayWithOffset obj)
 {
 }
Exemple #16
0
 public static extern bool Marshal_Invalid(ArrayWithOffset invalidArray);
Exemple #17
0
 public static extern bool Marshal_Invalid(ref ArrayWithOffset array);
	public bool Equals(ArrayWithOffset obj) {}