[asterisk-scf-commits] asterisk-scf/integration/test-utf.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Apr 7 13:30:04 CDT 2011


branch "master" has been updated
       via  de07f0a03c963c082b8ba075ef40da34b30547de (commit)
      from  b369e703bd13c9e99afb65e84c7aa6fbcff5526e (commit)

Summary of changes:
 src/CMakeLists.txt |   10 ++--
 src/TestUtf.cpp    |  139 +++++++++-------------------------------------------
 2 files changed, 30 insertions(+), 119 deletions(-)


- Log -----------------------------------------------------------------
commit de07f0a03c963c082b8ba075ef40da34b30547de
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Thu Apr 7 13:28:59 2011 -0500

    Refactored the boosttest/icebox service integration into IceBoxBoostTest.h under ice-util-cpp.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9a9676c..f8ba360 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,15 +7,14 @@ asterisk_scf_component_add_ice_libraries(testutf IceStorm)
 asterisk_scf_component_add_boost_libraries(testutf  unit_test_framework)
 
 include_directories(${API_INCLUDE_DIR})
-asterisk_scf_component_build_icebox(testutf)
-target_link_libraries(testutf asterisk-scf-api logging-client)
-
 
 if(NOT logger_dir)
    message(FATAL_ERROR "The logger directory could not be found ${logger_dir}")
 endif()
 include_directories(${logger_dir}/include)
 
+include_directories(${utils_dir}/TestFixture/include)
+
 include_directories(${PYTHON_INCLUDE_DIRS})
 
 if(integrated_build STREQUAL "true")
@@ -25,5 +24,8 @@ if(integrated_build STREQUAL "true")
    icebox_add_test(testutf testutf ${extra}../config/testutf.config)
 endif()
 
+asterisk_scf_component_build_icebox(testutf)
+target_link_libraries(testutf asterisk-scf-api logging-client)
+
 configure_file(UtfTestPythonConfig.py UtfTestPythonConfig.py COPYONLY)
-configure_file(UtfTestMockConfigurator.py UtfTestMockConfigurator.py COPYONLY)
\ No newline at end of file
+configure_file(UtfTestMockConfigurator.py UtfTestMockConfigurator.py COPYONLY)
diff --git a/src/TestUtf.cpp b/src/TestUtf.cpp
index a8fa39a..49ba57f 100644
--- a/src/TestUtf.cpp
+++ b/src/TestUtf.cpp
@@ -14,9 +14,7 @@
  * at the top of the source tree.
  */
 #define BOOST_TEST_MODULE TestUtf
-#define BOOST_TEST_NO_MAIN
 
-#include <boost/test/unit_test.hpp>
 #include <boost/test/debug.hpp>
 #include <boost/format.hpp>
 #include <boost/algorithm/string.hpp>
@@ -26,6 +24,7 @@
 #include <Ice/Ice.h>
 #include <IceBox/IceBox.h>
 
+#include <AsteriskSCF/IceBoxBoostTest.h>
 #include <AsteriskSCF/Logger/IceLogger.h>
 #include <AsteriskSCF/logger.h>
 
@@ -37,83 +36,14 @@ namespace
 Logger lg = getLoggerFactory().getLogger("AsteriskSCF.TestUtf");
 }
 
-/* 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;
-
-/**
- * Test service, for loading into icebox
- */
-class TestUtf : public IceBox::Service
-{
-public:
-    void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&);
-    void stop();
-};
-
-void TestUtf::start(std::string const &name,
-    Ice::CommunicatorPtr const &communicator,
-    Ice::StringSeq const &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((char const *) 0);
-
-    mCachedArgs.argc = argv.size() - 1;
-    mCachedArgs.argv = (char**)&argv[0];
-    mCachedArgs.inheritedProps = communicator->getProperties();
-
-    int r = ::boost::unit_test::unit_test_main(&init_unit_test, mCachedArgs.argc, mCachedArgs.argv);
-    exit(r);
-}
-
-void TestUtf::stop()
-{
-}
-
-extern "C"
-{
-ASTERISK_SCF_ICEBOX_EXPORT IceBox::Service* create(Ice::CommunicatorPtr communicator)
-{
-    return new TestUtf;
-}
-}
-
-/**
- * Pseudo singleton for sharing data among test artifacts.
- */
-struct SharedTestData
-{
-    static SharedTestData instance;
-
-    Ice::CommunicatorPtr communicator;
-    Ice::ObjectAdapterPtr adapter;
-};
-
-/**
- * Instantiate our shared data.
- */
-SharedTestData SharedTestData::instance;
-
 const string LogFileName("asterisk-scf.log"); // This val is currently hard-coded in logger service.
 /**
- * A global fixture for Ice initialization.
+ * A global fixture. Not much to do when running solely as an Ice client. (i.e. No servants)
  * Provides setup/teardown for the entire set of tests.
  */
