[asterisk-scf-commits] asterisk-scf/integration/logger.git branch "filename" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Mar 15 17:44:40 CDT 2011


branch "filename" has been updated
       via  f0b98e570b459ae5861d9541b2c2c4b2ff6b41ff (commit)
       via  87c1fcce07101a99f599bfe8ad0bb6a4aa360b02 (commit)
       via  299462b725655f8c2f57c05149e7e2deb59bbd5d (commit)
       via  90cdfbef42ca87e8c336ab54f6f02819d36ffb43 (commit)
       via  b2631be10abdb630e7f053c4aa2987006250bde7 (commit)
      from  89913e2ec673202c8ad86138f77cbd51ec4304b8 (commit)

Summary of changes:
 server/test/CMakeLists.txt             |   18 ++-
 server/test/ConfigurationComponent.cpp |   62 ++++++++-
 server/test/ConfigurationComponent.h   |    6 +-
 server/test/ConfigurationTest.cpp      |  231 ++++++++++++++++++++++++++++++++
 4 files changed, 308 insertions(+), 9 deletions(-)
 create mode 100644 server/test/ConfigurationTest.cpp


- Log -----------------------------------------------------------------
commit f0b98e570b459ae5861d9541b2c2c4b2ff6b41ff
Author: Mark Michelson <mmichelson at digium.com>
Date:   Tue Mar 15 17:44:13 2011 -0500

    Add tests for when we expect no file to be configured.

diff --git a/server/test/ConfigurationTest.cpp b/server/test/ConfigurationTest.cpp
index 736c76a..e4c9a07 100644
--- a/server/test/ConfigurationTest.cpp
+++ b/server/test/ConfigurationTest.cpp
@@ -119,15 +119,26 @@ BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
 
 static int serial = 100;
 
-static bool checkConfiguredFile(const boost::shared_ptr<LoggingConfigurationHelper> &confHelper,
+enum FileStatus
+{
+    CORRECT,
+    INCORRECT,
+    NONEXISTENT
+};
+
+static FileStatus checkConfiguredFile(const boost::shared_ptr<LoggingConfigurationHelper> &confHelper,
         const std::string &fileName)
 {
     FileItemPtr configuredFile = confHelper->getConfiguredOutputFile();
+    if (!configuredFile)
+    {
+        return NONEXISTENT;
+    }
     if (configuredFile->fileName == fileName)
     {
-        return true;
+        return CORRECT;
     }
-    return false;
+    return INCORRECT;
 }
 
 // Basic test that sets a logging file to use and then
@@ -144,9 +155,13 @@ BOOST_AUTO_TEST_CASE(SetAndRemoveFile)
     {
         BOOST_FAIL("SerialConflict thrown when setting output file");
     }
-    checkConfiguredFile(TestBed.confHelper, fileName);
+    FileStatus status = checkConfiguredFile(TestBed.confHelper, fileName);
+    BOOST_CHECK(status == CORRECT);
     TestBed.confHelper->removeLogOutFile(fileName);
-    //There should be no configured output files.
+    //Whenever we expect the return to be NONEXISTENT, the filename we
+    //pass in really doesn't matter.
+    status = checkConfiguredFile(TestBed.confHelper, fileName);
+    BOOST_CHECK(status == NONEXISTENT);
 }
 
 BOOST_AUTO_TEST_CASE(FileReplacement)
@@ -156,26 +171,27 @@ BOOST_AUTO_TEST_CASE(FileReplacement)
     try
     {
         TestBed.confHelper->setLogOutFile(fileName1, serial++);
-        bool correct = checkConfiguredFile(TestBed.confHelper, fileName1);
-        BOOST_CHECK(correct);
+        FileStatus status = checkConfiguredFile(TestBed.confHelper, fileName1);
+        BOOST_CHECK(status == CORRECT);
         TestBed.confHelper->setLogOutFile(fileName2, serial++);
+        status = checkConfiguredFile(TestBed.confHelper, fileName2);
+        BOOST_CHECK(status == CORRECT);
     }
     catch (const SerialConflict &sc)
     {
         BOOST_FAIL("SerialConflict thrown when setting output file");
     }
