From: hno <> Date: Thu, 24 May 2007 02:59:14 +0000 (+0000) Subject: Fix the cppunit tests to use setUp() rather than an static constructor to X-Git-Tag: SQUID_3_0_PRE7~240 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=16555581da7b6f45daad5ef6e5f864ea9d3d6989;p=thirdparty%2Fsquid.git Fix the cppunit tests to use setUp() rather than an static constructor to initialize memory pools etc. Static constructors is dangerous in that you don't know for sure in which order they will be called. The recent String pool change where the object size is dynamically calculated on startup is and example, where the requested pool size had not yet been calculated before the pools was created. --- diff --git a/src/gopher.cc b/src/gopher.cc index 016513b3b6..fb778de182 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,6 +1,6 @@ /* - * $Id: gopher.cc,v 1.205 2007/05/18 06:41:24 amosjeffries Exp $ + * $Id: gopher.cc,v 1.206 2007/05/23 20:59:14 hno Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -248,7 +248,7 @@ gopher_request_parse(const HttpRequest * req, char *type_id, char *request) if (request) { xstrncpy(request, path + 1, MAX_URL); /* convert %xx to char */ - url_convert_hex(request, 0); + rfc1738_unescape(request); } } diff --git a/src/protos.h b/src/protos.h index 66816a5470..a1d000f3e2 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.543 2007/05/18 06:41:25 amosjeffries Exp $ + * $Id: protos.h,v 1.544 2007/05/23 20:59:14 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -624,8 +624,6 @@ SQUIDCEXTERN void unlinkdClose(void); SQUIDCEXTERN void unlinkdUnlink(const char *); #endif -SQUIDCEXTERN char *url_convert_hex(char *org_url, int allocate); -SQUIDCEXTERN char *url_escape(const char *url); SQUIDCEXTERN protocol_t urlParseProtocol(const char *, const char *e = NULL); SQUIDCEXTERN void urlInitialize(void); SQUIDCEXTERN HttpRequest *urlParse(method_t, char *, HttpRequest *request = NULL); diff --git a/src/tests/testCacheManager.cc b/src/tests/testCacheManager.cc index e09e75b4f3..6ab2b275a8 100644 --- a/src/tests/testCacheManager.cc +++ b/src/tests/testCacheManager.cc @@ -17,12 +17,10 @@ shut_down(int) /* init memory pools */ -struct Initer +void testCacheManager::setUp() { - Initer() {Mem::Init();} -}; - -static Initer ensure_mempools; + Mem::Init(); +} /* * Test creating a CacheManager diff --git a/src/tests/testCacheManager.h b/src/tests/testCacheManager.h index ffc6e7fead..9db0cfd1d5 100644 --- a/src/tests/testCacheManager.h +++ b/src/tests/testCacheManager.h @@ -16,6 +16,7 @@ class testCacheManager : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE_END(); public: + void setUp(); protected: void testCreate(); diff --git a/src/tests/testDiskIO.cc b/src/tests/testDiskIO.cc index c8845e2de1..489768c8e1 100644 --- a/src/tests/testDiskIO.cc +++ b/src/tests/testDiskIO.cc @@ -16,14 +16,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION( testDiskIO ); -struct Initer { - Initer() { +void +testDiskIO::setUp() +{ Mem::Init(); DiskIOModule::SetupAllModules(); - }; -}; - -Initer ensure_inited; +} void testDiskIO::testFindDefault() diff --git a/src/tests/testDiskIO.h b/src/tests/testDiskIO.h index 70575ef69f..b1fcdfb2ab 100644 --- a/src/tests/testDiskIO.h +++ b/src/tests/testDiskIO.h @@ -15,6 +15,7 @@ class testDiskIO : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE_END(); public: + void setUp(); protected: void testFindDefault(); diff --git a/src/tests/testEvent.cc b/src/tests/testEvent.cc index 979f69750e..ad6881aece 100644 --- a/src/tests/testEvent.cc +++ b/src/tests/testEvent.cc @@ -19,16 +19,12 @@ shut_down(int) /* init legacy static-initialized modules */ -struct Initer +void +testEvent::setUp() { - Initer() - { - Mem::Init(); - statInit(); - } -}; - -static Initer ensure_mempools; + Mem::Init(); + statInit(); +} /* * Test creating a EventDispatcher and Scheduler diff --git a/src/tests/testEvent.h b/src/tests/testEvent.h index 6fa0b8e4a5..98cb3f7cd2 100644 --- a/src/tests/testEvent.h +++ b/src/tests/testEvent.h @@ -21,6 +21,7 @@ class testEvent : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE_END(); public: + void setUp(); protected: void testCreate(); diff --git a/src/tests/testEventLoop.cc b/src/tests/testEventLoop.cc index 1df52b6082..edbfd81c5d 100644 --- a/src/tests/testEventLoop.cc +++ b/src/tests/testEventLoop.cc @@ -20,16 +20,12 @@ shut_down(int) /* init legacy static-initialized modules */ -struct Initer +void +testEventLoop::setUp() { - Initer() - { - Mem::Init(); - statInit(); - } -}; - -static Initer ensure_mempools; + Mem::Init(); + statInit(); +} /* * Test creating a EventLoop diff --git a/src/tests/testEventLoop.h b/src/tests/testEventLoop.h index cd39c57555..658281337e 100644 --- a/src/tests/testEventLoop.h +++ b/src/tests/testEventLoop.h @@ -22,6 +22,7 @@ class testEventLoop : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE_END(); public: + void setUp(); protected: void testCreate(); diff --git a/src/tests/testHttpRequest.cc b/src/tests/testHttpRequest.cc index eb4b98ffbb..ecfcba8a37 100644 --- a/src/tests/testHttpRequest.cc +++ b/src/tests/testHttpRequest.cc @@ -17,12 +17,11 @@ shut_down(int) /* init memory pools */ -struct Initer +void +testHttpRequest::setUp() { - Initer() {Mem::Init();} -}; - -static Initer ensure_mempools; + Mem::Init(); +} /* * Test creating an HttpRequest object from a Url and method diff --git a/src/tests/testHttpRequest.h b/src/tests/testHttpRequest.h index a173a4c1f8..e81c73a7d8 100644 --- a/src/tests/testHttpRequest.h +++ b/src/tests/testHttpRequest.h @@ -16,6 +16,7 @@ class testHttpRequest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE_END(); public: + void setUp(); protected: void testCreateFromUrlAndMethod(); diff --git a/src/tests/testStoreEntryStream.cc b/src/tests/testStoreEntryStream.cc index db1c7e41c4..034e773d61 100644 --- a/src/tests/testStoreEntryStream.cc +++ b/src/tests/testStoreEntryStream.cc @@ -14,12 +14,10 @@ CPPUNIT_TEST_SUITE_REGISTRATION( testStoreEntryStream ); /* init memory pools */ -struct Initer +void testStoreEntryStream::setUp() { - Initer() {Mem::Init();} -}; - -static Initer ensure_mempools; + Mem::Init(); +} void testStoreEntryStream::testGetStream() diff --git a/src/tests/testStoreEntryStream.h b/src/tests/testStoreEntryStream.h index 0985d99b5a..4561fddd6e 100644 --- a/src/tests/testStoreEntryStream.h +++ b/src/tests/testStoreEntryStream.h @@ -15,6 +15,7 @@ class testStoreEntryStream : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE_END(); public: + void setUp(); protected: void testGetStream(); diff --git a/src/tests/testString.cc b/src/tests/testString.cc index 58baa4f902..f2340881a1 100644 --- a/src/tests/testString.cc +++ b/src/tests/testString.cc @@ -13,12 +13,11 @@ eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata) /* init memory pools */ -struct Initer +void +testString::setUp() { - Initer() {Mem::Init();} -}; - -static Initer ensure_mempools; + Mem::Init(); +} void testString::testDefaults() diff --git a/src/tests/testString.h b/src/tests/testString.h index 52951a2fef..d4ff1d051f 100644 --- a/src/tests/testString.h +++ b/src/tests/testString.h @@ -26,6 +26,7 @@ class testString : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE_END(); public: + void setUp(); protected: diff --git a/src/tests/testURL.cc b/src/tests/testURL.cc index de2fadc424..031161bdef 100644 --- a/src/tests/testURL.cc +++ b/src/tests/testURL.cc @@ -18,12 +18,11 @@ shut_down(int) /* init memory pools */ -struct Initer +void +testURL::setUp() { - Initer() {Mem::Init();} -}; - -static Initer ensure_mempools; + Mem::Init(); +} /* * we can construct a URL with a URLScheme. diff --git a/src/tests/testURL.h b/src/tests/testURL.h index 7ec1ce7f27..c4863fc510 100644 --- a/src/tests/testURL.h +++ b/src/tests/testURL.h @@ -16,6 +16,7 @@ class testURL : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE_END(); public: + void setUp(); protected: diff --git a/src/url.cc b/src/url.cc index de85758c89..45b64b94f4 100644 --- a/src/url.cc +++ b/src/url.cc @@ -1,6 +1,6 @@ /* - * $Id: url.cc,v 1.158 2007/05/18 06:41:25 amosjeffries Exp $ + * $Id: url.cc,v 1.159 2007/05/23 20:59:14 hno Exp $ * * DEBUG: section 23 URL Parsing * AUTHOR: Duane Wessels @@ -49,38 +49,6 @@ static const char valid_hostname_chars[] = "0123456789-." ; -/* convert %xx in url string to a character - * Allocate a new string and return a pointer to converted string */ - -char * -url_convert_hex(char *org_url, int allocate) -{ - static char code[] = "00"; - char *url = NULL; - char *s = NULL; - char *t = NULL; - url = allocate ? (char *) xstrdup(org_url) : org_url; - - if ((int) strlen(url) < 3 || !strchr(url, '%')) - return url; - - for (s = t = url; *s; s++) { - if (*s == '%' && *(s + 1) && *(s + 2)) { - code[0] = *(++s); - code[1] = *(++s); - *t++ = (char) strtol(code, NULL, 16); - } else { - *t++ = *s; - } - } - - do { - *t++ = *s; - } while (*s++); - - return url; -} - void urlInitialize(void) {