[DEV] split client and server

This commit is contained in:
Edouard DUPIN 2016-05-02 22:14:07 +02:00
parent 533e15ce8d
commit d8d002b669
9 changed files with 271 additions and 172 deletions

View File

@ -26,14 +26,10 @@ def get_maintainer():
def create(target, module_name):
my_module = module.Module(__file__, module_name, get_type())
my_module.add_module_depend(['test-debug'])
my_module.add_src_file([
'test/debug.cpp'
])
my_module.add_export_path(tools.get_current_path(__file__))
my_module.add_module_depend(['enet', 'gtest'])
my_module.add_module_depend(['enet', 'gtest', 'test-debug'])
my_module.add_src_file([
'test/main.cpp'
'test/main-client-http.cpp'
])
return my_module

41
lutin_enet-test-client.py Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
def get_type():
return "BINARY"
def get_sub_type():
return "TEST"
def get_desc():
return "e-net TEST test software for enet"
def get_licence():
return "APACHE-2"
def get_compagny_type():
return "com"
def get_compagny_name():
return "atria-soft"
def get_maintainer():
return ["Mr DUPIN Edouard <yui.heero@gmail.com>"]
def create(target, module_name):
my_module = module.Module(__file__, module_name, get_type())
my_module.add_export_path(tools.get_current_path(__file__))
my_module.add_module_depend(['enet', 'gtest', 'test-debug'])
my_module.add_src_file([
'test/main-client.cpp'
])
return my_module

41
lutin_enet-test-server.py Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
def get_type():
return "BINARY"
def get_sub_type():
return "TEST"
def get_desc():
return "e-net TEST test software for enet"
def get_licence():
return "APACHE-2"
def get_compagny_type():
return "com"
def get_compagny_name():
return "atria-soft"
def get_maintainer():
return ["Mr DUPIN Edouard <yui.heero@gmail.com>"]
def create(target, module_name):
my_module = module.Module(__file__, module_name, get_type())
my_module.add_export_path(tools.get_current_path(__file__))
my_module.add_module_depend(['enet', 'gtest', 'test-debug'])
my_module.add_src_file([
'test/main-server.cpp'
])
return my_module

View File

@ -1,12 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <test/debug.h>
int32_t appl::getLogId() {
static int32_t g_val = elog::registerInstance("enettest");
return g_val;
}

View File

@ -1,39 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <elog/log.h>
namespace appl {
int32_t getLogId();
};
#define APPL_BASE(info,data) ELOG_BASE(appl::getLogId(),info,data)
#define APPL_CRITICAL(data) APPL_BASE(1, data)
#define APPL_ERROR(data) APPL_BASE(2, data)
#define APPL_WARNING(data) APPL_BASE(3, data)
#ifdef DEBUG
#define APPL_INFO(data) APPL_BASE(4, data)
#define APPL_DEBUG(data) APPL_BASE(5, data)
#define APPL_VERBOSE(data) APPL_BASE(6, data)
#define APPL_TODO(data) APPL_BASE(4, "TODO : " << data)
#else
#define APPL_INFO(data) do { } while(false)
#define APPL_DEBUG(data) do { } while(false)
#define APPL_VERBOSE(data) do { } while(false)
#define APPL_TODO(data) do { } while(false)
#endif
#define APPL_ASSERT(cond,data) \
do { \
if (!(cond)) { \
APPL_CRITICAL(data); \
assert(!#cond); \
} \
} while (0)

63
test/main-client-http.cpp Normal file
View File

@ -0,0 +1,63 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <test-debug/debug.h>
#include <enet/Tcp.h>
#include <enet/Http.h>
#include <etk/etk.h>
#include <etk/stdTools.h>
int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : ");
TEST_PRINT(" " << _argv[0] << " [options]");
TEST_PRINT(" No options ...");
return -1;
}
}
TEST_INFO("==================================");
TEST_INFO("== Test HTTP client ==");
TEST_INFO("==================================");
#ifndef __TARGET_OS__Windows
// client mode ...
enet::Http connection;
connection.setServer("127.0.0.1");
connection.setKeepAlive(true);
TEST_INFO("----------------------------");
TEST_INFO("GET data : ");
if (connection.get("") == false) {
TEST_ERROR("can not GET data...");
return -1;
}
TEST_INFO("data : " << connection.dataString());
TEST_INFO("----------------------------");
TEST_INFO("POST data : ");
std::map<std::string, std::string> values;
values.insert(std::make_pair<std::string, std::string>("plop", "valuePlop"));
if (connection.post("", values) == false) {
TEST_ERROR("can not POST data...");
return -1;
}
TEST_INFO("data : " << connection.dataString());
TEST_INFO("----------------------------");
TEST_INFO("POST xml : ");
if (connection.post("", /*"application/xml"*/ "text/xml; charset=utf-8", "<plop><string>value1</string></plop>") == false) {
TEST_ERROR("can not POST XML data...");
return -1;
}
TEST_INFO("data : " << connection.dataString());
#else
TEST_CRITICAL("not implemented");
#endif
return 0;
}

63
test/main-client.cpp Normal file
View File

