Add PresenceAction vector to PresenceDevice

PiperOrigin-RevId: 518650656
This commit is contained in:
Anay Wadhera
2023-03-22 13:03:44 -07:00
committed by Copybara-Service
parent cbf50a3d49
commit abeabc3911
2 changed files with 14 additions and 0 deletions
+4
View File
@@ -25,6 +25,7 @@
#include "internal/proto/metadata.pb.h"
#include "presence/data_element.h"
#include "presence/device_motion.h"
#include "presence/presence_action.h"
namespace nearby {
namespace presence {
@@ -52,6 +53,8 @@ class PresenceDevice : public nearby::NearbyDevice {
std::vector<DataElement> GetExtendedProperties() const {
return extended_properties_;
}
void AddAction(const PresenceAction& action) { actions_.push_back(action); }
std::vector<PresenceAction> GetActions() const { return actions_; }
absl::string_view GetEndpointInfo() const override { return endpoint_info_; }
NearbyDevice::Type GetType() const override {
return NearbyDevice::Type::kPresenceDevice;
@@ -68,6 +71,7 @@ class PresenceDevice : public nearby::NearbyDevice {
const DeviceMotion device_motion_;
const Metadata metadata_;
std::vector<DataElement> extended_properties_;
std::vector<PresenceAction> actions_;
std::string endpoint_id_;
std::string endpoint_info_;
};
+10
View File
@@ -23,6 +23,7 @@
#include "internal/platform/ble_connection_info.h"
#include "internal/platform/logging.h"
#include "presence/data_element.h"
#include "presence/presence_action.h"
namespace nearby {
namespace presence {
@@ -37,6 +38,7 @@ constexpr float kTestConfidence = 0.1;
constexpr absl::string_view kMacAddr = "\x4C\x8B\x1D\xCE\xBA\xD1";
constexpr int kDataElementType = DataElement::kBatteryFieldType;
constexpr absl::string_view kDataElementValue = "15";
constexpr int kTestAction = 3;
Metadata CreateTestMetadata() {
Metadata metadata;
@@ -100,6 +102,14 @@ TEST(PresenceDevicetest, TestGetAddExtendedPropertiesVector) {
DataElement(kDataElementType, kDataElementValue));
}
TEST(PresenceDeviceTest, TestAddGetActions) {
Metadata metadata = CreateTestMetadata();
PresenceDevice device = PresenceDevice({kDefaultMotionType}, metadata);
device.AddAction({kTestAction});
ASSERT_EQ(device.GetActions().size(), 1);
EXPECT_EQ(device.GetActions()[0], PresenceAction(kTestAction));
}
TEST(PresenceDeviceTest, TestEndpointIdIsCorrectLength) {
Metadata metadata = CreateTestMetadata();
PresenceDevice device = PresenceDevice({kDefaultMotionType}, metadata);