/*******************************************************/
/*******************************************************/
-#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"
/*******************************************************/
/*******************************************************/
${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})
--- /dev/null
+#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;
+}