1 #define SQUID_UNIT_TEST 1
4 #include "testStoreController.h"
7 #include "TestSwapDir.h"
10 #include "StoreSearch.h"
12 CPPUNIT_TEST_SUITE_REGISTRATION( testStoreController
);
15 addSwapDir(TestSwapDirPointer aStore
)
17 allocate_new_swapdir(&Config
.cacheSwap
);
18 Config
.cacheSwap
.swapDirs
[Config
.cacheSwap
.n_configured
] = aStore
.getRaw();
19 ++Config
.cacheSwap
.n_configured
;
23 testStoreController::testStats()
25 StoreEntry
* logEntry
= new StoreEntry("dummy_url", "dummy_log_url");
26 logEntry
->store_status
= STORE_PENDING
;
27 StorePointer
aRoot (new StoreController
);
29 TestSwapDirPointer
aStore (new TestSwapDir
);
30 TestSwapDirPointer
aStore2 (new TestSwapDir
);
33 CPPUNIT_ASSERT(aStore
->statsCalled
== false);
34 CPPUNIT_ASSERT(aStore2
->statsCalled
== false);
35 Store::Stats(logEntry
);
36 free_cachedir(&Config
.cacheSwap
);
37 CPPUNIT_ASSERT(aStore
->statsCalled
== true);
38 CPPUNIT_ASSERT(aStore2
->statsCalled
== true);
45 static bool inited
= false;
52 Config
.Store
.avgObjectSize
= 1024;
54 Config
.Store
.objectsPerBucket
= 20;
56 Config
.Store
.maxObjectSize
= 2048;
58 Config
.store_dir_select_algorithm
= xstrdup("round-robin");
62 testStoreController::testMaxSize()
65 StoreEntry
* logEntry
= new StoreEntry("dummy_url", "dummy_log_url");
66 logEntry
->store_status
= STORE_PENDING
;
67 StorePointer
aRoot (new StoreController
);
69 TestSwapDirPointer
aStore (new TestSwapDir
);
70 TestSwapDirPointer
aStore2 (new TestSwapDir
);
73 CPPUNIT_ASSERT(Store::Root().maxSize() == 6);
74 free_cachedir(&Config
.cacheSwap
);
79 addedEntry(StorePointer hashStore
,
87 StoreEntry
*e
= new StoreEntry();
88 e
->store_status
= STORE_OK
;
89 e
->setMemStatus(NOT_IN_MEMORY
);
90 e
->swap_status
= SWAPOUT_DONE
; /* bogus haha */
91 e
->swap_filen
= 0; /* garh - lower level*/
94 for (int i
=0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
95 if (INDEXSD (i
) == aStore
.getRaw())
99 CPPUNIT_ASSERT (e
->swap_dirn
!= -1);
100 e
->swap_file_sz
= 0; /* garh lower level */
102 e
->lastref
= squid_curtime
;
103 e
->timestamp
= squid_curtime
;
104 e
->expires
= squid_curtime
;
105 e
->lastmod
= squid_curtime
;
107 EBIT_SET(e
->flags
, ENTRY_CACHABLE
);
108 EBIT_CLR(e
->flags
, RELEASE_REQUEST
);
109 EBIT_CLR(e
->flags
, KEY_PRIVATE
);
110 e
->ping_status
= PING_NONE
;
111 EBIT_CLR(e
->flags
, ENTRY_VALIDATED
);
112 e
->hashInsert((const cache_key
*)name
.termedBuf()); /* do it after we clear KEY_PRIVATE */
116 /* TODO make this a cbdata class */
118 static bool cbcalled
;
121 searchCallback(void *cbdata
)
127 testStoreController::testSearch()
130 StorePointer
aRoot (new StoreController());
132 TestSwapDirPointer
aStore (new TestSwapDir
);
133 TestSwapDirPointer
aStore2 (new TestSwapDir
);
136 Store::Root().init();
137 StoreEntry
* entry1
= addedEntry (&Store::Root(), aStore
.getRaw(), "name", NULL
, NULL
);
138 StoreEntry
* entry2
= addedEntry (&Store::Root(), aStore2
.getRaw(), "name2", NULL
, NULL
);
139 StoreSearchPointer search
= aRoot
->search (NULL
, NULL
); /* search for everything in the store */
141 /* nothing should be immediately available */
142 CPPUNIT_ASSERT(search
->error() == false);
143 CPPUNIT_ASSERT(search
->isDone() == false);
144 CPPUNIT_ASSERT(search
->currentItem() == NULL
);
147 CPPUNIT_ASSERT(search
->next() == false);
150 /* trigger a callback */
152 search
->next(searchCallback
, NULL
);
153 CPPUNIT_ASSERT(cbcalled
== true);
155 /* we should have access to a entry now, that matches the entry we had before */
156 CPPUNIT_ASSERT(search
->error() == false);
157 CPPUNIT_ASSERT(search
->isDone() == false);
158 /* note the hash order is random - the test happens to be in a nice order */
159 CPPUNIT_ASSERT(search
->currentItem() == entry1
);
160 //CPPUNIT_ASSERT(search->next() == false);
162 /* trigger another callback */
164 search
->next(searchCallback
, NULL
);
165 CPPUNIT_ASSERT(cbcalled
== true);
167 /* we should have access to a entry now, that matches the entry we had before */
168 CPPUNIT_ASSERT(search
->error() == false);
169 CPPUNIT_ASSERT(search
->isDone() == false);
170 CPPUNIT_ASSERT(search
->currentItem() == entry2
);
171 //CPPUNIT_ASSERT(search->next() == false);
173 /* trigger another callback */
175 search
->next(searchCallback
, NULL
);
176 CPPUNIT_ASSERT(cbcalled
== true);
178 /* now we should have no error, we should have finished and have no current item */
179 CPPUNIT_ASSERT(search
->error() == false);
180 CPPUNIT_ASSERT(search
->isDone() == true);
181 CPPUNIT_ASSERT(search
->currentItem() == NULL
);
182 //CPPUNIT_ASSERT(search->next() == false);