Files
ce_cdm/cdm/test/cdm_test_main.cpp
2020-04-10 16:13:07 -07:00

95 lines
3.1 KiB
C++

// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine Master
// License Agreement.
#include <assert.h>
#include <gtest/gtest.h>
#include <string.h>
#include <time.h>
#include <algorithm>
#include <string>
#include <vector>
#if defined(__linux__)
# include <sys/utsname.h>
#endif
#include "cdm.h"
#include "device_cert.h"
#include "log.h"
#include "test_base.h"
#include "test_host.h"
using namespace widevine;
TestHost* g_host = nullptr;
std::string g_sandbox_id = "";
namespace {
constexpr const char kSandboxIdParam[] = "--sandbox_id=";
// Following the pattern established by help text in test_base.cpp
constexpr const char kExtraHelpText[] =
" --sandbox_id=<sandbox_id>\n"
" Specifies the Sandbox ID that should be sent to OEMCrypto via\n"
" OEMCrypto_SetSandbox(). On most platforms, since Sandbox IDs are not\n"
" in use, this parameter should be omitted.\n";
} // namespace
int main(int argc, char** argv) {
// Find and filter out the Sandbox ID, if any.
std::vector<std::string> args(argv, argv + argc);
auto sandbox_id_iter = std::find_if(std::begin(args) + 1, std::end(args),
[](const std::string& elem) -> bool {
return elem.find(kSandboxIdParam) == 0;
});
if (sandbox_id_iter != std::end(args)) {
g_sandbox_id = sandbox_id_iter->substr(strlen(kSandboxIdParam));
args.erase(sandbox_id_iter);
}
// Set up a Host and initialize the library. This makes these services
// available to the tests. We would do this in the test suite itself, but the
// core & OEMCrypto tests don't know they depend on this for storage.
g_host = new TestHost();
Cdm::ClientInfo client_info;
// Set client info that denotes this as the test suite:
client_info.product_name = "CE cdm tests";
client_info.company_name = "www";
client_info.model_name = "www";
#if defined(__linux__)
client_info.device_name = "Linux";
{
struct utsname name;
if (uname(&name) == 0) {
client_info.arch_name = name.machine;
}
}
#else
client_info.device_name = "unknown";
#endif
client_info.build_info = __DATE__;
Cdm::Status status = Cdm::initialize(
Cdm::kNoSecureOutput, client_info, g_host, g_host, g_host,
static_cast<Cdm::LogLevel>(wvcdm::g_cutoff), g_sandbox_id);
(void)status; // status is now used when assertions are turned off.
assert(status == Cdm::kSuccess);
std::vector<const char*> new_argv(args.size());
std::transform(
std::begin(args), std::end(args), std::begin(new_argv),
[](const std::string& arg) -> const char* { return arg.c_str(); });
// This must take place after the call to Cdm::initialize() because it makes
// calls that are only valid after the library is initialized.
if (!wvcdm::WvCdmTestBase::Initialize(new_argv.size(), new_argv.data(),
kExtraHelpText)) {
return 0;
}
// Init gtest after oemcrypto and cdm host have been initialized.
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}