[asterisk-scf-commits] asterisk-scf/release/test-utf.git branch "master" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Fri Apr 15 12:25:37 CDT 2011
branch "master" has been created
at b766c0ae51f7363ca071a1901843d44ff1939052 (commit)
- Log -----------------------------------------------------------------
commit b766c0ae51f7363ca071a1901843d44ff1939052
Author: Ken Hunt <ken.hunt at digium.com>
Date: Fri Apr 15 12:16:34 2011 -0500
Linux compilation issues addressed.
diff --git a/src/TestUtf.cpp b/src/TestUtf.cpp
index 49ba57f..48e3f73 100644
--- a/src/TestUtf.cpp
+++ b/src/TestUtf.cpp
@@ -127,6 +127,7 @@ const char ChineseBytes[] =
*/
std::string getLastLoggedString()
{
+ std::string content;
try
{
vector<string> lines;
@@ -147,17 +148,18 @@ std::string getLastLoggedString()
size_t marker = line.find_first_of(":");
BOOST_CHECK(marker != std::string::npos);
- std::string content = line.substr(marker+1, line.length());
+
+ 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());
}
+ return(content);
}
/**
@@ -252,6 +254,8 @@ BOOST_AUTO_TEST_CASE(PyConfigTest)
// The return value will be platform specific. :-(
int val = std::system(command.c_str());
+ BOOST_MESSAGE("Return val from system command: " + val);
+
BOOST_CHECK(verifyLog(GreekBytes));
}
catch (const std::exception &e)
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);
commit b369e703bd13c9e99afb65e84c7aa6fbcff5526e
Author: Ken Hunt <ken.hunt at digium.com>
Date: Wed Apr 6 17:56:50 2011 -0500
Minor cleanup. Copyright headers, comments, etc.
diff --git a/src/UtfConfigurationIf.ice b/src/UtfConfigurationIf.ice
index eaf4b5a..ab2a02d 100644
--- a/src/UtfConfigurationIf.ice
+++ b/src/UtfConfigurationIf.ice
@@ -1,7 +1,7 @@
/*
* Asterisk SCF -- An open-source communications framework.
*
- * Copyright (C) 2010, Digium, Inc.
+ * Copyright (C) 2010-2011, Digium, Inc.
*
* See http://www.asterisk.org for more information about
* the Asterisk SCF project. Please do not directly contact
@@ -16,6 +16,12 @@
#pragma once
+//////////////////////////////////////
+// This file defines a test interface
+// for a simple configuration item.
+// Used for verifying correct handling
+// of UTF strings.
+
#include "ConfigurationIf.ice"
module AsteriskSCF
diff --git a/src/UtfTestMockConfigurator.py b/src/UtfTestMockConfigurator.py
index 4974063..fc58ad4 100644
--- a/src/UtfTestMockConfigurator.py
+++ b/src/UtfTestMockConfigurator.py
@@ -1,5 +1,19 @@
#!/usr/bin/env python
+# Asterisk SCF -- An open-source communications framework.
+#
+# Copyright (C) 2010-2011, 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.
+
# UTF-8 Testing mock configurator
# Bring in the common configuration infrastructure
diff --git a/src/UtfTestPythonConfig.py b/src/UtfTestPythonConfig.py
index c208c3f..acec12a 100644
--- a/src/UtfTestPythonConfig.py
+++ b/src/UtfTestPythonConfig.py
@@ -1,5 +1,19 @@
#!/usr/bin/env python
+# Asterisk SCF -- An open-source communications framework.
+#
+# Copyright (C) 2010-2011, 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.
+
# UTF-8 Testing of Python configurator
# Bring in the common configuration infrastructure
@@ -13,6 +27,7 @@ Ice.loadSlice('-I. --all TestUtfConfigurationIf.ice')
Ice.loadSlice('-I. --all LoggerIf.ice')
import AsteriskSCF.System.Configuration.UtfTest.V1
+# Get the command line options.
usage = "usage: %prog [options] arg1 arg2"
parser = OptionParser(usage=usage)
parser.add_option("--c", "--config", metavar="FILE",
@@ -26,7 +41,7 @@ parser.add_option("--Ice.Config", metavar="FILE",
if options.configfile:
configfile=options.configfile
-# Make a configurator application and let it run
+# Make a configurator-like application and let it run
iceapp = UtfTestMockConfigurator.ConfiguratorStub(configfile)
# UtfTestMockConfigurator class is NOT dervied from Ice.Application,
@@ -34,7 +49,7 @@ iceapp = UtfTestMockConfigurator.ConfiguratorStub(configfile)
iceapp.run(sys.argv)
print >> sys.stdout, "Ice app completed."
-# I am purposely not letting the communicator shutdown() operation get called.
+# I am purposely preventing the call to communicator shutdown().
# It hangs when on Windows when this script is invoked via std::system.
# val=iceapp.shutdown() # <<< HANGS
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)
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());
}
}
+
+
commit 106875f8c7b241eb99f2ca618bff0933cda59d36
Author: Ken Hunt <ken.hunt at digium.com>
Date: Tue Mar 22 13:59:07 2011 -0500
Minor cleanup for review.
diff --git a/config/testutf.config.in b/config/testutf.config.in
index 12613bf..9efee38 100644
--- a/config/testutf.config.in
+++ b/config/testutf.config.in
@@ -4,13 +4,13 @@ IceBox.InheritProperties=1
# Boost Test arguments can be passed here.
# IceBox.Service.TestUtf = TestUtf:create --log_level=all
-IceBox.Service.TestUtf=../src at testutf:create
+IceBox.Service.TestUtf=../src${binsubdir}@testutf:create
#IceBox.Service.TestUtf = TestUtf:create
-IceBox.Service.ServiceDiscovery=${service_locator_bindir}/src at service_locator:create
+IceBox.Service.ServiceDiscovery=${service_locator_bindir}/src${binsubdir}@service_locator:create
#IceBox.Service.ServiceDiscovery=service_locator:create
-IceBox.Service.Logger=${logger_bindir}/server/src at logging-service:createLoggingService
+IceBox.Service.Logger=${logger_bindir}/server/src${binsubdir}@logging-service:createLoggingService
#IceBox.Service.Logger=logging-service:createLoggingService
IceBox.LoadOrder=ServiceDiscovery,Logger,TestUtf
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 06b2360..4f7980f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -17,5 +17,8 @@ endif()
include_directories(${logger_dir}/include)
if(integrated_build STREQUAL "true")
- icebox_add_test(test ../config/testutf.config)
+ if(Win32)
+ set(extra "../")
+ endif()
+ icebox_add_test(testutf testutf ${extra}../config/testutf.config)
endif()
diff --git a/src/TestUtf.cpp b/src/TestUtf.cpp
index d160d90..396783b 100644
--- a/src/TestUtf.cpp
+++ b/src/TestUtf.cpp
@@ -174,6 +174,9 @@ BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
const std::string HardCoded("Τη γλώσσα μου έδωσαν ελληνική");
+/**
+ * Test passing a hard-coded UTF-8 string across the Ice interface to the logger.
+ */
BOOST_AUTO_TEST_CASE(LogUtfStringConstant)
{
bool addLocatorSucceeded(true);
@@ -188,6 +191,13 @@ BOOST_AUTO_TEST_CASE(LogUtfStringConstant)
}
}
+/**
+ * This tests loading Ice properties set to UTF-8 strings and sending to the logger.
+ * 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)
+ */
BOOST_AUTO_TEST_CASE(LogUtfIceProperties)
{
bool addLocatorSucceeded(true);
@@ -211,7 +221,12 @@ BOOST_AUTO_TEST_CASE(LogUtfIceProperties)
}
}
-
+/**
+ * This test compares the logged output to the original input data from the
+ * previous tests.
+ * Testing:
+ * - Logger handling the of UTF-8 string on server side.
+ */
BOOST_AUTO_TEST_CASE(LogUtfLogFile)
{
bool addLocatorSucceeded(true);
commit 4d051d4532f99323d14ada0237f559b66e6fac6d
Author: Ken Hunt <ken.hunt at digium.com>
Date: Mon Mar 21 20:16:34 2011 -0500
Basic UTF testing for Ice property files, Ice RPC calls, and Asterisk SCF logger.
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..b0e1cc6
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,20 @@
+# Test utf
+
+if(NOT integrated_build STREQUAL "true")
+
+ # Minimum we require is 2.8, any lower and stuff would fail horribly
+ cmake_minimum_required(VERSION 2.8)
+
+ # Include common AsteriskSCF build infrastructure
+ include(cmake/AsteriskSCF.cmake)
+
+ # This project is C++ based and requires a minimum of 3.4
+ asterisk_scf_project("Test UTF" 3.4 CXX)
+
+else()
+ set(test_utf_bindir ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
+endif()
+
+add_subdirectory(src)
+add_subdirectory(config)
+
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt
new file mode 100644
index 0000000..32a4848
--- /dev/null
+++ b/config/CMakeLists.txt
@@ -0,0 +1,9 @@
+#
+# Asterisk Scalable Communications Framework
+#
+# Copyright (C) 2010-2011 -- Digium, Inc.
+#
+# All rights reserved.
+#
+
+configure_file(testutf.config.in testutf.config)
diff --git a/config/testutf.config.in b/config/testutf.config.in
new file mode 100644
index 0000000..12613bf
--- /dev/null
+++ b/config/testutf.config.in
@@ -0,0 +1,83 @@
+# This is a configuration file a single process test of the UTF Test.
+
+IceBox.InheritProperties=1
+
+# Boost Test arguments can be passed here.
+# IceBox.Service.TestUtf = TestUtf:create --log_level=all
+IceBox.Service.TestUtf=../src at testutf:create
+#IceBox.Service.TestUtf = TestUtf:create
+
+IceBox.Service.ServiceDiscovery=${service_locator_bindir}/src at service_locator:create
+#IceBox.Service.ServiceDiscovery=service_locator:create
+
+IceBox.Service.Logger=${logger_bindir}/server/src at 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
+
+TestUtf.Endpoints=tcp -p 10097
+
+TestUtf.ThreadPool.Size=4
+TestUtf.ThreadPool.SizeMax=10
+TestUtf.ThreadPool.SizeWarn=9
+
+TestUtf.Standby = no
+
+TestUtf.Greek = ὕαλον
+TestUtf.Russian = "По ней стремился одиноко"
+TestUtf.Chinese = 私はガ
+
+
+##########################################
+# Service Locator properties
+
+AsteriskSCFIceStorm.InstanceName=AsteriskSCFIceStorm
+#
+# This property defines the endpoints on which the IceStorm
+# TopicManager listens.
+#
+AsteriskSCFIceStorm.TopicManager.Endpoints=default -p 10000
+
+#
+# This property defines the endpoints on which the topic
+# publisher objects listen. If you want to federate
+# IceStorm instances this must run on a fixed port (or use
+# IceGrid).
+#
+AsteriskSCFIceStorm.Publish.Endpoints=tcp -p 10001:udp -p 10001
+
+#
+# TopicManager Tracing
+#
+# 0 = no tracing
+# 1 = trace topic creation, subscription, unsubscription
+# 2 = like 1, but with more detailed subscription information
+#
+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
+ServiceLocatorManagementAdapter.Endpoints=tcp -p 4422
+
+# Test endpoints for the service locator adapter
+ServiceLocatorAdapter.Endpoints=tcp -p 4411
+
+# Logger configuration
+LoggerAdapter.Endpoints=default
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..06b2360
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,21 @@
+# Create UTF test project.
+asterisk_scf_component_init(testutf CXX)
+
+asterisk_scf_component_add_file(testutf TestUtf.cpp)
+
+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)
+
+if(integrated_build STREQUAL "true")
+ icebox_add_test(test ../config/testutf.config)
+endif()
diff --git a/src/TestUtf.cpp b/src/TestUtf.cpp
new file mode 100644
index 0000000..d160d90
--- /dev/null
+++ b/src/TestUtf.cpp
@@ -0,0 +1,263 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, 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 TestUtf
+#define BOOST_TEST_NO_MAIN
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/debug.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/algorithm/string.hpp>
+#include <fstream>
+
+#include <Ice/Ice.h>
+#include <IceBox/IceBox.h>
+
+#include <AsteriskSCF/Logger/IceLogger.h>
+#include <AsteriskSCF/logger.h>
+
+using namespace AsteriskSCF::System::Logging;
+using namespace std;
+
+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 LocatorObjectId("TestLocator");
+
+/**
+ * A global fixture for Ice initialization.
+ * Provides setup/teardown for the entire set of tests.
+ */
+struct GlobalIceFixture
+{
+ GlobalIceFixture()
+ {
+ BOOST_TEST_MESSAGE("Setting up Basic Rounting Service test fixture");
+
+ ::boost::debug::detect_memory_leaks(false);
+ ::boost::unit_test::unit_test_log.set_stream( std::cout );
+
+ 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);
+
+ Ice::PropertiesPtr props = SharedTestData::instance.communicator->getProperties();
+ SharedTestData::instance.adapter = SharedTestData::instance.communicator->createObjectAdapterWithEndpoints("TestUtf", "default -p 10100");
+
+ // setup the logger
+ ConfiguredIceLoggerPtr mIceLogger = createIceLogger(SharedTestData::instance.adapter);
+ getLoggerFactory().setLogOutput(mIceLogger->getLogger());
+
+ SharedTestData::instance.adapter->activate();
+
+ // Give the logger configuration time to complete.
+ IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1000));
+ }
+ catch (const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ status = 1;
+ }
+ catch (const char* msg)
+ {
+ cerr << msg << endl;
+ status = 1;
+ }
+ } // end Fixture() constructor
+
+ ~GlobalIceFixture()
+ {
+ BOOST_TEST_MESSAGE("Tearing down Routing Test global test fixture");
+
+
+ if (SharedTestData::instance.communicator)
+ {
+ SharedTestData::instance.communicator->shutdown();
+ SharedTestData::instance.communicator = 0;
+ }
+ }
+private:
+
+};
+
+BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
+
+const std::string HardCoded("Τη γλώσσα μου έδωσαν ελληνική");
+
+BOOST_AUTO_TEST_CASE(LogUtfStringConstant)
+{
+ bool addLocatorSucceeded(true);
+ try
+ {
+ BOOST_TEST_MESSAGE("BOOST_TEST_MESSAGE: s=" + HardCoded);
+ lg(Info) << "Logging a string const: " << HardCoded;
+ }
+ catch (...)
+ {
+ BOOST_CHECK(false);
+ }
+}
+
+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;
+
+ std::string Russian = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.Russian", "");
+ BOOST_TEST_MESSAGE("BOOST_TEST_MESSAGE: Russian = " + Russian);
+ lg(Info) << "Logging Russian: " << Russian;
+
+ std::string Chinese = SharedTestData::instance.communicator->getProperties()->getPropertyWithDefault("TestUtf.Chinese", "");
+ BOOST_TEST_MESSAGE("BOOST_TEST_MESSAGE: Chinese = " + Chinese);
+ lg(Info) << "Logging Chinese: " << Chinese;
+ }
+ catch (...)
+ {
+ BOOST_CHECK(false);
+ }
+}
+
+
+BOOST_AUTO_TEST_CASE(LogUtfLogFile)
+{
+ 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);
+ }
+ catch (...)
+ {
+ BOOST_CHECK(false);
+ }
+}
-----------------------------------------------------------------------
--
asterisk-scf/release/test-utf.git
More information about the asterisk-scf-commits
mailing list