TestChecksum.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2021, Peter Bocan <me@pbocan.net>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibCrypto/Checksum/Adler32.h>
  7. #include <LibCrypto/Checksum/CRC32.h>
  8. #include <LibTest/TestCase.h>
  9. TEST_CASE(test_adler32)
  10. {
  11. auto do_test = [](ReadonlyBytes input, u32 expected_result) {
  12. auto digest = Crypto::Checksum::Adler32(input).digest();
  13. EXPECT_EQ(digest, expected_result);
  14. };
  15. do_test(String("").bytes(), 0x1);
  16. do_test(String("a").bytes(), 0x00620062);
  17. do_test(String("abc").bytes(), 0x024d0127);
  18. do_test(String("message digest").bytes(), 0x29750586);
  19. do_test(String("abcdefghijklmnopqrstuvwxyz").bytes(), 0x90860b20);
  20. }
  21. TEST_CASE(test_crc32)
  22. {
  23. auto do_test = [](ReadonlyBytes input, u32 expected_result) {
  24. auto digest = Crypto::Checksum::CRC32(input).digest();
  25. EXPECT_EQ(digest, expected_result);
  26. };
  27. do_test(String("").bytes(), 0x0);
  28. do_test(String("The quick brown fox jumps over the lazy dog").bytes(), 0x414FA339);
  29. do_test(String("various CRC algorithms input data").bytes(), 0x9BD366AE);
  30. }