]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/tests/testStoreController.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / tests / testStoreController.cc
index 8d7c976e309e6619dd57a5b5b3ab0509f94c3cc7..a9b4faa90ed21798cc0aa0fabbdbd1c51eac1a17 100644 (file)
@@ -1,14 +1,20 @@
-#define SQUID_UNIT_TEST 1
+/*
+ * Copyright (C) 1996-2020 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 "testStoreController.h"
-#include "Store.h"
-#include "SwapDir.h"
-#include "TestSwapDir.h"
-#include "Mem.h"
+#include "MemObject.h"
+#include "SquidConfig.h"
 #include "SquidTime.h"
+#include "Store.h"
+#include "store/Disks.h"
 #include "StoreSearch.h"
+#include "testStoreController.h"
+#include "TestSwapDir.h"
 
 CPPUNIT_TEST_SUITE_REGISTRATION( testStoreController );
 
@@ -20,25 +26,24 @@ addSwapDir(TestSwapDirPointer aStore)
     ++Config.cacheSwap.n_configured;
 }
 
-
 void
 testStoreController::testStats()
 {
-    StoreEntry * logEntry = new StoreEntry("dummy_url", "dummy_log_url");
+    Store::Init();
+    StoreEntry *logEntry = new StoreEntry;
+    logEntry->createMemObject("dummy_storeId", NULL, HttpRequestMethod());
     logEntry->store_status = STORE_PENDING;
-    StorePointer aRoot (new StoreController);
-    Store::Root(aRoot);
     TestSwapDirPointer aStore (new TestSwapDir);
     TestSwapDirPointer aStore2 (new TestSwapDir);
     addSwapDir(aStore);
     addSwapDir(aStore2);
-    CPPUNIT_ASSERT(aStore->statsCalled == false);
-    CPPUNIT_ASSERT(aStore2->statsCalled == false);
+    CPPUNIT_ASSERT_EQUAL(false, aStore->statsCalled);
+    CPPUNIT_ASSERT_EQUAL(false, aStore2->statsCalled);
     Store::Stats(logEntry);
     free_cachedir(&Config.cacheSwap);
-    CPPUNIT_ASSERT(aStore->statsCalled == true);
-    CPPUNIT_ASSERT(aStore2->statsCalled == true);
-    Store::Root(NULL);
+    CPPUNIT_ASSERT_EQUAL(true, aStore->statsCalled);
+    CPPUNIT_ASSERT_EQUAL(true, aStore2->statsCalled);
+    Store::FreeMemory();
 }
 
 static void
@@ -49,6 +54,8 @@ commonInit()
     if (inited)
         return;
 
+    Config.memShared.defaultTo(false);
+
     Mem::Init();
 
     Config.Store.avgObjectSize = 1024;
@@ -64,22 +71,21 @@ void
 testStoreController::testMaxSize()
 {
     commonInit();
-    StoreEntry * logEntry = new StoreEntry("dummy_url", "dummy_log_url");
+    StoreEntry *logEntry = new StoreEntry;
+    logEntry->createMemObject("dummy_storeId", NULL, HttpRequestMethod());
     logEntry->store_status = STORE_PENDING;
-    StorePointer aRoot (new StoreController);
-    Store::Root(aRoot);
+    Store::Init();
     TestSwapDirPointer aStore (new TestSwapDir);
     TestSwapDirPointer aStore2 (new TestSwapDir);
     addSwapDir(aStore);
     addSwapDir(aStore2);
-    CPPUNIT_ASSERT(Store::Root().maxSize() == 6);
+    CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(6), Store::Root().maxSize());
     free_cachedir(&Config.cacheSwap);
-    Store::Root(NULL);
+    Store::FreeMemory();
 }
 
 static StoreEntry *
-addedEntry(StorePointer hashStore,
-           StorePointer aStore,
+addedEntry(Store::Disk *aStore,
            String name,
            String varySpec,
            String varyKey
@@ -93,25 +99,21 @@ addedEntry(StorePointer hashStore,
     e->swap_filen = 0; /* garh - lower level*/
     e->swap_dirn = -1;
 
-    for (int i=0; i < Config.cacheSwap.n_configured; i++) {
-        if (INDEXSD (i) == aStore.getRaw())
+    for (int i=0; i < Config.cacheSwap.n_configured; ++i) {
+        if (INDEXSD(i) == aStore)
             e->swap_dirn = i;
     }
 
     CPPUNIT_ASSERT (e->swap_dirn != -1);
     e->swap_file_sz = 0; /* garh lower level */
-    e->lock_count = 0;
     e->lastref = squid_curtime;
     e->timestamp = squid_curtime;
     e->expires = squid_curtime;
-    e->lastmod = squid_curtime;
+    e->lastModified(squid_curtime);
     e->refcount = 1;
-    EBIT_SET(e->flags, ENTRY_CACHABLE);
-    EBIT_CLR(e->flags, RELEASE_REQUEST);
-    EBIT_CLR(e->flags, KEY_PRIVATE);
     e->ping_status = PING_NONE;
     EBIT_CLR(e->flags, ENTRY_VALIDATED);
-    e->hashInsert((const cache_key *)name.termedBuf());        /* do it after we clear KEY_PRIVATE */
+    e->hashInsert((const cache_key *)name.termedBuf()); /* do it after we clear KEY_PRIVATE */
     return e;
 }
 
