From 05c3f10786dbf41168e8e3c4a3e8afe0d3c40854 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 22 Feb 2016 21:23:21 +0100 Subject: [PATCH] [DEV] integration of the test --- .gitignore | 4 + .travis.yml | 83 ++++++ esignal/Base.cpp | 2 +- esignal/Base.h | 2 +- esignal/Interface.cpp | 6 +- esignal/Interface.h | 4 +- esignal/Signal.h | 44 ++- lutin_esignal-test.py | 5 +- ...ignal_static_func.cpp => test_isignal.cpp} | 2 +- test/test_isignal_class_func.cpp | 0 test/test_isignal_recursive.cpp | 0 test/test_isignal_shared_ptr_func.cpp | 0 test/test_signal_arg.cpp | 217 -------------- test/test_signal_args.cpp | 65 ----- test/test_signal_class_func.cpp | 250 ++++++++++++++++ test/test_signal_shared_ptr_func.cpp | 275 ++++++++++++++++++ test/test_signal_static_func.cpp | 219 +++++++++----- test/test_signal_void.cpp | 0 18 files changed, 802 insertions(+), 376 deletions(-) create mode 100644 .travis.yml rename test/{test_isignal_static_func.cpp => test_isignal.cpp} (87%) delete mode 100644 test/test_isignal_class_func.cpp delete mode 100644 test/test_isignal_recursive.cpp delete mode 100644 test/test_isignal_shared_ptr_func.cpp delete mode 100644 test/test_signal_arg.cpp delete mode 100644 test/test_signal_args.cpp delete mode 100644 test/test_signal_void.cpp diff --git a/.gitignore b/.gitignore index b8bd026..11b29ce 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,7 @@ *.exe *.out *.app + +#python +*.pyc +__pycache__ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8905f82 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,83 @@ +language: cpp + +sudo: false + +branches: + only: + - master + - dev + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.9 + - expect + #- binutils-mingw-w64-x86-64 # 64bit MinGW + #- gcc-mingw-w64-x86-64 + #- g++-mingw-w64-x86-64 + +matrix: + include: + - os: linux + env: CONF=release BUILDER=gcc TARGET=Linux TAG=Linux COMPILATOR_OPTION="--compilator-version=4.9" GCOV=--gcov + compiler: gcc + - os: linux + env: CONF=debug BUILDER=clang TARGET=Linux + compiler: clang + #- os: linux + # env: CONF=release BUILDER=gcc TARGET=Windows TAG=Mingw + # compiler: x86_64-w64-mingw32-gcc + #- os: linux + # env: CONF=release BUILDER=gcc TARGET=Android TAG=Android DISABLE_PACKAGE=-p + # compiler: gcc + - os: osx + env: CONF=release BUILDER=clang TARGET=MacOs TAG=MacOs + compiler: clang + - os: osx + env: CONF=release BUILDER=clang TARGET=IOs TAG=IOs + compiler: clang + + +install: + - cd .. + - pip install --user lutin + - if [ "$TAG" == "Android" ]; then + git clone --depth 1 --branch master https://github.com/HeeroYui/android-download-tool; + ./android-download-tool/dl-android.sh; + fi + - git clone --depth 1 --branch master https://github.com/atria-soft/ci.git + - cd - + +before_script: + - cd .. + - git clone https://github.com/atria-soft/etk.git -b $TRAVIS_BRANCH + - git clone https://github.com/generic-library/gtest-lutin.git --recursive + - git clone https://github.com/generic-library/z-lutin.git --recursive + - pwd + - ls -l + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then + export PATH=$PATH:/Users/travis/Library/Python/2.7/bin/; + fi + - ./ci/build_send.py --tag=$TAG --status=START; + +script: + - lutin -w -j4 -C -P -t$TARGET -c $BUILDER $COMPILATOR_OPTION $BUS -m $CONF $GCOV $DISABLE_PACKAGE esignal-test; STATUS=$? + - ./ci/build_send.py --tag=$TAG --status="$STATUS"; + +after_script: + - if [ "$GCOV" != "" ]; then + ./ci/warning_send.py --find-path ./out/Linux_x86_64/$CONF/build/$BUILDER/esignal/; + fi + - ./out/Linux_x86_64/$CONF/staging/$BUILDER/esignal-test/esignal-test.app/bin/esignal-test --etk-log-level=3 | tee out_test.txt + - if [ "$GCOV" != "" ]; then + ./ci/test_send.py --file=out_test.txt; + lutin -C -P -t $TARGET -c $BUILDER $COMPILATOR_OPTION $BUS -m $CONF -p esignal?gcov; + ./ci/coverage_send.py --json=out/Linux_x86_64/$CONF/build/$BUILDER/esignal/esignal_coverage.json; + fi + +notifications: + email: + - yui.heero@gmail.com + diff --git a/esignal/Base.cpp b/esignal/Base.cpp index 7e91199..8a245bd 100644 --- a/esignal/Base.cpp +++ b/esignal/Base.cpp @@ -38,7 +38,7 @@ std::ostream& esignal::operator <<(std::ostream& _os, const esignal::Base& _obj) return _os; } -void esignal::Base::disconnect(const std::shared_ptr& _obj) { +void esignal::Base::disconnectShared(const std::shared_ptr& _obj) { } diff --git a/esignal/Base.h b/esignal/Base.h index 95d670e..2b9877a 100644 --- a/esignal/Base.h +++ b/esignal/Base.h @@ -34,7 +34,7 @@ namespace esignal { /** * @brief get name of the signal */ - virtual void disconnect(const std::shared_ptr& _obj); + virtual void disconnectShared(const std::shared_ptr& _obj); virtual void disconnect(std::size_t _uid) = 0; /** * @brief Get name of the signal. diff --git a/esignal/Interface.cpp b/esignal/Interface.cpp index 26330d1..4e6c88f 100644 --- a/esignal/Interface.cpp +++ b/esignal/Interface.cpp @@ -50,7 +50,7 @@ std::vector esignal::Interface::signalGetAll() const { return out; } -void esignal::Interface::signalUnBindAll(const std::shared_ptr& _object) { +void esignal::Interface::signalDisconnect(const std::shared_ptr& _object) { if (_object == nullptr) { ESIGNAL_ERROR("Input ERROR nullptr pointer Object ..."); return; @@ -59,11 +59,11 @@ void esignal::Interface::signalUnBindAll(const std::shared_ptr& _object) { if (it == nullptr) { continue; } - it->disconnect(_object); + it->disconnectShared(_object); } } -void esignal::Interface::signalUnConnect(size_t _uid) { +void esignal::Interface::signalDisconnect(size_t _uid) { for(auto &it : m_list) { if (it == nullptr) { continue; diff --git a/esignal/Interface.h b/esignal/Interface.h index a761b94..08a6025 100644 --- a/esignal/Interface.h +++ b/esignal/Interface.h @@ -41,8 +41,8 @@ namespace esignal { * @brief Remove binding on all event class. * @param[in] _sharedPtr sharedPtr to unlink (no type needed ...). */ - void signalUnBindAll(const std::shared_ptr& _sharedPtr); - void signalUnConnect(size_t _uid); + void signalDisconnect(const std::shared_ptr& _sharedPtr); + void signalDisconnect(size_t _uid); }; } diff --git a/esignal/Signal.h b/esignal/Signal.h index d84f5e0..5eb3833 100644 --- a/esignal/Signal.h +++ b/esignal/Signal.h @@ -72,7 +72,7 @@ namespace esignal { * @brief Emit the data on the observer. * @param[in] _values... Multiple value needed to send on observers */ - virtual void emit(Args... _values) { + virtual void emit(const Args&... _values) { if (m_removed == true) { return; } @@ -83,6 +83,10 @@ namespace esignal { std::cout << "LOL"<< std::endl; } } + public: + virtual bool isSharedPtr(const std::shared_ptr& _obj) { + return false; + } }; protected: std::vector> m_executors; //!< List of all executors. @@ -110,7 +114,7 @@ namespace esignal { * @brief Emit the data on the observer. * @param[in] _values... Multiple value needed to send on observers */ - virtual void emit(Args... _values) { + virtual void emit(const Args&... _values) { // TODO: maybe an error if the object is not manage by the same thread. std::shared_ptr destObject = m_object.lock(); if (destObject == nullptr) { @@ -127,6 +131,17 @@ namespace esignal { std::cout << "LOL"<< std::endl; } } + public: + virtual bool isSharedPtr(const std::shared_ptr& _obj) { + std::shared_ptr destObject = m_object.lock(); + if (destObject == nullptr) { + return true; + } + if (destObject == _obj) { + return true; + } + return false; + } }; public: /** @@ -200,6 +215,19 @@ namespace esignal { } m_callInProgress--; } + protected: + void removeIfPossible() { + auto it = m_executors.begin(); + while (it != m_executors.end()) { + if ( *it == nullptr + || (*it)->m_removed == true) { + it = m_executors.erase(it); + continue; + } + ++it; + } + } + public: /** * @brief Disconnect an observer of the signal. * @param[in] _uid Unique id of the signal. @@ -208,11 +236,19 @@ namespace esignal { for (size_t iii=0; iii < m_executors.size(); ++iii) { if (m_executors[iii]->m_uid == _uid) { m_executors[iii]->m_removed = true; - return; + break; } } + removeIfPossible(); + } + void disconnectShared(const std::shared_ptr& _obj) { + for (size_t iii=0; iii < m_executors.size(); ++iii) { + if (m_executors[iii]->isSharedPtr(_obj) == true) { + m_executors[iii]->m_removed = true; + } + } + removeIfPossible(); } - public: /** * @brief Get the number of observers connected on the signal. * @return The count of observer. diff --git a/lutin_esignal-test.py b/lutin_esignal-test.py index bf5890e..28044cf 100644 --- a/lutin_esignal-test.py +++ b/lutin_esignal-test.py @@ -33,10 +33,7 @@ def create(target, module_name): 'test/test_signal_recursive.cpp', 'test/test_signal_shared_ptr_func.cpp', 'test/test_signal_static_func.cpp', - 'test/test_isignal_class_func.cpp', - 'test/test_isignal_recursive.cpp', - 'test/test_isignal_shared_ptr_func.cpp', - 'test/test_isignal_static_func.cpp', + 'test/test_isignal.cpp' ]) my_module.add_module_depend(['esignal', 'gtest', 'test-debug']) return my_module diff --git a/test/test_isignal_static_func.cpp b/test/test_isignal.cpp similarity index 87% rename from test/test_isignal_static_func.cpp rename to test/test_isignal.cpp index 76103da..f16559b 100644 --- a/test/test_isignal_static_func.cpp +++ b/test/test_isignal.cpp @@ -15,6 +15,6 @@ #undef __class__ -#define __class__ "test_isignal_static_func" +#define __class__ "test_isignal" diff --git a/test/test_isignal_class_func.cpp b/test/test_isignal_class_func.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_isignal_recursive.cpp b/test/test_isignal_recursive.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_isignal_shared_ptr_func.cpp b/test/test_isignal_shared_ptr_func.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_signal_arg.cpp b/test/test_signal_arg.cpp deleted file mode 100644 index a43ee33..0000000 --- a/test/test_signal_arg.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2016, Edouard DUPIN, all right reserved - * - * @license APACHE v2.0 (see license file) - */ - -#define NAME "SingleArg" -#include -#include -#include -#include -#include - - -#undef __class__ -#define __class__ "test_signal_arg" -/* -class TestSingleArg : public esignal::Interface { - public: - esignal::Signal 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 { - 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; - } - void non_const(std::string _plopppp) { - std::cout << " 987654 " << _plopppp << std::endl; - } - void is_const(const std::string& _plopppp) { - std::cout << " 987654 " << _plopppp << std::endl; - } -}; - -class TestConnectShared : public std::enable_shared_from_this { - 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; - } - void non_const(std::string _plopppp) { - std::cout << " 987654 " << _plopppp << std::endl; - } - void is_const(const std::string& _plopppp) { - std::cout << " 987654 " << _plopppp << std::endl; - } -}; - -template -auto complete_args(Func _f, Arg... _arg) { - return [=]( auto&&... cargs ){ return _f( cargs..., _arg... ); }; -} - - -template -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 connectedClass = std::make_shared(); - connectedClass->connect(baseClass); - baseClass.emit(); - EXPECT_EQ(connectedClass->m_valueInt32, 22); - */ - - #if 0 - esignal::Signal signal; - /* - TestConnect connectedClass; - esignal::Connection h6564 = signal.connect(&connectedClass, TestConnect::non_const); - esignal::Connection h6565 = signal.connect(&connectedClass, TestConnect::is_const); - */ - - std::shared_ptr connectedClassShared = std::make_shared(); - signal.connect(connectedClassShared, &TestConnectShared::non_const); - signal.connect(connectedClassShared, &TestConnectShared::is_const); - #endif - - #if 0 - esignal::Signal signal; - // ---------------------------------------------------- - auto display_values_1 = []( int a, float b, char c){ - std::cout << " 1111 " << a << " " << b << " " << c << " " << std::endl; - }; - esignal::Connection h1 = signal.bind(display_values_1); - - // ---------------------------------------------------- - auto display_values_2 = []( int a, float b, char c, int w ){ - std::cout << " 2222 " << a << " " << b << " " << c << " " << w << std::endl; - }; - esignal::Connection h2 = signal.bind( complete_args( display_values_2, 72 ) ); - - // ---------------------------------------------------- - TestConnect connectedClass; - esignal::Connection h3 = signal.bind([&](int a, float b, char c) { - connectedClass.display_values_4(a,b,c); - }); - /* - signal.bind( [&](auto && ... _cargs) { - connectedClass.display_values_3(_cargs);} - ); - */ - esignal::Connection h4 = signal.bind(&connectedClass, &TestConnect::display_values_4); - esignal::Connection h5 = signal.bind(&connectedClass, &TestConnect::display_values_5, "coucou"); - - std::shared_ptr connectedClassShared = std::make_shared(); - signal.bind(connectedClassShared, &TestConnectShared::display_values_6); - signal.bind(connectedClassShared, &TestConnectShared::display_values_7, "coucou"); - - - signal.emit( 5, 2.99, 'k'); - - h1.disconnect(); - h2.disconnect(); - h3.disconnect(); - h4.disconnect(); - h5.disconnect(); - - //signal.bind( complete_class(&connectedClass, &TestConnect::display_values_3) ); - //signal.bind( TestConnect::display_values_3(&connectedClass) ); - - auto display_values_recursive = [&]( int a, float b, char c, int w ){ - std::cout << " 99999 " << a << " " << b << " " << c << " " << w << std::endl; - std::cout << " ----------------------------------" << std::endl; - if (a == 0) { - return; - } - signal.emit(a-1, 2.66, 'l'); - }; - esignal::Connection h6 = signal.bind( complete_args( display_values_recursive, 72 ) ); - // ---------------------------------------------------- - - signal.emit( 5, 2.99, 'k'); - #endif - - - - #if 0 - std::cout << "========> Nes Signal " << std::endl; - std::shared_ptr> signalShared = std::make_shared>(); - - std::cout << "========> Connect callback " << std::endl; - auto display_val = [&]( const std::string& a){ - std::cout << " 1010 " << a<< std::endl; - std::cout << " ----------------------------------" << std::endl; - }; - esignal::Connection h7 = signalShared->bind(display_val); - - std::cout << "========> Emit" << std::endl; - signalShared->emit("coucou"); - - std::cout << "========> Remove Signal " << std::endl; - signalShared.reset(); - - std::cout << "========> disconnect " << std::endl; - h7.disconnect(); - #endif - - - esignal::Signal signal; - - TestConnect connectedClass; - esignal::Connection h6564 = signal.connect(&connectedClass, &TestConnect::non_const); - h6564.disconnect(); - h6564 = signal.connect(&connectedClass, &TestConnect::is_const); - signal.emit("kljlkjlkjlkj"); - - std::cout << "========================================= " << std::endl; -} diff --git a/test/test_signal_args.cpp b/test/test_signal_args.cpp deleted file mode 100644 index 823f95b..0000000 --- a/test/test_signal_args.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2016, Edouard DUPIN, all right reserved - * - * @license APACHE v2.0 (see license file) - */ - -#define NAME "SingleArg" -#include -#include -#include -#include -#include - - -#undef __class__ -#define __class__ "test_signal_arg" -/* -class TestSingleArgs : public esignal::Interface { - public: - esignal::Signal 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 { - 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 connectedClass = std::make_shared(); - connectedClass->connect(baseClass); - baseClass.emit(); - EXPECT_EQ(connectedClass->m_valueInt32_1, 22); - EXPECT_EQ(connectedClass->m_valueInt32_2, 23); -} - -*/ \ No newline at end of file diff --git a/test/test_signal_class_func.cpp b/test/test_signal_class_func.cpp index e69de29..6d419fd 100644 --- a/test/test_signal_class_func.cpp +++ b/test/test_signal_class_func.cpp @@ -0,0 +1,250 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2016, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ + +#define NAME "SingleArg" +#include +#include +#include +#include +#include + + +#undef __class__ +#define __class__ "test_signal_class_func" +class testCallback { + public: + int32_t m_int32; + std::string m_string; + bool m_void; + testCallback() { + m_void = false; + m_int32 = 0; + m_string = ""; + } + void callbackVoid(){ + m_void = true; + } + void callbackInt(int32_t _a){ + m_int32 = _a; + } + void callbackConstInt(const int32_t& _a){ + m_int32 = _a; + } + void callbackString(std::string _b){ + m_string = _b; + } + void callbackConstString(const std::string& _b){ + m_string = _b; + } + void callbackIntString(int32_t _a, std::string _b){ + m_int32 = _a; + m_string = _b; + } + void callbackConstIntString(const int32_t& _a, const std::string& _b){ + m_int32 = _a; + m_string = _b; + } + void callbackMixedIntString(int32_t _a, const std::string& _b){ + m_int32 = _a; + m_string = _b; + } + void callbackPolyargs(const int32_t& _a, const std::string& _b, char _char, int _int) { + m_int32 = _a + _int; + m_string = _b + _char; + } + void callbackDisconnect(esignal::Connection* _connection) { + _connection->disconnect(); + } +}; + +TEST(test_signal_class_func, localFunctionVoid) { + testCallback localClass; + esignal::Signal<> signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackVoid); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(); + EXPECT_EQ(localClass.m_void, true); +} + +TEST(test_signal_class_func, localFunctionInt32) { + testCallback localClass; + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(12345); + EXPECT_EQ(localClass.m_int32, 12345); +} + +TEST(test_signal_class_func, localFunctionConstInt32) { + testCallback localClass; + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackConstInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(34567); + EXPECT_EQ(localClass.m_int32, 34567); +} + +TEST(test_signal_class_func, localFunctionString) { + testCallback localClass; + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackString); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit("plop"); + EXPECT_EQ(localClass.m_string, "plop"); +} + +TEST(test_signal_class_func, localFunctionConstString) { + testCallback localClass; + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackConstString); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit("plop1234"); + EXPECT_EQ(localClass.m_string, "plop1234"); +} + +TEST(test_signal_class_func, localFunctionIntString) { + testCallback localClass; + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackIntString); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(23456, "plop2"); + EXPECT_EQ(localClass.m_int32, 23456); + EXPECT_EQ(localClass.m_string, "plop2"); +} + +TEST(test_signal_class_func, localFunctionConstIntString) { + testCallback localClass; + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackConstIntString); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(246, "plop567"); + EXPECT_EQ(localClass.m_int32, 246); + EXPECT_EQ(localClass.m_string, "plop567"); +} + +TEST(test_signal_class_func, localFunctionMixedIntString) { + testCallback localClass; + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackMixedIntString); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(765, "plTGY"); + EXPECT_EQ(localClass.m_int32, 765); + EXPECT_EQ(localClass.m_string, "plTGY"); +} + +TEST(test_signal_class_func, localFunctionConstIntStringPolyArg) { + testCallback localClass; + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackPolyargs, 'c', 12365); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(246, "plop567"); + EXPECT_EQ(localClass.m_int32, 246 + 12365); + EXPECT_EQ(localClass.m_string, "plop567c"); +} + + +TEST(test_signal_class_func, disconnect) { + testCallback localClass; + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(12345); + EXPECT_EQ(localClass.m_int32, 12345); + connection1.disconnect(); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); +} + + +TEST(test_signal_class_func, connect_disconnect_multiple) { + testCallback localClass; + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&localClass, &testCallback::callbackInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + esignal::Connection connection2 = signal.connect(&localClass, &testCallback::callbackInt); + EXPECT_EQ(signal.size(), 2); + EXPECT_EQ(signal.empty(), false); + esignal::Connection connection3 = signal.connect(&localClass, &testCallback::callbackInt); + EXPECT_EQ(signal.size(), 3); + EXPECT_EQ(signal.empty(), false); + esignal::Connection connection4 = signal.connect(&localClass, &testCallback::callbackInt); + EXPECT_EQ(signal.size(), 4); + EXPECT_EQ(signal.empty(), false); + connection1.disconnect(); + EXPECT_EQ(signal.size(), 3); + EXPECT_EQ(signal.empty(), false); + connection2.disconnect(); + EXPECT_EQ(signal.size(), 2); + EXPECT_EQ(signal.empty(), false); + connection3.disconnect(); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + connection4.disconnect(); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + connection1.disconnect(); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection5; + connection5.disconnect(); + connection5 = signal.connect(&localClass, &testCallback::callbackInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + connection5 = signal.connect(&localClass, &testCallback::callbackInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); +} + + +TEST(test_signal_class_func, disconnect_inCallback) { + testCallback localClass; + esignal::Signal<> signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1; + connection1 = signal.connect(&localClass, &testCallback::callbackDisconnect, &connection1); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); +} + diff --git a/test/test_signal_shared_ptr_func.cpp b/test/test_signal_shared_ptr_func.cpp index e69de29..f47c9c9 100644 --- a/test/test_signal_shared_ptr_func.cpp +++ b/test/test_signal_shared_ptr_func.cpp @@ -0,0 +1,275 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2016, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ + +#define NAME "SingleArg" +#include +#include +#include +#include +#include + + +#undef __class__ +#define __class__ "test_signal_class_func" +class testCallbackShared : public std::enable_shared_from_this { + public: + int32_t m_int32; + std::string m_string; + bool m_void; + testCallbackShared() { + m_void = false; + m_int32 = 0; + m_string = ""; + } + virtual ~testCallbackShared() { + + } + void callbackVoid() { + m_void = true; + } + void callbackInt(int32_t _a) { + m_int32 = _a; + } + void callbackConstInt(const int32_t& _a) { + m_int32 = _a; + } + void callbackString(std::string _b) { + m_string = _b; + } + void callbackConstString(const std::string& _b) { + m_string = _b; + } + void callbackIntString(int32_t _a, std::string _b) { + m_int32 = _a; + m_string = _b; + } + void callbackConstIntString(const int32_t& _a, const std::string& _b) { + m_int32 = _a; + m_string = _b; + } + void callbackMixedIntString(int32_t _a, const std::string& _b) { + m_int32 = _a; + m_string = _b; + } + void callbackPolyargs(const int32_t& _a, const std::string& _b, char _char, int _int) { + m_int32 = _a + _int; + m_string = _b + _char; + } + void callbackDisconnect(esignal::Signal<>* _signal) { + _signal->disconnectShared(shared_from_this()); + } +}; + + +TEST(test_signal_shared_ptr_func, localFunctionVoid) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal<> signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + signal.connect(localClass, &testCallbackShared::callbackVoid); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(); + EXPECT_EQ(localClass->m_void, true); +} + +TEST(test_signal_shared_ptr_func, localFunctionInt32) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + #if 0 + signal.connect(localClass, &testCallbackShared::callbackInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(12345); + EXPECT_EQ(localClass->m_int32, 12345); + #else + TEST_TODO("can not connect shared_ptr class with other than 'const &' signal parameter ==> NOT BUILD"); + #endif +} + +TEST(test_signal_shared_ptr_func, localFunctionConstInt32) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + signal.connect(localClass, &testCallbackShared::callbackConstInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(34567); + EXPECT_EQ(localClass->m_int32, 34567); +} + +TEST(test_signal_shared_ptr_func, localFunctionString) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + #if 0 + signal.connect(localClass, &testCallbackShared::callbackString); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit("plop"); + EXPECT_EQ(localClass->m_string, "plop"); + #else + TEST_TODO("can not connect shared_ptr class with other than 'const &' signal parameter ==> NOT BUILD"); + #endif +} + +TEST(test_signal_shared_ptr_func, localFunctionConstString) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + signal.connect(localClass, &testCallbackShared::callbackConstString); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit("plop1234"); + EXPECT_EQ(localClass->m_string, "plop1234"); +} + +TEST(test_signal_shared_ptr_func, localFunctionIntString) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + #if 0 + signal.connect(localClass, &testCallbackShared::callbackIntString); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(23456, "plop2"); + EXPECT_EQ(localClass->m_int32, 23456); + EXPECT_EQ(localClass->m_string, "plop2"); + #else + TEST_TODO("can not connect shared_ptr class with other than 'const &' signal parameter ==> NOT BUILD"); + #endif +} + +TEST(test_signal_shared_ptr_func, localFunctionConstIntString) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + signal.connect(localClass, &testCallbackShared::callbackConstIntString); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(246, "plop567"); + EXPECT_EQ(localClass->m_int32, 246); + EXPECT_EQ(localClass->m_string, "plop567"); +} + +TEST(test_signal_shared_ptr_func, localFunctionMixedIntString) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + #if 0 + signal.connect(localClass, &testCallbackShared::callbackMixedIntString); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(765, "plTGY"); + EXPECT_EQ(localClass->m_int32, 765); + EXPECT_EQ(localClass->m_string, "plTGY"); + #else + TEST_TODO("can not connect shared_ptr class with other than 'const &' signal parameter ==> NOT BUILD"); + #endif +} + + +TEST(test_signal_shared_ptr_func, localFunctionConstIntStringPolyArg) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + signal.connect(localClass, &testCallbackShared::callbackPolyargs, 'c', 12365); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(246, "plop567"); + EXPECT_EQ(localClass->m_int32, 246 + 12365); + EXPECT_EQ(localClass->m_string, "plop567c"); +} + +class testCallbackSharedHerited : public testCallbackShared { + public: + void callbackHerited(const int32_t& _a, const std::string& _b) { + m_int32 = _a; + m_string = _b; + } +}; + + +TEST(test_signal_shared_ptr_func, localFunctionHerited) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + signal.connect(localClass, &testCallbackSharedHerited::callbackHerited); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(246, "plop567"); + EXPECT_EQ(localClass->m_int32, 246); + EXPECT_EQ(localClass->m_string, "plop567"); +} + + +TEST(test_signal_shared_ptr_func, disconnect) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + signal.connect(localClass, &testCallbackShared::callbackConstInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(34567); + EXPECT_EQ(localClass->m_int32, 34567); + signal.disconnectShared(localClass); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); +} + + +TEST(test_signal_shared_ptr_func, connect_disconnect_multiple) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + signal.connect(localClass, &testCallbackShared::callbackConstInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.connect(localClass, &testCallbackShared::callbackConstInt); + EXPECT_EQ(signal.size(), 2); + EXPECT_EQ(signal.empty(), false); + signal.connect(localClass, &testCallbackShared::callbackConstInt); + EXPECT_EQ(signal.size(), 3); + EXPECT_EQ(signal.empty(), false); + signal.connect(localClass, &testCallbackShared::callbackConstInt); + EXPECT_EQ(signal.size(), 4); + EXPECT_EQ(signal.empty(), false); + signal.disconnectShared(localClass); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + signal.disconnectShared(localClass); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); +} + + +TEST(test_signal_shared_ptr_func, disconnect_inCallback) { + std::shared_ptr localClass = std::make_shared(); + esignal::Signal<> signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + signal.connect(localClass, &testCallbackShared::callbackDisconnect, &signal); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); +} + diff --git a/test/test_signal_static_func.cpp b/test/test_signal_static_func.cpp index 945d973..7f45110 100644 --- a/test/test_signal_static_func.cpp +++ b/test/test_signal_static_func.cpp @@ -27,48 +27,52 @@ static void clear() { tmpRetString = ""; } -auto callbackVoid = [](){ +static void callbackVoid(){ tmpRetVoid = true; }; -auto callbackInt = [](int32_t _a){ +static void callbackInt(int32_t _a){ tmpRetInt32 = _a; }; -auto callbackConstInt = [](const int32_t& _a){ +static void callbackConstInt(const int32_t& _a){ tmpRetInt32 = _a; }; -auto callbackString = [](std::string _b){ +static void callbackString(std::string _b){ tmpRetString = _b; }; -auto callbackConstString = [](const std::string& _b){ +static void callbackConstString(const std::string& _b){ tmpRetString = _b; }; -auto callbackIntString = [](int32_t _a, std::string _b){ +static void callbackIntString(int32_t _a, std::string _b){ tmpRetInt32 = _a; tmpRetString = _b; }; -auto callbackConstIntString = [](const int32_t& _a, const std::string& _b){ +static void callbackConstIntString(const int32_t& _a, const std::string& _b){ tmpRetInt32 = _a; tmpRetString = _b; }; -auto callbackMixedIntString = [](int32_t _a, const std::string& _b){ +static void callbackMixedIntString(int32_t _a, const std::string& _b){ tmpRetInt32 = _a; tmpRetString = _b; }; +static void callbackPolyargs(const int32_t& _a, const std::string& _b, char _char, int _int) { + tmpRetInt32 = _a + _int; + tmpRetString = _b + _char; +} TEST(test_signal_static_func, localFunctionVoid) { clear(); esignal::Signal<> signal; EXPECT_EQ(signal.size(), 0); EXPECT_EQ(signal.empty(), true); - esignal::Connection connection1 = signal.connect(callbackVoid); + esignal::Connection connection1 = signal.connect(&callbackVoid); EXPECT_EQ(signal.size(), 1); EXPECT_EQ(signal.empty(), false); signal.emit(); @@ -80,7 +84,7 @@ TEST(test_signal_static_func, localFunctionInt32) { esignal::Signal signal; EXPECT_EQ(signal.size(), 0); EXPECT_EQ(signal.empty(), true); - esignal::Connection connection1 = signal.connect(callbackInt); + esignal::Connection connection1 = signal.connect(&callbackInt); EXPECT_EQ(signal.size(), 1); EXPECT_EQ(signal.empty(), false); signal.emit(12345); @@ -92,7 +96,7 @@ TEST(test_signal_static_func, localFunctionConstInt32) { esignal::Signal signal; EXPECT_EQ(signal.size(), 0); EXPECT_EQ(signal.empty(), true); - esignal::Connection connection1 = signal.connect(callbackConstInt); + esignal::Connection connection1 = signal.connect(&callbackConstInt); EXPECT_EQ(signal.size(), 1); EXPECT_EQ(signal.empty(), false); signal.emit(34567); @@ -104,7 +108,7 @@ TEST(test_signal_static_func, localFunctionString) { esignal::Signal signal; EXPECT_EQ(signal.size(), 0); EXPECT_EQ(signal.empty(), true); - esignal::Connection connection1 = signal.connect(callbackString); + esignal::Connection connection1 = signal.connect(&callbackString); EXPECT_EQ(signal.size(), 1); EXPECT_EQ(signal.empty(), false); signal.emit("plop"); @@ -116,7 +120,7 @@ TEST(test_signal_static_func, localFunctionConstString) { esignal::Signal signal; EXPECT_EQ(signal.size(), 0); EXPECT_EQ(signal.empty(), true); - esignal::Connection connection1 = signal.connect(callbackConstString); + esignal::Connection connection1 = signal.connect(&callbackConstString); EXPECT_EQ(signal.size(), 1); EXPECT_EQ(signal.empty(), false); signal.emit("plop1234"); @@ -128,7 +132,7 @@ TEST(test_signal_static_func, localFunctionIntString) { esignal::Signal signal; EXPECT_EQ(signal.size(), 0); EXPECT_EQ(signal.empty(), true); - esignal::Connection connection1 = signal.connect(callbackIntString); + esignal::Connection connection1 = signal.connect(&callbackIntString); EXPECT_EQ(signal.size(), 1); EXPECT_EQ(signal.empty(), false); signal.emit(23456, "plop2"); @@ -141,7 +145,7 @@ TEST(test_signal_static_func, localFunctionConstIntString) { esignal::Signal signal; EXPECT_EQ(signal.size(), 0); EXPECT_EQ(signal.empty(), true); - esignal::Connection connection1 = signal.connect(callbackConstIntString); + esignal::Connection connection1 = signal.connect(&callbackConstIntString); EXPECT_EQ(signal.size(), 1); EXPECT_EQ(signal.empty(), false); signal.emit(246, "plop567"); @@ -154,7 +158,7 @@ TEST(test_signal_static_func, localFunctionMixedIntString) { esignal::Signal signal; EXPECT_EQ(signal.size(), 0); EXPECT_EQ(signal.empty(), true); - esignal::Connection connection1 = signal.connect(callbackMixedIntString); + esignal::Connection connection1 = signal.connect(&callbackMixedIntString); EXPECT_EQ(signal.size(), 1); EXPECT_EQ(signal.empty(), false); signal.emit(765, "plTGY"); @@ -162,70 +166,129 @@ TEST(test_signal_static_func, localFunctionMixedIntString) { EXPECT_EQ(tmpRetString, "plTGY"); } +template +auto complete_args(Func _f, Arg... _arg) { + return [=]( auto&&... cargs ){ + return _f( cargs..., _arg... ); + }; +} + +TEST(test_signal_static_func, localFunctionConstIntStringPolyArg) { + clear(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(complete_args(&callbackPolyargs, 'c', 12365)); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(246, "plop567"); + EXPECT_EQ(tmpRetInt32, 246 + 12365); + EXPECT_EQ(tmpRetString, "plop567c"); +} + #if 0 - // ---------------------------------------------------- - auto display_values_2 = []( int a, float b, char c, int w ){ - std::cout << " 2222 " << a << " " << b << " " << c << " " << w << std::endl; - }; - esignal::Connection h2 = signal.connect( complete_args( display_values_2, 72 ) ); - - // ---------------------------------------------------- - TestConnect connectedClass; - esignal::Connection h3 = signal.bind([&](int a, float b, char c) { - connectedClass.display_values_4(a,b,c); - }); - /* - signal.bind( [&](auto && ... _cargs) { - connectedClass.display_values_3(_cargs);} - ); - */ - esignal::Connection h4 = signal.bind(&connectedClass, &TestConnect::display_values_4); - esignal::Connection h5 = signal.bind(&connectedClass, &TestConnect::display_values_5, "coucou"); - - std::shared_ptr connectedClassShared = std::make_shared(); - signal.bind(connectedClassShared, &TestConnectShared::display_values_6); - signal.bind(connectedClassShared, &TestConnectShared::display_values_7, "coucou"); - - - signal.emit( 5, 2.99, 'k'); +TEST(test_signal_static_func, localFunctionConstIntStringPolyArgWithJAJA) { + clear(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&callbackPolyargs, 'c', 12365); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(246, "plop567"); + EXPECT_EQ(tmpRetInt32, 246 + 12365); + EXPECT_EQ(tmpRetString, "plop567c"); } - -TEST(test_signal_static_func, localFunction) { - - esignal::Signal signal; - // ---------------------------------------------------- - auto display_values_1 = []( int a, float b, char c){ - std::cout << " 1111 " << a << " " << b << " " << c << " " << std::endl; - }; - esignal::Connection h1 = signal.bind(display_values_1); - - // ---------------------------------------------------- - auto display_values_2 = []( int a, float b, char c, int w ){ - std::cout << " 2222 " << a << " " << b << " " << c << " " << w << std::endl; - }; - esignal::Connection h2 = signal.bind( complete_args( display_values_2, 72 ) ); - - // ---------------------------------------------------- - TestConnect connectedClass; - esignal::Connection h3 = signal.bind([&](int a, float b, char c) { - connectedClass.display_values_4(a,b,c); - }); - /* - signal.bind( [&](auto && ... _cargs) { - connectedClass.display_values_3(_cargs);} - ); - */ - esignal::Connection h4 = signal.bind(&connectedClass, &TestConnect::display_values_4); - esignal::Connection h5 = signal.bind(&connectedClass, &TestConnect::display_values_5, "coucou"); - - std::shared_ptr connectedClassShared = std::make_shared(); - signal.bind(connectedClassShared, &TestConnectShared::display_values_6); - signal.bind(connectedClassShared, &TestConnectShared::display_values_7, "coucou"); - - - signal.emit( 5, 2.99, 'k'); -} - #endif +TEST(test_signal_static_func, localFunctionLambda) { + clear(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect( + [](int32_t _a, const std::string& _b) { + tmpRetInt32 = _a; + tmpRetString = _b; + } + ); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(246, "plop567"); + EXPECT_EQ(tmpRetInt32, 246); + EXPECT_EQ(tmpRetString, "plop567"); +} + +TEST(test_signal_static_func, disconnect) { + clear(); + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&callbackInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(12345); + EXPECT_EQ(tmpRetInt32, 12345); + connection1.disconnect(); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); +} + +TEST(test_signal_static_func, connect_disconnect_multiple) { + esignal::Signal signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1 = signal.connect(&callbackInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + esignal::Connection connection2 = signal.connect(&callbackInt); + EXPECT_EQ(signal.size(), 2); + EXPECT_EQ(signal.empty(), false); + esignal::Connection connection3 = signal.connect(&callbackInt); + EXPECT_EQ(signal.size(), 3); + EXPECT_EQ(signal.empty(), false); + esignal::Connection connection4 = signal.connect(&callbackInt); + EXPECT_EQ(signal.size(), 4); + EXPECT_EQ(signal.empty(), false); + connection1.disconnect(); + EXPECT_EQ(signal.size(), 3); + EXPECT_EQ(signal.empty(), false); + connection2.disconnect(); + EXPECT_EQ(signal.size(), 2); + EXPECT_EQ(signal.empty(), false); + connection3.disconnect(); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + connection4.disconnect(); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + connection1.disconnect(); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection5; + connection5.disconnect(); + connection5 = signal.connect(&callbackInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + connection5 = signal.connect(&callbackInt); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); +} + + +static void callbackDisconnect(esignal::Connection* _connection) { + _connection->disconnect(); +} +TEST(test_signal_static_func, disconnect_inCallback) { + esignal::Signal<> signal; + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); + esignal::Connection connection1; + connection1 = signal.connect(complete_args(&callbackDisconnect, &connection1)); + EXPECT_EQ(signal.size(), 1); + EXPECT_EQ(signal.empty(), false); + signal.emit(); + EXPECT_EQ(signal.size(), 0); + EXPECT_EQ(signal.empty(), true); +} diff --git a/test/test_signal_void.cpp b/test/test_signal_void.cpp deleted file mode 100644 index e69de29..0000000