From: Christian P. <cp...@us...> - 2005-01-06 17:00:47
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16781 Added Files: SignalTest.cpp Log Message: Added SignalTest. --- NEW FILE: SignalTest.cpp --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/Callback.h" #include "pclasses/Signal.h" #include "Test.h" namespace P { class Signal0Test: public UnitTest { public: void testFunc() { _testFunc = true; } static void testFuncStatic() { _testFuncStatic = true; } bool testFunc2() { return true; } static bool testFunc2Static() { return false; } void run() throw() { _testFunc = false; _testFuncStatic = false; // bind signals and see if methods did run Signal0<void> sig; sig.bind(function(&testFuncStatic)); sig.bind(method(this, &Signal0Test::testFunc)); sig.fire(); P_TEST(_testFunc == true); P_TEST(_testFuncStatic == true); // unbind signals and test again .. _testFunc = false; _testFuncStatic = false; sig.unbind(function(&testFuncStatic)); sig.unbind(method(this, &Signal0Test::testFunc)); sig.fire(); P_TEST(_testFunc == false); P_TEST(_testFuncStatic == false); // test signal with bool return-type Signal0<bool> sig2; sig2.bind(function(&testFunc2Static)); sig2.bind(method(this, &Signal0Test::testFunc2)); P_TEST(sig2.fire() == true); } private: bool _testFunc; static bool _testFuncStatic; }; bool Signal0Test::_testFuncStatic = false; } int main(int argc, char* argv[]) { P::Signal0Test s0t; s0t.run(); } |