Exemplo n.º 1
0
        public void TestArgumentExceptions()
        {
            var packed = new PackedByteArray();

            Assert.Throws <ArgumentNullException> (() => packed.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException> (() => packed.CopyTo(new byte[16], -1));
        }
Exemplo n.º 2
0
        public void TestBasicFunctionality()
        {
            var packed   = new PackedByteArray();
            var expected = new byte[1024];
            var buffer   = new byte[1024];
            int index    = 0;

            for (int i = 0; i < 257; i++)
            {
                expected[index++] = (byte)'A';
                packed.Add((byte)'A');
            }

            for (int i = 1; i < 26; i++)
            {
                expected[index++] = (byte)('A' + i);
                packed.Add((byte)('A' + i));
            }

            for (int i = 0; i < 128; i++)
            {
                expected[index++] = (byte)'B';
                packed.Add((byte)'B');
            }

            Assert.AreEqual(index, packed.Count, "Count");

            packed.CopyTo(buffer, 0);

            for (int i = 0; i < index; i++)
            {
                Assert.AreEqual(expected[i], buffer[i], "buffer[{0}]", i);
            }
        }
Exemplo n.º 3
0
		unsafe int Filter (byte* inbuf, int length, byte* outbuf)
		{
			byte* inend = inbuf + length;
			byte* outptr = outbuf;
			byte* inptr = inbuf;
			int count = 0;

			while (inptr < inend) {
				if ((*inptr).IsBlank ()) {
					lwsp.Add (*inptr);
				} else if (*inptr == (byte) '\r') {
					*outptr++ = *inptr;
					lwsp.Clear ();
					count++;
				} else if (*inptr == (byte) '\n') {
					*outptr++ = *inptr;
					lwsp.Clear ();
					count++;
				} else {
					if (lwsp.Count > 0) {
						lwsp.CopyTo (OutputBuffer, count);
						outptr += lwsp.Count;
						count += lwsp.Count;
						lwsp.Clear ();
					}

					*outptr++ = *inptr;
					count++;
				}

				inptr++;
			}

			return count;
		}