From 6232d13f5321b87ddf12a1aa36b4545da45f173d Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 17 Nov 2021 22:34:57 +0100 Subject: Travel3: Simple image and video display site Reads the images and videos from filesystem and builds a site in memroy. --- test/test_hasher.cc | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/test_hasher.cc (limited to 'test/test_hasher.cc') diff --git a/test/test_hasher.cc b/test/test_hasher.cc new file mode 100644 index 0000000..181b25b --- /dev/null +++ b/test/test_hasher.cc @@ -0,0 +1,82 @@ +#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(); +} -- cgit v1.2.3-70-g09d2