Ejemplo n.º 1
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());
    }
Ejemplo n.º 2
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));
    }