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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Mar 21 20:17:26 CDT 2011


branch "master" has been created
        at  4d051d4532f99323d14ada0237f559b66e6fac6d (commit)

- Log -----------------------------------------------------------------
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/integration/test-utf.git



More information about the asterisk-scf-commits mailing list