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
This commit is contained in:
Alex Dale
2023-03-17 15:50:34 -07:00
parent bfa8d39a63
commit 52bd76e0e2
21 changed files with 149 additions and 108 deletions

View File

@@ -460,56 +460,69 @@ enum CdmResponseEnum : int32_t {
// * android/include/mapErrors-inl.h
};
struct CdmResponseType {
explicit CdmResponseType(CdmResponseEnum status = NO_ERROR,
OEMCryptoResult oec_result = OEMCrypto_SUCCESS,
const char* crypto_session_method = nullptr)
: status_(status),
oec_result_(oec_result),
crypto_session_method_(crypto_session_method){};
explicit operator CdmResponseEnum() const { return status_; };
explicit operator std::string() {
std::string str = "status = ";
str.append(std::to_string(static_cast<int>(status_)));
if (oec_result_) {
str.append("; oec_result = ");
str.append(std::to_string(static_cast<int>(oec_result_)));
}
if (crypto_session_method_) {
str.append("; crypto_session_method = ");
str.append(crypto_session_method_);
}
return str;
}
CdmResponseEnum Enum() const { return status_; };
constexpr explicit operator int() const { return status_; };
OEMCryptoResult getOEMCryptoResult() const { return oec_result_; }
const char* getCryptoSessionMethod() const { return crypto_session_method_; }
bool operator==(CdmResponseEnum other) const { return status_ == other; }
bool operator!=(CdmResponseEnum other) const { return status_ != other; }
bool operator==(const CdmResponseType& other) const {
return status_ == other.status_ && oec_result_ == other.oec_result_ &&
crypto_session_method_ == other.crypto_session_method_;
}
bool operator!=(const CdmResponseType& other) const {
return !operator==(other);
class CdmResponseType {
public:
constexpr CdmResponseType() {}
constexpr explicit CdmResponseType(CdmResponseEnum code) : code_(code) {}
constexpr CdmResponseType(CdmResponseEnum code, OEMCryptoResult oemc_result,
const char* crypto_session_method)
: code_(code),
has_oemc_result_(true),
oemc_result_(oemc_result),
crypto_session_method_(crypto_session_method) {}
constexpr bool IsOk() const {
return (code_ == NO_ERROR) &&
(!HasOemcResult() || (oemc_result_ == OEMCrypto_SUCCESS));
}
constexpr explicit operator CdmResponseEnum() const { return code_; };
constexpr CdmResponseEnum code() const { return code_; };
// Returns the string representation of |code_|, ignores
// the other fields.
const char* GetCodeString() const;
constexpr bool HasOemcResult() const { return has_oemc_result_; }
constexpr OEMCryptoResult oemc_result() const { return oemc_result_; }
constexpr bool HasCryptoSessionMethod() const {
return crypto_session_method_ != nullptr;
}
constexpr const char* crypto_session_method() const {
return crypto_session_method_;
}
constexpr int ToInt() const { return static_cast<int>(code_); }
constexpr explicit operator int() const { return ToInt(); };
bool operator==(CdmResponseEnum other) const { return code_ == other; }
bool operator!=(CdmResponseEnum other) const { return code_ != other; }
bool operator==(const CdmResponseType& other) const;
bool operator!=(const CdmResponseType& other) const {
return !(*this == other);
}
std::string ToString() const;
private:
CdmResponseEnum status_;
OEMCryptoResult oec_result_;
const char* crypto_session_method_;
// CORE_DISALLOW_COPY_AND_ASSIGN(CdmResponseType);
CdmResponseEnum code_ = NO_ERROR;
// Setting |oemc_result_| is optional, only set if |has_oemc_result_|
// is true.
// TODO(b/254108623): Remove |has_oemc_result_| and replace |oemc_result_|
// with std::optional<OEMCryptoResult>.
bool has_oemc_result_ = false;
OEMCryptoResult oemc_result_ = OEMCrypto_SUCCESS;
const char* crypto_session_method_ = nullptr;
};
static inline bool operator==(const CdmResponseEnum lhs,
const CdmResponseType& rhs) {
return lhs == rhs.Enum();
return lhs == rhs.code();
}
static inline bool operator!=(const CdmResponseEnum lhs,
const CdmResponseType& rhs) {
return !(lhs == rhs.Enum());
return lhs != rhs.code();
}
enum CdmKeyStatus : int32_t {