[Pkg-running-devel] [antpm] 29/48: tests: test a few parts of lqueue

Kristof Ralovich ralovich-guest at moszumanska.debian.org
Mon Aug 11 10:10:33 UTC 2014


This is an automated email from the git hooks/post-receive script.

ralovich-guest pushed a commit to branch upstream
in repository antpm.

commit 3a65b419a784706b2bdd2e63cefc16eb19104a90
Author: RALOVICH, Kristof <tade60 at freemail.hu>
Date:   Wed Mar 26 15:36:57 2014 +0100

    tests: test a few parts of lqueue
---
 src/tests/CMakeLists.txt |   9 ++++
 src/tests/lq1.cpp        | 123 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 132 insertions(+)

diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 29935e0..19f534c 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -29,6 +29,14 @@ TARGET_LINK_LIBRARIES(sm1
   ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
 )
 
+ADD_EXECUTABLE(lq1
+  lq1.cpp
+)
+TARGET_LINK_LIBRARIES(lq1
+  antpm
+  ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
+)
+
 
 IF(VALGRIND_PROGRAM)
   function(add_my_test name binary)
@@ -68,3 +76,4 @@ ADD_MY_TEST(testUsbmon2AntCount  ../antpm-usbmon2ant --op count  ${CMAKE_CURRENT
 
 
 ADD_MY_TEST(testsm1 sm1)
+ADD_MY_TEST(testlq1 lq1)
diff --git a/src/tests/lq1.cpp b/src/tests/lq1.cpp
new file mode 100644
index 0000000..5fafdbd
--- /dev/null
+++ b/src/tests/lq1.cpp
@@ -0,0 +1,123 @@
+// -*- mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*-
+// ***** BEGIN LICENSE BLOCK *****
+//////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2014 RALOVICH, Kristóf                            //
+//                                                                      //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation; either version 3 of the License, or    //
+// (at your option) any later version.                                  //
+//                                                                      //
+// This program is distributed in the hope that it will be useful,      //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of       //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        //
+// GNU General Public License for more details.                         //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+// ***** END LICENSE BLOCK *****
+
+
+
+#include "common.hpp"
+#include "lqueue.hpp"
+
+#include <iostream>
+#include <string>
+#include <cctype>
+#include <boost/asio.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/array.hpp>
+#include <boost/bind.hpp>
+
+#define BOOST_TEST_MODULE lq1
+//#include <boost/test/included/unit_test.hpp>
+#include <boost/test/unit_test.hpp>
+
+using namespace std;
+using namespace antpm;
+//namespace fs = boost::filesystem;
+
+
+
+namespace antpm
+{
+
+template<>
+Log*
+ClassInstantiator<Log>::instantiate()
+{
+  return new Log(NULL);
+}
+
+}
+
+
+struct Producer
+{
+  lqueue2<int> _q;
+
+  lqueue3<int> q;
+  std::auto_ptr<boost::thread> q_th;
+
+  lqueue3_bg<double> q_bg;
+  volatile bool die;
+
+  void operator() ()
+  {
+    while(!die)
+    {
+      _q.push(234);
+      q.push(27);
+      q_bg.push(435.5543);
+      boost::thread::yield();
+    }
+  }
+
+  void start_q_th()
+  {
+    q_th.reset(new boost::thread(boost::bind(&lqueue3<int>::eventLoop, &q)));
+  }
+};
+
+bool
+onDataArrivedI(std::vector<int>& v)
+{
+  cout << v.size() << endl;
+  return true;
+}
+
+bool
+onDataArrived(std::vector<double>& v)
+{
+  cout << v.size() << endl;
+  return true;
+}
+
+BOOST_AUTO_TEST_CASE(test_lqueue1)
+{
+  antpm::Log::instance()->addSink(std::cout);
+  antpm::Log::instance()->setLogReportingLevel(antpm::LOG_DBG3);
+
+  BOOST_CHECK(true);
+
+
+
+  Producer p;
+  p.die = false;
+  p.q.setOnDataArrivedCallback(onDataArrivedI);
+  p.q_bg.setOnDataArrivedCallback(onDataArrived);
+
+  // https://svn.boost.org/trac/boost/ticket/2144
+  boost::thread th = boost::thread(boost::ref(p));
+  p.start_q_th();
+
+  boost::this_thread::sleep( boost::posix_time::milliseconds(20) );
+
+
+  p.q.kill();
+
+  p.die = true;
+  th.join();
+
+}
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-running/antpm.git



More information about the Pkg-running-devel mailing list