Fixes widevine metrics proto serialization

Changes to a much more efficient and more reusable protobuf format for
metrics.

Test: Widevine tests, Google Play and MediaDrm CTS test.
Bug: 73724218

Change-Id: I3299051d7a16bcd7758c8f272415ca40e10c1313
This commit is contained in:
Adam Stone
2018-02-20 19:12:02 -08:00
parent efc008c5a1
commit b19f0d106f
25 changed files with 1587 additions and 1867 deletions

View File

@@ -8,70 +8,57 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "metric_serialization.h"
#include "metrics.pb.h"
#include "scoped_ptr.h"
namespace wvcdm {
namespace metrics {
class MockMetricSerializer : public MetricSerializer {
public:
MOCK_METHOD2(SetString, void(const std::string& metric_id,
const std::string& value));
MOCK_METHOD2(SetInt32, void(const std::string& metric_id,
int32_t value));
MOCK_METHOD2(SetInt64, void(const std::string& metric_id,
int64_t value));
MOCK_METHOD2(SetDouble, void(const std::string& metric_id,
double value));
};
TEST(ValueMetricTest, StringValue) {
ValueMetric<std::string> metric;
metric.Record("foo");
class ValueMetricTest : public ::testing::Test {
public:
void SetUp() {
mock_serializer_.reset(new MockMetricSerializer());
}
protected:
scoped_ptr<MockMetricSerializer> mock_serializer_;
};
TEST_F(ValueMetricTest, StringValue) {
ValueMetric<std::string> value_metric("string/metric");
value_metric.Record("foo");
EXPECT_CALL(*mock_serializer_,
SetString("string/metric", "foo"));
value_metric.Serialize(mock_serializer_.get());
wvcdm::scoped_ptr<drm_metrics::ValueMetric> metric_proto(metric.ToProto());
ASSERT_EQ("foo", metric_proto->string_value());
ASSERT_FALSE(metric_proto->has_error_code());
}
TEST_F(ValueMetricTest, DoubleValue) {
ValueMetric<double> value_metric("double/metric");
value_metric.Record(42.0);
TEST(ValueMetricTest, DoubleValue) {
ValueMetric<double> metric;
metric.Record(42.0);
EXPECT_CALL(*mock_serializer_,
SetDouble("double/metric", 42.0));
value_metric.Serialize(mock_serializer_.get());
wvcdm::scoped_ptr<drm_metrics::ValueMetric> metric_proto(metric.ToProto());
ASSERT_EQ(42.0, metric_proto->double_value());
ASSERT_FALSE(metric_proto->has_error_code());
}
TEST_F(ValueMetricTest, Int32Value) {
ValueMetric<int32_t> value_metric("int32/metric");
value_metric.Record(42);
TEST(ValueMetricTest, Int32Value) {
ValueMetric<int32_t> metric;
metric.Record(42);
EXPECT_CALL(*mock_serializer_,
SetInt32("int32/metric", 42));
value_metric.Serialize(mock_serializer_.get());
wvcdm::scoped_ptr<drm_metrics::ValueMetric> metric_proto(metric.ToProto());
ASSERT_EQ(42, metric_proto->int_value());
ASSERT_FALSE(metric_proto->has_error_code());
}
TEST_F(ValueMetricTest, Int64Value) {
ValueMetric<int64_t> value_metric("int64/metric");
value_metric.Record(42);
TEST(ValueMetricTest, Int64Value) {
ValueMetric<int64_t> metric;
metric.Record(42);
EXPECT_CALL(*mock_serializer_,
SetInt64("int64/metric", 42));
value_metric.Serialize(mock_serializer_.get());
wvcdm::scoped_ptr<drm_metrics::ValueMetric> metric_proto(metric.ToProto());
ASSERT_EQ(42, metric_proto->int_value());
ASSERT_FALSE(metric_proto->has_error_code());
}
TEST(ValueMetricTest, SetError) {
ValueMetric<int64_t> metric;
metric.Record(42);
metric.SetError(7);
wvcdm::scoped_ptr<drm_metrics::ValueMetric> metric_proto(metric.ToProto());
ASSERT_EQ(7, metric_proto->error_code());
ASSERT_FALSE(metric_proto->has_int_value());
}
} // namespace metrics
} // namespace wvcdm