From: Michal 'vorner' Vaner Date: Wed, 20 Jun 2012 15:10:47 +0000 (+0200) Subject: [1976] Initialization X-Git-Tag: trac2351_base~97^2~7^2~2^2~21^2~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2536cfbce01e0fdd5b3d891beeedf2105ec8178c;p=thirdparty%2Fkea.git [1976] Initialization --- diff --git a/src/bin/auth/datasrc_configurator.h b/src/bin/auth/datasrc_configurator.h index f805c6ca5d..d5ba5295c6 100644 --- a/src/bin/auth/datasrc_configurator.h +++ b/src/bin/auth/datasrc_configurator.h @@ -47,6 +47,8 @@ private: { reconfigure(config); } + static Server* server_; + static isc::config::ModuleCCSession* session_; public: /// \brief Initializes the class. /// @@ -61,13 +63,25 @@ public: /// \param session The session to hook into and to access the configuration /// through. /// \param server It is the server to configure. - /// \throw InvalidOperation if this is called when already initialized. + /// \throw isc::InvalidOperation if this is called when already initialized. + /// \throw isc::InvalidParameter if any of the parameters is NULL /// \throw isc::config::ModuleCCError if the remote configuration is not /// available for some reason. static void init(isc::config::ModuleCCSession *session, Server *server) { - + if (session == NULL) { + isc_throw(isc::InvalidParameter, "The session must not be NULL"); + } + if (server == NULL) { + isc_throw(isc::InvalidParameter, "The server must not be NULL"); + } + if (server_ != NULL) { + isc_throw(isc::InvalidOperation, + "The configurator is already initialized"); + } + server_ = server; + session_ = session; } /// \brief Deinitializes the class. /// @@ -77,13 +91,31 @@ public: /// This can be called even if it is not initialized currently. You /// can initialize it again after this. static void deinit() { - + session_ = NULL; + server_ = NULL; } + /// \brief Reads new configuration and replaces the old one. + /// + /// It instructs the server to replace the lists with new ones as needed. + /// You don't need to call it directly (but you could, though the benefit + /// is unkown and it would be questionable at least). It is called + /// automatically on normal updates. + /// + /// \param config The configuration value to parse. It is in the form + /// as an update from the config manager. + /// \throw InvalidOperation if it is called when not initialized. static void reconfigure(const isc::data::ConstElementPtr& config) { } }; +template +isc::config::ModuleCCSession* +DataSourceConfiguratorGeneric::session_(NULL); + +template +Server* DataSourceConfiguratorGeneric::server_(NULL); + /// \brief Concrete version of DataSourceConfiguratorGeneric for the /// use in authoritative server. typedef DataSourceConfiguratorGeneric +#include +#include + +#include +#include + +using namespace isc; +using namespace isc::cc; +using namespace isc::config; +using namespace isc::data; +using namespace std; + namespace { +class DatasrcConfiguratorTest; + +class FakeList { + +}; + +// We use the test fixture as both parameters, this makes it possible +// to easily fake all needed methods and look that they were called. +typedef DataSourceConfiguratorGeneric Configurator; + +class DatasrcConfiguratorTest : public ::testing::Test { +protected: + DatasrcConfiguratorTest() : + session(ElementPtr(new ListElement), ElementPtr(new ListElement), + ElementPtr(new ListElement)), + specfile(string(TEST_OWN_DATA_DIR) + "/spec.spec") + { + initSession(); + } + void initSession() { + session.getMessages()->add(createAnswer()); + mccs.reset(new ModuleCCSession(specfile, session, NULL, NULL, false, + false)); + } + void TearDown() { + // Make sure no matter what we did, it is cleaned up. + Configurator::deinit(); + } + void init() { + Configurator::init(mccs.get(), this); + } + void SetUp() { + init(); + } + FakeSession session; + auto_ptr mccs; + const string specfile; +}; + +// Check the initialization (and deinitialization) +TEST_F(DatasrcConfiguratorTest, initialization) { + // It can't be initialized again + EXPECT_THROW(init(), InvalidOperation); + // Deinitialize to make the tests reasonable + Configurator::deinit(); + // Make sure there are enough messages in it, etc. + initSession(); + // If one of them is NULL, it does not work + EXPECT_THROW(Configurator::init(NULL, this), InvalidParameter); + EXPECT_THROW(Configurator::init(mccs.get(), NULL), InvalidParameter); + // But we can initialize it again now + EXPECT_NO_THROW(init()); +} + } diff --git a/src/bin/auth/tests/testdata/Makefile.am b/src/bin/auth/tests/testdata/Makefile.am index c86722f81d..7e42b70402 100644 --- a/src/bin/auth/tests/testdata/Makefile.am +++ b/src/bin/auth/tests/testdata/Makefile.am @@ -18,6 +18,7 @@ EXTRA_DIST += shortquestion_fromWire EXTRA_DIST += shortresponse_fromWire EXTRA_DIST += simplequery_fromWire.spec EXTRA_DIST += simpleresponse_fromWire.spec +EXTRA_DIST += spec.spec EXTRA_DIST += example.com EXTRA_DIST += example.sqlite3 diff --git a/src/bin/auth/tests/testdata/spec.spec b/src/bin/auth/tests/testdata/spec.spec new file mode 100644 index 0000000000..3e0a8226b0 --- /dev/null +++ b/src/bin/auth/tests/testdata/spec.spec @@ -0,0 +1,6 @@ +{ + "module_spec": { + "module_name": "test" + } +} +