buildbot@webrtc.org | 5ffd4a6 | 2014-06-04 21:57:16 +0000 | [diff] [blame] | 1 | #include "talk/base/sigslottester.h" |
| 2 | |
| 3 | #include "talk/base/gunit.h" |
| 4 | #include "talk/base/sigslot.h" |
| 5 | |
| 6 | namespace talk_base { |
| 7 | |
| 8 | TEST(SigslotTester, TestSignal1Arg) { |
| 9 | sigslot::signal1<int> source1; |
| 10 | int capture1; |
| 11 | SigslotTester1<int, int> slot1(&source1, &capture1); |
| 12 | EXPECT_EQ(0, slot1.callback_count()); |
| 13 | |
| 14 | source1.emit(10); |
| 15 | EXPECT_EQ(1, slot1.callback_count()); |
| 16 | EXPECT_EQ(10, capture1); |
| 17 | |
| 18 | source1.emit(20); |
| 19 | EXPECT_EQ(2, slot1.callback_count()); |
| 20 | EXPECT_EQ(20, capture1); |
| 21 | } |
| 22 | |
| 23 | TEST(SigslotTester, TestSignal2Args) { |
| 24 | sigslot::signal2<int, char> source2; |
| 25 | int capture1; |
| 26 | char capture2; |
| 27 | SigslotTester2<int, char, int, char> slot2(&source2, &capture1, &capture2); |
| 28 | EXPECT_EQ(0, slot2.callback_count()); |
| 29 | |
| 30 | source2.emit(10, 'x'); |
| 31 | EXPECT_EQ(1, slot2.callback_count()); |
| 32 | EXPECT_EQ(10, capture1); |
| 33 | EXPECT_EQ('x', capture2); |
| 34 | |
| 35 | source2.emit(20, 'y'); |
| 36 | EXPECT_EQ(2, slot2.callback_count()); |
| 37 | EXPECT_EQ(20, capture1); |
| 38 | EXPECT_EQ('y', capture2); |
| 39 | } |
| 40 | |
| 41 | // Since it applies for 1 and 2 args, we assume it will work for up to 5 args. |
| 42 | |
| 43 | TEST(SigslotTester, TestSignalWithConstReferenceArgs) { |
| 44 | sigslot::signal1<const std::string&> source1; |
| 45 | std::string capture1; |
| 46 | SigslotTester1<const std::string&, std::string> slot1(&source1, &capture1); |
| 47 | EXPECT_EQ(0, slot1.callback_count()); |
| 48 | source1.emit("hello"); |
| 49 | EXPECT_EQ(1, slot1.callback_count()); |
| 50 | EXPECT_EQ("hello", capture1); |
| 51 | } |
| 52 | |
| 53 | TEST(SigslotTester, TestSignalWithPointerToConstArgs) { |
| 54 | sigslot::signal1<const std::string*> source1; |
| 55 | const std::string* capture1; |
| 56 | SigslotTester1<const std::string*, const std::string*> slot1(&source1, |
| 57 | &capture1); |
| 58 | EXPECT_EQ(0, slot1.callback_count()); |
| 59 | source1.emit(NULL); |
| 60 | EXPECT_EQ(1, slot1.callback_count()); |
| 61 | EXPECT_EQ(NULL, capture1); |
| 62 | } |
| 63 | |
| 64 | TEST(SigslotTester, TestSignalWithConstPointerArgs) { |
| 65 | sigslot::signal1<std::string* const> source1; |
| 66 | std::string* capture1; |
| 67 | SigslotTester1<std::string* const, std::string*> slot1(&source1, &capture1); |
| 68 | EXPECT_EQ(0, slot1.callback_count()); |
| 69 | source1.emit(NULL); |
| 70 | EXPECT_EQ(1, slot1.callback_count()); |
| 71 | EXPECT_EQ(NULL, capture1); |
| 72 | } |
| 73 | |
| 74 | } // namespace talk_base |