]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix the cppunit tests to use setUp() rather than an static constructor to
authorhno <>
Thu, 24 May 2007 02:59:14 +0000 (02:59 +0000)
committerhno <>
Thu, 24 May 2007 02:59:14 +0000 (02:59 +0000)
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.

19 files changed:
src/gopher.cc
src/protos.h
src/tests/testCacheManager.cc
src/tests/testCacheManager.h
src/tests/testDiskIO.cc
src/tests/testDiskIO.h
src/tests/testEvent.cc
src/tests/testEvent.h
src/tests/testEventLoop.cc
src/tests/testEventLoop.h
src/tests/testHttpRequest.cc
src/tests/testHttpRequest.h
src/tests/testStoreEntryStream.cc
src/tests/testStoreEntryStream.h
src/tests/testString.cc
src/tests/testString.h
src/tests/testURL.cc
src/tests/testURL.h
src/url.cc

index 016513b3b6a9060b8e7b0fa5880e0bd4a29902aa..fb778de1829d4b3edd9a6d66f53dea9ced04c203 100644 (file)
@@ -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);
     }
 }
 
index 66816a54701a4a2f985c54ad3d9d284cbb66b676..a1d000f3e2279f64313a115b75504752385bd577 100644 (file)
@@ -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);
index e09e75b4f3463017ebaa3e71fad262d46a231f43..6ab2b275a8aa449a238c49a1116fa7a051a9437d 100644 (file)
@@ -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
index ffc6e7fead657adad900339cfc87f5b87192284b..9db0cfd1d52b1ad4313c32a31e7774d7839b9c1c 100644 (file)
@@ -16,6 +16,7 @@ class testCacheManager : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE_END();
 
 public:
+    void setUp();
 
 protected:
     void testCreate();
index c8845e2de16f92762d3cff83c3b2bc954f4a575d..489768c8e1010d28516b3b32e91e18a58b357cda 100644 (file)
 
 CPPUNIT_TEST_SUITE_REGISTRATION( testDiskIO );
 
-struct Initer {
-  Initer() {
+void
+testDiskIO::setUp()
+{
     Mem::Init();
     DiskIOModule::SetupAllModules();
-  };
-};
-
-Initer ensure_inited;
+}
 
 void
 testDiskIO::testFindDefault()
index 70575ef69feb6da614b90b0b5b483ba0e2962d1b..b1fcdfb2abf5a2b87ead4c94b8444a9f9314cbf9 100644 (file)
@@ -15,6 +15,7 @@ class testDiskIO : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE_END();
 
 public:
+    void setUp();
 
 protected:
     void testFindDefault();
index 979f69750e88b0a80c88a08f58836e77f935623b..ad6881aeceaadb60b7d741687c9f01fee0e4b2b8 100644 (file)
@@ -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
index 6fa0b8e4a570292d83b97b24439fde23c28891df..98cb3f7cd245b4b60cd16c5ec6d331d7c9c24710 100644 (file)
@@ -21,6 +21,7 @@ class testEvent : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE_END();
 
 public:
+    void setUp();
 
 protected:
     void testCreate();
index 1df52b60820566f6f6212b4e5f87d1317bcbb5c5..edbfd81c5dba856170b909ddd27b57c6d59eac59 100644 (file)
@@ -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
index cd39c575552822aaf1a2316db884f11bea56d7a0..658281337efb388c53984e824ee342032f505c57 100644 (file)
@@ -22,6 +22,7 @@ class testEventLoop : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE_END();
 
 public:
+    void setUp();
 
 protected:
     void testCreate();
index eb4b98ffbb18d0f5e001b6cdfb5123a66b75823b..ecfcba8a376989ac524eca7cc148acf7c0376bad 100644 (file)
@@ -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
index a173a4c1f8a89d9e0e87acac1f72722eaebe13a8..e81c73a7d889c3825810355f33917949bb3d89a5 100644 (file)
@@ -16,6 +16,7 @@ class testHttpRequest : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE_END();
 
 public:
+    void setUp();
 
 protected:
     void testCreateFromUrlAndMethod();
index db1c7e41c4bd72207fe229993ca6b86f2f6a0177..034e773d61b3197ca940dd72b43008ae1f37ac1f 100644 (file)
@@ -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()
index 0985d99b5a3371ec43636f88a1ba91ecd5b47638..4561fddd6ee363223d9806e604b048238bb8a4d8 100644 (file)
@@ -15,6 +15,7 @@ class testStoreEntryStream : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE_END();
 
 public:
+    void setUp();
 
 protected:
     void testGetStream();
index 58baa4f9026df3495c8c4fd141c5df58c89d7915..f2340881a117ebf71d8382858608cd64c335d637 100644 (file)
@@ -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()
index 52951a2fefc9b9f1f451d0c69d376eca0da92e85..d4ff1d051fb6019ea341e5bb7b11b617bda7d603 100644 (file)
@@ -26,6 +26,7 @@ class testString : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE_END();
 
 public:
+    void setUp();
 
 protected:
 
index de2fadc4245e657ea9bcaff4d1646cd082d3e085..031161bdefb3c88347ec498d859d2d84754f3266 100644 (file)
@@ -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.
index 7ec1ce7f271fbdbeffdd8f6b82cf8d0da04a069b..c4863fc510a79764c230e6eccde5c66a86e3cc82 100644 (file)
@@ -16,6 +16,7 @@ class testURL : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST_SUITE_END();
 
 public:
+    void setUp();
 
 protected:
 
index de85758c89a9d31ecdd8e87e395ab99702507036..45b64b94f485f87ab08470f627938991e3553776 100644 (file)
@@ -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)
 {