-    bool correct = checkConfiguredFile(TestBed.confHelper, fileName2);
-    BOOST_CHECK(correct);
     TestBed.confHelper->removeLogOutFile(fileName2);
-    //There should be no configured output files.
+    FileStatus status = checkConfiguredFile(TestBed.confHelper, fileName2);
+    BOOST_CHECK(status == NONEXISTENT);
 }
 
 BOOST_AUTO_TEST_CASE(NonexistentRemoval)
 {
     const std::string fileName("frankensteinspleens.txt");
     TestBed.confHelper->removeLogOutFile(fileName);
-    //There should be no configured output files, and
-    //nothing catastrophic should have occurred.
+    FileStatus status = checkConfiguredFile(TestBed.confHelper, fileName);
+    BOOST_CHECK(status == NONEXISTENT);
 }
 
 BOOST_AUTO_TEST_CASE(PurposefulSerialConflict)
@@ -190,18 +206,20 @@ BOOST_AUTO_TEST_CASE(PurposefulSerialConflict)
     {
         BOOST_FAIL("SerialConflict thrown when setting output file");
     }
-    bool correct = checkConfiguredFile(TestBed.confHelper, fileName1);
-    BOOST_CHECK(correct);
+    FileStatus status = checkConfiguredFile(TestBed.confHelper, fileName1);
+    BOOST_CHECK(status == CORRECT);
+    bool exceptionHit = false;
     try
     {
         TestBed.confHelper->setLogOutFile(fileName2, serial++);
     }
     catch (const SerialConflict &ex)
     {
-        // We should hit this.
+        exceptionHit = true;
     }
-    correct = checkConfiguredFile(TestBed.confHelper, fileName1);
-    BOOST_CHECK(correct);
+    BOOST_CHECK(exceptionHit == true);
+    status = checkConfiguredFile(TestBed.confHelper, fileName1);
+    BOOST_CHECK(status == CORRECT);
 }
 
 extern "C"

commit 87c1fcce07101a99f599bfe8ad0bb6a4aa360b02
Author: Mark Michelson <mmichelson at digium.com>
Date:   Tue Mar 15 17:32:46 2011 -0500

    Make sure to add test to the suite.

diff --git a/server/test/CMakeLists.txt b/server/test/CMakeLists.txt
index 49486fc..41d2cc4 100644
--- a/server/test/CMakeLists.txt
+++ b/server/test/CMakeLists.txt
@@ -35,4 +35,6 @@ include_directories(${API_INCLUDE_DIR})
 asterisk_scf_component_build_icebox(ConfigurationTest)
 target_link_libraries(ConfigurationTest asterisk-scf-api)
 
-boost_add_test(logging-service-test)
+if(integrated_build STREQUAL "true")
+   icebox_add_test(ConfigurationTest ../config/testloggingserver.conf)
+endif()

commit 299462b725655f8c2f57c05149e7e2deb59bbd5d
Author: Mark Michelson <mmichelson at digium.com>
Date:   Tue Mar 15 17:12:17 2011 -0500

    Add some testing for correctness after setting configuration.
    
    I just need to add something similar for making sure nothing is there
    and I'll be SET.

diff --git a/server/test/ConfigurationComponent.cpp b/server/test/ConfigurationComponent.cpp
index e745a7b..5a09832 100644
--- a/server/test/ConfigurationComponent.cpp
+++ b/server/test/ConfigurationComponent.cpp
@@ -29,10 +29,10 @@ namespace
 using namespace AsteriskSCF::System::Configuration::V1;
 using namespace AsteriskSCF::System::Logger::V1;
 
-LoggingConfigurationPusher::LoggingConfigurationPusher(const ConfigurationServicePrx &config)
+LoggingConfigurationHelper::LoggingConfigurationHelper(const ConfigurationServicePrx &config)
     : mConfigPrx(config) { }
 
