]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/tests/testACLMaxUserIP.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / tests / testACLMaxUserIP.cc
index 24b96939603b13f98fade36c23de267dfa84f7df..9185a4b8c2cb09c2be79776415988a03b52bf189 100644 (file)
@@ -1,47 +1,61 @@
-#define SQUID_UNIT_TEST 1
+/*
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
 
-#include "squid-old.h"
+#include "squid.h"
 
 #if USE_AUTH
 
-#include "testACLMaxUserIP.h"
 #include "auth/AclMaxUserIp.h"
+#include "ConfigParser.h"
+#include "testACLMaxUserIP.h"
+#include "unitTestMain.h"
 
-#if HAVE_STDEXCEPT
 #include <stdexcept>
-#endif
 
 CPPUNIT_TEST_SUITE_REGISTRATION( testACLMaxUserIP );
 
-
 void
 testACLMaxUserIP::testDefaults()
 {
     ACLMaxUserIP anACL("max_user_ip");
     /* 0 is not a valid maximum, so we start at 0 */
-    CPPUNIT_ASSERT(anACL.getMaximum() == 0);
+    CPPUNIT_ASSERT_EQUAL(0,anACL.getMaximum());
     /* and we have no option to turn strict OFF, so start ON. */
-    CPPUNIT_ASSERT(anACL.getStrict() == false);
+    CPPUNIT_ASSERT_EQUAL(false,anACL.getStrict());
     /* an unparsed acl must not be valid - there is no sane default */
-    CPPUNIT_ASSERT(!anACL.valid());
+    CPPUNIT_ASSERT_EQUAL(false,anACL.valid());
 }
 
+ACL::Prototype ACLMaxUserIP::RegistryProtoype(&ACLMaxUserIP::RegistryEntry_, "max_user_ip");
+ACLMaxUserIP ACLMaxUserIP::RegistryEntry_("max_user_ip");
 
 void
 testACLMaxUserIP::testParseLine()
 {
     /* a config line to pass with a lead-in token to seed the parser. */
-    char * line = xstrdup("token -s 1");
+    char * line = xstrdup("test max_user_ip -s 1");
     /* seed the parser */
-    strtok(line, w_space);
-    ACLMaxUserIP anACL("max_user_ip");
-    anACL.parse();
-    /* we want a maximum of one, and strict to be true */
-    CPPUNIT_ASSERT(anACL.getMaximum() == 1);
-    CPPUNIT_ASSERT(anACL.getStrict() == true);
-    /* the acl must be vaid */
-    CPPUNIT_ASSERT(anACL.valid());
+    ConfigParser::SetCfgLine(line);
+    ACL *anACL = NULL;
+    ConfigParser LegacyParser;
+    ACL::ParseAclLine(LegacyParser, &anACL);
+    ACLMaxUserIP *maxUserIpACL = dynamic_cast<ACLMaxUserIP *>(anACL);
+    CPPUNIT_ASSERT(maxUserIpACL);
+    if (maxUserIpACL) {
+        /* we want a maximum of one, and strict to be true */
+        CPPUNIT_ASSERT_EQUAL(1, maxUserIpACL->getMaximum());
+        CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL->getStrict());
+        /* the acl must be vaid */
+        CPPUNIT_ASSERT_EQUAL(true, maxUserIpACL->valid());
+    }
+    delete anACL;
     xfree(line);
 }
 
 #endif /* USE_AUTH */
+