Create common MockEventLogger.

PiperOrigin-RevId: 624994414
This commit is contained in:
Francis Tsui
2024-04-15 10:00:17 -07:00
committed by Copybara-Service
parent 63b12edb45
commit a8bf25d692
8 changed files with 56 additions and 30 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ cc_test(
srcs = ["analytics_recorder_test.cc"],
deps = [
":analytics",
"//internal/analytics:event_logger",
"//internal/analytics:mock_event_logger",
"//internal/proto/analytics:fast_pair_log_cc_proto",
"//proto:fast_pair_enums_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
@@ -19,7 +19,7 @@
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "internal/analytics/event_logger.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/proto/analytics/fast_pair_log.proto.h"
#include "proto/fast_pair_enums.proto.h"
#include "google/protobuf/message_lite.h"
@@ -29,17 +29,10 @@ namespace fastpair {
namespace analytics {
namespace {
using ::nearby::analytics::MockEventLogger;
using ::nearby::proto::fastpair::FastPairEvent;
using ::nearby::proto::fastpair::FastPairLog;
class MockEventLogger : public ::nearby::analytics::EventLogger {
public:
MockEventLogger() = default;
~MockEventLogger() override = default;
MOCK_METHOD(void, Log, (const ::google::protobuf::MessageLite& message), (override));
};
class AnalyticsRecorderTest : public ::testing::Test {
public:
AnalyticsRecorderTest() = default;
+13
View File
@@ -28,3 +28,16 @@ cc_library(
],
deps = ["@com_google_protobuf//:protobuf_lite"],
)
cc_library(
name = "mock_event_logger",
testonly = True,
hdrs = ["mock_event_logger.h"],
compatible_with = ["//buildenv/target:non_prod"],
visibility = ["//visibility:public"],
deps = [
":event_logger",
"@com_google_googletest//:gtest_for_library_testonly",
"@com_google_protobuf//:protobuf_lite",
],
)
+34
View File
@@ -0,0 +1,34 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_MOCK_EVENT_LOGGER_H_
#define THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_MOCK_EVENT_LOGGER_H_
#include "gmock/gmock.h"
#include "internal/analytics/event_logger.h"
#include "google/protobuf/message_lite.h"
namespace nearby::analytics {
class MockEventLogger : public ::nearby::analytics::EventLogger {
public:
MockEventLogger() = default;
~MockEventLogger() override = default;
MOCK_METHOD(void, Log, (const ::google::protobuf::MessageLite& message), (override));
};
} // namespace nearby::analytics
#endif // THIRD_PARTY_NEARBY_INTERNAL_ANALYTICS_MOCK_EVENT_LOGGER_H_
+1 -1
View File
@@ -320,7 +320,7 @@ cc_test(
"//base:casts",
"//connections:core_types",
"//internal/account",
"//internal/analytics:event_logger",
"//internal/analytics:mock_event_logger",
"//internal/base:files",
"//internal/flags:nearby_flags",
"//internal/network:types",
+1 -1
View File
@@ -45,7 +45,7 @@ cc_test(
srcs = ["analytics_recorder_test.cc"],
deps = [
":analytics",
"//internal/analytics:event_logger",
"//internal/analytics:mock_event_logger",
"//internal/platform/implementation/g3", # fixdeps: keep
"//proto:sharing_enums_cc_proto",
"//sharing:types",
+2 -9
View File
@@ -26,7 +26,7 @@
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
#include "internal/analytics/event_logger.h"
#include "internal/analytics/mock_event_logger.h"
#include "proto/sharing_enums.pb.h"
#include "sharing/analytics/analytics_device_settings.h"
#include "sharing/analytics/analytics_information.h"
@@ -48,6 +48,7 @@ namespace {
using ::location::nearby::proto::sharing::EventCategory;
using ::location::nearby::proto::sharing::EventType;
using ::location::nearby::proto::sharing::OSType;
using ::nearby::analytics::MockEventLogger;
using ::nearby::sharing::analytics::proto::SharingLog;
using ::nearby::sharing::proto::DataUsage;
using ::nearby::sharing::proto::DeviceVisibility;
@@ -59,14 +60,6 @@ constexpr absl::string_view kFileMimeType = "application/pdf";
constexpr absl::string_view kTextMimeType = "text/plain";
constexpr absl::string_view kAppPackageName = "com.google.android.youtube";
class MockEventLogger : public ::nearby::analytics::EventLogger {
public:
MockEventLogger() = default;
~MockEventLogger() override = default;
MOCK_METHOD(void, Log, (const ::google::protobuf::MessageLite& message), (override));
};
class AnalyticsRecorderTest : public ::testing::Test {
public:
AnalyticsRecorderTest() = default;
+2 -9
View File
@@ -20,7 +20,7 @@
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "internal/analytics/event_logger.h"
#include "internal/analytics/mock_event_logger.h"
#include "proto/sharing_enums.pb.h"
#include "sharing/common/nearby_share_prefs.h"
#include "sharing/internal/test/fake_preference_manager.h"
@@ -32,16 +32,9 @@ namespace sharing {
namespace {
using ::location::nearby::proto::sharing::EventCategory;
using ::location::nearby::proto::sharing::EventType;
using ::nearby::analytics::EventLogger;
using ::nearby::analytics::MockEventLogger;
using ::nearby::sharing::analytics::proto::SharingLog;
class MockEventLogger : public EventLogger {
public:
~MockEventLogger() override = default;
MOCK_METHOD(void, Log, (const proto2::MessageLite& message), (override));
};
class NearbySharingEventLoggerTest : public ::testing::Test {
public:
NearbySharingEventLoggerTest() = default;