diff --git a/presence/BUILD b/presence/BUILD index 7ccd0290..8e5bbc14 100644 --- a/presence/BUILD +++ b/presence/BUILD @@ -17,13 +17,18 @@ cc_library( name = "types", srcs = [ "device_motion.cc", + "discovery_filter.cc", "presence_action.cc", "presence_identity.cc", + "presence_zone.cc", ], hdrs = [ "device_motion.h", + "discovery_filter.h", + "discovery_options.h", "presence_action.h", "presence_identity.h", + "presence_zone.h", ], visibility = [ "//third_party/nearby/presence:__subpackages__", @@ -40,8 +45,11 @@ cc_test( size = "small", srcs = [ "device_motion_test.cc", + "discovery_filter_test.cc", + "discovery_options_test.cc", "presence_action_test.cc", "presence_identity_test.cc", + "presence_zone_test.cc", ], shard_count = 6, deps = [ diff --git a/presence/device_motion.h b/presence/device_motion.h index 2dcd4bc8..6a41dbf1 100644 --- a/presence/device_motion.h +++ b/presence/device_motion.h @@ -24,7 +24,6 @@ class DeviceMotion { }; DeviceMotion(MotionType motion_type = MotionType::kPointAndHold, float confidence = 0) noexcept; - ~DeviceMotion() noexcept = default; MotionType GetMotionType() const; float GetConfidence() const; diff --git a/presence/device_motion_test.cc b/presence/device_motion_test.cc index 6ff71b79..26af0b2b 100644 --- a/presence/device_motion_test.cc +++ b/presence/device_motion_test.cc @@ -20,11 +20,11 @@ namespace nearby { namespace presence { - -static constexpr DeviceMotion::MotionType kDefaultMotionType = +namespace { +static const DeviceMotion::MotionType kDefaultMotionType = DeviceMotion::MotionType::kPointAndHold; -static constexpr float kDefaultConfidence = 0; -static constexpr float kConfidenceForTest = 0.1; +static const float kDefaultConfidence = 0; +static const float kConfidenceForTest = 0.1; TEST(DeviceMotionTest, DefaultConstructorWorks) { DeviceMotion motion; EXPECT_EQ(motion.GetMotionType(), kDefaultMotionType); @@ -56,5 +56,6 @@ TEST(DeviceMotionTest, CopyInitEquals) { EXPECT_EQ(motion1, motion2); } +} // namespace } // namespace presence } // namespace nearby diff --git a/presence/discovery_filter.cc b/presence/discovery_filter.cc new file mode 100644 index 00000000..acfab3dd --- /dev/null +++ b/presence/discovery_filter.cc @@ -0,0 +1,34 @@ +// Copyright 2020 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 "third_party/nearby/presence/discovery_filter.h" + +namespace nearby { +namespace presence { + +DiscoveryFilter::DiscoveryFilter( + const std::vector& actions, + const std::vector& identities, + const std::vector& zones) noexcept + : actions_(actions), identities_(identities), zones_(zones) {} +std::vector DiscoveryFilter::GetActions() const { + return actions_; +} +std::vector DiscoveryFilter::GetIdentities() const { + return identities_; +} +std::vector DiscoveryFilter::GetZones() const { return zones_; } + +} // namespace presence +} // namespace nearby diff --git a/presence/discovery_filter.h b/presence/discovery_filter.h new file mode 100644 index 00000000..308068ff --- /dev/null +++ b/presence/discovery_filter.h @@ -0,0 +1,43 @@ +// Copyright 2020 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_DISCOVERY_FILTER_H_ +#define THIRD_PARTY_NEARBY_PRESENCE_DISCOVERY_FILTER_H_ + +#include + +#include "third_party/nearby/presence/presence_action.h" +#include "third_party/nearby/presence/presence_identity.h" +#include "third_party/nearby/presence/presence_zone.h" +namespace nearby { +namespace presence { +class DiscoveryFilter { + public: + DiscoveryFilter(const std::vector& = {}, + const std::vector& = {}, + const std::vector& = {}) noexcept; + std::vector GetActions() const; + std::vector GetIdentities() const; + std::vector GetZones() const; + + private: + const std::vector actions_; + const std::vector identities_; + const std::vector zones_; +}; + +} // namespace presence +} // namespace nearby + +#endif // THIRD_PARTY_NEARBY_PRESENCE_DISCOVERY_FILTER_H_ diff --git a/presence/discovery_filter_test.cc b/presence/discovery_filter_test.cc new file mode 100644 index 00000000..543191b4 --- /dev/null +++ b/presence/discovery_filter_test.cc @@ -0,0 +1,50 @@ +// Copyright 2020 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 "third_party/nearby/presence/discovery_filter.h" + +#include "gmock/gmock.h" +#include "protobuf-matchers/protocol-buffer-matchers.h" +#include "gtest/gtest.h" + +namespace nearby { +namespace presence { +namespace { + +const PresenceAction kTestAction = {1}; +const PresenceIdentity kTestIdentity = { + PresenceIdentity::IdentityType::kTrusted}; + +TEST(DiscoveryFilterTest, DefaultConstructorWorks) { + DiscoveryFilter filter; + EXPECT_EQ(filter.GetActions().size(), 0); + EXPECT_EQ(filter.GetIdentities().size(), 0); + EXPECT_EQ(filter.GetZones().size(), 0); +} + +TEST(DiscoveryFilterTest, PartiallyInitializationWorks) { + DiscoveryFilter filter1{{kTestAction}, {kTestIdentity}}; + DiscoveryFilter filter2{{kTestAction}}; + EXPECT_EQ(filter1.GetActions(), filter2.GetActions()); + EXPECT_NE(filter1.GetIdentities(), filter2.GetIdentities()); + EXPECT_EQ(filter1.GetZones(), filter2.GetZones()); + + EXPECT_EQ(filter1.GetActions()[0], kTestAction); + EXPECT_EQ(filter1.GetIdentities()[0], kTestIdentity); + EXPECT_EQ(filter1.GetZones().capacity(), 0); +} + +} // namespace +} // namespace presence +} // namespace nearby diff --git a/presence/discovery_options.h b/presence/discovery_options.h new file mode 100644 index 00000000..44dcfc0b --- /dev/null +++ b/presence/discovery_options.h @@ -0,0 +1,34 @@ +// Copyright 2020 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_DISCOVERY_OPTIONS_H_ +#define THIRD_PARTY_NEARBY_PRESENCE_DISCOVERY_OPTIONS_H_ + +namespace nearby { +namespace presence { +struct DiscoveryOptions { + const bool local_wifi_only_; +}; + +inline bool operator==(const DiscoveryOptions& o1, const DiscoveryOptions& o2) { + return o1.local_wifi_only_ == o2.local_wifi_only_; +} + +inline bool operator!=(const DiscoveryOptions& o1, const DiscoveryOptions& o2) { + return !(o1 == o2); +} + +} // namespace presence +} // namespace nearby +#endif // THIRD_PARTY_NEARBY_PRESENCE_DISCOVERY_OPTIONS_H_ diff --git a/presence/discovery_options_test.cc b/presence/discovery_options_test.cc new file mode 100644 index 00000000..c10d8404 --- /dev/null +++ b/presence/discovery_options_test.cc @@ -0,0 +1,51 @@ +// Copyright 2020 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 "third_party/nearby/presence/discovery_options.h" + +#include "gmock/gmock.h" +#include "protobuf-matchers/protocol-buffer-matchers.h" +#include "gtest/gtest.h" + +namespace nearby { +namespace presence { +namespace { + +constexpr bool kTestLocalWifiOnly = false; +TEST(DiscoveryOptionsTest, NoDefaultConstructor) { + EXPECT_FALSE(std::is_trivially_constructible::value); +} + +TEST(DiscoveryOptionsTest, ExplicitInitEquals) { + DiscoveryOptions option1 = {kTestLocalWifiOnly}; + DiscoveryOptions option2 = {kTestLocalWifiOnly}; + EXPECT_EQ(option1, option2); + EXPECT_EQ(option1.local_wifi_only_, kTestLocalWifiOnly); +} + +TEST(DiscoveryOptionsTest, ExplicitInitNotEquals) { + DiscoveryOptions option1 = {kTestLocalWifiOnly}; + DiscoveryOptions option2 = {!kTestLocalWifiOnly}; + EXPECT_NE(option1, option2); +} + +TEST(DiscoveryOptionsTest, CopyInitEquals) { + DiscoveryOptions option1 = {kTestLocalWifiOnly}; + DiscoveryOptions option2 = {option1}; + EXPECT_EQ(option1, option2); +} + +} // namespace +} // namespace presence +} // namespace nearby diff --git a/presence/presence_action.h b/presence/presence_action.h index 51a50c88..a073f6b6 100644 --- a/presence/presence_action.h +++ b/presence/presence_action.h @@ -20,7 +20,6 @@ namespace presence { class PresenceAction { public: PresenceAction(int action_identifier = 1); - ~PresenceAction() noexcept = default; int GetActionIdentifier() const; private: diff --git a/presence/presence_action_test.cc b/presence/presence_action_test.cc index f9f59227..ee66268a 100644 --- a/presence/presence_action_test.cc +++ b/presence/presence_action_test.cc @@ -20,8 +20,9 @@ namespace nearby { namespace presence { -static constexpr int kDefaultActionIdentifier = 1; -static constexpr int kTestActionIdentifier = 2; +namespace { +constexpr int kDefaultActionIdentifier = 1; +constexpr int kTestActionIdentifier = 2; TEST(PresenceActionTest, DefaultConstructorWorks) { PresenceAction action; EXPECT_EQ(action.GetActionIdentifier(), kDefaultActionIdentifier); @@ -53,5 +54,6 @@ TEST(PresenceActionTest, CopyInitEquals) { EXPECT_EQ(action1, action2); } +} // namespace } // namespace presence } // namespace nearby diff --git a/presence/presence_identity.h b/presence/presence_identity.h index 14ccb69f..48895924 100644 --- a/presence/presence_identity.h +++ b/presence/presence_identity.h @@ -24,7 +24,6 @@ class PresenceIdentity { kTrusted, }; PresenceIdentity(IdentityType type = IdentityType::kPrivate) noexcept; - ~PresenceIdentity() noexcept = default; IdentityType GetIdentityType() const; private: diff --git a/presence/presence_identity_test.cc b/presence/presence_identity_test.cc index 67794ab2..332eda4c 100644 --- a/presence/presence_identity_test.cc +++ b/presence/presence_identity_test.cc @@ -20,9 +20,10 @@ namespace nearby { namespace presence { -static constexpr PresenceIdentity::IdentityType kDefaultIdentityType = +namespace { +constexpr PresenceIdentity::IdentityType kDefaultIdentityType = PresenceIdentity::IdentityType::kPrivate; -static constexpr PresenceIdentity::IdentityType kTestIdentityType = +constexpr PresenceIdentity::IdentityType kTestIdentityType = PresenceIdentity::IdentityType::kTrusted; TEST(PresenceIdentityTest, DefaultIsError) { @@ -55,5 +56,6 @@ TEST(PresenceIdentityTest, CopyInitEquals) { EXPECT_EQ(identity1, identity2); } +} // namespace } // namespace presence } // namespace nearby diff --git a/presence/presence_zone.cc b/presence/presence_zone.cc new file mode 100644 index 00000000..26f1262e --- /dev/null +++ b/presence/presence_zone.cc @@ -0,0 +1,82 @@ +// Copyright 2020 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 "third_party/nearby/presence/presence_zone.h" + +namespace nearby { +namespace presence { + +PresenceZone::DistanceBoundary::DistanceBoundary(float min_distance_meters, + float max_distance_meters, + RangeType range_type) noexcept + : min_distance_meters_(min_distance_meters), + max_distance_meters_(max_distance_meters), + range_type_(range_type) {} + +float PresenceZone::DistanceBoundary::GetMinDistanceMeters() const { + return min_distance_meters_; +} + +float PresenceZone::DistanceBoundary::GetMaxDistanceMeters() const { + return max_distance_meters_; +} + +PresenceZone::DistanceBoundary::RangeType +PresenceZone::DistanceBoundary::GetRangeType() const { + return range_type_; +} + +PresenceZone::AngleOfArrivalBoundary::AngleOfArrivalBoundary( + float min_angle_degrees, float max_angle_degrees) noexcept + : min_angle_degrees_(min_angle_degrees), + max_angle_degrees_(max_angle_degrees) {} + +float PresenceZone::AngleOfArrivalBoundary::GetMinAngleDegrees() const { + return min_angle_degrees_; +} + +float PresenceZone::AngleOfArrivalBoundary::GetMaxAngleDegrees() const { + return max_angle_degrees_; +} + +PresenceZone::PresenceZone( + const DistanceBoundary& distance_boundary, + const AngleOfArrivalBoundary& azimuth_angle_boundary, + const AngleOfArrivalBoundary& elevation_angle_boundary, + const std::vector& device_motions) + : distance_boundary_(distance_boundary), + azimuth_angle_boundary_(azimuth_angle_boundary), + elevation_angle_boundary_(elevation_angle_boundary), + device_motions_(device_motions) {} + +PresenceZone::DistanceBoundary PresenceZone::GetDistanceBoundary() const { + return distance_boundary_; +} + +PresenceZone::AngleOfArrivalBoundary PresenceZone::GetAzimuthAngleBoundary() + const { + return azimuth_angle_boundary_; +} + +PresenceZone::AngleOfArrivalBoundary PresenceZone::GetElevationAngleBoundary() + const { + return elevation_angle_boundary_; +} + +std::vector PresenceZone::GetLocalDeviceMotions() const { + return device_motions_; +} + +} // namespace presence +} // namespace nearby diff --git a/presence/presence_zone.h b/presence/presence_zone.h new file mode 100644 index 00000000..9b8509a5 --- /dev/null +++ b/presence/presence_zone.h @@ -0,0 +1,110 @@ +// Copyright 2020 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_PRESENCE_ZONE_H_ +#define THIRD_PARTY_NEARBY_PRESENCE_PRESENCE_ZONE_H_ + +#include + +#include "third_party/nearby/presence/device_motion.h" +namespace nearby { +namespace presence { +class PresenceZone { + public: + class DistanceBoundary { + public: + enum class RangeType { + kRangeUnknown = 0, + kFar, // Distance is very far away from the peer device. + kLong, // Distance is relatively long from the peer device, typically a + // few meters. + kClose, // Distance is close to the peer device, typically with one or + // two meter. + kWithinReach, // Distance is very close to the peer device, typically + // within one meter or less. + kWithinTap, // Distance is within tap range to the peer device, typically + // within ~0.127 meters. + }; + DistanceBoundary(float = 0, float = 0, + RangeType = RangeType::kRangeUnknown) noexcept; + float GetMinDistanceMeters() const; + float GetMaxDistanceMeters() const; + RangeType GetRangeType() const; + + private: + const float min_distance_meters_; + const float max_distance_meters_; + const RangeType range_type_; + }; + + class AngleOfArrivalBoundary { + public: + AngleOfArrivalBoundary(float = 0, float = 0) noexcept; + float GetMinAngleDegrees() const; + float GetMaxAngleDegrees() const; + + private: + const float min_angle_degrees_; + const float max_angle_degrees_; + }; + + PresenceZone(const DistanceBoundary& = {}, const AngleOfArrivalBoundary& = {}, + const AngleOfArrivalBoundary& = {}, + const std::vector& = {}); + DistanceBoundary GetDistanceBoundary() const; + AngleOfArrivalBoundary GetAzimuthAngleBoundary() const; + AngleOfArrivalBoundary GetElevationAngleBoundary() const; + std::vector GetLocalDeviceMotions() const; + + private: + const DistanceBoundary distance_boundary_; + const AngleOfArrivalBoundary azimuth_angle_boundary_; + const AngleOfArrivalBoundary elevation_angle_boundary_; + const std::vector device_motions_; +}; + +inline bool operator==(const PresenceZone::DistanceBoundary& d1, + const PresenceZone::DistanceBoundary& d2) { + return d1.GetMinDistanceMeters() == d2.GetMinDistanceMeters() && + d1.GetMaxDistanceMeters() == d2.GetMaxDistanceMeters() && + d1.GetRangeType() == d2.GetRangeType(); +} +inline bool operator!=(const PresenceZone::DistanceBoundary& d1, + const PresenceZone::DistanceBoundary& d2) { + return !(d1 == d2); +} +inline bool operator==(const PresenceZone::AngleOfArrivalBoundary& a1, + const PresenceZone::AngleOfArrivalBoundary& a2) { + return a1.GetMinAngleDegrees() == a2.GetMinAngleDegrees() && + a1.GetMaxAngleDegrees() == a2.GetMaxAngleDegrees(); +} +inline bool operator!=(const PresenceZone::AngleOfArrivalBoundary& a1, + const PresenceZone::AngleOfArrivalBoundary& a2) { + return !(a1 == a2); +} + +inline bool operator==(const PresenceZone& z1, const PresenceZone& z2) { + return z1.GetDistanceBoundary() == z2.GetDistanceBoundary() && + z1.GetAzimuthAngleBoundary() == z2.GetAzimuthAngleBoundary() && + z1.GetElevationAngleBoundary() == z2.GetElevationAngleBoundary() && + z1.GetLocalDeviceMotions() == z2.GetLocalDeviceMotions(); +} +inline bool operator!=(const PresenceZone& z1, const PresenceZone& z2) { + return !(z1 == z2); +} + +} // namespace presence +} // namespace nearby + +#endif // THIRD_PARTY_NEARBY_PRESENCE_PRESENCE_ZONE_H_ diff --git a/presence/presence_zone_test.cc b/presence/presence_zone_test.cc new file mode 100644 index 00000000..fb77f742 --- /dev/null +++ b/presence/presence_zone_test.cc @@ -0,0 +1,221 @@ +// Copyright 2020 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 "third_party/nearby/presence/presence_zone.h" + +#include "gmock/gmock.h" +#include "protobuf-matchers/protocol-buffer-matchers.h" +#include "gtest/gtest.h" +#include "third_party/nearby/presence/device_motion.h" + +namespace nearby { +namespace presence { +namespace { + +using DistanceBoundary = nearby::presence::PresenceZone::DistanceBoundary; +using RangeType = nearby::presence::PresenceZone::DistanceBoundary::RangeType; +using AngleOfArrivalBoundary = + nearby::presence::PresenceZone::AngleOfArrivalBoundary; + +static const float kDefaultDistanceMeters = 0; +static const float kTestMinDistanceMeters = 1; +static const float kTestMaxDistanceMeters = 2; + +static const float kDefaultDegrees = 0; +static const float kTestMinAngleDegrees = 10; +static const float kTestMaxAngleDegrees = 20; + +static const float kTestConfidence = 0.1; + +static const RangeType kDefaultRangeType = RangeType::kRangeUnknown; +static const RangeType kTestRangeType = RangeType::kClose; + +static const DistanceBoundary kDefaultDistanceBoundary; +static const DistanceBoundary kTestDistanceBoundary = { + kTestMinDistanceMeters, kTestMaxDistanceMeters, kTestRangeType}; +static const AngleOfArrivalBoundary kDefaultAngleBoundary; +static const AngleOfArrivalBoundary kTestAzimuthAngleBoundary = { + kTestMinAngleDegrees, kTestMaxAngleDegrees}; +static const AngleOfArrivalBoundary kTestElevationAngleBoundary = { + kTestMinAngleDegrees, kTestMaxAngleDegrees}; +static const DeviceMotion kTestDeviceMotion = { + DeviceMotion::MotionType::kPointAndHold, kTestConfidence}; + +TEST(DistanceBoundaryTest, DefaultConstructorWorks) { + DistanceBoundary boundary; + EXPECT_EQ(boundary.GetMinDistanceMeters(), kDefaultDistanceMeters); + EXPECT_EQ(boundary.GetMaxDistanceMeters(), kDefaultDistanceMeters); + EXPECT_EQ(boundary.GetRangeType(), kDefaultRangeType); +} + +TEST(DistanceBoundaryTest, DefaultEquals) { + DistanceBoundary boundary1; + DistanceBoundary boundary2; + EXPECT_EQ(boundary1, boundary2); +} + +TEST(DistanceBoundaryTest, PartiallyInitializationWorks) { + DistanceBoundary boundary1 = {kTestMinDistanceMeters, kTestMaxDistanceMeters}; + DistanceBoundary boundary2 = {kTestMinDistanceMeters}; + EXPECT_EQ(boundary1.GetMinDistanceMeters(), kTestMinDistanceMeters); + EXPECT_EQ(boundary1.GetMaxDistanceMeters(), kTestMaxDistanceMeters); + EXPECT_EQ(boundary1.GetRangeType(), kDefaultRangeType); + EXPECT_EQ(boundary2.GetMinDistanceMeters(), kTestMinDistanceMeters); + EXPECT_EQ(boundary2.GetMaxDistanceMeters(), kDefaultDistanceMeters); + EXPECT_EQ(boundary2.GetRangeType(), kDefaultRangeType); +} + +TEST(DistanceBoundaryTest, ExplicitInitEquals) { + DistanceBoundary boundary1 = {kTestMinDistanceMeters, kTestMaxDistanceMeters, + kTestRangeType}; + DistanceBoundary boundary2 = {kTestMinDistanceMeters, kTestMaxDistanceMeters, + kTestRangeType}; + EXPECT_EQ(boundary1.GetMinDistanceMeters(), kTestMinDistanceMeters); + EXPECT_EQ(boundary1.GetMaxDistanceMeters(), kTestMaxDistanceMeters); + EXPECT_EQ(boundary1.GetRangeType(), kTestRangeType); + EXPECT_EQ(boundary1, boundary2); +} + +TEST(DistanceBoundaryTest, ExplicitInitNotEquals) { + DistanceBoundary boundary1 = {kTestMinDistanceMeters, kTestMaxDistanceMeters, + kTestRangeType}; + DistanceBoundary boundary2 = {kTestMinDistanceMeters + 0.1f, + kTestMaxDistanceMeters, kTestRangeType}; + EXPECT_NE(boundary1, boundary2); +} + +TEST(DistanceBoundaryTest, CopyInitEquals) { + DistanceBoundary boundary1 = {kTestMinDistanceMeters, kTestMaxDistanceMeters, + kTestRangeType}; + DistanceBoundary boundary2 = {boundary1}; + EXPECT_EQ(boundary1, boundary2); +} + +TEST(AngleOfArrivalBoundaryTest, DefaultConstructorWorks) { + AngleOfArrivalBoundary aoa_boundary; + EXPECT_EQ(aoa_boundary.GetMinAngleDegrees(), kDefaultDegrees); + EXPECT_EQ(aoa_boundary.GetMaxAngleDegrees(), kDefaultDegrees); +} + +TEST(AngleOfArrivalBoundaryTest, DefaultEquals) { + AngleOfArrivalBoundary aoa_boundary1; + AngleOfArrivalBoundary aoa_boundary2; + EXPECT_EQ(aoa_boundary1, aoa_boundary2); +} + +TEST(AngleOfArrivalBoundaryTest, PartiallyInitializationWorks) { + AngleOfArrivalBoundary aoa_boundary = {kTestMinAngleDegrees}; + EXPECT_EQ(aoa_boundary.GetMinAngleDegrees(), kTestMinAngleDegrees); + EXPECT_EQ(aoa_boundary.GetMaxAngleDegrees(), kDefaultDegrees); +} + +TEST(AngleOfArrivalBoundaryTest, ExplicitInitEquals) { + AngleOfArrivalBoundary aoa_boundary1 = {kTestMinAngleDegrees, + kTestMaxAngleDegrees}; + AngleOfArrivalBoundary aoa_boundary2 = {kTestMinAngleDegrees, + kTestMaxAngleDegrees}; + EXPECT_EQ(aoa_boundary1.GetMinAngleDegrees(), kTestMinAngleDegrees); + EXPECT_EQ(aoa_boundary1.GetMaxAngleDegrees(), kTestMaxAngleDegrees); + EXPECT_EQ(aoa_boundary1, aoa_boundary2); +} + +TEST(AngleOfArrivalBoundaryTest, ExplicitInitNotEquals) { + AngleOfArrivalBoundary aoa_boundary1 = {kTestMinAngleDegrees, + kTestMaxAngleDegrees}; + AngleOfArrivalBoundary aoa_boundary2 = {kTestMinAngleDegrees, + kTestMaxAngleDegrees + 0.1f}; + EXPECT_NE(aoa_boundary1, aoa_boundary2); +} + +TEST(AngleOfArrivalBoundaryTest, CopyInitEquals) { + AngleOfArrivalBoundary aoa_boundary1 = {kTestMinAngleDegrees, + kTestMaxAngleDegrees}; + AngleOfArrivalBoundary aoa_boundary2 = {aoa_boundary1}; + EXPECT_EQ(aoa_boundary1, aoa_boundary2); +} + +TEST(PresenceZoneTest, DefaultConstructorWorks) { + PresenceZone zone; + EXPECT_EQ(zone.GetDistanceBoundary(), kDefaultDistanceBoundary); + EXPECT_EQ(zone.GetAzimuthAngleBoundary(), kDefaultAngleBoundary); + EXPECT_EQ(zone.GetElevationAngleBoundary(), kDefaultAngleBoundary); + EXPECT_EQ(zone.GetLocalDeviceMotions().capacity(), 0); +} + +TEST(PresenceZoneTest, DefaultEquals) { + PresenceZone zone1; + PresenceZone zone2; + EXPECT_EQ(zone1, zone2); +} + +TEST(PresenceZoneTest, PartiallyInitializationWorks) { + PresenceZone zone1 = {kTestDistanceBoundary, kTestAzimuthAngleBoundary, + kTestElevationAngleBoundary}; + PresenceZone zone2 = {kTestDistanceBoundary, kTestAzimuthAngleBoundary}; + PresenceZone zone3 = {kTestDistanceBoundary}; + EXPECT_EQ(zone1.GetDistanceBoundary(), kTestDistanceBoundary); + EXPECT_EQ(zone1.GetAzimuthAngleBoundary(), kTestAzimuthAngleBoundary); + EXPECT_EQ(zone1.GetElevationAngleBoundary(), kTestElevationAngleBoundary); + EXPECT_EQ(zone1.GetLocalDeviceMotions().capacity(), 0); + EXPECT_EQ(zone2.GetDistanceBoundary(), kTestDistanceBoundary); + EXPECT_EQ(zone2.GetAzimuthAngleBoundary(), kTestAzimuthAngleBoundary); + EXPECT_EQ(zone2.GetElevationAngleBoundary(), kDefaultAngleBoundary); + EXPECT_EQ(zone2.GetLocalDeviceMotions().capacity(), 0); + EXPECT_EQ(zone3.GetDistanceBoundary(), kTestDistanceBoundary); + EXPECT_EQ(zone3.GetAzimuthAngleBoundary(), kDefaultAngleBoundary); + EXPECT_EQ(zone3.GetElevationAngleBoundary(), kDefaultAngleBoundary); + EXPECT_EQ(zone3.GetLocalDeviceMotions().capacity(), 0); +} + +TEST(PresenceZoneTest, ExplicitInitEquals) { + PresenceZone zone1 = {kTestDistanceBoundary, + kTestAzimuthAngleBoundary, + kTestElevationAngleBoundary, + {kTestDeviceMotion}}; + PresenceZone zone2 = {kTestDistanceBoundary, + kTestAzimuthAngleBoundary, + kTestElevationAngleBoundary, + {kTestDeviceMotion}}; + EXPECT_EQ(zone1.GetDistanceBoundary(), kTestDistanceBoundary); + EXPECT_EQ(zone1.GetAzimuthAngleBoundary(), kTestAzimuthAngleBoundary); + EXPECT_EQ(zone1.GetElevationAngleBoundary(), kTestElevationAngleBoundary); + EXPECT_EQ(zone1.GetLocalDeviceMotions().size(), 1); + EXPECT_EQ(zone1.GetLocalDeviceMotions()[0], kTestDeviceMotion); + EXPECT_EQ(zone1, zone2); +} + +TEST(PresenceZoneTest, ExplicitInitNotEquals) { + PresenceZone zone1 = {kTestDistanceBoundary, + kTestAzimuthAngleBoundary, + kTestElevationAngleBoundary, + {kTestDeviceMotion}}; + PresenceZone zone2 = {kTestDistanceBoundary, + kTestAzimuthAngleBoundary, + kTestElevationAngleBoundary, + {}}; + EXPECT_NE(zone1, zone2); +} + +TEST(PresenceZoneTest, CopyInitEquals) { + PresenceZone zone1 = {kTestDistanceBoundary, + kTestAzimuthAngleBoundary, + kTestElevationAngleBoundary, + {kTestDeviceMotion}}; + PresenceZone zone2 = {zone1}; + EXPECT_EQ(zone1, zone2); +} + +} // namespace +} // namespace presence +} // namespace nearby