Skip to content

Commit 93f6d40

Browse files
committed
Reset global cache size before each archive test.
1 parent a96c516 commit 93f6d40

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

test/archive.cpp

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ using zim::unittests::TempFile;
4343
using zim::unittests::TestItem;
4444
using zim::unittests::IsFrontArticle;
4545

46+
class ZimArchive: public testing::Test {
47+
protected:
48+
void SetUp() override {
49+
zim::set_cluster_cache_max_size(0);
50+
zim::set_cluster_cache_max_size(CLUSTER_CACHE_SIZE);
51+
ASSERT_EQ(zim::get_cluster_cache_current_size(), 0);
52+
}
53+
};
54+
4655
using TestContextImpl = std::vector<std::pair<std::string, std::string> >;
4756
struct TestContext : TestContextImpl {
4857
TestContext(const std::initializer_list<value_type>& il)
@@ -80,7 +89,7 @@ emptyZimArchiveContent()
8089
return content;
8190
}
8291

83-
TEST(ZimArchive, openingAnInvalidZimArchiveFails)
92+
TEST_F(ZimArchive, openingAnInvalidZimArchiveFails)
8493
{
8594
const char* const prefixes[] = { "ZIM\x04", "" };
8695
const unsigned char bytes[] = {0x00, 0x01, 0x11, 0x30, 0xFF};
@@ -101,7 +110,7 @@ TEST(ZimArchive, openingAnInvalidZimArchiveFails)
101110
}
102111
}
103112

