blob: b427ef67c2d398b92bb1446a9c185cfb0e54abd7 [file] [log] [blame]
buildbot@webrtc.org5ffd4a62014-06-04 21:57:16 +00001#include "talk/base/sigslottester.h"
2
3#include "talk/base/gunit.h"
4#include "talk/base/sigslot.h"
5
6namespace talk_base {
7
8TEST(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
23TEST(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
43TEST(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
53TEST(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
64TEST(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