Patrik Höglund | d8f3c17 | 2018-09-26 12:39:17 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef API_TEST_TEST_DEPENDENCY_FACTORY_H_ |
| 12 | #define API_TEST_TEST_DEPENDENCY_FACTORY_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | |
| 16 | #include "api/test/video_quality_test_fixture.h" |
Patrik Höglund | d8f3c17 | 2018-09-26 12:39:17 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // Override this class if to inject custom components into WebRTC tests. |
| 21 | // Not all WebRTC tests get their components from here, so you need to make |
| 22 | // sure the tests you want actually use this class. |
| 23 | // |
| 24 | // This class is not thread safe and you need to make call calls from the same |
| 25 | // (test main) thread. |
| 26 | class TestDependencyFactory { |
| 27 | public: |
| 28 | virtual ~TestDependencyFactory() = default; |
| 29 | |
| 30 | // The singleton MUST be stateless since tests execute in any order. It must |
| 31 | // be set before tests start executing. |
| 32 | static const TestDependencyFactory& GetInstance(); |
| 33 | static void SetInstance(std::unique_ptr<TestDependencyFactory> instance); |
| 34 | |
| 35 | // Returns the component a test should use. Returning nullptr means that the |
| 36 | // test is free to use whatever defaults it wants. The injection components |
| 37 | // themselves can be mutable, but we need to make new ones for every test that |
| 38 | // executes so state doesn't spread between tests. |
| 39 | virtual std::unique_ptr<VideoQualityTestFixtureInterface::InjectionComponents> |
| 40 | CreateComponents() const; |
| 41 | |
| 42 | private: |
| 43 | static std::unique_ptr<TestDependencyFactory> instance_; |
| 44 | }; |
| 45 | |
| 46 | } // namespace webrtc |
| 47 | |
| 48 | #endif // API_TEST_TEST_DEPENDENCY_FACTORY_H_ |