+/*
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
#include "squid.h"
-#include "testStore.h"
#include "Store.h"
+#include "testStore.h"
+#include "unitTestMain.h"
CPPUNIT_TEST_SUITE_REGISTRATION( testStore );
-/* subclass of Store to allow testing of methods without having all the
- * other components live
- */
-
-class TestStore : public Store
-{
-
-public:
- TestStore() : statsCalled (false) {}
-
- bool statsCalled;
-
- virtual int callback();
-
- virtual StoreEntry* get
- (const cache_key*);
-
- virtual void get
- (String, void (*)(StoreEntry*, void*), void*);
-
- virtual void init();
-
-virtual void maintain() {};
-
- virtual size_t maxSize() const;
-
- virtual size_t minSize() const;
-
- virtual void stat(StoreEntry &) const; /* output stats to the provided store entry */
-
- virtual void reference(StoreEntry &){} /* Reference this object */
-
- virtual void dereference(StoreEntry &){} /* Unreference this object */
-
- virtual void updateSize(size_t size, int sign) {}
-
- virtual StoreSearch *search(String const url, HttpRequest *);
-};
-
-typedef RefCount<TestStore> TestStorePointer;
-
int
TestStore::callback()
{
}
StoreEntry*
-
-TestStore::get
- (const cache_key*)
+TestStore::get(const cache_key*)
{
return NULL;
}
void
-
-TestStore::get
- (String, void (*)(StoreEntry*, void*), void*)
+TestStore::get(String, void (*)(StoreEntry*, void*), void*)
{}
void
-
TestStore::init()
{}
-size_t
+uint64_t
TestStore::maxSize() const
{
return 3;
}
-size_t
+uint64_t
TestStore::minSize() const
{
return 1;
}
+uint64_t
+TestStore::currentSize() const
+{
+ return 2;
+}
+
+uint64_t
+TestStore::currentCount() const
+{
+ return 2;
+}
+
+int64_t
+TestStore::maxObjectSize() const
+{
+ return 1;
+}
+
+void
+TestStore::getStats(StoreInfoStats &) const
+{
+}
+
void
TestStore::stat(StoreEntry &) const
{
}
StoreSearch *
-TestStore::search(String const url, HttpRequest *)
+TestStore::search()
{
return NULL;
}
void
testStore::testSetRoot()
{
- StorePointer aStore (new TestStore);
- Store::Root(aStore);
+ Store::Controller *aStore(new TestStore);
+ Store::Init(aStore);
- CPPUNIT_ASSERT(&Store::Root() == aStore.getRaw());
- Store::Root(NULL);
+ CPPUNIT_ASSERT_EQUAL(&Store::Root(), aStore);
+ Store::FreeMemory();
}
void
testStore::testUnsetRoot()
{
- StorePointer aStore (new TestStore);
- StorePointer aStore2 (new TestStore);
- Store::Root(aStore);
- Store::Root(aStore2);
- CPPUNIT_ASSERT(&Store::Root() == aStore2.getRaw());
- Store::Root(NULL);
+ Store::Controller *aStore(new TestStore);
+ Store::Controller *aStore2(new TestStore);
+ Store::Init(aStore);
+ Store::FreeMemory();
+ Store::Init(aStore2);
+ CPPUNIT_ASSERT_EQUAL(&Store::Root(),aStore2);
+ Store::FreeMemory();
}
void
testStore::testStats()
{
- TestStorePointer aStore (new TestStore);
- Store::Root(aStore.getRaw());
- CPPUNIT_ASSERT(aStore->statsCalled == false);
- Store::Stats(NullStoreEntry::getInstance());
- CPPUNIT_ASSERT(aStore->statsCalled == true);
- Store::Root(NULL);
+ TestStore *aStore(new TestStore);
+ Store::Init(aStore);
+ CPPUNIT_ASSERT_EQUAL(false, aStore->statsCalled);
+ StoreEntry entry;
+ Store::Stats(&entry);
+ CPPUNIT_ASSERT_EQUAL(true, aStore->statsCalled);
+ Store::FreeMemory();
}
void
testStore::testMaxSize()
{
- StorePointer aStore (new TestStore);
- Store::Root(aStore.getRaw());
- CPPUNIT_ASSERT(aStore->maxSize() == 3);
- Store::Root(NULL);
+ Store::Controller *aStore(new TestStore);
+ Store::Init(aStore);
+ CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(3), aStore->maxSize());
+ Store::FreeMemory();
}
+