SignalSlot_test.cc revision 4670cafe
14670cafeSShuo Chen#include "../SignalSlotTrivial.h" 24670cafeSShuo Chen 34670cafeSShuo Chen#include <boost/bind.hpp> 44670cafeSShuo Chen 54670cafeSShuo Chen#define BOOST_TEST_MAIN 64670cafeSShuo Chen#ifdef BOOST_TEST_DYN_LINK 74670cafeSShuo Chen#include <boost/test/unit_test.hpp> 84670cafeSShuo Chen#else 94670cafeSShuo Chen#include <boost/test/included/unit_test.hpp> 104670cafeSShuo Chen#endif 114670cafeSShuo Chen 124670cafeSShuo Chenclass String 134670cafeSShuo Chen{ 144670cafeSShuo Chen public: 154670cafeSShuo Chen String(const char* str) 164670cafeSShuo Chen { 174670cafeSShuo Chen printf("String ctor this %p\n", this); 184670cafeSShuo Chen } 194670cafeSShuo Chen 204670cafeSShuo Chen String(const String& rhs) 214670cafeSShuo Chen { 224670cafeSShuo Chen printf("String copy ctor this %p, rhs %p\n", this, &rhs); 234670cafeSShuo Chen } 244670cafeSShuo Chen 254670cafeSShuo Chen String(String&& rhs) 264670cafeSShuo Chen { 274670cafeSShuo Chen printf("String move ctor this %p, rhs %p\n", this, &rhs); 284670cafeSShuo Chen } 294670cafeSShuo Chen}; 304670cafeSShuo Chen 314670cafeSShuo Chenclass Foo : boost::noncopyable 324670cafeSShuo Chen{ 334670cafeSShuo Chen public: 344670cafeSShuo Chen void zero(); 354670cafeSShuo Chen void zeroc() const; 364670cafeSShuo Chen void one(int); 374670cafeSShuo Chen void oner(int&); 384670cafeSShuo Chen void onec(int) const; 394670cafeSShuo Chen void oneString(const String& str); 404670cafeSShuo Chen // void oneStringRR(String&& str); 414670cafeSShuo Chen static void szero(); 424670cafeSShuo Chen static void sone(int); 434670cafeSShuo Chen static void soneString(const String& str); 444670cafeSShuo Chen}; 454670cafeSShuo Chen 464670cafeSShuo Chenvoid Foo::zero() 474670cafeSShuo Chen{ 484670cafeSShuo Chen printf("Foo::zero()\n"); 494670cafeSShuo Chen} 504670cafeSShuo Chen 514670cafeSShuo Chenvoid Foo::zeroc() const 524670cafeSShuo Chen{ 534670cafeSShuo Chen printf("Foo::zeroc()\n"); 544670cafeSShuo Chen} 554670cafeSShuo Chen 564670cafeSShuo Chenvoid Foo::szero() 574670cafeSShuo Chen{ 584670cafeSShuo Chen printf("Foo::szero()\n"); 594670cafeSShuo Chen} 604670cafeSShuo Chen 614670cafeSShuo Chenvoid Foo::one(int x) 624670cafeSShuo Chen{ 634670cafeSShuo Chen printf("Foo::one() x=%d\n", x); 644670cafeSShuo Chen} 654670cafeSShuo Chen 664670cafeSShuo Chenvoid Foo::onec(int x) const 674670cafeSShuo Chen{ 684670cafeSShuo Chen printf("Foo::onec() x=%d\n", x); 694670cafeSShuo Chen} 704670cafeSShuo Chen 714670cafeSShuo Chenvoid Foo::sone(int x) 724670cafeSShuo Chen{ 734670cafeSShuo Chen printf("Foo::sone() x=%d\n", x); 744670cafeSShuo Chen} 754670cafeSShuo Chen 764670cafeSShuo Chenvoid Foo::oneString(const String& str) 774670cafeSShuo Chen{ 784670cafeSShuo Chen printf("Foo::oneString\n"); 794670cafeSShuo Chen} 804670cafeSShuo Chen 814670cafeSShuo Chenvoid Foo::soneString(const String& str) 824670cafeSShuo Chen{ 834670cafeSShuo Chen printf("Foo::soneString\n"); 844670cafeSShuo Chen} 854670cafeSShuo Chen 864670cafeSShuo ChenBOOST_AUTO_TEST_CASE(testSignalSlotTrivialZero) 874670cafeSShuo Chen{ 884670cafeSShuo Chen SignalTrivial<void()> signal; 894670cafeSShuo Chen 904670cafeSShuo Chen printf("========\n"); 914670cafeSShuo Chen signal.call(); 924670cafeSShuo Chen 934670cafeSShuo Chen signal.connect(&Foo::szero); 944670cafeSShuo Chen 954670cafeSShuo Chen printf("========\n"); 964670cafeSShuo Chen signal.call(); 974670cafeSShuo Chen 984670cafeSShuo Chen Foo f; 994670cafeSShuo Chen signal.connect(boost::bind(&Foo::zero, &f)); 1004670cafeSShuo Chen 1014670cafeSShuo Chen printf("========\n"); 1024670cafeSShuo Chen signal.call(); 1034670cafeSShuo Chen 1044670cafeSShuo Chen signal.connect(boost::bind(&Foo::one, &f, 42)); 1054670cafeSShuo Chen 1064670cafeSShuo Chen printf("========\n"); 1074670cafeSShuo Chen signal.call(); 1084670cafeSShuo Chen 1094670cafeSShuo Chen const Foo cf; 1104670cafeSShuo Chen signal.connect(boost::bind(&Foo::zeroc, &cf)); 1114670cafeSShuo Chen 1124670cafeSShuo Chen printf("========\n"); 1134670cafeSShuo Chen signal.call(); 1144670cafeSShuo Chen 1154670cafeSShuo Chen signal.connect(boost::bind(&Foo::onec, &cf, 128)); 1164670cafeSShuo Chen 1174670cafeSShuo Chen printf("========\n"); 1184670cafeSShuo Chen signal.call(); 1194670cafeSShuo Chen 1204670cafeSShuo Chen printf("========\n"); 1214670cafeSShuo Chen signal.call(); 1224670cafeSShuo Chen} 1234670cafeSShuo Chen 1244670cafeSShuo ChenBOOST_AUTO_TEST_CASE(testSignalSlotTrivialOne) 1254670cafeSShuo Chen{ 1264670cafeSShuo Chen SignalTrivial<void(int)> signal; 1274670cafeSShuo Chen 1284670cafeSShuo Chen printf("========\n"); 1294670cafeSShuo Chen signal.call(50); 1304670cafeSShuo Chen 1314670cafeSShuo Chen signal.connect(&Foo::sone); 1324670cafeSShuo Chen 1334670cafeSShuo Chen printf("========\n"); 1344670cafeSShuo Chen signal.call(51); 1354670cafeSShuo Chen 1364670cafeSShuo Chen Foo f; 1374670cafeSShuo Chen signal.connect(boost::bind(&Foo::one, &f, _1)); 1384670cafeSShuo Chen 1394670cafeSShuo Chen printf("========\n"); 1404670cafeSShuo Chen signal.call(52); 1414670cafeSShuo Chen 1424670cafeSShuo Chen const Foo cf; 1434670cafeSShuo Chen signal.connect(boost::bind(&Foo::onec, &cf, _1)); 1444670cafeSShuo Chen 1454670cafeSShuo Chen printf("========\n"); 1464670cafeSShuo Chen signal.call(53); 1474670cafeSShuo Chen} 1484670cafeSShuo Chen 1494670cafeSShuo ChenBOOST_AUTO_TEST_CASE(testSignalSlotTrivialString) 1504670cafeSShuo Chen{ 1514670cafeSShuo Chen SignalTrivial<void(const String&)> signal; 1524670cafeSShuo Chen signal.call("hello"); 1534670cafeSShuo Chen 1544670cafeSShuo Chen signal.connect(&Foo::soneString); 1554670cafeSShuo Chen 1564670cafeSShuo Chen printf("========\n"); 1574670cafeSShuo Chen signal.call("hello"); 1584670cafeSShuo Chen 1594670cafeSShuo Chen Foo f; 1604670cafeSShuo Chen signal.connect(boost::bind(&Foo::oneString, &f, _1)); 1614670cafeSShuo Chen 1624670cafeSShuo Chen printf("========\n"); 1634670cafeSShuo Chen signal.call("hello"); 1644670cafeSShuo Chen} 1654670cafeSShuo Chen 166