104-
TEST(ZimArchive, openingAnEmptyZimArchiveSucceeds)
113+
TEST_F(ZimArchive, openingAnEmptyZimArchiveSucceeds)
105114
{
106115
const auto tmpfile = makeTempFile("empty_zim_file", emptyZimArchiveContent());
107116

@@ -122,7 +131,7 @@ bool isNastyOffset(int offset) {
122131
return true;
123132
}
124133

125-
TEST(ZimArchive, nastyEmptyZimArchive)
134+
TEST_F(ZimArchive, nastyEmptyZimArchive)
126135
{
127136
const std::string correctContent = emptyZimArchiveContent();
128137
for ( int offset = 0; offset < 80; ++offset ) {
@@ -136,7 +145,7 @@ TEST(ZimArchive, nastyEmptyZimArchive)
136145
}
137146
}
138147

139-
TEST(ZimArchive, wrongChecksumInEmptyZimArchive)
148+
TEST_F(ZimArchive, wrongChecksumInEmptyZimArchive)
140149
{
141150
std::string zimfileContent = emptyZimArchiveContent();
142151
zimfileContent[85] = '\xff';
@@ -147,7 +156,7 @@ TEST(ZimArchive, wrongChecksumInEmptyZimArchive)
147156
}
148157

149158

150-
TEST(ZimArchive, openCreatedArchive)
159+
TEST_F(ZimArchive, openCreatedArchive)
151160
{
152161
TempFile temp("zimfile");
153162
auto tempPath = temp.path();
@@ -245,7 +254,7 @@ TEST(ZimArchive, openCreatedArchive)
245254
}
246255

247256
#if WITH_TEST_DATA
248-
TEST(ZimArchive, openRealZimArchive)
257+
TEST_F(ZimArchive, openRealZimArchive)
249258
{
250259
const char* const zimfiles[] = {
251260
"small.zim",
@@ -266,7 +275,7 @@ TEST(ZimArchive, openRealZimArchive)
266275
}
267276
}
268277

269-
TEST(ZimArchive, openSplitZimArchive)
278+
TEST_F(ZimArchive, openSplitZimArchive)
270279
{
271280
const char* fname = "wikibooks_be_all_nopic_2017-02_splitted.zim";
272281

@@ -286,7 +295,7 @@ struct TestCacheConfig {
286295
size_t dirent_lookup_cache_size;
287296
};
288297

289-
TEST(ZimArchive, cacheDontImpactReading)
298+
TEST_F(ZimArchive, cacheDontImpactReading)
290299
{
291300
const TestCacheConfig cache_configs[] = {
292301
{0, 0, 0},
@@ -335,7 +344,7 @@ TEST(ZimArchive, cacheDontImpactReading)
335344
}
336345
}
337346

338-
TEST(ZimArchive, cacheClean) {
347+
TEST_F(ZimArchive, cacheClean) {
339348
for (auto& testfile: getDataFilePath("wikibooks_be_all_nopic_2017-02.zim")) {
340349
EXPECT_EQ(zim::get_cluster_cache_current_size(), 0); // No clusters in cache
341350
{
@@ -354,7 +363,7 @@ TEST(ZimArchive, cacheClean) {
354363
}
355364
}
356365

357-
TEST(ZimArchive, cacheChange)
366+
TEST_F(ZimArchive, cacheChange)
358367
{
359368
// We test only one variant here.
360369
// Each variant has cluster of different size (especially the old "withns" which
@@ -433,7 +442,7 @@ TEST(ZimArchive, cacheChange)
433442
}
434443

435444

436-
TEST(ZimArchive, MultiZimCache)
445+
TEST_F(ZimArchive, MultiZimCache)
437446
{
438447
// Get a list of several zim files to open (whatever the variant)
439448
std::vector<std::string> zimPaths;
@@ -494,7 +503,7 @@ TEST(ZimArchive, MultiZimCache)
494503
EXPECT_EQ(zim::get_cluster_cache_current_size(), 0);
495504
}
496505

497-
TEST(ZimArchive, openDontFallbackOnNonSplitZimArchive)
506+
TEST_F(ZimArchive, openDontFallbackOnNonSplitZimArchive)
498507
{
499508
const char* fname = "wikibooks_be_all_nopic_2017-02.zim";
500509

@@ -510,7 +519,7 @@ TEST(ZimArchive, openDontFallbackOnNonSplitZimArchive)
510519
}
511520
}
512521

513-
TEST(ZimArchive, openNonExistantZimArchive)
522+
TEST_F(ZimArchive, openNonExistantZimArchive)
514523
{
515524
const std::string fname = "non_existant.zim";
516525

@@ -523,7 +532,7 @@ TEST(ZimArchive, openNonExistantZimArchive)
523532
}
524533
}
525534

526-
TEST(ZimArchive, openNonExistantZimSplitArchive)
535+
TEST_F(ZimArchive, openNonExistantZimSplitArchive)
527536
{
528537
const std::string fname = "non_existant.zimaa";
529538

@@ -536,7 +545,7 @@ TEST(ZimArchive, openNonExistantZimSplitArchive)
536545
}
537546
}
538547

539-
TEST(ZimArchive, randomEntry)
548+
TEST_F(ZimArchive, randomEntry)
540549
{
541550
const char* const zimfiles[] = {
542551
"wikibooks_be_all_nopic_2017-02.zim",
@@ -561,7 +570,7 @@ TEST(ZimArchive, randomEntry)
561570
}
562571
}
563572

564-
TEST(ZimArchive, illustration)
573+
TEST_F(ZimArchive, illustration)
565574
{
566575
const char* const zimfiles[] = {
567576
"small.zim",
@@ -606,7 +615,7 @@ struct TestDataInfo {
606615
}
607616
};
608617

609-
TEST(ZimArchive, articleNumber)
618+
TEST_F(ZimArchive, articleNumber)
610619
{
611620
TestDataInfo zimfiles[] = {
612621
// Name mediaCount, withns nons noTitleListingV0
@@ -672,7 +681,7 @@ for(auto& testfile: getDataFilePath(ZIMNAME, CAT)) {EXPECT_BROKEN_ZIMFILE(testfi
672681
#define WITH_TITLE_IDX_CAT {"withns", "nons"}
673682

674683
#if WITH_TEST_DATA
675-
TEST(ZimArchive, validate)
684+
TEST_F(ZimArchive, validate)
676685
{
677686
zim::IntegrityCheckList all;
678687
all.set();
@@ -870,7 +879,7 @@ void checkEquivalence(const zim::Archive& archive1, const zim::Archive& archive2
870879
#endif
871880
}
872881

873-
TEST(ZimArchive, multipart)
882+
TEST_F(ZimArchive, multipart)
874883
{
875884
auto nonSplittedZims = getDataFilePath("wikibooks_be_all_nopic_2017-02.zim");
876885
auto splittedZims = getDataFilePath("wikibooks_be_all_nopic_2017-02_splitted.zim");
@@ -899,7 +908,7 @@ TEST(ZimArchive, multipart)
899908
#endif
900909

901910
#ifndef _WIN32
902-
TEST(ZimArchive, openByFD)
911+
TEST_F(ZimArchive, openByFD)
903912
{
904913
for(auto& testfile: getDataFilePath("small.zim")) {
905914
const zim::Archive archive1(testfile.path);
@@ -910,7 +919,7 @@ TEST(ZimArchive, openByFD)
910919
}
911920
}
912921

913-
TEST(ZimArchive, openZIMFileEmbeddedInAnotherFile)
922+
TEST_F(ZimArchive, openZIMFileEmbeddedInAnotherFile)
914923
{
915924
auto normalZims = getDataFilePath("small.zim");
916925
auto embeddedZims = getDataFilePath("small.zim.embedded");
@@ -926,7 +935,7 @@ TEST(ZimArchive, openZIMFileEmbeddedInAnotherFile)
926935
}
927936
}
928937

929-
TEST(ZimArchive, openZIMFileMultiPartEmbeddedInAnotherFile)
938+
TEST_F(ZimArchive, openZIMFileMultiPartEmbeddedInAnotherFile)
930939
{
931940
auto normalZims = getDataFilePath("small.zim");
932941
auto embeddedZims = getDataFilePath("small.zim.embedded.multi");
@@ -969,7 +978,7 @@ zim::Blob readItemData(const zim::Item::DirectAccessInfo& dai, zim::size_type si
969978
return zim::Blob(data, size);
970979
}
971980

972-
TEST(ZimArchive, getDirectAccessInformation)
981+
TEST_F(ZimArchive, getDirectAccessInformation)
973982
{
974983
for(auto& testfile:getDataFilePath("small.zim")) {
975984
const zim::Archive archive(testfile.path);
@@ -990,7 +999,7 @@ TEST(ZimArchive, getDirectAccessInformation)
990999
}
9911000

9921001
#ifndef _WIN32
993-
TEST(ZimArchive, getDirectAccessInformationInAnArchiveOpenedByFD)
1002+
TEST_F(ZimArchive, getDirectAccessInformationInAnArchiveOpenedByFD)
9941003
{
9951004
for(auto& testfile:getDataFilePath("small.zim")) {
9961005
const int fd = OPEN_READ_ONLY(testfile.path);
@@ -1011,7 +1020,7 @@ TEST(ZimArchive, getDirectAccessInformationInAnArchiveOpenedByFD)
10111020
}
10121021
}
10131022

1014-
TEST(ZimArchive, getDirectAccessInformationFromEmbeddedArchive)
1023+
TEST_F(ZimArchive, getDirectAccessInformationFromEmbeddedArchive)
10151024
{
10161025
auto normalZims = getDataFilePath("small.zim");
10171026
auto embeddedZims = getDataFilePath("small.zim.embedded");

0 commit comments

Comments
 (0)