#include "common.hh" #include "file_test.hh" #include "hasher.hh" #include "logger.hh" #include "looper.hh" #include "task_runner.hh" #include namespace { class HasherTest : public FileTest { public: void SetUp() override { FileTest::SetUp(); hasher_ = Hasher::create(logger_, runner_, 1); } void wait() { looper_->run(logger_.get()); } void TearDown() override { hasher_.reset(); std::error_code err; std::filesystem::remove(path(), err); } Hasher* hasher() const { return hasher_.get(); } void quit() { looper_->quit(); } private: std::shared_ptr logger_ = Logger::create_null(); std::shared_ptr looper_ = Looper::create(); std::shared_ptr runner_ = TaskRunner::create(looper_); std::unique_ptr hasher_; }; } // namespace TEST_F(HasherTest, sanity) { write("foobar"); close(); hasher()->hash(path(), [this](std::string hash, uint64_t size) { EXPECT_EQ( "c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2", hash); EXPECT_EQ(6, size); quit(); }); wait(); } TEST_F(HasherTest, empty) { write(""); close(); hasher()->hash(path(), [this](std::string hash, uint64_t size) { EXPECT_EQ( "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", hash); EXPECT_EQ(0, size); quit(); }); wait(); } TEST_F(HasherTest, non_existent) { hasher()->hash(path() / "non_existent", [this](std::string hash, uint64_t size) { EXPECT_EQ("", hash); EXPECT_EQ(0, size); quit(); }); wait(); }