X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/9a4ffe576267539ae5549f0c77cc8ab37c2516fb..b821e492d6dc4e1e8fd1f83590e12e3fbccad717:/test/libapt/hashsums_test.cc diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index e2d0aec5b..3da89052b 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -108,55 +109,54 @@ int main(int argc, char** argv) Test("The quick brown fox jumps over the lazy dog.", "91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bb" "c6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed"); - FILE* fd = fopen(argv[1], "r"); - if (fd == NULL) { + FileFd fd(argv[1], FileFd::ReadOnly); + if (fd.IsOpen() == false) { std::cerr << "Can't open file for 1. testing: " << argv[1] << std::endl; return 1; } { Hashes hashes; - hashes.AddFD(fileno(fd)); + hashes.AddFD(fd.Fd()); equals(argv[2], hashes.MD5.Result().Value()); equals(argv[3], hashes.SHA1.Result().Value()); equals(argv[4], hashes.SHA256.Result().Value()); equals(argv[5], hashes.SHA512.Result().Value()); } - fseek(fd, 0L, SEEK_END); - unsigned long sz = ftell(fd); - fseek(fd, 0L, SEEK_SET); + unsigned long sz = fd.FileSize(); + fd.Seek(0); { Hashes hashes; - hashes.AddFD(fileno(fd), sz); + hashes.AddFD(fd.Fd(), sz); equals(argv[2], hashes.MD5.Result().Value()); equals(argv[3], hashes.SHA1.Result().Value()); equals(argv[4], hashes.SHA256.Result().Value()); equals(argv[5], hashes.SHA512.Result().Value()); } - fseek(fd, 0L, SEEK_SET); + fd.Seek(0); { MD5Summation md5; - md5.AddFD(fileno(fd)); + md5.AddFD(fd.Fd()); equals(argv[2], md5.Result().Value()); } - fseek(fd, 0L, SEEK_SET); + fd.Seek(0); { SHA1Summation sha1; - sha1.AddFD(fileno(fd)); + sha1.AddFD(fd.Fd()); equals(argv[3], sha1.Result().Value()); } - fseek(fd, 0L, SEEK_SET); + fd.Seek(0); { SHA256Summation sha2; - sha2.AddFD(fileno(fd)); + sha2.AddFD(fd.Fd()); equals(argv[4], sha2.Result().Value()); } - fseek(fd, 0L, SEEK_SET); + fd.Seek(0); { SHA512Summation sha2; - sha2.AddFD(fileno(fd)); + sha2.AddFD(fd.Fd()); equals(argv[5], sha2.Result().Value()); } - fclose(fd); + fd.Close(); // test HashString code {