blob: b8d5735f9d37f23d2be2dbf3d5209e2d233505d7 [file] [log] [blame]
henrike@webrtc.org4e5f65a2014-06-05 20:40:111/*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 04:47:3111#include "rtc_base/sigslottester.h"
henrike@webrtc.org4e5f65a2014-06-05 20:40:1112
13#include <string>
14
Artem Titove41c4332018-07-25 13:04:2815#include "rtc_base/third_party/sigslot/sigslot.h"
Yves Gerey3e707812018-11-28 15:47:4916#include "test/gtest.h"
henrike@webrtc.org4e5f65a2014-06-05 20:40:1117
18namespace rtc {
19
20TEST(SigslotTester, TestSignal1Arg) {
21 sigslot::signal1<int> source1;
22 int capture1;
23 SigslotTester1<int, int> slot1(&source1, &capture1);
24 EXPECT_EQ(0, slot1.callback_count());
25
26 source1.emit(10);
27 EXPECT_EQ(1, slot1.callback_count());
28 EXPECT_EQ(10, capture1);
29
30 source1.emit(20);
31 EXPECT_EQ(2, slot1.callback_count());
32 EXPECT_EQ(20, capture1);
33}
34
35TEST(SigslotTester, TestSignal2Args) {
36 sigslot::signal2<int, char> source2;
37 int capture1;
38 char capture2;
39 SigslotTester2<int, char, int, char> slot2(&source2, &capture1, &capture2);
40 EXPECT_EQ(0, slot2.callback_count());
41
42 source2.emit(10, 'x');
43 EXPECT_EQ(1, slot2.callback_count());
44 EXPECT_EQ(10, capture1);
45 EXPECT_EQ('x', capture2);
46
47 source2.emit(20, 'y');
48 EXPECT_EQ(2, slot2.callback_count());
49 EXPECT_EQ(20, capture1);
50 EXPECT_EQ('y', capture2);
51}
52
53// Since it applies for 1 and 2 args, we assume it will work for up to 5 args.
54
55TEST(SigslotTester, TestSignalWithConstReferenceArgs) {
56 sigslot::signal1<const std::string&> source1;
57 std::string capture1;
58 SigslotTester1<const std::string&, std::string> slot1(&source1, &capture1);
59 EXPECT_EQ(0, slot1.callback_count());
60 source1.emit("hello");
61 EXPECT_EQ(1, slot1.callback_count());
62 EXPECT_EQ("hello", capture1);
63}
64
65TEST(SigslotTester, TestSignalWithPointerToConstArgs) {
66 sigslot::signal1<const std::string*> source1;
67 const std::string* capture1;
68 SigslotTester1<const std::string*, const std::string*> slot1(&source1,
69 &capture1);
70 EXPECT_EQ(0, slot1.callback_count());
deadbeef37f5ecf2017-02-27 22:06:4171 source1.emit(nullptr);
henrike@webrtc.org4e5f65a2014-06-05 20:40:1172 EXPECT_EQ(1, slot1.callback_count());
deadbeef37f5ecf2017-02-27 22:06:4173 EXPECT_EQ(nullptr, capture1);
henrike@webrtc.org4e5f65a2014-06-05 20:40:1174}
75
76TEST(SigslotTester, TestSignalWithConstPointerArgs) {
77 sigslot::signal1<std::string* const> source1;
78 std::string* capture1;
79 SigslotTester1<std::string* const, std::string*> slot1(&source1, &capture1);
80 EXPECT_EQ(0, slot1.callback_count());
deadbeef37f5ecf2017-02-27 22:06:4181 source1.emit(nullptr);
henrike@webrtc.org4e5f65a2014-06-05 20:40:1182 EXPECT_EQ(1, slot1.callback_count());
deadbeef37f5ecf2017-02-27 22:06:4183 EXPECT_EQ(nullptr, capture1);
henrike@webrtc.org4e5f65a2014-06-05 20:40:1184}
85
86} // namespace rtc