]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testCacheManager.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / tests / testCacheManager.cc
1 #define SQUID_UNIT_TEST 1
2
3 #include "squid.h"
4 #include "CacheManager.h"
5 #include "Mem.h"
6 #include "mgr/Action.h"
7 #include "Store.h"
8 #include "testCacheManager.h"
9
10 #include <cppunit/TestAssert.h>
11
12 CPPUNIT_TEST_SUITE_REGISTRATION( testCacheManager );
13
14 /* init memory pools */
15
16 void testCacheManager::setUp()
17 {
18 Mem::Init();
19 }
20
21 /*
22 * Test creating a CacheManager
23 */
24 void
25 testCacheManager::testCreate()
26 {
27 CacheManager::GetInstance(); //it's a singleton..
28 }
29
30 /* an action to register */
31 static void
32 dummy_action(StoreEntry * sentry)
33 {
34 sentry->flags=1;
35 }
36
37 /*
38 * registering an action makes it findable.
39 */
40 void
41 testCacheManager::testRegister()
42 {
43 CacheManager *manager=CacheManager::GetInstance();
44 CPPUNIT_ASSERT(manager != NULL);
45
46 manager->registerProfile("sample", "my sample", &dummy_action, false, false);
47 Mgr::Action::Pointer action = manager->createNamedAction("sample");
48 CPPUNIT_ASSERT(action != NULL);
49
50 const Mgr::ActionProfile::Pointer profile = action->command().profile;
51 CPPUNIT_ASSERT(profile != NULL);
52 CPPUNIT_ASSERT(profile->creator != NULL);
53 CPPUNIT_ASSERT_EQUAL(false, profile->isPwReq);
54 CPPUNIT_ASSERT_EQUAL(false, profile->isAtomic);
55 CPPUNIT_ASSERT_EQUAL(String("sample"), String(action->name()));
56
57 StoreEntry *sentry=new StoreEntry();
58 sentry->flags=0x25; //arbitrary test value
59 action->run(sentry, false);
60 CPPUNIT_ASSERT_EQUAL(1,(int)sentry->flags);
61 }