]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/tests/testCacheManager.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / tests / testCacheManager.cc
index 02b165a61835a60810256c1f4341a6b98e932b9c..e7e70748b45d9ed922ca2c09d04492719140b993 100644 (file)
@@ -1,20 +1,22 @@
-#include "squid.h"
-#include <cppunit/TestAssert.h>
+/*
+ * Copyright (C) 1996-2018 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 "Mem.h"
-#include "testCacheManager.h"
+#include "squid.h"
 #include "CacheManager.h"
+#include "mgr/Action.h"
+#include "Store.h"
+#include "testCacheManager.h"
+#include "unitTestMain.h"
 
+#include <cppunit/TestAssert.h>
 
 CPPUNIT_TEST_SUITE_REGISTRATION( testCacheManager );
 
-/* stub functions to link successfully */
-void
-shut_down(int)
-{}
-
-/* end stubs */
-
 /* init memory pools */
 
 void testCacheManager::setUp()
@@ -28,13 +30,15 @@ void testCacheManager::setUp()
 void
 testCacheManager::testCreate()
 {
-    CacheManager();
+    CacheManager::GetInstance(); //it's a singleton..
 }
 
 /* an action to register */
 static void
 dummy_action(StoreEntry * sentry)
-{}
+{
+    sentry->flags=1;
+}
 
 /*
  * registering an action makes it findable.
@@ -42,12 +46,23 @@ dummy_action(StoreEntry * sentry)
 void
 testCacheManager::testRegister()
 {
-    CacheManager manager;
-    manager.registerAction("sample", "my sample", &dummy_action, false, false);
-    CacheManagerAction *anAction = manager.findAction("sample");
-    CPPUNIT_ASSERT_EQUAL(String("sample"), String(anAction->action));
-    CPPUNIT_ASSERT_EQUAL(String("my sample"), String(anAction->desc));
-    CPPUNIT_ASSERT_EQUAL(&dummy_action, anAction->handler);
-    CPPUNIT_ASSERT_EQUAL(0, (int)anAction->flags.pw_req);
-    CPPUNIT_ASSERT_EQUAL(0, (int)anAction->flags.atomic);
+    CacheManager *manager=CacheManager::GetInstance();
+    CPPUNIT_ASSERT(manager != NULL);
+
+    manager->registerProfile("sample", "my sample", &dummy_action, false, false);
+    Mgr::Action::Pointer action = manager->createNamedAction("sample");
+    CPPUNIT_ASSERT(action != NULL);
+
+    const Mgr::ActionProfile::Pointer profile = action->command().profile;
+    CPPUNIT_ASSERT(profile != NULL);
+    CPPUNIT_ASSERT(profile->creator != NULL);
+    CPPUNIT_ASSERT_EQUAL(false, profile->isPwReq);
+    CPPUNIT_ASSERT_EQUAL(false, profile->isAtomic);
+    CPPUNIT_ASSERT_EQUAL(String("sample"), String(action->name()));
+
+    StoreEntry *sentry=new StoreEntry();
+    sentry->flags=0x25; //arbitrary test value
+    action->run(sentry, false);
+    CPPUNIT_ASSERT_EQUAL(1,(int)sentry->flags);
 }
+