AsyncEngine.h \
cache_cf.h \
AuthReg.h \
- YesNoNone.h \
- YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
CacheDigest.h \
tests/testSBufList \
tests/testConfigParser \
tests/testStatHist \
- tests/testLookupTable
+ tests/testLookupTable \
+ tests/testYesNoNone
if HAVE_FS_ROCK
check_PROGRAMS += tests/testRock
log/access_log.h \
tests/stub_access_log.cc \
cache_cf.h \
- YesNoNone.h \
tests/stub_cache_cf.cc \
tests/stub_cache_manager.cc \
tests/stub_comm.cc \
log/access_log.h \
tests/stub_access_log.cc \
cache_cf.h \
- YesNoNone.h \
tests/stub_cache_cf.cc \
tests/stub_client_side.cc \
tests/stub_debug.cc \
cache_manager.cc \
cache_cf.h \
AuthReg.h \
- YesNoNone.h \
- YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
CachePeer.cc \
tests/stub_access_log.cc \
tests/stub_acl.cc \
cache_cf.h \
- YesNoNone.h \
tests/stub_cache_cf.cc \
tests/stub_cache_manager.cc \
tests/stub_client_db.cc \
tests/stub_CacheDigest.cc \
cache_cf.h \
AuthReg.h \
- YesNoNone.h \
- YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
CachePeer.cc \
cache_manager.cc \
cache_cf.h \
AuthReg.h \
- YesNoNone.h \
- YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
CachePeer.cc \
BodyPipe.cc \
cache_cf.h \
AuthReg.h \
- YesNoNone.h \
- YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
CachePeer.cc \
mime_header.h \
String.cc \
cache_cf.h \
- YesNoNone.h \
$(SBUF_SOURCE) \
SBufAlgos.h \
SBufAlgos.cc \
cache_manager.cc \
cache_cf.h \
AuthReg.h \
- YesNoNone.h \
- YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
debug.cc \
tests/stub_access_log.cc \
tests/stub_acl.cc \
cache_cf.h \
- YesNoNone.h \
tests/stub_cache_cf.cc \
tests/stub_cache_manager.cc \
tests/stub_client_side_request.cc \
tests/testString.cc \
tests/testString.h \
cache_cf.h \
- YesNoNone.h \
tests/stub_cache_cf.cc \
tests/stub_cache_manager.cc \
tests/stub_cbdata.cc \
ConfigOption.cc \
tests/stub_acl.cc \
cache_cf.h \
- YesNoNone.h \
tests/stub_cache_cf.cc \
tests/stub_helper.cc \
cbdata.cc \
log/access_log.h \
tests/stub_access_log.cc \
cache_cf.h \
- YesNoNone.h \
tests/stub_cache_cf.cc \
client_db.h \
tests/stub_cache_manager.cc \
BodyPipe.cc \
cache_cf.h \
AuthReg.h \
- YesNoNone.h \
- YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
tests/stub_cache_manager.cc \
tests/testConfigParser.cc \
tests/testConfigParser.h \
cache_cf.h \
- YesNoNone.h \
tests/stub_cache_cf.cc \
tests/stub_cache_manager.cc \
tests/stub_cbdata.cc \
$(XTRA_LIBS)
tests_testEnumIterator_DEPENDENCIES =
+tests_testYesNoNone_SOURCES = \
+ tests/testYesNoNone.cc \
+ tests/testYesNoNone.h
+nodist_tests_testYesNoNone_SOURCES = \
+ tests/STUB.h \
+ base/YesNoNone.h
+tests_testYesNoNone_LDADD= \
+ $(SQUID_CPPUNIT_LIBS) \
+ $(COMPAT_LIB) \
+ $(XTRA_LIBS)
+tests_testYesNoNone_LDFLAGS = $(LIBADD_DL)
+
TESTS += testHeaders
## Special Universal .h dependency test script
#include "acl/forward.h"
#include "base/RefCount.h"
+#include "base/YesNoNone.h"
#include "ClientDelayConfig.h"
#include "DelayConfig.h"
#include "helper/ChildConfig.h"
#include "ssl/support.h"
#endif
#include "store/forward.h"
-#include "YesNoNone.h"
#if USE_OPENSSL
class sslproxy_cert_sign;
+++ /dev/null
-/*
- * Copyright (C) 1996-2016 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.h"
-#include "YesNoNone.h"
-
-YesNoNone::operator void*() const
-{
- assert(option != 0); // must call configure() first
- return option > 0 ? (void*)this : NULL;
-}
-
-void
-YesNoNone::configure(bool beSet)
-{
- option = beSet ? +1 : -1;
-}
-
+++ /dev/null
-/*
- * Copyright (C) 1996-2016 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.
- */
-
-#ifndef SQUID_YESNONONE_H_
-#define SQUID_YESNONONE_H_
-
-/// Used for boolean enabled/disabled options with complex default logic.
-/// Allows Squid to compute the right default after configuration.
-/// Checks that not-yet-defined option values are not used.
-class YesNoNone
-{
-// TODO: generalize to non-boolean option types
-public:
- YesNoNone(): option(0) {}
-
- /// returns true iff enabled; asserts if the option has not been configured
- operator void *() const; // TODO: use a fancy/safer version of the operator
-
- /// enables or disables the option;
- void configure(bool beSet);
-
- /// whether the option was enabled or disabled, by user or Squid
- bool configured() const { return option != 0; }
-
-private:
- enum { optUnspecified = -1, optDisabled = 0, optEnabled = 1 };
- int option; ///< configured value or zero
-};
-
-#endif /* SQUID_YESNONONE_H_ */
-
#include "adaptation/Elements.h"
#include "base/RefCount.h"
+#include "base/YesNoNone.h"
#include "security/PeerOptions.h"
#include "SquidString.h"
-#include "YesNoNone.h"
namespace Adaptation
{
{
Adaptation::Service::finalize();
if (!cfg().connectionEncryption.configured())
- writeableCfg().connectionEncryption.configure(true);
+ writeableCfg().connectionEncryption.defaultTo(true);
theService = FindAdapterService(cfg().uri);
if (theService) {
try {
if (cfg().secure.encryptTransport) {
debugs(3, DBG_IMPORTANT, "Initializing service " << cfg().resource << " SSL context");
sslContext = writeableCfg().secure.createClientContext(true);
- if (!cfg().connectionEncryption.configured())
- writeableCfg().connectionEncryption.configure(true);
- } else if (!cfg().connectionEncryption.configured())
- writeableCfg().connectionEncryption.configure(false);
+ }
+
+ if (!cfg().connectionEncryption.configured())
+ writeableCfg().connectionEncryption.defaultTo(cfg().secure.encryptTransport);
theSessionFailures.configure(TheConfig.oldest_service_failure > 0 ?
TheConfig.oldest_service_failure : -1);
Subscription.h \
TextException.cc \
TextException.h \
- TidyPointer.h
+ TidyPointer.h \
+ YesNoNone.h
--- /dev/null
+/*
+ * Copyright (C) 1996-2016 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.
+ */
+
+#ifndef SQUID_YESNONONE_H_
+#define SQUID_YESNONONE_H_
+
+#include "base/TextException.h"
+
+// TODO: generalize / template to non-boolean option types
+// and make YesNoNone the boolean instance of the template
+
+/**
+ * Used for boolean enabled/disabled options with complex default logic.
+ * Allows Squid to compute the right default after configuration.
+ * Checks that not-yet-defined option values are not used.
+ * Allows for implicit default Yes/No values to be used by initialization
+ * without configure() being called, but not dumped as squid.conf content.
+ *
+ * Use x.configure(bool) when the value is configured.
+ * Use x.defaultTo(bool) to assign defaults.
+ */
+class YesNoNone
+{
+ enum SetHow : uint8_t { optUnspecified = 0, optImplicitly = 1, optConfigured = 2 };
+
+public:
+ // this constructor initializes to 'unspecified' state
+ YesNoNone():
+ setHow_(optUnspecified),
+ option(false)
+ {}
+
+ // this constructor initializes to 'implicit' state
+ explicit YesNoNone(bool beSet):
+ setHow_(optImplicitly),
+ option(beSet)
+ {}
+
+ /// the boolean equivalent of the value stored.
+ /// asserts if the value has not been set.
+ explicit operator bool() const {
+ Must(setHow_ != optUnspecified);
+ return option;
+ }
+
+ /// enables or disables the option; updating to 'configured' state
+ void configure(bool beSet) {
+ setHow_ = optConfigured;
+ option = beSet;
+ }
+
+ /// enables or disables the option; updating to 'implicit' state
+ void defaultTo(bool beSet) {
+ Must(setHow_ != optConfigured);
+ setHow_ = optImplicitly;
+ option = beSet;
+ }
+
+ /// whether the option was enabled or disabled,
+ /// by squid.conf values resulting in explicit configure() usage.
+ bool configured() const {return setHow_ == optConfigured;}
+
+private:
+ SetHow setHow_; ///< how the option was set
+ bool option; ///< specified yes/no value; meaningless if optUnspecified
+};
+
+#endif /* SQUID_YESNONONE_H_ */
+
#include "acl/Acl.h"
#include "ConfigParser.h"
#include "wordlist.h"
-#include "YesNoNone.h"
#define STUB_API "cache_cf.cc"
#include "tests/STUB.h"
void ConfigParser::ParseUShort(unsigned short *var) STUB
void dump_acl_access(StoreEntry * entry, const char *name, acl_access * head) STUB
void dump_acl_list(StoreEntry*, ACLList*) STUB
-YesNoNone::operator void*() const { STUB_NOP; return NULL; }
if (0 > system ("rm -rf " TESTDIR))
throw std::runtime_error("Failed to clean test work directory");
+ Config.memShared.defaultTo(false);
+
// use current directory for shared segments (on path-based OSes)
Ipc::Mem::Segment::BasePath = getcwd(cwd,MAXPATHLEN);
if (Ipc::Mem::Segment::BasePath == NULL)
if (inited)
return;
+ Config.memShared.defaultTo(false);
+
Mem::Init();
Config.Store.avgObjectSize = 1024;
Config.replPolicy = new RemovalPolicySettings;
Config.replPolicy->type = xstrdup("lru");
+ Config.memShared.defaultTo(false);
+
/* garh garh */
storeReplAdd("lru", createRemovalPolicy_lru);
--- /dev/null
+/*
+ * Copyright (C) 1996-2016 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.h"
+#include "base/YesNoNone.h"
+#include "tests/testYesNoNone.h"
+#include "unitTestMain.h"
+
+#include <stdexcept>
+
+CPPUNIT_TEST_SUITE_REGISTRATION( testYesNoNone );
+
+void
+testYesNoNone::testBasics()
+{
+ // unconfigured, non-implicit
+ {
+ YesNoNone v;
+ CPPUNIT_ASSERT_EQUAL(false, v.configured());
+ // cannot test the value it is 'undefined' and will assert
+ }
+ // implicit dtor test
+
+ // unconfigured, implicit true
+ {
+ YesNoNone v(true);
+ CPPUNIT_ASSERT_EQUAL(false, v.configured());
+ CPPUNIT_ASSERT(v);
+ CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(v));
+
+ // check explicit setter method
+ v.configure(false);
+ CPPUNIT_ASSERT_EQUAL(true, v.configured());
+ CPPUNIT_ASSERT(!v);
+ CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(v));
+ }
+
+ // unconfigured, implicit false
+ {
+ YesNoNone v(false);
+ CPPUNIT_ASSERT_EQUAL(false, v.configured());
+ CPPUNIT_ASSERT(!v);
+ CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(v));
+
+ // check assignment operator
+ v = YesNoNone(true);
+ CPPUNIT_ASSERT_EQUAL(false, v.configured());
+ CPPUNIT_ASSERT(v);
+ CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(v));
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 1996-2016 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.
+ */
+
+#ifndef SQUID_SRC_TESTS_TESTYESNONONE_H
+#define SQUID_SRC_TESTS_TESTYESNONONE_H
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/*
+ * demonstration test file, as new idioms are made they will
+ * be shown in the testYesNoNone source.
+ */
+
+class testYesNoNone : public CPPUNIT_NS::TestFixture
+{
+ CPPUNIT_TEST_SUITE( testYesNoNone );
+ /* note the statement here and then the actual prototype below */
+ CPPUNIT_TEST( testBasics );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+
+protected:
+ void testBasics();
+};
+
+#endif /* SQUID_SRC_TESTS_TESTYESNONONE_H */
+