-void LoggingConfigurationPusher::setLogOutFile(const std::string &fileName, int serialNumber)
+void LoggingConfigurationHelper::setLogOutFile(const std::string &fileName, int serialNumber)
 {
     ConfigurationGroupSeq groups;
     LoggerGeneralGroupPtr generalGroup(new LoggerGeneralGroup);
@@ -43,7 +43,7 @@ void LoggingConfigurationPusher::setLogOutFile(const std::string &fileName, int
     mConfigPrx->setConfiguration(groups);
 }
 
-void LoggingConfigurationPusher::removeLogOutFile(const std::string &fileName)
+void LoggingConfigurationHelper::removeLogOutFile(const std::string &fileName)
 {
     ConfigurationGroupSeq groups;
     LoggerGeneralGroupPtr generalGroup(new LoggerGeneralGroup);
@@ -52,3 +52,59 @@ void LoggingConfigurationPusher::removeLogOutFile(const std::string &fileName)
     generalGroup->configurationItems.insert(make_pair(FileItemName, fileItem));
     mConfigPrx->removeConfigurationItems(groups);
 }
+
+AsteriskSCF::System::Logger::V1::FileItemPtr LoggingConfigurationHelper::getConfiguredOutputFile()
+{
+    //Part 1: Retrieval from the configuration service.
+
+    ConfigurationGroupSeq queryGroups;
+    LoggerGeneralGroupPtr generalGroup(new LoggerGeneralGroup);
+    FileItemPtr file(new FileItem);
+    generalGroup->configurationItems.insert(make_pair(FileItemName, file));
+    queryGroups.push_back(generalGroup);
+
+    ConfigurationGroupSeq returnedGroups = mConfigPrx->getConfiguration(queryGroups);
+
+    class Visitor : public LoggerConfigurationGroupVisitor
+    {
+    public:
+        Visitor(FileItemPtr &fileItem)
+            : returnFile(fileItem) { }
+    private:
+        void visitLoggerGeneralGroup(const LoggerGeneralGroupPtr &group)
+        {
+            class ItemVisitor : public LoggerConfigurationItemVisitor
+            {
+            public:
+                ItemVisitor(FileItemPtr &fileItem)
+                    : returnFile(fileItem) { }
+            private:
+                void visitFileItem(const FileItemPtr &fileItem)
+                {
+                    returnFile = fileItem;
+                }
+                FileItemPtr &returnFile;
+            };
+
+            LoggerConfigurationItemVisitorPtr generalVisitor = new ItemVisitor(returnFile);
+
+            for (ConfigurationItemDict::const_iterator item = group->configurationItems.begin();
+                    item != group->configurationItems.end();
+                    ++item)
+            {
+                item->second->visit(generalVisitor);
+            }
+        }
+        FileItemPtr &returnFile;
+    };
+
+    FileItemPtr returnFile = 0;
+    LoggerConfigurationGroupVisitorPtr v = new Visitor(returnFile);
+
+    for (ConfigurationGroupSeq::const_iterator group = returnedGroups.begin(); group != returnedGroups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+
+    return returnFile;
+}
diff --git a/server/test/ConfigurationComponent.h b/server/test/ConfigurationComponent.h
index ab9a6ab..228fc36 100644
--- a/server/test/ConfigurationComponent.h
+++ b/server/test/ConfigurationComponent.h
@@ -19,13 +19,15 @@
  */
 
 #include <AsteriskSCF/System/Component/ConfigurationIf.h>
+#include "LoggingConfigurationIf.h"
 
-class LoggingConfigurationPusher
+class LoggingConfigurationHelper
 {
 public:
-    LoggingConfigurationPusher(const AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx &config);
+    LoggingConfigurationHelper(const AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx &config);
     void setLogOutFile(const std::string &fileName, int serialNumber);
     void removeLogOutFile(const std::string &fileName);
+    AsteriskSCF::System::Logger::V1::FileItemPtr getConfiguredOutputFile();
 private:
     AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx mConfigPrx;
 };
diff --git a/server/test/ConfigurationTest.cpp b/server/test/ConfigurationTest.cpp
index 748d258..736c76a 100644
--- a/server/test/ConfigurationTest.cpp
+++ b/server/test/ConfigurationTest.cpp
@@ -29,6 +29,7 @@
 #include "ConfigurationComponent.h"
 
 using namespace AsteriskSCF::System::Configuration::V1;
+using namespace AsteriskSCF::System::Logger::V1;
 
 /* Cache the command line arguments so that Ice can be initialized within the global fixture. */
 struct ArgCacheType
@@ -73,7 +74,7 @@ struct SharedTestData
 {
     Ice::CommunicatorPtr communicator;
     Ice::ObjectAdapterPtr adapter;
-    boost::shared_ptr<LoggingConfigurationPusher> confPusher;
+    boost::shared_ptr<LoggingConfigurationHelper> confHelper;
 };
 
 static SharedTestData TestBed;
@@ -94,7 +95,7 @@ struct GlobalIceFixture
             TestBed.communicator = Ice::initialize(initData);
             TestBed.adapter = TestBed.communicator->createObjectAdapterWithEndpoints("LoggerTestAdapter", "default");
             Ice::ObjectPrx loggerObj = TestBed.communicator->propertyToProxy("LoggerServer.Proxy");
-            TestBed.confPusher.reset(new LoggingConfigurationPusher(ConfigurationServicePrx::checkedCast(loggerObj)));
+            TestBed.confHelper.reset(new LoggingConfigurationHelper(ConfigurationServicePrx::checkedCast(loggerObj)));
         }
         catch (const Ice::Exception &ex)
         {
@@ -118,6 +119,17 @@ BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
 
 static int serial = 100;
 
+static bool checkConfiguredFile(const boost::shared_ptr<LoggingConfigurationHelper> &confHelper,
+        const std::string &fileName)
+{
+    FileItemPtr configuredFile = confHelper->getConfiguredOutputFile();
+    if (configuredFile->fileName == fileName)
+    {
+        return true;
+    }
+    return false;
+}
+
 // Basic test that sets a logging file to use and then
 // Removes the configuration. If this doesn't work, then
 // none of the other tests will work.
@@ -126,14 +138,14 @@ BOOST_AUTO_TEST_CASE(SetAndRemoveFile)
     const std::string fileName("zombiebrains.txt");
     try
     {
-        TestBed.confPusher->setLogOutFile(fileName, serial++);
+        TestBed.confHelper->setLogOutFile(fileName, serial++);
     }
     catch (const SerialConflict &sc)
     {
-        //We should not hit this
+        BOOST_FAIL("SerialConflict thrown when setting output file");
     }
-    //There should be one configured output file.
-    TestBed.confPusher->removeLogOutFile(fileName);
+    checkConfiguredFile(TestBed.confHelper, fileName);
+    TestBed.confHelper->removeLogOutFile(fileName);
     //There should be no configured output files.
 }
 
@@ -143,24 +155,25 @@ BOOST_AUTO_TEST_CASE(FileReplacement)
     const std::string fileName2("skeletonstomachs.txt");
     try
     {
-        TestBed.confPusher->setLogOutFile(fileName1, serial++);
-        //There should be one configured output file.
-        TestBed.confPusher->setLogOutFile(fileName2, serial++);
+        TestBed.confHelper->setLogOutFile(fileName1, serial++);
+        bool correct = checkConfiguredFile(TestBed.confHelper, fileName1);
+        BOOST_CHECK(correct);
+        TestBed.confHelper->setLogOutFile(fileName2, serial++);
     }
     catch (const SerialConflict &sc)
     {
-        //We should not hit this
+        BOOST_FAIL("SerialConflict thrown when setting output file");
     }
-    //There should still be one configured output file. The
-    //name of the output file should be different now.
-    TestBed.confPusher->removeLogOutFile(fileName2);
+    bool correct = checkConfiguredFile(TestBed.confHelper, fileName2);
+    BOOST_CHECK(correct);
+    TestBed.confHelper->removeLogOutFile(fileName2);
     //There should be no configured output files.
 }
 
 BOOST_AUTO_TEST_CASE(NonexistentRemoval)
 {
     const std::string fileName("frankensteinspleens.txt");
-    TestBed.confPusher->removeLogOutFile(fileName);
+    TestBed.confHelper->removeLogOutFile(fileName);
     //There should be no configured output files, and
     //nothing catastrophic should have occurred.
 }
