mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
[Device Provider] Add FakeDeviceProvider for testing
Create a FakeDeviceProvider class which will be used in testing for NearbyPresence and NearbyConnections. To assist with testing PresenceService will store a NearbyDeviceProvider base class instead of the implementation specific PresenceDeviceProvider. PiperOrigin-RevId: 625845617
This commit is contained in:
committed by
Copybara-Service
parent
012b9b0569
commit
5c933e5b9c
@@ -39,6 +39,7 @@ cc_library(
|
||||
":authentication_status",
|
||||
":authentication_transport_interface",
|
||||
"//internal/platform:connection_info",
|
||||
"//internal/platform:types",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/types:variant",
|
||||
],
|
||||
@@ -55,3 +56,24 @@ cc_library(
|
||||
"//sharing:__subpackages__",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "test_support",
|
||||
testonly = 1,
|
||||
srcs = [
|
||||
"fake_device_provider.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"fake_device_provider.h",
|
||||
],
|
||||
compatible_with = ["//buildenv/target:non_prod"],
|
||||
visibility = [
|
||||
"//presence:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
":authentication_status",
|
||||
":authentication_transport_interface",
|
||||
":device",
|
||||
"@com_google_absl//absl/strings:string_view",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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.
|
||||
|
||||
#include "internal/interop/fake_device_provider.h"
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/interop/authentication_status.h"
|
||||
#include "internal/interop/authentication_transport.h"
|
||||
#include "internal/interop/device.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
FakeDeviceProvider::FakeDeviceProvider() = default;
|
||||
|
||||
const NearbyDevice* FakeDeviceProvider::GetLocalDevice() { return nullptr; }
|
||||
|
||||
AuthenticationStatus FakeDeviceProvider::AuthenticateAsInitiator(
|
||||
const NearbyDevice& remote_device, absl::string_view shared_secret,
|
||||
const AuthenticationTransport& authentication_transport) const {
|
||||
return AuthenticationStatus::kSuccess;
|
||||
}
|
||||
|
||||
AuthenticationStatus FakeDeviceProvider::AuthenticateAsResponder(
|
||||
absl::string_view shared_secret,
|
||||
const AuthenticationTransport& authentication_transport) const {
|
||||
return AuthenticationStatus::kSuccess;
|
||||
}
|
||||
|
||||
} // namespace nearby
|
||||
@@ -0,0 +1,45 @@
|
||||
// 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_PRESENCE_FAKE_DEVICE_PROVIDER_H_
|
||||
#define THIRD_PARTY_NEARBY_PRESENCE_FAKE_DEVICE_PROVIDER_H_
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/interop/authentication_status.h"
|
||||
#include "internal/interop/authentication_transport.h"
|
||||
#include "internal/interop/device.h"
|
||||
#include "internal/interop/device_provider.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
class FakeDeviceProvider : public NearbyDeviceProvider {
|
||||
public:
|
||||
FakeDeviceProvider();
|
||||
FakeDeviceProvider(const FakeDeviceProvider&) = delete;
|
||||
FakeDeviceProvider& operator=(const FakeDeviceProvider&) = delete;
|
||||
|
||||
const NearbyDevice* GetLocalDevice() override;
|
||||
|
||||
AuthenticationStatus AuthenticateAsInitiator(
|
||||
const NearbyDevice& remote_device, absl::string_view shared_secret,
|
||||
const AuthenticationTransport& authentication_transport) const override;
|
||||
|
||||
AuthenticationStatus AuthenticateAsResponder(
|
||||
absl::string_view shared_secret,
|
||||
const AuthenticationTransport& authentication_transport) const override;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_PRESENCE_FAKE_DEVICE_PROVIDER_H_
|
||||
@@ -143,6 +143,7 @@ cc_library(
|
||||
"//internal/auth:__subpackages__",
|
||||
"//internal/data:__subpackages__",
|
||||
"//internal/flags:__subpackages__",
|
||||
"//internal/interop:__subpackages__",
|
||||
"//internal/network:__subpackages__",
|
||||
"//internal/platform:__subpackages__",
|
||||
"//internal/preferences:__subpackages__",
|
||||
|
||||
@@ -66,8 +66,11 @@ cc_library(
|
||||
deps = [
|
||||
":presence",
|
||||
":types",
|
||||
"//internal/interop:device",
|
||||
"//internal/interop:test_support",
|
||||
"//internal/platform:types",
|
||||
"//internal/proto:metadata_cc_proto",
|
||||
"//presence/implementation:internal", # build_cleaner: keep
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "internal/interop/device_provider.h"
|
||||
#include "internal/platform/borrowable.h"
|
||||
#include "presence/fake_presence_client.h"
|
||||
|
||||
@@ -75,9 +76,8 @@ void FakePresenceService::UpdateDeviceIdentityMetaData(
|
||||
}
|
||||
}
|
||||
|
||||
// Not implemented.
|
||||
PresenceDeviceProvider* FakePresenceService::GetLocalDeviceProvider() {
|
||||
return nullptr;
|
||||
NearbyDeviceProvider* FakePresenceService::GetLocalDeviceProvider() {
|
||||
return provider_;
|
||||
}
|
||||
|
||||
void FakePresenceService::GetLocalPublicCredentials(
|
||||
|
||||
@@ -15,11 +15,13 @@
|
||||
#ifndef THIRD_PARTY_NEARBY_PRESENCE_FAKE_PRESENCE_SERVICE_H_
|
||||
#define THIRD_PARTY_NEARBY_PRESENCE_FAKE_PRESENCE_SERVICE_H_
|
||||
|
||||
#include "internal/interop/device_provider.h"
|
||||
#include "internal/interop/fake_device_provider.h"
|
||||
#include "internal/platform/borrowable.h"
|
||||
#include "internal/proto/metadata.pb.h"
|
||||
#include "presence/broadcast_request.h"
|
||||
#include "presence/data_types.h"
|
||||
#include "presence/presence_client.h"
|
||||
#include "presence/presence_device_provider.h"
|
||||
#include "presence/presence_service.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -53,7 +55,7 @@ class FakePresenceService : public PresenceService {
|
||||
int credential_life_cycle_days, int contiguous_copy_of_credentials,
|
||||
GenerateCredentialsResultCallback credentials_generated_cb) override;
|
||||
|
||||
PresenceDeviceProvider* GetLocalDeviceProvider() override;
|
||||
NearbyDeviceProvider* GetLocalDeviceProvider() override;
|
||||
|
||||
::nearby::internal::DeviceIdentityMetaData GetDeviceIdentityMetaData()
|
||||
override {
|
||||
@@ -98,6 +100,10 @@ class FakePresenceService : public PresenceService {
|
||||
shared_credentials_ = shared_credentials;
|
||||
}
|
||||
|
||||
void SetDeviceProvider(NearbyDeviceProvider* provider) {
|
||||
provider_ = provider;
|
||||
}
|
||||
|
||||
private:
|
||||
FakePresenceClient* most_recent_fake_presence_client_ = nullptr;
|
||||
std::vector<nearby::internal::SharedCredential> shared_credentials_;
|
||||
@@ -106,6 +112,7 @@ class FakePresenceService : public PresenceService {
|
||||
absl::Status update_remote_public_credentials_status_;
|
||||
absl::Status get_public_credentials_status_;
|
||||
::nearby::internal::DeviceIdentityMetaData metadata_;
|
||||
NearbyDeviceProvider* provider_;
|
||||
::nearby::Lender<PresenceService*> lender_{this};
|
||||
};
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "internal/interop/device_provider.h"
|
||||
#include "internal/proto/metadata.pb.h"
|
||||
#include "presence/data_types.h"
|
||||
#include "presence/presence_client.h"
|
||||
#include "presence/presence_device_provider.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
@@ -49,7 +49,7 @@ class PresenceService {
|
||||
int credential_life_cycle_days, int contiguous_copy_of_credentials,
|
||||
GenerateCredentialsResultCallback credentials_generated_cb) = 0;
|
||||
|
||||
virtual PresenceDeviceProvider* GetLocalDeviceProvider() = 0;
|
||||
virtual NearbyDeviceProvider* GetLocalDeviceProvider() = 0;
|
||||
|
||||
virtual void GetLocalPublicCredentials(
|
||||
const CredentialSelector& credential_selector,
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "presence/presence_device_provider.h"
|
||||
#include "presence/presence_service.h"
|
||||
#include "presence/scan_request.h"
|
||||
#include "internal/interop/device_provider.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
@@ -70,7 +71,7 @@ class PresenceServiceImpl : public PresenceService {
|
||||
int credential_life_cycle_days, int contiguous_copy_of_credentials,
|
||||
GenerateCredentialsResultCallback credentials_generated_cb) override;
|
||||
|
||||
PresenceDeviceProvider* GetLocalDeviceProvider() override {
|
||||
NearbyDeviceProvider* GetLocalDeviceProvider() override {
|
||||
return &provider_;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user