nmdaemon tests was added
authori.metelytsia <i.metelytsia@samsung.com>
Tue, 18 Apr 2017 13:29:04 +0000 (16:29 +0300)
committeri.metelytsia <i.metelytsia@samsung.com>
Tue, 18 Apr 2017 13:34:21 +0000 (16:34 +0300)
network-manager/nmdaemon/main_def.h
network-manager/nmdaemon/nmdaemon.manifest
network-manager/packaging/ioswsec.spec
network-manager/test/CMakeLists.txt
network-manager/test/test_nmdaemon.cpp [new file with mode: 0644]

index 37818c2..dbea111 100644 (file)
@@ -3,8 +3,8 @@
 
 /*******************************************************/
 /*******************************************************/
-#define PID_FILE_NAME                               "/var/run/nmd.pid"
-#define LOG_FILE_NAME                               "/var/log/nmd.log"
+#define PID_FILE_NAME                               "/var/run/nmdaemon.pid"
+#define LOG_FILE_NAME                               "/var/log/nmdaemon.log"
 
 /*******************************************************/
 /*******************************************************/
index 5cf92b5..06c79f0 100644 (file)
@@ -1,6 +1,6 @@
 <manifest>
     <define>
-        <domain name='nm' policy='shared' />
+        <domain name='nmdaemon' policy='shared' />
         <request>
             <smack request="device::app_logging" type="w"/>
             <smack request="system::use_internet" type="rw"/>
index a355b14..09a840e 100644 (file)
@@ -16,6 +16,7 @@ BuildRequires: gtest-devel
 %endif
 BuildRequires: pkgconfig(dpm)
 BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(boost)
 
 
 %define _tests_dir /usr/apps/network-manager
index 10de7e1..753922d 100644 (file)
@@ -7,13 +7,13 @@ include_directories (
     ${NETWORK_MANAGER_LIB}/REST/inc
 )
 
-add_executable (${PROJECT_NAME} test_all.cpp test_REST.cpp)
+add_executable (${PROJECT_NAME} test_all.cpp test_REST.cpp test_nmdaemon.cpp)
 
 add_dependencies (${PROJECT_NAME} ${NETWORK_MANAGER_LIB_PROJECT_NAME})
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 
-target_link_libraries(${PROJECT_NAME} ${GTEST_LIB} ${NETWORK_MANAGER_LIB_PROJECT_NAME} pthread)
+target_link_libraries(${PROJECT_NAME} ${GTEST_LIB} ${NETWORK_MANAGER_LIB_PROJECT_NAME} pthread boost_system boost_thread)
 
 install(TARGETS ${PROJECT_NAME} DESTINATION ${TESTS_DIR})
 install(FILES tests.manifest DESTINATION ${MANIFESTDIR})
diff --git a/network-manager/test/test_nmdaemon.cpp b/network-manager/test/test_nmdaemon.cpp
new file mode 100644 (file)
index 0000000..1398a16
--- /dev/null
@@ -0,0 +1,71 @@
+#include <iostream>
+#include <string>
+
+#include <gtest/gtest.h>
+
+#include <boost/thread.hpp>
+#include <boost/bind.hpp>
+#include <boost/asio.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
+
+//using namespace std;
+using namespace boost::asio;
+using boost::system::error_code;
+
+static io_service s_srv;
+static ip::tcp::endpoint s_ep(ip::address::from_string("127.0.0.1"), 12345);
+static const char* s_msgs[] = {"thread 1", "thread 2", "thread 3", 0};
+static int s_res = 0;
+
+size_t complete(const char* _buff, const error_code& _err, size_t _size)
+{
+    if(_err)
+        return 0;
+    return (std::find(_buff, _buff + _size, '\n') < (_buff + _size)) ? 0 : 1;
+}
+
+void echo(std::string _msg)
+{
+    ip::tcp::socket sock(s_srv);
+    sock.connect(s_ep);
+
+    _msg += "\n";
+    sock.write_some(buffer(_msg));
+
+    char buff[1024];
+    int bytes = read(sock, buffer(buff), boost::bind(complete, buff, _1, _2));
+
+    std::string copy(buff, bytes - 1);
+    _msg = _msg.substr(0, _msg.size() - 1);
+    if(copy == _msg)
+    {
+       s_res++;
+       std::cout << "server echoed " << _msg << ": " "OK" << std::endl;
+    }
+    else
+    {
+       std::cout << "server echoed " << _msg << ": " "FAIL" << std::endl;
+    }
+
+    sock.close();
+}
+
+bool test()
+{
+    boost::thread_group threads;
+    for(const char** msg = s_msgs; *msg; ++msg)
+    {
+        threads.create_thread(boost::bind(echo, *msg));
+        boost::this_thread::sleep(boost::posix_time::millisec(100));
+    }
+    threads.join_all();
+    return (s_res == 3);
+}
+
+TEST(test_nmdaemon, test)
+{
+    std::cout << "=== start ===" << std::endl;
+    ASSERT_TRUE(test());
+    std::cout << "=== stop ===" << std::endl;
+}