-struct GlobalIceFixture
+struct GlobalFixture
 {
-    GlobalIceFixture()
+    GlobalFixture()
     {
         BOOST_TEST_MESSAGE("Setting up test fixture");
 
@@ -130,55 +60,34 @@ struct GlobalIceFixture
         {
         }
 
-        int status = 0;
         try
         {
-            Ice::InitializationData initData;
-            initData.properties = mCachedArgs.inheritedProps;
-
-            // Set up incoming adapter. This is where we'll publish our proxies.
-            SharedTestData::instance.communicator = Ice::initialize(initData);
+            IceBoxTestEnv.adapter = IceBoxTestEnv.communicator->createObjectAdapter("TestUtf");
 
-            Ice::PropertiesPtr props = SharedTestData::instance.communicator->getProperties();
-            SharedTestData::instance.adapter = SharedTestData::instance.communicator->createObjectAdapter("TestUtf");
-
-            // setup the logger
-            ConfiguredIceLoggerPtr mIceLogger = createIceLogger(SharedTestData::instance.adapter);
+            ConfiguredIceLoggerPtr mIceLogger = createIceLogger(IceBoxTestEnv.adapter);
             getLoggerFactory().setLogOutput(mIceLogger->getLogger());
 
-            SharedTestData::instance.adapter->activate();
+            IceBoxTestEnv.adapter->activate();
 
             // Give the logger configuration time to complete. 
             IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(2000));
         }
-        catch (const Ice::Exception& ex)
-        {
-            cerr << ex << endl;
-            status = 1;
-        }
-        catch (const char* msg)
+        catch(const Ice::Exception& e)
         {
-            cerr << msg << endl;
-            status = 1;
+            cerr << e << endl;
         }
+
+
     } // end Fixture() constructor
 
-    ~GlobalIceFixture()
+    ~GlobalFixture()
     {
         BOOST_TEST_MESSAGE("Tearing down global test fixture");
-
-
-        if (SharedTestData::instance.communicator)
-        {
-            SharedTestData::instance.communicator->shutdown();
-            SharedTestData::instance.communicator = 0;
-        }
     }
-private:
-
+    
 };
 
-BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
+BOOST_GLOBAL_FIXTURE(GlobalFixture);
 
 const std::string HardCoded("Τη γλώσσα μου έδωσαν ελληνική");
 
@@ -261,13 +170,13 @@ bool verifyLog(const char* bytes)
 
     string lastLoggedStr = getLastLoggedString();
     
-    int compareVal = lastLoggedStr.compare(compareStr);
+    int compareResult = lastLoggedStr.compare(compareStr);
 
     // To see this output, pass boost this parameter to the UtfTest component via the Icebox property: --log_level=all 
-    string db = str(boost::format("verifyLog: lastLoggedStr.length=%1%, compareStr.length=%2%, compareResult=%3%") % lastLoggedStr.length() % compareStr.length() % compareVal);
+    string db = str(boost::format("verifyLog: lastLoggedStr.length=%1%, compareStr.length=%2%, compareResult=%3%") % lastLoggedStr.length() % compareStr.length() % compareResult);
     BOOST_MESSAGE(db);
 
-    return (lastLoggedStr.compare(compareStr) == 0);
+    return (compareResult == 0);
 }
 
 /**
@@ -300,17 +209,17 @@ BOOST_AUTO_TEST_CASE(LogUtfIceProperties)
 {
     try
     {
-        std::string Greek = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.Greek", "");
+        std::string Greek = IceBoxTestEnv.communicator->getProperties()->getPropertyWithDefault("TestUtf.Greek", "");
         BOOST_TEST_MESSAGE("BOOST_TEST_MESSAGE: Greek = " + Greek);
         lg(Info) << "Logging Greek: " << Greek;
         BOOST_CHECK(verifyLog(GreekBytes));
 
-        std::string Russian = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.Russian", "");
+        std::string Russian = IceBoxTestEnv.communicator->getProperties()->getPropertyWithDefault("TestUtf.Russian", "");
         BOOST_TEST_MESSAGE("BOOST_TEST_MESSAGE: Russian = " + Russian);
         lg(Info) << "Logging Russian: " << Russian;
         BOOST_CHECK(verifyLog(RussianBytes));
 
-        std::string Chinese = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.Chinese", "");
+        std::string Chinese = IceBoxTestEnv.communicator->getProperties()->getPropertyWithDefault("TestUtf.Chinese", "");
         BOOST_TEST_MESSAGE("BOOST_TEST_MESSAGE: Chinese = " + Chinese);
         lg(Info) << "Logging Chinese: " << Chinese;
         BOOST_CHECK(verifyLog(ChineseBytes));
@@ -332,10 +241,10 @@ BOOST_AUTO_TEST_CASE(PyConfigTest)
 {
     try
     {
-         std::string pyCommand = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.PythonName", "python");
-         std::string pyConfigFile = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.PyTestConfigFile", "testutf.configurator.config");
-         std::string pyScript = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.ScriptLocation", "UtfTestPythonConfig.py");
-         std::string iceConfigFile = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("Ice.Config", "testutf.config");
+         std::string pyCommand = IceBoxTestEnv.communicator->getProperties()->getPropertyWithDefault("TestUtf.PythonName", "python");
+         std::string pyConfigFile = IceBoxTestEnv.communicator->getProperties()->getPropertyWithDefault("TestUtf.PyTestConfigFile", "testutf.configurator.config");
+         std::string pyScript = IceBoxTestEnv.communicator->getProperties()->getPropertyWithDefault("TestUtf.ScriptLocation", "UtfTestPythonConfig.py");
+         std::string iceConfigFile = IceBoxTestEnv.communicator->getProperties()->getPropertyWithDefault("Ice.Config", "testutf.config");
        
          string command = pyCommand + " " + pyScript + " --config=" + pyConfigFile + " --Ice.Config=" + iceConfigFile ;
          BOOST_MESSAGE("Launching python configurator test: " + command);

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


-- 
asterisk-scf/integration/test-utf.git



More information about the asterisk-scf-commits mailing list