| OLD | NEW |
| (Empty) |
| 1 /* | |
| 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 | |
| 11 #include "webrtc/base/sigslottester.h" | |
| 12 | |
| 13 #include <string> | |
| 14 | |
| 15 #include "webrtc/base/gunit.h" | |
| 16 #include "webrtc/base/sigslot.h" | |
| 17 | |
| 18 namespace rtc { | |
| 19 | |
| 20 TEST(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 | |
| 35 TEST(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 | |
| 55 TEST(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 | |
| 65 TEST(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()); | |
| 71 source1.emit(nullptr); | |
| 72 EXPECT_EQ(1, slot1.callback_count()); | |
| 73 EXPECT_EQ(nullptr, capture1); | |
| 74 } | |
| 75 | |
| 76 TEST(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()); | |
| 81 source1.emit(nullptr); | |
| 82 EXPECT_EQ(1, slot1.callback_count()); | |
| 83 EXPECT_EQ(nullptr, capture1); | |
| 84 } | |
| 85 | |
| 86 } // namespace rtc | |
| OLD | NEW |