Files
android/libwvdrmengine/cdm/metrics/test/value_metric_unittest.cpp
John W. Bruce b182a7445e Replace scoped_ptr With std::unique_ptr
(This is a merge of http://go/wvgerrit/65782)

We have had our own scoped_ptr implementation that is used throughout
the codebase. Now that we support C++11, we can replace these with
std::unique_ptr.

Doing this replacement exposed a few places where the two were not
interchangeable. OEMCrypto Ref was doing some unsafe things with passing
scoped_ptrs to functions and has been updated to use move semantics. And
a few constructors were explicitly constructing a scoped_ptr with NULL,
which is ambiguous with std::unique_ptr. These have been replaced with
default constructor calls.

Bug: 111851141
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I37d6d7aad4906709381c74f0c5439f826d2be768
2018-11-14 10:50:34 -08:00

65 lines
1.6 KiB
C++

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