public void Validate_with_advanced_options_should_throw_if_parameters_incorrect(bool provideCompressedBytes, int inputOffset, int inputLength, Type expectedExceptionType)
        {
            var uncompressedBytes = Encoding.ASCII.GetBytes("Hello, hello, howdy?");                         // 20 bytes
            var compressedBytes   = provideCompressedBytes ? SnappyCodec.Compress(uncompressedBytes) : null; // 22 bytes

            var exception = Record.Exception(() => SnappyCodec.Validate(compressedBytes, inputOffset, inputLength));

            exception.Should().BeOfType(expectedExceptionType);
        }
示例#2
0
        public void ValidateExceptions()
        {
            var uncompressed = Encoding.ASCII.GetBytes("Hello, hello, howdy?");
            var compressed   = SnappyCodec.Compress(uncompressed);
            var buffer       = new byte[100];

            Assert.Throws <ArgumentNullException>(() => SnappyCodec.Validate(null));
            Assert.Throws <ArgumentNullException>(() => SnappyCodec.Validate(null, 0, 3));
            Assert.Throws <ArgumentOutOfRangeException>(() => SnappyCodec.Validate(compressed, -1, uncompressed.Length));
            Assert.Throws <ArgumentOutOfRangeException>(() => SnappyCodec.Validate(compressed, 0, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => SnappyCodec.Validate(compressed, compressed.Length - 2, 4));
        }
示例#3
0
        public void Validate()
        {
            var uncompressed = Encoding.ASCII.GetBytes("Hello, hello, howdy?");
            var compressed   = SnappyCodec.Compress(uncompressed);
            var buffer       = new byte[100];

            Assert.IsTrue(SnappyCodec.Validate(compressed));
            var rubbish = new byte[10];

            new Random(0).NextBytes(rubbish);
            Assert.IsFalse(SnappyCodec.Validate(rubbish, 0, rubbish.Length));
            Assert.IsFalse(SnappyCodec.Validate(compressed, 0, 0));
            Assert.IsFalse(SnappyCodec.Validate(compressed, compressed.Length, 0));
        }
示例#4
0
 public void Validation(string name)
 {
     Benchmark.Run("Validating", name, benchmark =>
     {
         var compressed = SnappyCodec.Compress(benchmark.Input);
         bool ok        = false;
         benchmark.Stopwatch.Start();
         for (int i = 0; i < benchmark.Iterations; ++i)
         {
             ok = SnappyCodec.Validate(compressed);
         }
         benchmark.Stopwatch.Stop();
         Assert.IsTrue(ok);
     });
 }
        public void Validate_should_work_as_expected()
        {
            var uncompressedBytes = Encoding.ASCII.GetBytes("Hello, hello, howdy?");

            var compressedBytes = SnappyCodec.Compress(uncompressedBytes);
            var isValid         = SnappyCodec.Validate(compressedBytes);

            isValid.Should().BeTrue();

            isValid = SnappyCodec.Validate(compressedBytes, 0, 0);
            isValid.Should().BeFalse();

            isValid = SnappyCodec.Validate(compressedBytes, compressedBytes.Length, 0);
            isValid.Should().BeFalse();

            var randomBytes = new byte[10];

            new Random(0).NextBytes(randomBytes);

            var isRandomBytesValid = SnappyCodec.Validate(randomBytes, 0, randomBytes.Length);

            isRandomBytesValid.Should().BeFalse();
        }
        public void Validate_should_throw_if_parameter_null()
        {
            var exception = Record.Exception(() => SnappyCodec.Validate(null));

            exception.Should().BeOfType <ArgumentNullException>();
        }