- // test HashSumValue which doesn't calculate but just stores sums
- {
- string md5sum = argv[2];
- MD5SumValue md5(md5sum);
- equals(md5.Value(), md5sum);
- }
- {
- string sha1sum = argv[3];
- SHA1SumValue sha1(sha1sum);
- equals(sha1.Value(), sha1sum);
- }
- {
- string sha2sum = argv[4];
- SHA256SumValue sha2(sha2sum);
- equals(sha2.Value(), sha2sum);
- }
- {
- string sha2sum = argv[5];
- SHA512SumValue sha2(sha2sum);
- equals(sha2.Value(), sha2sum);
- }
+ /* to compare our result with an independent source we call the specific binaries
+ and read their result back. We do this with a little trick by claiming that the
+ summation is a compressor – and open the 'compressed' file later on directly to
+ read out the summation sum calculated by it */
+ APT::Configuration::Compressor compress(type, ".ext", type, NULL, NULL, 99);
+ std::string name("apt-test-");
+ name.append("hashsums").append(".XXXXXX");
+ char * tempfile = strdup(name.c_str());
+ int tempfile_fd = mkstemp(tempfile);
+ close(tempfile_fd);
+ ASSERT_NE(-1, tempfile_fd);
+
+ FileFd fd;
+ ASSERT_TRUE(fd.Open(tempfile, FileFd::WriteOnly | FileFd::Empty, compress));
+ ASSERT_TRUE(fd.IsOpen());
+ FileFd input(__FILE__, FileFd::ReadOnly);
+ ASSERT_TRUE(input.IsOpen());
+ ASSERT_NE(0, input.FileSize());
+ ASSERT_TRUE(CopyFile(input, fd));
+ ASSERT_TRUE(input.IsOpen());
+ ASSERT_TRUE(fd.IsOpen());
+ ASSERT_FALSE(fd.Failed());
+ input.Close();
+ fd.Close();
+ ASSERT_TRUE(fd.Open(tempfile, FileFd::ReadOnly, FileFd::None));
+ ASSERT_TRUE(fd.IsOpen());
+ ASSERT_NE(0, fd.FileSize());
+ ASSERT_FALSE(fd.Failed());
+ unlink(tempfile);
+ free(tempfile);
+ char readback[2000];
+ unsigned long long actual;
+ ASSERT_TRUE(fd.Read(readback, sizeof(readback)/sizeof(readback[0]), &actual));
+ actual -= 4;
+ readback[actual] = '\0';
+ sum = readback;
+}
+TEST(HashSumsTest, FileBased)
+{
+ std::string summation;