From 2cfbb3eef0fc55932a2e3e0113bd3089f8688adb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 6 Apr 2020 19:55:06 +0100 Subject: EntryResolvers return where they got the resolution from --- netfs/ice/entryResolver.h | 11 +++++++++-- netfs/lib/entCache.h | 11 ++++++++--- netfs/lib/entCache.impl.h | 17 +++++++++++++---- netfs/unittests/testLib.cpp | 20 ++++++++++++++------ 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/netfs/ice/entryResolver.h b/netfs/ice/entryResolver.h index cbdc789..14f2d5d 100644 --- a/netfs/ice/entryResolver.h +++ b/netfs/ice/entryResolver.h @@ -1,13 +1,20 @@ #ifndef NETFS_ENTRYRESOLVER_H #define NETFS_ENTRYRESOLVER_H +#include + +enum class ResolvedAs : uint8_t { + Real, + Fallback, +}; + template class EntryResolver { public: virtual ~EntryResolver() = default; - virtual void getID(const name_t &, id_t *) const = 0; - virtual void getName(const id_t &, name_t *) const = 0; + virtual ResolvedAs getID(const name_t &, id_t *) const = 0; + virtual ResolvedAs getName(const id_t &, name_t *) const = 0; }; #endif diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h index e6a77dc..e0a06b5 100644 --- a/netfs/lib/entCache.h +++ b/netfs/lib/entCache.h @@ -39,10 +39,15 @@ class EntCache : public EntryResolver; - void getID(const name_t &, id_t *) const override; - void getName(const id_t &, name_t *) const override; + struct Resolution : public entry_ptr { + Resolution(entry_ptr, ResolvedAs = ResolvedAs::Real); + ResolvedAs resolution; + }; + + ResolvedAs getID(const name_t &, id_t *) const override; + ResolvedAs getName(const id_t &, name_t *) const override; template - entry_ptr getEntry(const key_t &) const; + Resolution getEntry(const key_t &) const; void setFallback(entry_t fb); void clearFallback(); diff --git a/netfs/lib/entCache.impl.h b/netfs/lib/entCache.impl.h index e83fb49..e0a8f85 100644 --- a/netfs/lib/entCache.impl.h +++ b/netfs/lib/entCache.impl.h @@ -38,24 +38,33 @@ template EntCache::~EntCache() = default; template -void +ResolvedAs EntCache::getID(const EntCache::name_t & u, EntCache::id_t * target) const { auto e = getEntry(u); *target = e->id; + return e.resolution; } template -void +ResolvedAs EntCache::getName(const EntCache::id_t & u, EntCache::name_t * target) const { auto e = getEntry(u); *target = e->name; + return e.resolution; +} + +template +EntCache::Resolution::Resolution(entry_ptr e, ResolvedAs res) : + entry_ptr(std::move(e)), + resolution(res) +{ } template template -typename EntCache::entry_ptr +typename EntCache::Resolution EntCache::getEntry(const key_t & key) const { if (fillTime + 60 > time(nullptr)) { @@ -68,7 +77,7 @@ EntCache::getEntry(const key_t & key) const return ent; } if (fallback) { - return fallback; + return { fallback, ResolvedAs::Fallback }; } throw NetFS::SystemError(EPERM); } diff --git a/netfs/unittests/testLib.cpp b/netfs/unittests/testLib.cpp index 91ca683..1e80590 100644 --- a/netfs/unittests/testLib.cpp +++ b/netfs/unittests/testLib.cpp @@ -4,6 +4,14 @@ #include #include +namespace std { + ostream & operator<<(ostream & strm, const ResolvedAs & r) + { + strm << r; + return strm; + } +} + struct TestEntry { TestEntry(int i, std::string n) : id(i), @@ -48,14 +56,14 @@ BOOST_DATA_TEST_CASE(notfoundname, BadNames, name) BOOST_DATA_TEST_CASE(foundid, GoodNames ^ GoodIds, name, id) { std::string outname; - BOOST_REQUIRE_NO_THROW(getName(id, &outname)); + BOOST_CHECK_EQUAL(getName(id, &outname), ResolvedAs::Real); BOOST_CHECK_EQUAL(name, outname); } BOOST_DATA_TEST_CASE(foundname, GoodNames ^ GoodIds, name, id) { int outid; - BOOST_REQUIRE_NO_THROW(getID(name, &outid)); + BOOST_CHECK_EQUAL(getID(name, &outid), ResolvedAs::Real); BOOST_CHECK_EQUAL(id, outid); } @@ -71,28 +79,28 @@ BOOST_FIXTURE_TEST_SUITE(tecfb, TestEntCacheWithFallback); BOOST_DATA_TEST_CASE(notfoundid, BadIds, id) { std::string outname; - BOOST_REQUIRE_NO_THROW(getName(id, &outname)); + BOOST_CHECK_EQUAL(getName(id, &outname), ResolvedAs::Fallback); BOOST_CHECK_EQUAL(outname, fallback->name); } BOOST_DATA_TEST_CASE(notfoundname, BadNames, name) { int outid; - BOOST_REQUIRE_NO_THROW(getID(name, &outid)); + BOOST_CHECK_EQUAL(getID(name, &outid), ResolvedAs::Fallback); BOOST_CHECK_EQUAL(outid, fallback->id); } BOOST_DATA_TEST_CASE(foundid, GoodNames ^ GoodIds, name, id) { std::string outname; - BOOST_REQUIRE_NO_THROW(getName(id, &outname)); + BOOST_CHECK_EQUAL(getName(id, &outname), ResolvedAs::Real); BOOST_CHECK_EQUAL(name, outname); } BOOST_DATA_TEST_CASE(foundname, GoodNames ^ GoodIds, name, id) { int outid; - BOOST_REQUIRE_NO_THROW(getID(name, &outid)); + BOOST_CHECK_EQUAL(getID(name, &outid), ResolvedAs::Real); BOOST_CHECK_EQUAL(id, outid); } -- cgit v1.2.3