test_dependency_factory.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #ifndef API_TEST_TEST_DEPENDENCY_FACTORY_H_
  11. #define API_TEST_TEST_DEPENDENCY_FACTORY_H_
  12. #include <memory>
  13. #include "api/test/video_quality_test_fixture.h"
  14. namespace webrtc {
  15. // Override this class if to inject custom components into WebRTC tests.
  16. // Not all WebRTC tests get their components from here, so you need to make
  17. // sure the tests you want actually use this class.
  18. //
  19. // This class is not thread safe and you need to make call calls from the same
  20. // (test main) thread.
  21. class TestDependencyFactory {
  22. public:
  23. virtual ~TestDependencyFactory() = default;
  24. // The singleton MUST be stateless since tests execute in any order. It must
  25. // be set before tests start executing.
  26. static const TestDependencyFactory& GetInstance();
  27. static void SetInstance(std::unique_ptr<TestDependencyFactory> instance);
  28. // Returns the component a test should use. Returning nullptr means that the
  29. // test is free to use whatever defaults it wants. The injection components
  30. // themselves can be mutable, but we need to make new ones for every test that
  31. // executes so state doesn't spread between tests.
  32. virtual std::unique_ptr<VideoQualityTestFixtureInterface::InjectionComponents>
  33. CreateComponents() const;
  34. private:
  35. static std::unique_ptr<TestDependencyFactory> instance_;
  36. };
  37. } // namespace webrtc
  38. #endif // API_TEST_TEST_DEPENDENCY_FACTORY_H_