Exemplo n.º 1
0
        public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEvenSpaceForTruncationEllipses()
        {
            byte[] buffer   = new byte[20];
            int    startPos = buffer.Length - EllipsesWithBrackets.Length + 1; // Not enough space for "{...}\n".
            int    endPos   = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos);

            Assert.Equal(startPos, endPos);
        }
Exemplo n.º 2
0
        public void SelfDiagnosticsEventListener_EncodeInBuffer_Null()
        {
            byte[] buffer   = new byte[20];
            int    startPos = 0;
            int    endPos   = SelfDiagnosticsEventListener.EncodeInBuffer(null, false, buffer, startPos);

            Assert.Equal(startPos, endPos);
        }
Exemplo n.º 3
0
        public void SelfDiagnosticsEventListener_EncodeInBuffer_Empty()
        {
            byte[] buffer   = new byte[20];
            int    startPos = 0;
            int    endPos   = SelfDiagnosticsEventListener.EncodeInBuffer(string.Empty, false, buffer, startPos);

            byte[] expected = Encoding.UTF8.GetBytes(string.Empty);
            AssertBufferOutput(expected, buffer, startPos, endPos);
        }
Exemplo n.º 4
0
        public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEvenSpaceForTruncatedString()
        {
            byte[] buffer   = new byte[20];
            int    startPos = buffer.Length - EllipsesWithBrackets.Length; // Just enough space for "{...}\n".
            int    endPos   = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos);

            byte[] expected = Encoding.UTF8.GetBytes("{...}\0");
            AssertBufferOutput(expected, buffer, startPos, endPos + 1);
        }
Exemplo n.º 5
0
        public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_EnoughSpace()
        {
            byte[] buffer   = new byte[20];
            int    startPos = buffer.Length - EllipsesWithBrackets.Length - 6; // Just enough space for "abc" even if "...\n" need to be added.
            int    endPos   = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos);

            byte[] expected = Encoding.UTF8.GetBytes("{abc}\0");
            AssertBufferOutput(expected, buffer, startPos, endPos + 1);
        }
Exemplo n.º 6
0
        public void SelfDiagnosticsEventListener_EncodeInBuffer_EnoughSpace()
        {
            byte[] buffer   = new byte[20];
            int    startPos = buffer.Length - Ellipses.Length - 6; // Just enough space for "abc" even if "...\n" needs to be added.
            int    endPos   = SelfDiagnosticsEventListener.EncodeInBuffer("abc", false, buffer, startPos);

            // '\n' will be appended to the original string "abc" after EncodeInBuffer is called.
            // The byte where '\n' will be placed should not be touched within EncodeInBuffer, so it stays as '\0'.
            byte[] expected = Encoding.UTF8.GetBytes("abc\0");
            AssertBufferOutput(expected, buffer, startPos, endPos + 1);
        }
Exemplo n.º 7
0
        public void SelfDiagnosticsEventListener_EncodeInBuffer_NotEnoughSpaceForFullString()
        {
            byte[] buffer   = new byte[20];
            int    startPos = buffer.Length - Ellipses.Length - 5; // Just not space for "abc" if "...\n" needs to be added.

            // It's a quick estimate by assumption that most Unicode characters takes up to 2 16-bit UTF-16 chars,
            // which can be up to 4 bytes when encoded in UTF-8.
            int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", false, buffer, startPos);

            byte[] expected = Encoding.UTF8.GetBytes("ab...\0");
            AssertBufferOutput(expected, buffer, startPos, endPos + 1);
        }