[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "workqueue" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Apr 5 18:35:39 CDT 2011


branch "workqueue" has been updated
       via  bcab7364effa06658e074cdc729ca444ecf9d7e1 (commit)
      from  2ccdcf9806863b2cfe34397f87714b270bd74961 (commit)

Summary of changes:
 ThreadPool/test/CMakeLists.txt          |   23 +++++++
 ThreadPool/test/TestThreadPool.cpp      |  101 +++++++++++++++++++++++++++++++
 {WorkQueue => ThreadPool}/test/test.cpp |    2 +-
 3 files changed, 125 insertions(+), 1 deletions(-)
 create mode 100644 ThreadPool/test/CMakeLists.txt
 create mode 100644 ThreadPool/test/TestThreadPool.cpp
 copy {WorkQueue => ThreadPool}/test/test.cpp (93%)


- Log -----------------------------------------------------------------
commit bcab7364effa06658e074cdc729ca444ecf9d7e1
Author: Mark Michelson <mmichelson at digium.com>
Date:   Tue Apr 5 18:34:56 2011 -0500

    Add initial test code.

diff --git a/ThreadPool/test/CMakeLists.txt b/ThreadPool/test/CMakeLists.txt
new file mode 100644
index 0000000..78678df
--- /dev/null
+++ b/ThreadPool/test/CMakeLists.txt
@@ -0,0 +1,23 @@
+#
+# Asterisk Scalable Communications Framework
+#
+# Copyright (C) 2011 -- Digium, Inc.
+#
+# All rights reserved.
+#
+
+asterisk_scf_component_init(ThreadPoolTest CXX)
+
+include_directories(${API_INCLUDE_DIR})
+include_directories(../src)
+include_directories(../include)
+
+asterisk_scf_component_add_file(ThreadPoolTest TestThreadPool.cpp)
+asterisk_scf_component_add_file(ThreadPoolTest test.cpp)
+asterisk_scf_component_add_boost_libraries(ThreadPoolTest unit_test_framework)
+
+asterisk_scf_component_build_standalone(ThreadPoolTest)
+target_link_libraries(ThreadPoolTest asterisk-scf-api)
+target_link_libraries(ThreadPoolTest ThreadPool)
+
+boost_add_test(ThreadPoolTest)
diff --git a/ThreadPool/test/TestThreadPool.cpp b/ThreadPool/test/TestThreadPool.cpp
new file mode 100644
index 0000000..dcf06e5
--- /dev/null
+++ b/ThreadPool/test/TestThreadPool.cpp
@@ -0,0 +1,101 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 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.
+ */
+
+#include <boost/test/unit_test.hpp>
+
+#include <AsteriskSCF/WorkQueue.h>
+
+using namespace AsteriskSCF::System::ThreadPool::V1;
+using namespace AsteriskSCF::ThreadPool;
+
+using namespace AsteriskSCF::System::WorkQueue::V1;
+using namespace AsteriskSCF::WorkQueue;
+
+class TestListener : public PoolListener
+{
+public:
+    TestListener() : mActive(0), mIdle(0), mZombie(0), mTasks(0), 
+        mWorkAddedNotice(false), mWasEmpty(false), mEmptyNotice(false) { }
+    
+    void stateChanged(const PoolPtr& pool, int active, int idle, int zombie)
+    {
+        boost::lock_guard<boost::mutex> lock(mLock);
+        mActive = active;
+        mIdle = idle;
+        mZombie = zombie;
+    }
+
+    void queueWorkAdded(const PoolPtr& pool, int count, bool wasEmpty)
+    {
+        boost::lock_guard<boost::mutex> lock(mLock);
+        mTasks = count;
+        mWasEmpty = wasEmpty;
+        mWorkAddedNotice = true;
+    }
+
+    void queueEmptied(const PoolPtr& pool)
+    {
+        boost::lock_guard<boost::mutex> lock(mLock);
+        mEmptyNotice = true;
+    }
+
+    int mActive;
+    int mIdle;
+    int mZombie;
+    int mTasks;
+
+    bool mWorkAddedNotice;
+    bool mWasEmpty;
+    bool mEmptyNotice;
+
+    boost::mutex mLock;
+};
+
+typedef IceUtil::Handle<TestListener> TestListenerPtr;
+
+class SimpleTask : public Work
+{
+public:
+    SimpleTask() : taskExecuted(false) { }
+    void execute()
+    {
+        taskExecuted = true;
+    }
+    bool taskExecuted;
+};
+
+typedef IceUtil::Handle<SimpleTask> SimpleTaskPtr;
+
+BOOST_AUTO_TEST_SUITE(ThreadPoolTest)
+
+BOOST_AUTO_TEST_CASE(addWork)
+{
+    TestListenerPtr listener(new TestListener);
+    QueuePtr queue(new WorkQueue());
+    SimpleTaskPtr work(new SimpleTask());
+    PoolPtr Pool(new ThreadPool(listener, queue));
+
+    queue->enqueueWork(work);
+
+    BOOST_CHECK(listener->mWorkAddedNotice == true);
+    BOOST_CHECK(listener->mWasEmpty == true);
+    BOOST_CHECK(listener->mTasks == 1);
+    BOOST_CHECK(listener->mActive == 0);
+    BOOST_CHECK(listener->mIdle == 0);
+    BOOST_CHECK(listener->mZombie == 0);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/ThreadPool/test/test.cpp b/ThreadPool/test/test.cpp
new file mode 100644
index 0000000..96c31c2
--- /dev/null
+++ b/ThreadPool/test/test.cpp
@@ -0,0 +1,18 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 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 ThreadPool
+#include <boost/test/unit_test.hpp>

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


-- 
asterisk-scf/integration/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list