cksum.test 1.2 KB

1234567891011121314151617181920212223242526272829
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. # Default behavior on stdin and on files.
  5. testing "on stdin" "echo -n hello | cksum" "3287646509 5\n" "" ""
  6. echo -n "hello" > tmpfile
  7. testing "on file" "cksum tmpfile" "3287646509 5 tmpfile\n" "" ""
  8. rm -f tmpfile
  9. touch one two
  10. testing "on multiple files" "cksum one two" "4294967295 0 one\n4294967295 0 two\n" "" ""
  11. rm -f one two
  12. # Check the length suppression, both calculate the CRC on 'abc' but the second
  13. # option has length suppression on and has the length concatenated to 'abc'.
  14. testing "on abc including length" "cksum" "1219131554 3\n" "" 'abc'
  15. toyonly testing "on abc excluding length" "cksum -N" "1219131554\n" "" 'abc\x3'
  16. # cksum on no contents gives 0xffffffff (=4294967295)
  17. testing "on no data post-inversion" "echo -n "" | cksum" "4294967295 0\n" "" ""
  18. # If we do preinversion we will then get 0.
  19. toyonly testing "on no data pre+post-inversion" "echo -n "" | cksum -P" "0 0\n" "" ""
  20. # If we skip the post-inversion we also get 0
  21. toyonly testing "on no data no inversion" "echo -n "" | cksum -I" "0 0\n" "" ""
  22. # Two wrongs make a right.
  23. toyonly testing "on no data pre-inversion" "echo -n "" | cksum -PI" "4294967295 0\n" "" ""