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

Side by Side Diff: base/callback_helpers_unittest.cc

Issue 2091503004: Add move constructor in ScopedClosureRunner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « base/callback_helpers.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/callback_helpers.h" 5 #include "base/callback_helpers.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 int run_count_3 = 0; 51 int run_count_3 = 0;
52 { 52 {
53 base::ScopedClosureRunner runner(base::Bind(&Increment, &run_count_3)); 53 base::ScopedClosureRunner runner(base::Bind(&Increment, &run_count_3));
54 EXPECT_EQ(0, run_count_3); 54 EXPECT_EQ(0, run_count_3);
55 runner.Reset(); 55 runner.Reset();
56 EXPECT_EQ(1, run_count_3); 56 EXPECT_EQ(1, run_count_3);
57 } 57 }
58 EXPECT_EQ(1, run_count_3); 58 EXPECT_EQ(1, run_count_3);
59 } 59 }
60 60
61 TEST(BindHelpersTest, TestScopedClosureRunnerMoveConstructor) {
62 int run_count = 0;
63 {
64 std::unique_ptr<base::ScopedClosureRunner> runner(
65 new base::ScopedClosureRunner(base::Bind(&Increment, &run_count)));
66 base::ScopedClosureRunner runner2(std::move(*runner));
67 runner.reset();
68 EXPECT_EQ(0, run_count);
69 }
70 EXPECT_EQ(1, run_count);
71 }
72
73 TEST(BindHelpersTest, TestScopedClosureRunnerMoveAssignment) {
74 int run_count = 0;
75 {
76 base::ScopedClosureRunner runner;
77 {
78 base::ScopedClosureRunner runner2(base::Bind(&Increment, &run_count));
79 runner = std::move(runner2);
80 }
81 EXPECT_EQ(0, run_count);
82 }
83 EXPECT_EQ(1, run_count);
84 }
85
86 TEST(BindHelpersTest, TestScopedClosureRunnerRunOnReplace) {
87 int run_count1 = 0;
88 int run_count2 = 0;
89 {
90 base::ScopedClosureRunner runner1(base::Bind(&Increment, &run_count1));
91 {
92 base::ScopedClosureRunner runner2(base::Bind(&Increment, &run_count2));
93 runner1 = std::move(runner2);
94 EXPECT_EQ(1, run_count1);
95 EXPECT_EQ(0, run_count2);
96 }
97 EXPECT_EQ(1, run_count1);
98 EXPECT_EQ(0, run_count2);
99 }
100 EXPECT_EQ(1, run_count1);
101 EXPECT_EQ(1, run_count2);
102 }
103
61 } // namespace 104 } // namespace
OLDNEW
« no previous file with comments | « base/callback_helpers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698