vaapi_image_decoder_test_common.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2019 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. #include "media/gpu/vaapi/vaapi_image_decoder_test_common.h"
  5. #include "base/bind.h"
  6. #include "base/callback.h"
  7. #include "base/command_line.h"
  8. #include "base/files/file_path.h"
  9. #include "base/files/file_util.h"
  10. #include "base/logging.h"
  11. #include "media/base/test_data_util.h"
  12. #include "media/gpu/vaapi/vaapi_image_decoder.h"
  13. namespace media {
  14. VaapiImageDecoderTestCommon::VaapiImageDecoderTestCommon(
  15. std::unique_ptr<VaapiImageDecoder> decoder)
  16. : decoder_(std::move(decoder)) {
  17. const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
  18. if (cmd_line && cmd_line->HasSwitch("test_data_path"))
  19. test_data_path_ = cmd_line->GetSwitchValueASCII("test_data_path");
  20. }
  21. VaapiImageDecoderTestCommon::~VaapiImageDecoderTestCommon() = default;
  22. void VaapiImageDecoderTestCommon::SetUp() {
  23. ASSERT_TRUE(
  24. decoder_->Initialize(base::BindRepeating([](VaapiFunctions function) {
  25. LOG(FATAL) << "Oh noes! Decoder failed";
  26. })));
  27. }
  28. base::FilePath VaapiImageDecoderTestCommon::FindTestDataFilePath(
  29. const std::string& file_name) const {
  30. const base::FilePath file_path = base::FilePath(file_name);
  31. if (base::PathExists(file_path))
  32. return file_path;
  33. if (!test_data_path_.empty())
  34. return base::FilePath(test_data_path_).Append(file_path);
  35. return GetTestDataFilePath(file_name);
  36. }
  37. } // namespace media