// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // This file defines tests that implementations of TaskRunner should // pass in order to be conformant, as well as test cases for optional behavior. // Here's how you use it to test your implementation. // // Say your class is called MyTaskRunner. Then you need to define a // class called MyTaskRunnerTestDelegate in my_task_runner_unittest.cc // like this: // // class MyTaskRunnerTestDelegate { // public: // // Tasks posted to the task runner after this and before // // StopTaskRunner() is called is called should run successfully. // void StartTaskRunner() { // ... // } // // // Should return the task runner implementation. Only called // // after StartTaskRunner and before StopTaskRunner. // scoped_refptr<MyTaskRunner> GetTaskRunner() { // ... // } // // // Stop the task runner and make sure all tasks posted before // // this is called are run. Caveat: delayed tasks are not run, // they're simply deleted. // void StopTaskRunner() { // ... // } // }; // // The TaskRunnerTest test harness will have a member variable of // this delegate type and will call its functions in the various // tests. // // Then you simply #include this file as well as gtest.h and add the // following statement to my_task_runner_unittest.cc: // // INSTANTIATE_TYPED_TEST_SUITE_P( // MyTaskRunner, TaskRunnerTest, MyTaskRunnerTestDelegate); // // Easy! #ifndef BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_ #define BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_ #include <cstddef> #include <map> #include "base/functional/bind.h" #include "base/functional/callback.h" #include "base/location.h" #include "base/memory/ref_counted.h" #include "base/synchronization/condition_variable.h" #include "base/synchronization/lock.h" #include "base/task/single_thread_task_runner.h" #include "base/task/task_runner.h" #include "base/threading/thread.h" #include "testing/gtest/include/gtest/gtest.h" base // namespace base #endif // BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_