thread_pool_unittest.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/task/thread_pool.h"
  5. #include "base/bind.h"
  6. #include "base/location.h"
  7. #include "base/run_loop.h"
  8. #include "base/test/bind.h"
  9. #include "base/test/task_environment.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. namespace base {
  12. TEST(ThreadPool, PostTaskAndReplyWithResultThreeArgs) {
  13. base::test::TaskEnvironment env;
  14. base::RunLoop run_loop;
  15. base::ThreadPool::PostTaskAndReplyWithResult(
  16. FROM_HERE, base::BindOnce([]() { return 3; }),
  17. base::OnceCallback<void(int)>(
  18. base::BindLambdaForTesting([&run_loop](int x) {
  19. EXPECT_EQ(x, 3);
  20. run_loop.Quit();
  21. })));
  22. run_loop.Run();
  23. }
  24. TEST(ThreadPool, PostTaskAndReplyWithResultFourArgs) {
  25. base::test::TaskEnvironment env;
  26. base::RunLoop run_loop;
  27. base::ThreadPool::PostTaskAndReplyWithResult(
  28. FROM_HERE, /*traits=*/{}, base::BindOnce([]() { return 3; }),
  29. base::OnceCallback<void(int)>(
  30. base::BindLambdaForTesting([&run_loop](int x) {
  31. EXPECT_EQ(x, 3);
  32. run_loop.Quit();
  33. })));
  34. run_loop.Run();
  35. }
  36. } // namespace base