@@ -129,59 +131,59 @@ void
 testStoreController::testSearch()
 {
     commonInit();
-    StorePointer aRoot (new StoreController());
-    Store::Root(aRoot);
+    Store::Init();
     TestSwapDirPointer aStore (new TestSwapDir);
     TestSwapDirPointer aStore2 (new TestSwapDir);
     addSwapDir(aStore);
     addSwapDir(aStore2);
     Store::Root().init();
-    StoreEntry * entry1 = addedEntry (&Store::Root(), aStore.getRaw(), "name", NULL, NULL);
-    StoreEntry * entry2 = addedEntry (&Store::Root(), aStore2.getRaw(), "name2", NULL, NULL);
-    StoreSearchPointer search = aRoot->search (NULL, NULL); /* search for everything in the store */
+    StoreEntry * entry1 = addedEntry(aStore.getRaw(), "name", NULL, NULL);
+    StoreEntry * entry2 = addedEntry(aStore2.getRaw(), "name2", NULL, NULL);
+    StoreSearchPointer search = Store::Root().search(); /* search for everything in the store */
 
     /* nothing should be immediately available */
-    CPPUNIT_ASSERT(search->error() == false);
-    CPPUNIT_ASSERT(search->isDone() == false);
-    CPPUNIT_ASSERT(search->currentItem() == NULL);
+    CPPUNIT_ASSERT_EQUAL(false, search->error());
+    CPPUNIT_ASSERT_EQUAL(false, search->isDone());
+    CPPUNIT_ASSERT_EQUAL(static_cast<StoreEntry *>(NULL), search->currentItem());
 #if 0
 
-    CPPUNIT_ASSERT(search->next() == false);
+    CPPUNIT_ASSERT_EQUAL(false, search->next());
 #endif
 
     /* trigger a callback */
     cbcalled = false;
     search->next(searchCallback, NULL);
-    CPPUNIT_ASSERT(cbcalled == true);
+    CPPUNIT_ASSERT_EQUAL(true, cbcalled);
 
     /* we should have access to a entry now, that matches the entry we had before */
-    CPPUNIT_ASSERT(search->error() == false);
-    CPPUNIT_ASSERT(search->isDone() == false);
+    CPPUNIT_ASSERT_EQUAL(false, search->error());
+    CPPUNIT_ASSERT_EQUAL(false, search->isDone());
     /* note the hash order is random - the test happens to be in a nice order */
-    CPPUNIT_ASSERT(search->currentItem() == entry1);
-    //CPPUNIT_ASSERT(search->next() == false);
+    CPPUNIT_ASSERT_EQUAL(entry1, search->currentItem());
+    //CPPUNIT_ASSERT_EQUAL(false, search->next());
 
     /* trigger another callback */
     cbcalled = false;
     search->next(searchCallback, NULL);
-    CPPUNIT_ASSERT(cbcalled == true);
+    CPPUNIT_ASSERT_EQUAL(true, cbcalled);
 
     /* we should have access to a entry now, that matches the entry we had before */
-    CPPUNIT_ASSERT(search->error() == false);
-    CPPUNIT_ASSERT(search->isDone() == false);
-    CPPUNIT_ASSERT(search->currentItem() == entry2);
-    //CPPUNIT_ASSERT(search->next() == false);
+    CPPUNIT_ASSERT_EQUAL(false, search->error());
+    CPPUNIT_ASSERT_EQUAL(false, search->isDone());
+    CPPUNIT_ASSERT_EQUAL(entry2, search->currentItem());
+    //CPPUNIT_ASSERT_EQUAL(false, search->next());
 
     /* trigger another callback */
     cbcalled = false;
     search->next(searchCallback, NULL);
-    CPPUNIT_ASSERT(cbcalled == true);
+    CPPUNIT_ASSERT_EQUAL(true, cbcalled);
 
     /* now we should have no error, we should have finished and have no current item */
-    CPPUNIT_ASSERT(search->error() == false);
-    CPPUNIT_ASSERT(search->isDone() == true);
-    CPPUNIT_ASSERT(search->currentItem() == NULL);
-    //CPPUNIT_ASSERT(search->next() == false);
+    CPPUNIT_ASSERT_EQUAL(false, search->error());
+    CPPUNIT_ASSERT_EQUAL(true, search->isDone());
+    CPPUNIT_ASSERT_EQUAL(static_cast<StoreEntry *>(NULL), search->currentItem());
+    //CPPUNIT_ASSERT_EQUAL(false, search->next());
 
-    Store::Root(NULL);
+    Store::FreeMemory();
 }
+