Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2722)

Unified Diff: base/callback_list_unittest.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/callback_list.h ('k') | base/callback_list_unittest.nc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/callback_list_unittest.cc
diff --git a/base/callback_list_unittest.cc b/base/callback_list_unittest.cc
index 010efc54f74a292491af42ab9c99d1857cd28d03..62081e9a72dec3f4819ae8cf57e767e96bd48f6c 100644
--- a/base/callback_list_unittest.cc
+++ b/base/callback_list_unittest.cc
@@ -4,12 +4,12 @@
#include "base/callback_list.h"
+#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
@@ -38,7 +38,7 @@ class Remover {
removal_subscription_.reset();
}
void SetSubscriptionToRemove(
- scoped_ptr<CallbackList<void(void)>::Subscription> sub) {
+ std::unique_ptr<CallbackList<void(void)>::Subscription> sub) {
removal_subscription_ = std::move(sub);
}
@@ -46,7 +46,7 @@ class Remover {
private:
int total_;
- scoped_ptr<CallbackList<void(void)>::Subscription> removal_subscription_;
+ std::unique_ptr<CallbackList<void(void)>::Subscription> removal_subscription_;
DISALLOW_COPY_AND_ASSIGN(Remover);
};
@@ -74,7 +74,7 @@ class Adder {
bool added_;
int total_;
CallbackList<void(void)>* cb_reg_;
- scoped_ptr<CallbackList<void(void)>::Subscription> subscription_;
+ std::unique_ptr<CallbackList<void(void)>::Subscription> subscription_;
DISALLOW_COPY_AND_ASSIGN(Adder);
};
@@ -118,42 +118,43 @@ TEST(CallbackListTest, ArityTest) {
Summer s;
CallbackList<void(int)> c1;
- scoped_ptr<CallbackList<void(int)>::Subscription> subscription1 =
+ std::unique_ptr<CallbackList<void(int)>::Subscription> subscription1 =
c1.Add(Bind(&Summer::AddOneParam, Unretained(&s)));
c1.Notify(1);
EXPECT_EQ(1, s.value());
CallbackList<void(int, int)> c2;
- scoped_ptr<CallbackList<void(int, int)>::Subscription> subscription2 =
+ std::unique_ptr<CallbackList<void(int, int)>::Subscription> subscription2 =
c2.Add(Bind(&Summer::AddTwoParam, Unretained(&s)));
c2.Notify(1, 2);
EXPECT_EQ(3, s.value());
CallbackList<void(int, int, int)> c3;
- scoped_ptr<CallbackList<void(int, int, int)>::Subscription>
+ std::unique_ptr<CallbackList<void(int, int, int)>::Subscription>
subscription3 = c3.Add(Bind(&Summer::AddThreeParam, Unretained(&s)));
c3.Notify(1, 2, 3);
EXPECT_EQ(6, s.value());
CallbackList<void(int, int, int, int)> c4;
- scoped_ptr<CallbackList<void(int, int, int, int)>::Subscription>
+ std::unique_ptr<CallbackList<void(int, int, int, int)>::Subscription>
subscription4 = c4.Add(Bind(&Summer::AddFourParam, Unretained(&s)));
c4.Notify(1, 2, 3, 4);
EXPECT_EQ(10, s.value());
CallbackList<void(int, int, int, int, int)> c5;
- scoped_ptr<CallbackList<void(int, int, int, int, int)>::Subscription>
+ std::unique_ptr<CallbackList<void(int, int, int, int, int)>::Subscription>
subscription5 = c5.Add(Bind(&Summer::AddFiveParam, Unretained(&s)));
c5.Notify(1, 2, 3, 4, 5);
EXPECT_EQ(15, s.value());
CallbackList<void(int, int, int, int, int, int)> c6;
- scoped_ptr<CallbackList<void(int, int, int, int, int, int)>::Subscription>
+ std::unique_ptr<
+ CallbackList<void(int, int, int, int, int, int)>::Subscription>
subscription6 = c6.Add(Bind(&Summer::AddSixParam, Unretained(&s)));
c6.Notify(1, 2, 3, 4, 5, 6);
@@ -166,9 +167,9 @@ TEST(CallbackListTest, BasicTest) {
CallbackList<void(void)> cb_reg;
Listener a, b, c;
- scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription =
+ std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a)));
- scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription =
+ std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b)));
EXPECT_TRUE(a_subscription.get());
@@ -181,7 +182,7 @@ TEST(CallbackListTest, BasicTest) {
b_subscription.reset();
- scoped_ptr<CallbackList<void(void)>::Subscription> c_subscription =
+ std::unique_ptr<CallbackList<void(void)>::Subscription> c_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&c)));
cb_reg.Notify();
@@ -201,9 +202,9 @@ TEST(CallbackListTest, BasicTestWithParams) {
CallbackList<void(int)> cb_reg;
Listener a(1), b(-1), c(1);
- scoped_ptr<CallbackList<void(int)>::Subscription> a_subscription =
+ std::unique_ptr<CallbackList<void(int)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&a)));
- scoped_ptr<CallbackList<void(int)>::Subscription> b_subscription =
+ std::unique_ptr<CallbackList<void(int)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&b)));
EXPECT_TRUE(a_subscription.get());
@@ -216,7 +217,7 @@ TEST(CallbackListTest, BasicTestWithParams) {
b_subscription.reset();
- scoped_ptr<CallbackList<void(int)>::Subscription> c_subscription =
+ std::unique_ptr<CallbackList<void(int)>::Subscription> c_subscription =
cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&c)));
cb_reg.Notify(10);
@@ -237,15 +238,15 @@ TEST(CallbackListTest, RemoveCallbacksDuringIteration) {
Listener a, b;
Remover remover_1, remover_2;
- scoped_ptr<CallbackList<void(void)>::Subscription> remover_1_sub =
- cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove,
- Unretained(&remover_1)));
- scoped_ptr<CallbackList<void(void)>::Subscription> remover_2_sub =
- cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove,
- Unretained(&remover_2)));
- scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription =
+ std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub =
+ cb_reg.Add(
+ Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1)));
+ std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub =
+ cb_reg.Add(
+ Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2)));
+ std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a)));
- scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription =
+ std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b)));
// |remover_1| will remove itself.
@@ -278,9 +279,9 @@ TEST(CallbackListTest, AddCallbacksDuringIteration) {
CallbackList<void(void)> cb_reg;
Adder a(&cb_reg);
Listener b;
- scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription =
+ std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Adder::AddCallback, Unretained(&a)));
- scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription =
+ std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b)));
cb_reg.Notify();
@@ -308,7 +309,7 @@ TEST(CallbackList, RemovalCallback) {
cb_reg.set_removal_callback(
Bind(&Counter::Increment, Unretained(&remove_count)));
- scoped_ptr<CallbackList<void(void)>::Subscription> subscription =
+ std::unique_ptr<CallbackList<void(void)>::Subscription> subscription =
cb_reg.Add(Bind(&DoNothing));
// Removing a subscription outside of iteration signals the callback.
@@ -318,12 +319,12 @@ TEST(CallbackList, RemovalCallback) {
// Configure two subscriptions to remove themselves.
Remover remover_1, remover_2;
- scoped_ptr<CallbackList<void(void)>::Subscription> remover_1_sub =
- cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove,
- Unretained(&remover_1)));
- scoped_ptr<CallbackList<void(void)>::Subscription> remover_2_sub =
- cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove,
- Unretained(&remover_2)));
+ std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub =
+ cb_reg.Add(
+ Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1)));
+ std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub =
+ cb_reg.Add(
+ Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2)));
remover_1.SetSubscriptionToRemove(std::move(remover_1_sub));
remover_2.SetSubscriptionToRemove(std::move(remover_2_sub));
« no previous file with comments | « base/callback_list.h ('k') | base/callback_list_unittest.nc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698