@@ -171,15 +184,24 @@ BOOST_AUTO_TEST_CASE(PurposefulSerialConflict)
     const std::string fileName2("ghostlungs.txt");
     try
     {
-        TestBed.confPusher->setLogOutFile(fileName1, serial--);
-        //There should be one configured output file.
-        TestBed.confPusher->setLogOutFile(fileName2, serial++);
+        TestBed.confHelper->setLogOutFile(fileName1, serial--);
+    }
+    catch (const SerialConflict &ex)
+    {
+        BOOST_FAIL("SerialConflict thrown when setting output file");
+    }
+    bool correct = checkConfiguredFile(TestBed.confHelper, fileName1);
+    BOOST_CHECK(correct);
+    try
+    {
+        TestBed.confHelper->setLogOutFile(fileName2, serial++);
     }
     catch (const SerialConflict &ex)
     {
-        // We should hit this on the second call to setLogOutFile
+        // We should hit this.
     }
-    //There should be one configured output file, the old one.
+    correct = checkConfiguredFile(TestBed.confHelper, fileName1);
+    BOOST_CHECK(correct);
 }
 
 extern "C"

commit 90cdfbef42ca87e8c336ab54f6f02819d36ffb43
Author: Mark Michelson <mmichelson at digium.com>
Date:   Tue Mar 15 15:26:03 2011 -0500

    Add test case skeletons.

