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

Unified Diff: net/base/test_completion_callback_unittest.cc

Issue 699693002: Introducing net::TestCompletionClosure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self reviewed Created 6 years, 1 month 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
Index: net/base/test_completion_callback_unittest.cc
diff --git a/net/base/test_completion_callback_unittest.cc b/net/base/test_completion_callback_unittest.cc
index 704273ebc7f41f583711363617579d71b1893262..7aa4f6cb9dba382961301639c4f3124050cb4a52 100644
--- a/net/base/test_completion_callback_unittest.cc
+++ b/net/base/test_completion_callback_unittest.cc
@@ -13,10 +13,18 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-typedef PlatformTest TestCompletionCallbackTest;
+namespace {
const int kMagicResult = 8888;
+void CallClosureAfterCheckingResult(const base::Closure& closure,
+ bool* did_check_result,
+ int result) {
+ DCHECK_EQ(result, kMagicResult);
+ *did_check_result = true;
+ closure.Run();
+}
+
// ExampleEmployer is a toy version of HostResolver
// TODO: restore damage done in extracting example from real code
// (e.g. bring back real destructor, bring back comments)
@@ -111,13 +119,32 @@ bool ExampleEmployer::DoSomething(const net::CompletionCallback& callback) {
return true;
}
+} // namespace
+
+typedef PlatformTest TestCompletionCallbackTest;
+
TEST_F(TestCompletionCallbackTest, Simple) {
ExampleEmployer boss;
net::TestCompletionCallback callback;
bool queued = boss.DoSomething(callback.callback());
- EXPECT_EQ(queued, true);
+ EXPECT_TRUE(queued);
int result = callback.WaitForResult();
EXPECT_EQ(result, kMagicResult);
}
+TEST_F(TestCompletionCallbackTest, Closure) {
+ ExampleEmployer boss;
+ net::TestClosureCallback closure;
+ bool did_check_result = false;
+ net::CompletionCallback completion_callback =
+ base::Bind(&CallClosureAfterCheckingResult,
+ closure.callback(), base::Unretained(&did_check_result));
+ bool queued = boss.DoSomething(completion_callback);
+ EXPECT_TRUE(queued);
+
+ EXPECT_FALSE(did_check_result);
+ closure.WaitForResult();
+ EXPECT_TRUE(did_check_result);
+}
+
// TODO: test deleting ExampleEmployer while work outstanding
« net/base/test_completion_callback.h ('K') | « net/base/test_completion_callback.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698