gl_test_setup_helper.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2021 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. #ifndef GPU_COMMAND_BUFFER_TESTS_GL_TEST_SETUP_HELPER_H_
  5. #define GPU_COMMAND_BUFFER_TESTS_GL_TEST_SETUP_HELPER_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/test/task_environment.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. #include "ui/gl/gl_display.h"
  10. namespace gpu {
  11. // Helper class to automatically set-up and initialize GL environment before
  12. // every test, and tear down the environment after every test. This should
  13. // normally be used from base::TestSuite instances, so that it takes care of the
  14. // set-up/tear-down between every test, and each test does not have to do this
  15. // explicitly.
  16. class GLTestSetupHelper : public testing::EmptyTestEventListener {
  17. public:
  18. GLTestSetupHelper();
  19. ~GLTestSetupHelper();
  20. // testing::EmptyTestEventListener:
  21. void OnTestStart(const testing::TestInfo& test_info) override;
  22. void OnTestEnd(const testing::TestInfo& test_info) override;
  23. private:
  24. std::unique_ptr<base::test::TaskEnvironment> task_environment_;
  25. raw_ptr<gl::GLDisplay> display_ = nullptr;
  26. };
  27. } // namespace gpu
  28. #endif // GPU_COMMAND_BUFFER_TESTS_GL_TEST_SETUP_HELPER_H_