diff --git a/server/test/ConfigurationTest.cpp b/server/test/ConfigurationTest.cpp
index 51dcd14..748d258 100644
--- a/server/test/ConfigurationTest.cpp
+++ b/server/test/ConfigurationTest.cpp
@@ -19,12 +19,15 @@
 
 #include <boost/test/unit_test.hpp>
 #include <boost/test/debug.hpp>
+#include <boost/shared_ptr.hpp>
 
 #include <Ice/Ice.h>
 #include <IceBox/IceBox.h>
 
 #include <AsteriskSCF/System/Component/ConfigurationIf.h>
 
+#include "ConfigurationComponent.h"
+
 using namespace AsteriskSCF::System::Configuration::V1;
 
 /* Cache the command line arguments so that Ice can be initialized within the global fixture. */
@@ -70,7 +73,7 @@ struct SharedTestData
 {
     Ice::CommunicatorPtr communicator;
     Ice::ObjectAdapterPtr adapter;
-    ConfigurationServicePrx loggerConfigurationServer;
+    boost::shared_ptr<LoggingConfigurationPusher> confPusher;
 };
 
 static SharedTestData TestBed;
@@ -91,12 +94,14 @@ struct GlobalIceFixture
             TestBed.communicator = Ice::initialize(initData);
             TestBed.adapter = TestBed.communicator->createObjectAdapterWithEndpoints("LoggerTestAdapter", "default");
             Ice::ObjectPrx loggerObj = TestBed.communicator->propertyToProxy("LoggerServer.Proxy");
-            TestBed.loggerConfigurationServer = ConfigurationServicePrx::checkedCast(loggerObj);
+            TestBed.confPusher.reset(new LoggingConfigurationPusher(ConfigurationServicePrx::checkedCast(loggerObj)));
         }
         catch (const Ice::Exception &ex)
         {
             std::cerr << ex << std::endl;
         }
+
+
     }
     ~GlobalIceFixture()
     {
@@ -109,6 +114,74 @@ struct GlobalIceFixture
     }
 };
 
+BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
+
+static int serial = 100;
+
+// Basic test that sets a logging file to use and then
+// Removes the configuration. If this doesn't work, then
+// none of the other tests will work.
+BOOST_AUTO_TEST_CASE(SetAndRemoveFile)
+{
+    const std::string fileName("zombiebrains.txt");
+    try
+    {
+        TestBed.confPusher->setLogOutFile(fileName, serial++);
+    }
+    catch (const SerialConflict &sc)
+    {
+        //We should not hit this
+    }
+    //There should be one configured output file.
+    TestBed.confPusher->removeLogOutFile(fileName);
+    //There should be no configured output files.
+}
+
+BOOST_AUTO_TEST_CASE(FileReplacement)
+{
+    const std::string fileName1("mummyhearts.txt");
+    const std::string fileName2("skeletonstomachs.txt");
+    try
+    {
+        TestBed.confPusher->setLogOutFile(fileName1, serial++);
+        //There should be one configured output file.
+        TestBed.confPusher->setLogOutFile(fileName2, serial++);
+    }
+    catch (const SerialConflict &sc)
+    {
+        //We should not hit this
+    }
+    //There should still be one configured output file. The
+    //name of the output file should be different now.
+    TestBed.confPusher->removeLogOutFile(fileName2);
+    //There should be no configured output files.
+}
+
+BOOST_AUTO_TEST_CASE(NonexistentRemoval)
+{
+    const std::string fileName("frankensteinspleens.txt");
+    TestBed.confPusher->removeLogOutFile(fileName);
+    //There should be no configured output files, and
+    //nothing catastrophic should have occurred.
+}
+
+BOOST_AUTO_TEST_CASE(PurposefulSerialConflict)
+{
+    const std::string fileName1("goblinlivers.txt");
+    const std::string fileName2("ghostlungs.txt");
+    try
+    {
+        TestBed.confPusher->setLogOutFile(fileName1, serial--);
+        //There should be one configured output file.
+        TestBed.confPusher->setLogOutFile(fileName2, serial++);
+    }
+    catch (const SerialConflict &ex)
+    {
+        // We should hit this on the second call to setLogOutFile
+    }
+    //There should be one configured output file, the old one.
+}
+
 extern "C"
 {
 IceBox::Service* create(Ice::CommunicatorPtr communicator)

commit b2631be10abdb630e7f053c4aa2987006250bde7
Author: Mark Michelson <mmichelson at digium.com>
Date:   Tue Mar 15 14:33:49 2011 -0500

    Get some initial setup for the configuration test up and make sure it compiles.
    
    This took waaaaaay longer than it should have.

diff --git a/server/test/CMakeLists.txt b/server/test/CMakeLists.txt
index d98c113..49486fc 100644
--- a/server/test/CMakeLists.txt
+++ b/server/test/CMakeLists.txt
@@ -15,10 +15,7 @@ include_directories(../../include)
 
 asterisk_scf_component_add_file(logging-service-test LoggingServer-test.cpp)
 asterisk_scf_component_add_file(logging-service-test server-test.cpp)
-asterisk_scf_component_add_file(logging-service-test ConfigurationComponent.cpp)
-asterisk_scf_component_add_file(logging-service-test ConfigurationComponent.h)
 
-asterisk_scf_component_add_slice(logging-service-test ../local-slice/LoggingConfigurationIf.ice)
 asterisk_scf_component_add_boost_libraries(logging-service-test unit_test_framework)
 
 include_directories(${API_INCLUDE_DIR})
@@ -27,4 +24,15 @@ target_link_libraries(logging-service-test asterisk-scf-api)
 
 target_link_libraries(logging-service-test logging-service-lib)
 
+asterisk_scf_component_init(ConfigurationTest CXX)
+
+asterisk_scf_component_add_file(ConfigurationTest ConfigurationTest.cpp)
+asterisk_scf_component_add_file(ConfigurationTest ConfigurationComponent.cpp)
+asterisk_scf_component_add_file(ConfigurationTest ConfigurationComponent.h)
+asterisk_scf_component_add_slice(ConfigurationTest ../local-slice/LoggingConfigurationIf.ice)
+asterisk_scf_component_add_boost_libraries(ConfigurationTest unit_test_framework)
+include_directories(${API_INCLUDE_DIR})
+asterisk_scf_component_build_icebox(ConfigurationTest)
+target_link_libraries(ConfigurationTest asterisk-scf-api)
+
 boost_add_test(logging-service-test)
diff --git a/server/test/ConfigurationTest.cpp b/server/test/ConfigurationTest.cpp
new file mode 100644
index 0000000..51dcd14
--- /dev/null
+++ b/server/test/ConfigurationTest.cpp
@@ -0,0 +1,118 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#define BOOST_TEST_MODULE LoggerTestSuite
+#define BOOST_TEST_NO_MAIN
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/debug.hpp>
+
+#include <Ice/Ice.h>
+#include <IceBox/IceBox.h>
+
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+
+using namespace AsteriskSCF::System::Configuration::V1;
+
+/* Cache the command line arguments so that Ice can be initialized within the global fixture. */
+struct ArgCacheType
+{
+public:
+    int argc;
+    char **argv;
+    Ice::PropertiesPtr inheritedProps;
+};
+static ArgCacheType mCachedArgs;
+
+class LoggerConfigurationTest : public IceBox::Service
+{
+public:
+    void start(const std::string &name,
+            const Ice::CommunicatorPtr &communicator,
+            const Ice::StringSeq &args)
+    {
+        std::vector<char const *> argv;
+        argv.push_back(name.c_str());
+        for (Ice::StringSeq::const_iterator i = args.begin();
+             i != args.end();
+             ++i)
+        {
+            argv.push_back(i->c_str());
+        }
+        // null terminated list
+        argv.push_back((const char *) 0);
+    
+        mCachedArgs.argc = argv.size() - 1;
+        mCachedArgs.argv = (char**)&argv[0];
+    
+        int r = ::boost::unit_test::unit_test_main(&init_unit_test, mCachedArgs.argc, mCachedArgs.argv);
+        exit(r);
+    
+    }
+    
+    void stop() { }
+};
+
+struct SharedTestData
+{
+    Ice::CommunicatorPtr communicator;
+    Ice::ObjectAdapterPtr adapter;
+    ConfigurationServicePrx loggerConfigurationServer;
+};
+
+static SharedTestData TestBed;
+
+struct GlobalIceFixture
+{
+    GlobalIceFixture()
+    {
+        BOOST_TEST_MESSAGE("Setting up Logger Server global test fixture");
+        ::boost::debug::detect_memory_leaks(false);
+        ::boost::unit_test::unit_test_log.set_stream(std::cout);
+
+        try
+        {
+            Ice::InitializationData initData;
+            initData.properties = mCachedArgs.inheritedProps;
+
+            TestBed.communicator = Ice::initialize(initData);
+            TestBed.adapter = TestBed.communicator->createObjectAdapterWithEndpoints("LoggerTestAdapter", "default");
+            Ice::ObjectPrx loggerObj = TestBed.communicator->propertyToProxy("LoggerServer.Proxy");
+            TestBed.loggerConfigurationServer = ConfigurationServicePrx::checkedCast(loggerObj);
+        }
+        catch (const Ice::Exception &ex)
+        {
+            std::cerr << ex << std::endl;
+        }
+    }
+    ~GlobalIceFixture()
+    {
+        BOOST_TEST_MESSAGE("Killing the Logging Server global test fixture");
+        if (TestBed.communicator)
+        {
+            TestBed.communicator->shutdown();
+            TestBed.communicator = 0;
+        }
+    }
+};
+
+extern "C"
+{
+IceBox::Service* create(Ice::CommunicatorPtr communicator)
+{
+    return new LoggerConfigurationTest;
+}
+}

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/logger.git



More information about the asterisk-scf-commits mailing list