[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
Tue Apr 5 20:12:28 CDT 2011


branch "master" has been updated
       via  04d3fcd13f2fe2212f3594c7c8bf2113ceb9eb81 (commit)
      from  106875f8c7b241eb99f2ca618bff0933cda59d36 (commit)

Summary of changes:
 config/testutf.config.in |   39 +++++-----
 src/TestUtf.cpp          |  192 +++++++++++++++++++++++++++++++---------------
 2 files changed, 151 insertions(+), 80 deletions(-)


- Log -----------------------------------------------------------------
commit 04d3fcd13f2fe2212f3594c7c8bf2113ceb9eb81
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue Apr 5 20:10:53 2011 -0500

    Incorporated review feedback.

diff --git a/config/testutf.config.in b/config/testutf.config.in
index 9efee38..9388ac8 100644
--- a/config/testutf.config.in
+++ b/config/testutf.config.in
@@ -1,29 +1,23 @@
-# This is a configuration file a single process test of the UTF Test.
+#
+# This is a configuration file for the UTF Test.
+#
+
+Ice.Warn.UnknownProperties=0
 
+############################################
+# Icebox properties for the test environment.
 IceBox.InheritProperties=1
 
 # Boost Test arguments can be passed here.
-# IceBox.Service.TestUtf = TestUtf:create --log_level=all
-IceBox.Service.TestUtf=../src${binsubdir}@testutf:create
-#IceBox.Service.TestUtf = TestUtf:create
+#   Example: IceBox.Service.TestUtf = TestUtf:create --log_level=all
+IceBox.Service.TestUtf=testutf:create --log_level=all
 
-IceBox.Service.ServiceDiscovery=${service_locator_bindir}/src${binsubdir}@service_locator:create
-#IceBox.Service.ServiceDiscovery=service_locator:create
+IceBox.Service.ServiceDiscovery=service_locator:create
 
-IceBox.Service.Logger=${logger_bindir}/server/src${binsubdir}@logging-service:createLoggingService
-#IceBox.Service.Logger=logging-service:createLoggingService
+IceBox.Service.Logger=logging-service:createLoggingService
 
 IceBox.LoadOrder=ServiceDiscovery,Logger,TestUtf
 
-# Where to find the Service Locator manager. We need the Service Locator in order to be able to plug in to the Asterisk SCF system Discovery mechanisms.
-LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
-
-# Where to find the Service Locator.
-LocatorService.Proxy=LocatorService:tcp -p 4411
-
-# Test endpoints for IceStorm
-TopicManager.Proxy=AsteriskSCFIceStorm/TopicManager:default -p 10000
-
 ###########################################
 # UTF Test properties
 
@@ -36,9 +30,18 @@ TestUtf.ThreadPool.SizeWarn=9
 TestUtf.Standby = no
 
 TestUtf.Greek = ὕαλον
-TestUtf.Russian = "По ней стремился одиноко"
+TestUtf.Russian = По ней стремился
 TestUtf.Chinese = 私はガ
 
+TestUtf.ScriptLocation=UtfConfigurator.py
+
+# Where to find the Service Locator manager. We need the Service Locator in order to be able to plug in to the Asterisk SCF system Discovery mechanisms.
+LocatorServiceManagement.Proxy=LocatorServiceManagement:tcp -p 4422
+# Where to find the Service Locator.
+LocatorService.Proxy=LocatorService:tcp -p 4411
+
+# Test endpoints for IceStorm
+TopicManager.Proxy=AsteriskSCFIceStorm/TopicManager:default -p 10000
 
 ##########################################
 # Service Locator properties
diff --git a/src/TestUtf.cpp b/src/TestUtf.cpp
index 396783b..eb09be6 100644
--- a/src/TestUtf.cpp
+++ b/src/TestUtf.cpp
@@ -18,8 +18,9 @@
 
 #include <boost/test/unit_test.hpp>
 #include <boost/test/debug.hpp>
-#include <boost/thread/thread.hpp> 
+#include <boost/format.hpp>
 #include <boost/algorithm/string.hpp>
+
 #include <fstream>
 
 #include <Ice/Ice.h>
@@ -100,15 +101,12 @@ struct SharedTestData
     Ice::ObjectAdapterPtr adapter;
 };
 
-
 /**
  * Instantiate our shared data.
  */
 SharedTestData SharedTestData::instance;
 
