예제 #1
0
    public void FixedLengthArray_ToArray()
    {
        Windows.Win32.System.RestartManager.RM_PROCESS_INFO.__char_64 fixedCharArray = default;
        fixedCharArray = "hi";
        char[] expected = new char[fixedCharArray.Length];
        expected[0] = fixedCharArray._0;
        expected[1] = fixedCharArray._1;
        char[] actual = fixedCharArray.ToArray();
        Assert.Equal <char>(expected, actual);

        actual = fixedCharArray.ToArray(3);
        Assert.Equal <char>(expected.Take(3), actual);
    }
예제 #2
0
    public void FixedLengthArray_CopyTo()
    {
        Windows.Win32.System.RestartManager.RM_PROCESS_INFO.__char_64 fixedCharArray = default;
        fixedCharArray = "hi";
        Span <char> span = new char[fixedCharArray.Length];

        fixedCharArray.CopyTo(span);
        Assert.Equal('h', span[0]);
        Assert.Equal('i', span[1]);
        Assert.Equal(0, span[2]);

        span.Clear();
        fixedCharArray.CopyTo(span, 1);
        Assert.Equal('h', span[0]);
        Assert.Equal(0, span[1]);
    }
예제 #3
0
    public unsafe void FixedCharArray_ToString()
    {
        Windows.Win32.System.RestartManager.RM_PROCESS_INFO.__char_64 fixedCharArray = default;
        Assert.Equal(string.Empty, fixedCharArray.ToString());
        fixedCharArray._0 = 'H';
        Assert.Equal("H", fixedCharArray.ToString());
        fixedCharArray._1 = 'i';
        Assert.Equal("Hi", fixedCharArray.ToString());

        char *p = &fixedCharArray._0;

        for (int i = 0; i < fixedCharArray.Length; i++)
        {
            *(p + i) = 'x';
        }

        Assert.Equal(new string('x', fixedCharArray.Length), fixedCharArray.ToString());
    }
예제 #4
0
    public void FixedCharArraySetWithString()
    {
        Windows.Win32.System.RestartManager.RM_PROCESS_INFO.__char_64 fixedCharArray = default;

        fixedCharArray = null;
        Assert.Equal(string.Empty, fixedCharArray.ToString());

        fixedCharArray = string.Empty;
        Assert.Equal(string.Empty, fixedCharArray.ToString());

        fixedCharArray = "hi there";
        Assert.Equal("hi there", fixedCharArray.ToString());

        string expected = new string('x', fixedCharArray.Length);

        fixedCharArray = expected;
        Assert.Equal(expected, fixedCharArray.ToString());

        Assert.Throws <ArgumentException>(() => fixedCharArray = new string('x', fixedCharArray.Length + 1));
    }
예제 #5
0
    public void FixedLengthArray_Equals()
    {
        Windows.Win32.System.RestartManager.RM_PROCESS_INFO.__char_64 fixedCharArray = default;
        fixedCharArray = "hi";

        Assert.True(fixedCharArray.Equals("hi"));
        Assert.False(fixedCharArray.Equals("h"));
        Assert.False(fixedCharArray.Equals("d"));
        Assert.False(fixedCharArray.Equals("hid"));

        char[] buffer = new char[fixedCharArray.Length];
        Assert.False(fixedCharArray.Equals(buffer));
        Assert.False(fixedCharArray.Equals(buffer.AsSpan(0, 2)));

        buffer[0] = 'h';
        buffer[1] = 'i';
        Assert.True(fixedCharArray.Equals(buffer));
        Assert.True(fixedCharArray.Equals(buffer.AsSpan(0, 2)));
        Assert.True(fixedCharArray.Equals(buffer.AsSpan(0, 3)));

        // This should be false because the remainder of the fixed length array is non-default.
        Assert.False(fixedCharArray.Equals(buffer.AsSpan(0, 1)));
        Assert.False(fixedCharArray.Equals(buffer.AsSpan(0, 0)));
    }