[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
Wed Apr 6 17:39:06 CDT 2011


branch "master" has been updated
       via  96e4a7757c342197c6c9254b1a561cdb168c6a66 (commit)
      from  04d3fcd13f2fe2212f3594c7c8bf2113ceb9eb81 (commit)

Summary of changes:
 config/CMakeLists.txt                 |    7 +++
 config/testutf.config.in              |   17 ++++----
 config/testutf.configurator.config.in |    3 +
 src/CMakeLists.txt                    |    5 ++
 src/TestUtf.cpp                       |   22 +++++++---
 src/UtfConfigurationIf.ice            |   56 ++++++++++++++++++++++++
 src/UtfTestMockConfigurator.py        |   75 +++++++++++++++++++++++++++++++++
 src/UtfTestPythonConfig.py            |   41 ++++++++++++++++++
 8 files changed, 210 insertions(+), 16 deletions(-)
 create mode 100644 config/testutf.configurator.config.in
 create mode 100644 src/UtfConfigurationIf.ice
 create mode 100644 src/UtfTestMockConfigurator.py
 create mode 100644 src/UtfTestPythonConfig.py


- Log -----------------------------------------------------------------
commit 96e4a7757c342197c6c9254b1a561cdb168c6a66
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Wed Apr 6 17:37:33 2011 -0500

    Added UTF testing of python script that behaves similarly to Asterisk SCF python-based configurators.

diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt
index 32a4848..a3dfce0 100644
--- a/config/CMakeLists.txt
+++ b/config/CMakeLists.txt
@@ -6,4 +6,11 @@
 # All rights reserved.
 #
 
+if(WIN32 AND (CMAKE_BUILD_TYPE STREQUAL debug))
+    set(PYTHON_NAME "python_d")
+else()
+    set(PYTHON_NAME "python")
+endif()
+
 configure_file(testutf.config.in testutf.config)
+configure_file(testutf.configurator.config.in testutf.configurator.config)
diff --git a/config/testutf.config.in b/config/testutf.config.in
index 9388ac8..c4d8fde 100644
--- a/config/testutf.config.in
+++ b/config/testutf.config.in
@@ -33,7 +33,12 @@ TestUtf.Greek = ὕαλον
 TestUtf.Russian = По ней стремился
 TestUtf.Chinese = 私はガ
 
-TestUtf.ScriptLocation=UtfConfigurator.py
+TestUtf.ScriptLocation=UtfTestPythonConfig.py
+TestUtf.PyTestConfigFile = testutf.configurator.config
+TestUtf.PythonName = ${PYTHON_NAME}
+
+#####################################
+# Other settings for test driver.
 
 # 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
@@ -43,9 +48,6 @@ LocatorService.Proxy=LocatorService:tcp -p 4411
 # Test endpoints for IceStorm
 TopicManager.Proxy=AsteriskSCFIceStorm/TopicManager:default -p 10000
 
-##########################################
-# Service Locator properties
-
 AsteriskSCFIceStorm.InstanceName=AsteriskSCFIceStorm
 #
 # This property defines the endpoints on which the IceStorm
@@ -70,15 +72,12 @@ AsteriskSCFIceStorm.Publish.Endpoints=tcp -p 10001:udp -p 10001
 #
 AsteriskSCFIceStorm.Trace.TopicManager=2
 AsteriskSCFIceStorm.Transient=1
-
-#
 AsteriskSCFIceStorm.Flush.Timeout=2000
-# This is a configuration file used in conjunction with the service locator test driver
 
-# Test endpoints for the service locator management adapter
+# Endpoints for the service locator management adapter
 ServiceLocatorManagementAdapter.Endpoints=tcp -p 4422
 
-# Test endpoints for the service locator adapter
+# Endpoints for the service locator adapter
 ServiceLocatorAdapter.Endpoints=tcp -p 4411
 
 # Logger configuration
diff --git a/config/testutf.configurator.config.in b/config/testutf.configurator.config.in
new file mode 100644
index 0000000..02e1547
--- /dev/null
+++ b/config/testutf.configurator.config.in
@@ -0,0 +1,3 @@
+[general]
+utftext=ὕαλον
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4f7980f..9a9676c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -16,9 +16,14 @@ if(NOT logger_dir)
 endif()
 include_directories(${logger_dir}/include)
 
+include_directories(${PYTHON_INCLUDE_DIRS})
+
 if(integrated_build STREQUAL "true")
    if(Win32)
       set(extra "../")
    endif()
    icebox_add_test(testutf testutf ${extra}../config/testutf.config)
 endif()
+
+configure_file(UtfTestPythonConfig.py UtfTestPythonConfig.py COPYONLY)
+configure_file(UtfTestMockConfigurator.py UtfTestMockConfigurator.py COPYONLY)
\ No newline at end of file
diff --git a/src/TestUtf.cpp b/src/TestUtf.cpp
index eb09be6..a8fa39a 100644
--- a/src/TestUtf.cpp
+++ b/src/TestUtf.cpp
@@ -258,14 +258,13 @@ std::string getLastLoggedString()
 bool verifyLog(const char* bytes)
 {
     string compareStr(bytes);
-    //IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1000));
 
     string lastLoggedStr = getLastLoggedString();
     
-    int debugVal = lastLoggedStr.compare(compareStr);
+    int compareVal = 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);
+    // 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);
     BOOST_MESSAGE(db);
 
     return (lastLoggedStr.compare(compareStr) == 0);
@@ -333,9 +332,18 @@ BOOST_AUTO_TEST_CASE(PyConfigTest)
 {
     try
     {
-        // Incomplete!
-        //system("python_d --config=configurator.config");
-        //system("python_d Simply.py");
+         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");
+       
+         string command = pyCommand + " " + pyScript + " --config=" + pyConfigFile + " --Ice.Config=" + iceConfigFile ;
+         BOOST_MESSAGE("Launching python configurator test: " + command);
+
+         // The return value will be platform specific. :-(
+         int val = std::system(command.c_str());
+
+         BOOST_CHECK(verifyLog(GreekBytes));
     }
     catch (const std::exception &e)
     {
diff --git a/src/UtfConfigurationIf.ice b/src/UtfConfigurationIf.ice
new file mode 100644
index 0000000..eaf4b5a
--- /dev/null
+++ b/src/UtfConfigurationIf.ice
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "ConfigurationIf.ice"
+
+module AsteriskSCF
+{
+
+module System
+{
+
+module Configuration
+{
+
+module UtfTest
+{
+
+["suppress"]
+module V1
+{
+
+   /* General configuration group of items. */
+   class GeneralGroup extends AsteriskSCF::System::Configuration::V1::ConfigurationGroup
+   {
+   };
+
+   /* Simple test item. */
+   class UtfTestItem extends AsteriskSCF::System::Configuration::V1::ConfigurationItem
+   {
+      string utftext;
+   };
+
+}; /* End of namespace V1 */
+
+}; /* End of namespace UtfTest */
+
+}; /* End of namespace Configuration */
+
+}; /* End of namespace System */
+
+}; /* End of namespace AsteriskSCF */
diff --git a/src/UtfTestMockConfigurator.py b/src/UtfTestMockConfigurator.py
new file mode 100644
index 0000000..4974063
--- /dev/null
+++ b/src/UtfTestMockConfigurator.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+
+# UTF-8 Testing mock configurator
+
+# Bring in the common configuration infrastructure
+import ConfigParser, os, Ice, getopt, sys, time
+
+#  -IC:\Ice-3.4.1\slice 
+# Load our component specific configuration definitions
+
+Ice.loadSlice('-I. -IC:\Ice-3.4.1\slice --all TestUtfConfigurationIf.ice LoggerIf.ice ServiceLocatorIf.ice')
+
+import AsteriskSCF.System.Configuration.UtfTest.V1
+import AsteriskSCF.System.Configuration.V1
+import AsteriskSCF.System.Logging
+import AsteriskSCF.Core.Discovery.V1
+
+# Exception class used within the configurator application
+class ConfiguratorError(Exception):
+    def __init__(self, value):
+        self.value = value
+
+    def __str__(self):
+        return repr(self.value)
+
+# This class emulates the Asterisk SCF configurator in that it loads 
+# a config file using ConfigParser. To test UTF strings in the config files,
+# this class sends the config item to the logger. 
+class ConfiguratorStub:
+    def __init__(self, configFile):
+        if configFile == '':
+	    raise  ConfiguratorError('Configuration utility implementation issue - No default configuration filename specified.')
+
+        self.configFile = configFile
+
+        self.status = 0
+        self.ic = None
+	try:
+	    self.ic = Ice.initialize(sys.argv)
+	except:
+	    traceback.print_exc()
+	    self.status = 1
+
+    # This operation will hang on Windows if launched via std::system()
+    def shutdown(self):
+	print >> sys.stdout, "shutdown(): called"
+	if self.ic:
+	    try:
+	        print >> sys.stdout, "shutdown(): destroying communicator..."
+                self.ic.destroy() # <<< HANGS
+	        print >> sys.stdout, "shutdown(): communicator destroyed."
+	    except:
+		trackback_print_exc()
+		self.status = 1
+
+        return self.status
+
+    def run(self, args):
+        config = ConfigParser.ConfigParser()
+
+	try:
+	    config.readfp(open(self.configFile))
+	except IOError:
+	    print >> sys.stderr, "Config file " + self.configFile + " could not be loaded."
+	    return -1
+
+        params = AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams()
+	params.category = AsteriskSCF.System.Logging.LoggingServerCategory
+        serviceLocator =  AsteriskSCF.Core.Discovery.V1.ServiceLocatorPrx.checkedCast(self.ic.propertyToProxy("LocatorService.Proxy"))
+	loggingService =  AsteriskSCF.System.Logging.LoggingServerPrx.uncheckedCast(serviceLocator.locate(params))
+
+	utftext = "Python UTF Config:" +  config.get('general', 'utftext')
+	loggingService.logs('Python.UtfTest', AsteriskSCF.System.Logging.Level.Critical, utftext)
+
+        return 0
diff --git a/src/UtfTestPythonConfig.py b/src/UtfTestPythonConfig.py
new file mode 100644
index 0000000..c208c3f
--- /dev/null
+++ b/src/UtfTestPythonConfig.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+# UTF-8 Testing of Python configurator
+
+# Bring in the common configuration infrastructure
+import Ice
+import Ice_BuiltinSequences_ice
+import UtfTestMockConfigurator, sys
+from optparse import OptionParser
+
+# Load our component specific configuration definitions
+Ice.loadSlice('-I. --all TestUtfConfigurationIf.ice')
+Ice.loadSlice('-I. --all LoggerIf.ice')
+import AsteriskSCF.System.Configuration.UtfTest.V1
+
+usage = "usage: %prog [options] arg1 arg2"
+parser = OptionParser(usage=usage)
+parser.add_option("--c", "--config", metavar="FILE", 
+		  help="Config-like file to process.", 
+		  dest="configfile", 
+		  default="testutf.configurator.config")
+parser.add_option("--Ice.Config", metavar="FILE", 
+		  help="Config-like file to process.") 
+(options, args) = parser.parse_args()
+
+if options.configfile:
+    configfile=options.configfile
+
+# Make a configurator application and let it run
+iceapp = UtfTestMockConfigurator.ConfiguratorStub(configfile)
+
+# UtfTestMockConfigurator class is NOT dervied from Ice.Application,
+# which is why we're calling run() instead of main(). 
+iceapp.run(sys.argv)
+print >> sys.stdout, "Ice app completed."
+
+# I am purposely not letting the communicator shutdown() operation get called.
+# It hangs when on Windows when this script is invoked via std::system.
+# val=iceapp.shutdown() # <<< HANGS
+
+sys.exit(0)

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


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



More information about the asterisk-scf-commits mailing list