Beispiel #1
0
        private void CheckTemplate <T>(BaseChecksum <T> check, string fileName, TestKind kind, T expected)
        {
            check.Reset();
            try
            {
                string filePath = Path.Combine(TestSetup.SampleDir, fileName);
                using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    switch (kind)
                    {
                    case TestKind.Array:
                    {
                        int    bytesRead = 0;
                        byte[] buffer    = new byte[64 * 1024];
                        do
                        {
                            bytesRead = fs.Read(buffer, 0, buffer.Length);
                            check.Append(buffer, 0, bytesRead);
                        }while (0 < bytesRead);
                    }
                    break;

                    case TestKind.Span:
                    {
                        int    bytesRead = 0;
                        byte[] buffer    = new byte[64 * 1024];
                        do
                        {
                            bytesRead = fs.Read(buffer, 0, buffer.Length);
                            check.Append(buffer.AsSpan(0, bytesRead));
                        }while (0 < bytesRead);
                    }
                    break;

                    case TestKind.Stream:
                        check.Append(fs);
                        break;
                    }
                }

                Console.WriteLine($"(Check) Expected   checksum of {fileName} : 0x{expected:X16}");
                Console.WriteLine($"(Check) Calculated checksum of {fileName} : 0x{check.Checksum:X16}");
                Assert.AreEqual(expected, check.Checksum);
            }
            finally
            {
                check.Reset();
            }
        }
Beispiel #2
0
        private void ResetTemplate <T>(BaseChecksum <T> check, string firstFileName, string secondFileName)
        {
            try
            {
                // Get first cheksum
                check.Reset();
                string firstFilePath = Path.Combine(TestSetup.SampleDir, firstFileName);
                using (FileStream fs = new FileStream(firstFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    check.Append(fs);
                }
                T firstCheck = check.Checksum;

                // Get concat cheksum
                string secondFilePath = Path.Combine(TestSetup.SampleDir, secondFileName);
                using (FileStream fs = new FileStream(secondFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    check.Append(fs);
                }
                T concatCheck = check.Checksum;

                // Reset and get concat checksum again
                check.Reset(firstCheck);
                using (FileStream fs = new FileStream(secondFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    check.Append(fs);
                }
                T actualCheck = check.Checksum;

                Console.WriteLine($"(Check) Expected   checksum : 0x{concatCheck:X16}");
                Console.WriteLine($"(Check) Calculated checksum : 0x{actualCheck:X16}");
                Assert.AreEqual(concatCheck, actualCheck);
            }
            finally
            {
                check.Reset();
            }
        }