// Copyright 2014 Google Inc. All Rights Reserved. #include "cdm_test_config.h" #include #include #include "log.h" #include "string_conversions.h" // Default license server, can be configured using --server command line option // Default key id (pssh), can be configured using --keyid command line option std::string g_client_auth; std::string g_key_id; std::string g_license_server; std::string g_wrong_key_id; int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); wvcdm::InitLogging(argc, argv); wvcdm::ConfigTestEnv config(kLicenseServerId); g_client_auth.assign(config.client_auth()); g_wrong_key_id.assign(config.wrong_key_id()); // The following variables are configurable through command line options. g_license_server.assign(config.license_server()); g_key_id.assign(config.key_id()); std::string license_server(g_license_server); int show_usage = 0; static const struct option long_options[] = { {"keyid", required_argument, NULL, 'k'}, {"server", required_argument, NULL, 's'}, {NULL, 0, NULL, '\0'}}; int option_index = 0; int opt = 0; while ((opt = getopt_long(argc, argv, "k:s:v", long_options, &option_index)) != -1) { switch (opt) { case 'k': { g_key_id.clear(); g_key_id.assign(optarg); break; } case 's': { g_license_server.clear(); g_license_server.assign(optarg); break; } case 'v': { // This option has already been consumed by wvcdm::InitLogging() above. // We only tell getopt about it so that it is not an error. We ignore // the option here when seen. // TODO: Stop passing argv to InitLogging, and instead set the log // level here through the logging API. We should keep all command-line // parsing at the application level, rather than split between various // apps and various platform-specific logging implementations. break; } case '?': { show_usage = 1; break; } } } if (show_usage) { std::cout << std::endl; std::cout << "usage: " << argv[0] << " [options]" << std::endl << std::endl; std::cout << std::setw(30) << std::left << " --server="; std::cout << "configure the license server url, please include http[s] in the url" << std::endl; std::cout << std::setw(30) << std::left << " "; std::cout << "default: " << license_server << std::endl; std::cout << std::setw(30) << std::left << " --keyid="; std::cout << "configure the key id or pssh, in hex format" << std::endl; std::cout << std::setw(30) << std::left << " default keyid:"; std::cout << g_key_id << std::endl; return 0; } std::cout << std::endl; std::cout << "Server: " << g_license_server << std::endl; std::cout << "KeyID: " << g_key_id << std::endl << std::endl; g_key_id = wvcdm::a2bs_hex(g_key_id); config.set_license_server(g_license_server); config.set_key_id(g_key_id); return RUN_ALL_TESTS(); }