- Hashes hashes;
- hashes.AddFD(fileno(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);
-
- Hashes hashes2;
- hashes2.AddFD(fileno(fd), sz);
- fclose(fd);
- equals(argv[2], hashes2.MD5.Result().Value());
- equals(argv[3], hashes2.SHA1.Result().Value());
- equals(argv[4], hashes2.SHA256.Result().Value());
- equals(argv[5], hashes2.SHA512.Result().Value());
-
- return 0;
+ unsigned long sz = fd.FileSize();
+ fd.Seek(0);
+ {
+ Hashes hashes;
+ hashes.AddFD(fd.Fd(), sz);
+ HashStringList list = hashes.GetHashStringList();
+ EXPECT_FALSE(list.empty());
+ EXPECT_EQ(4, list.size());
+ EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue());
+ EXPECT_EQ(sha1.Value(), list.find("SHA1")->HashValue());
+ EXPECT_EQ(sha256.Value(), list.find("SHA256")->HashValue());
+ EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue());
+ }
+ fd.Seek(0);
+ {
+ MD5Summation MD5;
+ MD5.AddFD(fd.Fd());
+ EXPECT_EQ(md5.Value(), MD5.Result().Value());
+ }
+ fd.Seek(0);
+ {
+ SHA1Summation SHA1;
+ SHA1.AddFD(fd.Fd());
+ EXPECT_EQ(sha1.Value(), SHA1.Result().Value());
+ }
+ fd.Seek(0);
+ {
+ SHA256Summation SHA2;
+ SHA2.AddFD(fd.Fd());
+ EXPECT_EQ(sha256.Value(), SHA2.Result().Value());
+ }
+ fd.Seek(0);
+ {
+ SHA512Summation SHA2;
+ SHA2.AddFD(fd.Fd());
+ EXPECT_EQ(sha512.Value(), SHA2.Result().Value());
+ }
+ fd.Close();
+
+ HashString sha2file("SHA512", sha512.Value());
+ EXPECT_TRUE(sha2file.VerifyFile(__FILE__));
+ HashString sha2wrong("SHA512", "00000000000");
+ EXPECT_FALSE(sha2wrong.VerifyFile(__FILE__));
+ EXPECT_EQ(sha2file, sha2file);
+ EXPECT_TRUE(sha2file == sha2file);
+ EXPECT_NE(sha2file, sha2wrong);
+ EXPECT_TRUE(sha2file != sha2wrong);
+
+ HashString sha2big("SHA256", sha256.Value());
+ EXPECT_TRUE(sha2big.VerifyFile(__FILE__));
+ HashString sha2small("sha256:" + sha256.Value());
+ EXPECT_TRUE(sha2small.VerifyFile(__FILE__));
+ EXPECT_EQ(sha2big, sha2small);
+ EXPECT_TRUE(sha2big == sha2small);
+ EXPECT_FALSE(sha2big != sha2small);
+
+ HashStringList hashes;
+ EXPECT_TRUE(hashes.empty());
+ EXPECT_TRUE(hashes.push_back(sha2file));
+ EXPECT_FALSE(hashes.empty());
+ EXPECT_EQ(1, hashes.size());
+
+ HashStringList wrong;
+ EXPECT_TRUE(wrong.push_back(sha2wrong));
+ EXPECT_NE(wrong, hashes);
+ EXPECT_FALSE(wrong == hashes);
+ EXPECT_TRUE(wrong != hashes);
+
+ HashStringList similar;
+ EXPECT_TRUE(similar.push_back(sha2big));
+ EXPECT_NE(similar, hashes);
+ EXPECT_FALSE(similar == hashes);
+ EXPECT_TRUE(similar != hashes);
+
+ EXPECT_TRUE(hashes.push_back(sha2big));
+ EXPECT_EQ(2, hashes.size());
+ EXPECT_TRUE(hashes.push_back(sha2small));
+ EXPECT_EQ(2, hashes.size());
+ EXPECT_FALSE(hashes.push_back(sha2wrong));
+ EXPECT_EQ(2, hashes.size());
+ EXPECT_TRUE(hashes.VerifyFile(__FILE__));
+
+ EXPECT_EQ(similar, hashes);
+ EXPECT_TRUE(similar == hashes);
+ EXPECT_FALSE(similar != hashes);
+ similar.clear();
+ EXPECT_TRUE(similar.empty());
+ EXPECT_EQ(0, similar.size());
+ EXPECT_NE(similar, hashes);
+ EXPECT_FALSE(similar == hashes);
+ EXPECT_TRUE(similar != hashes);