[DEV] add missing test
This commit is contained in:
33
test/main.cpp
Normal file
33
test/main.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#define NAME "Empty"
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/etk.h>
|
||||
#include <test-debug/debug.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "etktest"
|
||||
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
::testing::InitGoogleTest(&_argc, const_cast<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("esvg-test - help : ");
|
||||
TEST_PRINT(" " << _argv[0] << " [options]");
|
||||
TEST_PRINT(" No optiions ...");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
//etk::initDefaultFolder("esvg-test");
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
140
test/test_signal_arg.cpp
Normal file
140
test/test_signal_arg.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#define NAME "SingleArg"
|
||||
#include <gtest/gtest.h>
|
||||
#include <esignal/Signal.h>
|
||||
#include <esignal/Interface.h>
|
||||
#include <memory>
|
||||
#include <test-debug/debug.h>
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "test_signal_arg"
|
||||
/*
|
||||
class TestSingleArg : public esignal::Interface {
|
||||
public:
|
||||
esignal::Signal<int32_t> signalInt32;
|
||||
|
||||
TestSingleArg() :
|
||||
signalInt32(*this, "value-int", "Select value change integer") {
|
||||
|
||||
}
|
||||
void emit() {
|
||||
TEST_DEBUG("Emit signal int32 : value=22");
|
||||
signalInt32.emit(22);
|
||||
}
|
||||
};
|
||||
|
||||
class TestConnect : public std::enable_shared_from_this<TestConnect> {
|
||||
public:
|
||||
int32_t m_valueInt32;
|
||||
public:
|
||||
TestConnect():
|
||||
m_valueInt32(0) {
|
||||
|
||||
}
|
||||
void connect(TestSingleArg& _remote) {
|
||||
TEST_DEBUG("connect on signalInt32");
|
||||
_remote.signalInt32.bind(shared_from_this(), &TestConnect::onCallbackInt);
|
||||
}
|
||||
void onCallbackInt(const int32_t& _value) {
|
||||
TEST_DEBUG("onCallbackInt " << _value);
|
||||
m_valueInt32 = _value;
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
class TestConnect {
|
||||
public:
|
||||
TestConnect() {
|
||||
|
||||
}
|
||||
void display_values_4( int a, float b, char c) {
|
||||
std::cout << " 4444 " << a << " " << b << " " << c << std::endl;
|
||||
}
|
||||
void display_values_5( int a, float b, char c, std::string _plopppp) {
|
||||
std::cout << " 5555 " << a << " " << b << " " << c << " " << _plopppp << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
class TestConnectShared : public std::enable_shared_from_this<TestConnectShared>{
|
||||
public:
|
||||
TestConnectShared() {
|
||||
|
||||
}
|
||||
void display_values_6( int a, float b, char c) {
|
||||
std::cout << " 6666 " << a << " " << b << " " << c << std::endl;
|
||||
}
|
||||
void display_values_7( int a, float b, char c, std::string _plopppp) {
|
||||
std::cout << " 7777 " << a << " " << b << " " << c << " " << _plopppp << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Func, class... Arg>
|
||||
auto complete_args(Func _f, Arg... _arg) {
|
||||
return [=]( auto&&... cargs ){ return _f( cargs..., _arg... ); };
|
||||
}
|
||||
|
||||
|
||||
template<class pointer, class Func, class... Arg>
|
||||
auto complete_class(pointer* _class, Func _f, Arg... _arg) {
|
||||
return [=]( auto&&... cargs ){
|
||||
//_class->*_f(cargs..., _arg...);
|
||||
(*_class.*_f)(cargs..., _arg...);
|
||||
};
|
||||
}
|
||||
|
||||
TEST(test_signal_arg, checkType) {
|
||||
/*
|
||||
TestSingleArg baseClass;
|
||||
std::shared_ptr<TestConnect> connectedClass = std::make_shared<TestConnect>();
|
||||
connectedClass->connect(baseClass);
|
||||
baseClass.emit();
|
||||
EXPECT_EQ(connectedClass->m_valueInt32, 22);
|
||||
*/
|
||||
esignal::Signal<int, float, char> signal;
|
||||
// ----------------------------------------------------
|
||||
auto display_values_1 = []( int a, float b, char c){
|
||||
std::cout << " 1111 " << a << " " << b << " " << c << " " << std::endl;
|
||||
};
|
||||
signal.connect(display_values_1);
|
||||
|
||||
// ----------------------------------------------------
|
||||
auto display_values_2 = []( int a, float b, char c, int w ){
|
||||
std::cout << " 2222 " << a << " " << b << " " << c << " " << w << std::endl;
|
||||
};
|
||||
signal.connect( complete_args( display_values_2, 72 ) );
|
||||
|
||||
// ----------------------------------------------------
|
||||
TestConnect connectedClass;
|
||||
signal.connect( [&](int a, float b, char c) {
|
||||
connectedClass.display_values_4(a,b,c);}
|
||||
);
|
||||
/*
|
||||
signal.connect( [&](auto && ... _cargs) {
|
||||
connectedClass.display_values_3(_cargs);}
|
||||
);
|
||||
*/
|
||||
signal.connect(&connectedClass, &TestConnect::display_values_4);
|
||||
signal.connect(&connectedClass, &TestConnect::display_values_5, "coucou");
|
||||
|
||||
std::shared_ptr<TestConnectShared> connectedClassShared = std::make_shared<TestConnectShared>();
|
||||
signal.connect(connectedClassShared, &TestConnectShared::display_values_6);
|
||||
signal.connect(connectedClassShared, &TestConnectShared::display_values_7, "coucou");
|
||||
|
||||
|
||||
//signal.connect( complete_class(&connectedClass, &TestConnect::display_values_3) );
|
||||
//signal.connect( TestConnect::display_values_3(&connectedClass) );
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
|
||||
signal.emit( 42, 2.99, 'k');
|
||||
|
||||
}
|
||||
65
test/test_signal_args.cpp
Normal file
65
test/test_signal_args.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#define NAME "SingleArg"
|
||||
#include <gtest/gtest.h>
|
||||
#include <esignal/Signal.h>
|
||||
#include <esignal/Interface.h>
|
||||
#include <memory>
|
||||
#include <test-debug/debug.h>
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "test_signal_arg"
|
||||
/*
|
||||
class TestSingleArgs : public esignal::Interface {
|
||||
public:
|
||||
esignal::Signal<int32_t, int32_t> signalInt32;
|
||||
|
||||
TestSingleArgs() :
|
||||
signalInt32(*this, "value-int", "Select value change integer") {
|
||||
|
||||
}
|
||||
void emit() {
|
||||
TEST_DEBUG("Emit signal int32 : value=22,23");
|
||||
signalInt32.emit(22, 23);
|
||||
}
|
||||
};
|
||||
|
||||
class TestConnect : public std::enable_shared_from_this<TestConnect> {
|
||||
public:
|
||||
int32_t m_valueInt32_1;
|
||||
int32_t m_valueInt32_2;
|
||||
public:
|
||||
TestConnect():
|
||||
m_valueInt32_1(0),
|
||||
m_valueInt32_2(0) {
|
||||
|
||||
}
|
||||
void connect(TestSingleArgs& _remote) {
|
||||
TEST_DEBUG("connect on signalInt32");
|
||||
_remote.signalInt32.bind(shared_from_this(), &TestConnect::onCallbackInt);
|
||||
}
|
||||
void onCallbackInt(const int32_t& _value1, const int32_t& _value2) {
|
||||
TEST_DEBUG("onCallbackInt " << _value1 << " " << _value2);
|
||||
m_valueInt32_1 = _value1;
|
||||
m_valueInt32_2 = _value2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TEST(test_signal_arg, checkType) {
|
||||
TestSingleArgs baseClass;
|
||||
std::shared_ptr<TestConnect> connectedClass = std::make_shared<TestConnect>();
|
||||
connectedClass->connect(baseClass);
|
||||
baseClass.emit();
|
||||
EXPECT_EQ(connectedClass->m_valueInt32_1, 22);
|
||||
EXPECT_EQ(connectedClass->m_valueInt32_2, 23);
|
||||
}
|
||||
|
||||
*/
|
||||
0
test/test_signal_void.cpp
Normal file
0
test/test_signal_void.cpp
Normal file
Reference in New Issue
Block a user