-
-const string LocatorObjectId("TestLocator");
-
+const string LogFileName("asterisk-scf.log"); // This val is currently hard-coded in logger service.
 /**
  * A global fixture for Ice initialization.
  * Provides setup/teardown for the entire set of tests.
@@ -117,11 +115,21 @@ struct GlobalIceFixture
 {
     GlobalIceFixture()
     {
-        BOOST_TEST_MESSAGE("Setting up Basic Rounting Service test fixture");
+        BOOST_TEST_MESSAGE("Setting up test fixture");
 
         ::boost::debug::detect_memory_leaks(false);
         ::boost::unit_test::unit_test_log.set_stream( std::cout );
 
+        try
+        {
+            // Delete old log file.
+            string command("rm " + LogFileName);
+            system(command.c_str());
+        }
+        catch(const std::exception&)
+        {
+        }
+
         int status = 0;
         try
         {
@@ -132,7 +140,7 @@ struct GlobalIceFixture
             SharedTestData::instance.communicator = Ice::initialize(initData);
 
             Ice::PropertiesPtr props = SharedTestData::instance.communicator->getProperties();
-            SharedTestData::instance.adapter = SharedTestData::instance.communicator->createObjectAdapterWithEndpoints("TestUtf", "default -p 10100");
+            SharedTestData::instance.adapter = SharedTestData::instance.communicator->createObjectAdapter("TestUtf");
 
             // setup the logger
             ConfiguredIceLoggerPtr mIceLogger = createIceLogger(SharedTestData::instance.adapter);
@@ -141,7 +149,7 @@ struct GlobalIceFixture
             SharedTestData::instance.adapter->activate();
 
             // Give the logger configuration time to complete. 
-            IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1000));
+            IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(2000));
         }
         catch (const Ice::Exception& ex)
         {
@@ -157,7 +165,7 @@ struct GlobalIceFixture
 
     ~GlobalIceFixture()
     {
-        BOOST_TEST_MESSAGE("Tearing down Routing Test global test fixture");
+        BOOST_TEST_MESSAGE("Tearing down global test fixture");
 
 
         if (SharedTestData::instance.communicator)
@@ -174,20 +182,110 @@ BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
 
 const std::string HardCoded("Τη γλώσσα μου έδωσαν ελληνική");
 
+// Test values for comparisons.
+const char HardCodedBytes[] = 
+{ 
+    '\xce','\xa4','\xce','\xb7','\x20','\xce','\xb3','\xce','\xbb','\xcf',
+    '\x8e','\xcf','\x83','\xcf','\x83','\xce','\xb1','\x20','\xce','\xbc',
+    '\xce','\xbf','\xcf','\x85','\x20','\xce','\xad','\xce','\xb4','\xcf',
+    '\x89','\xcf','\x83','\xce','\xb1','\xce','\xbd','\x20','\xce','\xb5',
+    '\xce','\xbb','\xce','\xbb','\xce','\xb7','\xce','\xbd','\xce','\xb9',
+    '\xce','\xba','\xce','\xae',0
+};
+
+const char GreekBytes[] = 
+{
+    '\xe1','\xbd','\x95','\xce','\xb1','\xce','\xbb','\xce','\xbf','\xce',
+    '\xbd',0
+};
+
+const char RussianBytes[] = 
+{
+    '\xd0','\x9f','\xd0','\xbe','\x20','\xd0','\xbd','\xd0','\xb5','\xd0',
+    '\xb9','\x20','\xd1','\x81','\xd1','\x82','\xd1','\x80','\xd0','\xb5',
+    '\xd0','\xbc','\xd0','\xb8','\xd0','\xbb','\xd1','\x81','\xd1','\x8f',
+    0   
+};
+
+const char ChineseBytes[] = 
+{
+    '\xe7','\xa7','\x81','\xe3','\x81','\xaf','\xe3','\x82','\xac',0
+};
+
+/**
+ * Utiltity to return the last string logged. This assumes
+ * a particular output format, as used in throughout these tests. 
+ */
+std::string getLastLoggedString()
+{
+    try
+    {
+        vector<string> lines;
+
+        // Open the log file we've been creating.
+        std::ifstream instream(LogFileName);
+        BOOST_CHECK(instream.is_open() && instream.good());
+
+        std::string line;
+        while(std::getline(instream, line))
+        {
+            BOOST_CHECK(instream.rdstate() == ifstream::goodbit);
+            lines.push_back(line);
+        }
+        BOOST_CHECK(lines.size() > 0);
+        
+        line = lines[lines.size() - 1];
+
+        size_t marker = line.find_first_of(":");
+        BOOST_CHECK(marker != std::string::npos);
+        std::string content = line.substr(marker+1, line.length());
+        BOOST_CHECK(content.length() > 0);
+        boost::trim(content);
+
+        return(content);
+    }
+    catch (const std::exception &e)
+    {
+        BOOST_FAIL(e.what());
+    }
+
+}
+
+/**
+ * Utiltity to verify a byte sequence of UTF encoding matches the 
+ * last string written to the log file. 
+ */
+bool verifyLog(const char* bytes)
+{
+    string compareStr(bytes);
+    //IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1000));
+
+    string lastLoggedStr = getLastLoggedString();
+    
+    int debugVal = lastLoggedStr.compare(compareStr);
+
+    // To see this output, pass in boost parameter: --log_level=all 
+    string db = str(boost::format("verifyLog: lastLoggedStr.length=%1%, compareStr.length=%2%, compareResult=%3%") % lastLoggedStr.length() % compareStr.length() % debugVal);
+    BOOST_MESSAGE(db);
+
+    return (lastLoggedStr.compare(compareStr) == 0);
+}
+
 /**
  * Test passing a hard-coded UTF-8 string across the Ice interface to the logger.
  */
 BOOST_AUTO_TEST_CASE(LogUtfStringConstant)
 {
-    bool addLocatorSucceeded(true);
     try
     {
         BOOST_TEST_MESSAGE("BOOST_TEST_MESSAGE: s=" + HardCoded);
-		lg(Info) << "Logging a string const: " << HardCoded;
+        lg(Info) << "Logging a string const: " << HardCoded;
+
+        BOOST_CHECK(verifyLog(HardCodedBytes));
     }
-    catch (...)
+    catch (const std::exception &e)
     {
-        BOOST_CHECK(false);
+        BOOST_FAIL(e.what());
     }
 }
 
