Files
android/libwvdrmengine/cdm/metrics/test/value_metric_unittest.cpp
Adam Stone b19f0d106f 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
2018-03-22 16:36:18 -07:00

65 lines
1.6 KiB
C++

// Copyright 2017 Google Inc. All Rights Reserved.
//
// Unit tests for ValueMetric.
#include <string>
#include "value_metric.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "metrics.pb.h"
#include "scoped_ptr.h"
namespace wvcdm {
namespace metrics {
TEST(ValueMetricTest, StringValue) {
ValueMetric<std::string> metric;
metric.Record("foo");
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(ValueMetricTest, DoubleValue) {
ValueMetric<double> metric;
metric.Record(42.0);
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(ValueMetricTest, Int32Value) {
ValueMetric<int32_t> metric;
metric.Record(42);
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, Int64Value) {
ValueMetric<int64_t> metric;
metric.Record(42);
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