Sanity check that we can instantiate a CallbackList for each arity.
| 100 | |
| 101 | // Sanity check that we can instantiate a CallbackList for each arity. |
| 102 | TEST(CallbackListTest, ArityTest) { |
| 103 | Summer s; |
| 104 | |
| 105 | CallbackList<void(int)> c1; |
| 106 | scoped_ptr<CallbackList<void(int)>::Subscription> subscription1 = |
| 107 | c1.Add(Bind(&Summer::AddOneParam, Unretained(&s))); |
| 108 | |
| 109 | c1.Notify(1); |
| 110 | EXPECT_EQ(1, s.value()); |
| 111 | |
| 112 | CallbackList<void(int, int)> c2; |
| 113 | scoped_ptr<CallbackList<void(int, int)>::Subscription> subscription2 = |
| 114 | c2.Add(Bind(&Summer::AddTwoParam, Unretained(&s))); |
| 115 | |
| 116 | c2.Notify(1, 2); |
| 117 | EXPECT_EQ(3, s.value()); |
| 118 | |
| 119 | CallbackList<void(int, int, int)> c3; |
| 120 | scoped_ptr<CallbackList<void(int, int, int)>::Subscription> |
| 121 | subscription3 = c3.Add(Bind(&Summer::AddThreeParam, Unretained(&s))); |
| 122 | |
| 123 | c3.Notify(1, 2, 3); |
| 124 | EXPECT_EQ(6, s.value()); |
| 125 | |
| 126 | CallbackList<void(int, int, int, int)> c4; |
| 127 | scoped_ptr<CallbackList<void(int, int, int, int)>::Subscription> |
| 128 | subscription4 = c4.Add(Bind(&Summer::AddFourParam, Unretained(&s))); |
| 129 | |
| 130 | c4.Notify(1, 2, 3, 4); |
| 131 | EXPECT_EQ(10, s.value()); |
| 132 | |
| 133 | CallbackList<void(int, int, int, int, int)> c5; |
| 134 | scoped_ptr<CallbackList<void(int, int, int, int, int)>::Subscription> |
| 135 | subscription5 = c5.Add(Bind(&Summer::AddFiveParam, Unretained(&s))); |
| 136 | |
| 137 | c5.Notify(1, 2, 3, 4, 5); |
| 138 | EXPECT_EQ(15, s.value()); |
| 139 | |
| 140 | CallbackList<void(int, int, int, int, int, int)> c6; |
| 141 | scoped_ptr<CallbackList<void(int, int, int, int, int, int)>::Subscription> |
| 142 | subscription6 = c6.Add(Bind(&Summer::AddSixParam, Unretained(&s))); |
| 143 | |
| 144 | c6.Notify(1, 2, 3, 4, 5, 6); |
| 145 | EXPECT_EQ(21, s.value()); |
| 146 | } |
| 147 | |
| 148 | // Sanity check that closures added to the list will be run, and those removed |
| 149 | // from the list will not be run. |