blob: ac2dd704518f79d20ca08d4e5944f1a9887d999f [file] [log] [blame]
Patrik Höglundd8f3c172018-09-26 14:39:17 +02001/*
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"
17#include "rtc_base/thread_checker.h"
18
19namespace webrtc {
20
21// Override this class if to inject custom components into WebRTC tests.
22// Not all WebRTC tests get their components from here, so you need to make
23// sure the tests you want actually use this class.
24//
25// This class is not thread safe and you need to make call calls from the same
26// (test main) thread.
27class TestDependencyFactory {
28 public:
29 virtual ~TestDependencyFactory() = default;
30
31 // The singleton MUST be stateless since tests execute in any order. It must
32 // be set before tests start executing.
33 static const TestDependencyFactory& GetInstance();
34 static void SetInstance(std::unique_ptr<TestDependencyFactory> instance);
35
36 // Returns the component a test should use. Returning nullptr means that the
37 // test is free to use whatever defaults it wants. The injection components
38 // themselves can be mutable, but we need to make new ones for every test that
39 // executes so state doesn't spread between tests.
40 virtual std::unique_ptr<VideoQualityTestFixtureInterface::InjectionComponents>
41 CreateComponents() const;
42
43 private:
44 static std::unique_ptr<TestDependencyFactory> instance_;
45};
46
47} // namespace webrtc
48
49#endif // API_TEST_TEST_DEPENDENCY_FACTORY_H_