Files
android/libwvdrmengine/cdm/metrics/src/attribute_handler.cpp
Alex Dale 52bd76e0e2 Fixed test and log formatting for CdmResponseType.
[ Merge of http://go/wvgerrit/168397 ]

When CdmResponseType (enum) was transformed to CdmResponseType
(struct), the test printers where not updated to print the result
of failed comparisons.  In addition, several logs statements were
updated haphazardly, leaving inconsistencies and potential
compiler-specific behavior.

This CL replaces CdmResponseType std::string operator with a ToString()
method.  This is to make it consistent with Google's C++ style guide
on conversion operators vs methods.  The string conversion function is
now defined in wv_cdm_types.cpp instead of inline in the header file.

The PrintTo function has been implemented along with the other CDM
test printers in test_printers.cpp.

Bug: 273989359
Test: run_x86_64_tests
Test: MediaDrmParameterizedTests on redfin
Test: Forrest drm_compliance
Change-Id: Ibfaa17029046b75b1c8c278f7bd7e04a24379848
2023-03-27 11:21:45 -07:00

131 lines
4.4 KiB
C++

// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
//
// This file contains implementations for the AttributeHandler.
#include "attribute_handler.h"
#include "OEMCryptoCENC.h"
#include "field_tuples.h"
#include "pow2bucket.h"
#include "wv_cdm_types.h"
namespace wvcdm {
namespace metrics {
//
// Specializations for setting attribute fields.
//
template <>
void SetAttributeField<drm_metrics::Attributes::kErrorCodeFieldNumber,
CdmResponseType>(const CdmResponseType& cdm_error,
drm_metrics::Attributes* attributes) {
attributes->set_error_code(cdm_error.code());
}
template <>
void SetAttributeField<drm_metrics::Attributes::kErrorCodeFieldNumber,
CdmResponseEnum>(const CdmResponseEnum& cdm_error,
drm_metrics::Attributes* attributes) {
attributes->set_error_code(cdm_error);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kCdmSecurityLevelFieldNumber,
CdmSecurityLevel>(
const CdmSecurityLevel& cdm_security_level,
drm_metrics::Attributes* attributes) {
attributes->set_cdm_security_level(cdm_security_level);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kSecurityLevelFieldNumber,
RequestedSecurityLevel>(
const RequestedSecurityLevel& security_level,
drm_metrics::Attributes* attributes) {
attributes->set_security_level(security_level);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kErrorCodeBoolFieldNumber,
bool>(const bool& cdm_error,
drm_metrics::Attributes* attributes) {
attributes->set_error_code_bool(cdm_error);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kOemCryptoResultFieldNumber,
OEMCryptoResult>(
const OEMCryptoResult& oem_crypto_result,
drm_metrics::Attributes* attributes) {
attributes->set_oem_crypto_result(oem_crypto_result);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kLengthFieldNumber, Pow2Bucket>(
const Pow2Bucket& pow2, drm_metrics::Attributes* attributes) {
attributes->set_length(pow2.value());
}
template <>
void SetAttributeField<drm_metrics::Attributes::kEncryptionAlgorithmFieldNumber,
CdmEncryptionAlgorithm>(
const CdmEncryptionAlgorithm& encryption_algorithm,
drm_metrics::Attributes* attributes) {
attributes->set_encryption_algorithm(encryption_algorithm);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kSigningAlgorithmFieldNumber,
CdmSigningAlgorithm>(
const CdmSigningAlgorithm& signing_algorithm,
drm_metrics::Attributes* attributes) {
attributes->set_signing_algorithm(signing_algorithm);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kKeyRequestTypeFieldNumber,
CdmKeyRequestType>(
const CdmKeyRequestType& key_request_type,
drm_metrics::Attributes* attributes) {
attributes->set_key_request_type(key_request_type);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kLicenseTypeFieldNumber,
CdmLicenseType>(const CdmLicenseType& license_type,
drm_metrics::Attributes* attributes) {
attributes->set_license_type(license_type);
}
template <>
void SetAttributeField<drm_metrics::Attributes::kErrorDetailFieldNumber,
int32_t>(const int32_t& error_detail,
drm_metrics::Attributes* attributes) {
attributes->set_error_detail(error_detail);
}
template <>
void SetAttributeField<
drm_metrics::Attributes::kOemCryptoSignatureHashAlgorithmFieldNumber,
OEMCrypto_SignatureHashAlgorithm>(
const OEMCrypto_SignatureHashAlgorithm& algorithm,
drm_metrics::Attributes* attributes) {
attributes->set_oem_crypto_signature_hash_algorithm(algorithm);
}
template <>
void SetAttributeField<0, util::Unused>(const util::Unused&,
drm_metrics::Attributes*) {
// Intentionally empty.
}
// Specializations only used by tests.
template <>
void SetAttributeField<drm_metrics::Attributes::kErrorCodeFieldNumber, int>(
const int& cdm_error, drm_metrics::Attributes* attributes) {
attributes->set_error_code(cdm_error);
}
} // namespace metrics
} // namespace wvcdm