@ -0,0 +1,63 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <test-debug/debug.h>
#include <enet/Tcp.h>
#include <enet/Http.h>
#include <etk/etk.h>
#include <etk/stdTools.h>
int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : ");
TEST_PRINT(" " << _argv[0] << " [options]");
TEST_PRINT(" No options ...");
return -1;
}
}
TEST_INFO("==================================");
TEST_INFO("== Test TCP client ==");
TEST_INFO("==================================");
#ifndef __TARGET_OS__Windows
// client mode ...
enet::Tcp connection;
connection.setHostNane("127.0.0.1");
connection.setPort(31234);
connection.setServer(false);
TEST_INFO("CLIENT connect ...");
if (connection.link() == false) {
TEST_ERROR("can not link to the socket...");
return -1;
}
int32_t iii = 0;
while ( connection.getConnectionStatus() == enet::Tcp::statusLink
&& iii<10000) {
char data[1024];
int32_t len = connection.read(data, 1024);
TEST_INFO("read len=" << len << " data='" << data << "'");
iii++;
}
if (iii>=10000) {
TEST_INFO("auto disconnected");
} else if (connection.getConnectionStatus() != enet::Tcp::statusLink) {
TEST_INFO("server disconnected");
} else {
TEST_INFO("ERROR disconnected");
}
if (connection.unlink() == false) {
TEST_ERROR("can not unlink to the socket...");
return -1;
}
#else
TEST_CRITICAL("not implemented");
#endif
return 0;
}

61
test/main-server.cpp Normal file
View File

@ -0,0 +1,61 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <test-debug/debug.h>
#include <enet/Tcp.h>
#include <enet/Http.h>
#include <etk/etk.h>
#include <etk/stdTools.h>
int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : ");
TEST_PRINT(" " << _argv[0] << " [options]");
TEST_PRINT(" No options ...");
return -1;
}
}
TEST_INFO("==================================");
TEST_INFO("== Test TCP server ==");
TEST_INFO("==================================");
#ifndef __TARGET_OS__Windows
// server mode ...
enet::Tcp connection;
connection.setHostNane("127.0.0.1");
connection.setPort(31234);
connection.setServer(true);
TEST_INFO("SERVER connect ...");
if (connection.link() == false) {
TEST_ERROR("can not link to the socket...");
return -1;
}
int32_t iii = 0;
while (connection.getConnectionStatus() == enet::Tcp::statusLink) {
int32_t len = connection.write("plop" + etk::to_string(iii));
TEST_INFO("write len=" << len);
iii++;
}
if (iii>=1000000) {
TEST_INFO("auto disconnected");
} else if (connection.getConnectionStatus() != enet::Tcp::statusLink) {
TEST_INFO("server disconnected");
} else {
TEST_INFO("ERROR disconnected");
}
if (connection.unlink() == false) {
TEST_ERROR("can not unlink to the socket...");
return -1;
}
#else
TEST_CRITICAL("not implemented");
#endif
return 0;
}

View File

@ -1,115 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <test/debug.h>
#include <enet/Tcp.h>
#include <enet/Http.h>
#include <etk/etk.h>
#include <etk/stdTools.h>
#undef __class__
#define __class__ "test"
int main(int argc, const char *argv[]) {
etk::init(argc, argv);
#ifndef __TARGET_OS__Windows
APPL_VERBOSE("plop");
if (argc > 2) {
// client mode ...
enet::Http connection;
connection.setServer("127.0.0.1");
connection.setKeepAlive(true);
APPL_INFO("----------------------------");
APPL_INFO("GET data : ");
if (connection.get("") == false) {
APPL_ERROR("can not GET data...");
return -1;
}
APPL_INFO("data : " << connection.dataString());
APPL_INFO("----------------------------");
APPL_INFO("POST data : ");
std::map<std::string, std::string> values;
values.insert(std::make_pair<std::string, std::string>("plop", "valuePlop"));
if (connection.post("", values) == false) {
APPL_ERROR("can not POST data...");
return -1;
}
APPL_INFO("data : " << connection.dataString());
APPL_INFO("----------------------------");
APPL_INFO("POST xml : ");
if (connection.post("", /*"application/xml"*/ "text/xml; charset=utf-8", "<plop><string>value1</string></plop>") == false) {
APPL_ERROR("can not POST XML data...");
return -1;
}
APPL_INFO("data : " << connection.dataString());
} else if (argc > 1) {
// client mode ...
enet::Tcp connection;
connection.setHostNane("127.0.0.1");
connection.setPort(31234);
connection.setServer(false);
APPL_INFO("CLIENT connect ...");
if (connection.link() == false) {
APPL_ERROR("can not link to the socket...");
return -1;
}
int32_t iii = 0;
while ( connection.getConnectionStatus() == enet::Tcp::statusLink
&& iii<10000) {
char data[1024];
int32_t len = connection.read(data, 1024);
APPL_INFO("read len=" << len << " data='" << data << "'");
iii++;
}
if (iii>=10000) {
APPL_INFO("auto disconnected");
} else if (connection.getConnectionStatus() != enet::Tcp::statusLink) {
APPL_INFO("server disconnected");
} else {
APPL_INFO("ERROR disconnected");
}
if (connection.unlink() == false) {
APPL_ERROR("can not unlink to the socket...");
return -1;
}
} else {
// server mode ...
enet::Tcp connection;
connection.setHostNane("127.0.0.1");
connection.setPort(31234);
connection.setServer(true);
APPL_INFO("SERVER connect ...");
if (connection.link() == false) {
APPL_ERROR("can not link to the socket...");
return -1;
}
int32_t iii = 0;
while (connection.getConnectionStatus() == enet::Tcp::statusLink) {
int32_t len = connection.write("plop" + etk::to_string(iii));
APPL_INFO("write len=" << len);
iii++;
}
if (iii>=1000000) {
APPL_INFO("auto disconnected");
} else if (connection.getConnectionStatus() != enet::Tcp::statusLink) {
APPL_INFO("server disconnected");
} else {
APPL_INFO("ERROR disconnected");
}
if (connection.unlink() == false) {
APPL_ERROR("can not unlink to the socket...");
return -1;
}
}
#else
APPL_CRITICAL("not implemented");
#endif
return 0;
}