예제 #1
0
        public void TestCompressionMultipleUses()
        {
            var compress      = new CompressionOutputContext();
            var domain_stream = new MemoryStream();

            var domain       = new Domain("example.com");
            var domain_bytes = compress.SerializeDomain(domain);

            domain_stream.Write(domain_bytes, 0, domain_bytes.Length);

            domain       = new Domain("hostmaster.example.com");
            domain_bytes = compress.SerializeDomain(domain);
            domain_stream.Write(domain_bytes, 0, domain_bytes.Length);

            var expected = new byte[]
            {
                7, // Length of 'example'
                101,
                120,
                97,
                109,
                112,
                108,
                101,
                3, // Length of com
                99,
                111,
                109,
                0,  // Length of root
                10, // Length of hostmaster
                104,
                111,
                115,
                116,
                109,
                97,
                115,
                116,
                101,
                114,
                // Two bytes worth of pointer - they should have 1 at the 15th
                // bit and the 14th bit on the MSB, and the LSB should be 0
                // (since that is the offset of the start of the example.com
                // domain
                192,
                0
            };

            Assert.That(domain_stream.ToArray(), Is.EqualTo(expected));
        }
예제 #2
0
        public void TestCompressionFirstUse()
        {
            var compress     = new CompressionOutputContext();
            var domain       = new Domain("example.com");
            var domain_bytes = compress.SerializeDomain(domain);

            var expected = new byte[]
            {
                7, // Length of 'example'
                101,
                120,
                97,
                109,
                112,
                108,
                101,
                3, // Length of com
                99,
                111,
                109,
                0 // Length of root
            };

            Assert.That(domain_bytes, Is.EqualTo(expected));
        }
예제 #3
0
        public void TestCompressionLowerCase()
        {
            var compress     = new CompressionOutputContext();
            var domain       = new Domain("EXAMPLE.COM");
            var domain_bytes = compress.SerializeDomain(domain);

            compress.MoveForward((UInt16)domain_bytes.Length);

            var expected = new byte[]
            {
                7, // Length of 'example'
                101,
                120,
                97,
                109,
                112,
                108,
                101,
                3, // Length of com
                99,
                111,
                109,
                0 // Length of root
            };

            Assert.That(domain_bytes, Is.EqualTo(expected));
        }
예제 #4
0
 /**
  * Writes a domain name to the output stream, possibly compressing it.
  */
 public void WriteDomain(Domain domain)
 {
     WriteBytesNoForward(compress.SerializeDomain(domain));
 }