Beispiel #1
0
        public void TestDisplayBufferAscii()
        {
            var rb = new Session.ReadBufferIoResult
            {
                Success        = true,
                Result         = new string[] { "30 31 32 33 34 35 36" },
                Command        = "ReadBuffer(Ascii)",
                StatusLine     = "U F U C(host.mycompany.com) I 2 1 7 0 1 0x0 -",
                ReadBufferType = Session.ReadBufferType.Ascii,
                Encoding       = Encoding.UTF8,
                Origin         = 0
            };
            var b = new DisplayBuffer(rb);

            // Basic functionality.
            Assert.AreEqual("123456", b.Ascii(6));
            Assert.AreEqual("12", b.Ascii(0, 1, 2));
            Assert.AreEqual(new string[] { "12" }, b.Ascii(0, 1, 1, 2));
            Assert.AreEqual(string.Empty, b.Ascii(0));
            Assert.AreEqual(string.Empty, b.Ascii(0, 1, 0));

            // Handy shortcut functionality.
            Assert.AreEqual(true, b.AsciiEquals(0, 1, "123456"));
            Assert.AreEqual(true, b.AsciiMatches(0, 1, 6, "1.*6"));

            // Exceptions.
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(99));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(100, 1, 2));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(-100, 1, 2));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(0, 100, 2));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(0, -100, 2));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(0, 1, 999, 2));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(0, 1, -1, 2));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(0, 1, 1, 999));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(0, 1, 1, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(-1, 1, 1, 2));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(999, 1, 1, 2));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(0, -1, 1, 2));
            Assert.Throws <ArgumentOutOfRangeException>(() => b.Ascii(0, 999, 1, 2));

            rb = new Session.ReadBufferIoResult
            {
                Success        = true,
                Result         = new string[] { "30 31 32 33 34 35 36" },
                Command        = "ReadBuffer(Ebcdic)",
                StatusLine     = "U F U C(host.mycompany.com) I 2 1 7 0 1 0x0 -",
                ReadBufferType = Session.ReadBufferType.Ebcdic,
                Encoding       = Encoding.UTF8
            };
            b = new DisplayBuffer(rb);
            Assert.Throws <InvalidOperationException>(() => b.Ascii(1));
            Assert.Throws <InvalidOperationException>(() => b.Ascii(0, 1, 2));
            Assert.Throws <InvalidOperationException>(() => b.Ascii(0, 1, 1, 2));
        }
Beispiel #2
0
        public void TestDisplayBufferAsciiFieldDbcs()
        {
            var rb = new Session.ReadBufferIoResult
            {
                Success = true,
                Result  = new string[]
                {
                    "SF(c0=e0) 30 31 0e e6b581 - e585ad - e79599 - 0f SF(c0=e0) 0e e58898 - e7a1ab - e69fb3 - e99986 - e581bb - e8928c - e798a4 - 0f 47 48",
                    "SF(c0=e0) 61 62 63 64 65 66 SF(c0=e0) 67 68 69 6a 6b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
                },
                Command        = "ReadBuffer(Ascii)",
                StatusLine     = "U F U C(host.mycompany.com) I 2 2 30 0 1 0x0 -",
                ReadBufferType = Session.ReadBufferType.Ascii,
                Encoding       = Encoding.UTF8
            };
            var b = new DisplayBuffer(rb);

            // Verify that the field length is 7 characters, not 10 buffer positions.
            Assert.AreEqual(7, b.FieldLength(0, 1));

            // Verify that we get the right 7 characters.
            Assert.AreEqual("01 流六留 ", b.AsciiField());

            // Verify that AsciiEquals does the right thing with DBCS. This also exercises 3-arg Ascii().
            Assert.AreEqual(true, b.AsciiEquals(0, 1, "01 流六留 "));

            // Verify that Ascii with a rectangle will scan extra buffer positions to fulfill the request.
            var rectangle = b.Ascii(0, 4, 2, 2);

            Assert.AreEqual("流六", rectangle[0]);
            Assert.AreEqual("de", rectangle[1]);

            // Verify that a rectangle will not wrap.
            rectangle = b.Ascii(0, 25, 1, 5);
            Assert.AreEqual(4, rectangle[0].Length);
        }