@@ -196,83 +294,53 @@ BOOST_AUTO_TEST_CASE(LogUtfStringConstant)
  * Testing:
  *   - Ice properties as UTF-8 strings
  *   - Passing UTF-8 encoded strings across Ice interface
- *   - Logger handling the UTF-8 string (at least that the client side is free of exceptions)
+ *   - Logger client handling the UTF-8 string without throwing exceptions
+ *   - Logger server's file out put matches
  */
 BOOST_AUTO_TEST_CASE(LogUtfIceProperties)
 {
-    bool addLocatorSucceeded(true);
     try
     {
         std::string Greek = SharedTestData::instance.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", "");
         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", "");
         BOOST_TEST_MESSAGE("BOOST_TEST_MESSAGE: Chinese = " + Chinese);
         lg(Info) << "Logging Chinese: " << Chinese;
+        BOOST_CHECK(verifyLog(ChineseBytes));
     }
-    catch (...)
+    catch (const std::exception &e)
     {
-        BOOST_CHECK(false);
+        BOOST_FAIL(e.what());
     }
 }
 
 /**
- * This test compares the logged output to the original input data from the 
- * previous tests.
+ * This tests loading configuration data in the same method our Python congigurator does. 
+ * The config file loaded by Python has a UTF-8 string that it sends to the logger. 
  * Testing:
- *   - Logger handling the of UTF-8 string on server side.
+ *   - Python configurators loading UTF-8 strings
+ *   - Python configurator sending UTF-8 encoded strings across Ice interface
  */
-BOOST_AUTO_TEST_CASE(LogUtfLogFile)
+BOOST_AUTO_TEST_CASE(PyConfigTest)
 {
-    bool addLocatorSucceeded(true);
     try
     {
-        // Open the log file we've been creating.
-        std::ifstream instream("asterisk-scf.log");
-        std::string line;
-
-        // The first line should match our hard-coded value
-        std::getline(instream, line);
-        size_t marker = line.find_first_of(":");
-        std::string content = line.substr(marker+1, line.length());
-        boost::trim(content);
-
-        BOOST_CHECK(content.compare(HardCoded) == 0);
-
-        // Next line should match our property with Greek UTF string
-        std::getline(instream, line);
-        marker = line.find_first_of(":");
-        content = line.substr(marker+1, line.length());
-        boost::trim(content);
-
-        std::string Greek = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.Greek", "");
-        BOOST_CHECK(content.compare(Greek) == 0);
-
-        // Next line should match our property with Russian UTF string
-        std::getline(instream, line);
-        marker = line.find_first_of(":");
-        content = line.substr(marker+1, line.length());
-        boost::trim(content);
-
-        std::string Russian = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.Russian", "");
-        BOOST_CHECK(content.compare(Russian) == 0);
-
-        // Next line should match our property with Chineses UTF string
-        std::getline(instream, line);
-        marker = line.find_first_of(":");
-        content = line.substr(marker+1, line.length());
-        boost::trim(content);
-
-        std::string Chinese = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.Chinese", "");
-        BOOST_CHECK(content.compare(Chinese) == 0);
+        // Incomplete!
+        //system("python_d --config=configurator.config");
+        //system("python_d Simply.py");
     }
-    catch (...)
+    catch (const std::exception &e)
     {
-        BOOST_CHECK(false);
+        BOOST_FAIL(e.what());
     }
 }
+
+

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


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



More information about the asterisk-scf-commits mailing list