summaryrefslogtreecommitdiff
path: root/test/test_hasher.cc
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
committerJoel Klinghed <the_jk@spawned.biz>2021-11-17 22:34:57 +0100
commit6232d13f5321b87ddf12a1aa36b4545da45f173d (patch)
tree23f3316470a14136debd9d02f9e920ca2b06f4cc /test/test_hasher.cc
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in memroy.
Diffstat (limited to 'test/test_hasher.cc')
-rw-r--r--test/test_hasher.cc82
1 files changed, 82 insertions, 0 deletions
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 <gtest/gtest.h>
+
+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_ = Logger::create_null();
+ std::shared_ptr<Looper> looper_ = Looper::create();
+ std::shared_ptr<TaskRunner> runner_ = TaskRunner::create(looper_);
+ std::unique_ptr<Hasher> 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();
+}