This is part one of a mult-part change to revise some metrics. Several metrics are currently EventMetric type when they should be a simpler type. Test: Added unit tests for the new types. Also, re-ran existing tests. Verified playback works with Google Play, and re-ran Widevine GTS tests. Bug: 36220619 Change-Id: I2ec8fc355f66ad4834dd722aacd22541fb9c94ad
78 lines
2.0 KiB
C++
78 lines
2.0 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 "metric_serialization.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));
|
|
};
|
|
|
|
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());
|
|
}
|
|
|
|
TEST_F(ValueMetricTest, DoubleValue) {
|
|
ValueMetric<double> value_metric("double/metric");
|
|
value_metric.Record(42.0);
|
|
|
|
EXPECT_CALL(*mock_serializer_,
|
|
SetDouble("double/metric", 42.0));
|
|
value_metric.Serialize(mock_serializer_.get());
|
|
}
|
|
|
|
TEST_F(ValueMetricTest, Int32Value) {
|
|
ValueMetric<int32_t> value_metric("int32/metric");
|
|
value_metric.Record(42);
|
|
|
|
EXPECT_CALL(*mock_serializer_,
|
|
SetInt32("int32/metric", 42));
|
|
value_metric.Serialize(mock_serializer_.get());
|
|
}
|
|
|
|
TEST_F(ValueMetricTest, Int64Value) {
|
|
ValueMetric<int64_t> value_metric("int64/metric");
|
|
value_metric.Record(42);
|
|
|
|
EXPECT_CALL(*mock_serializer_,
|
|
SetInt64("int64/metric", 42));
|
|
value_metric.Serialize(mock_serializer_.get());
|
|
}
|
|
|
|
} // namespace metrics
|
|
} // namespace wvcdm
|
|
|