Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5d7834e authored by Jack He's avatar Jack He Committed by Automerger Merge Worker
Browse files

Merge "Fix LeDevice, ClassicDevice, Device, AdapterConfig less than operators" am: ee3cd94f

parents 9c47618e ee3cd94f
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -45,7 +45,13 @@ class AdapterConfig {
    return !(*this == other);
  }
  bool operator<(const AdapterConfig& other) const {
    return config_ < other.config_ && memory_only_config_ < other.memory_only_config_ && section_ < other.section_;
    if (config_ != other.config_) {
      return config_ < other.config_;
    }
    if (memory_only_config_ != other.memory_only_config_) {
      return memory_only_config_ < other.memory_only_config_;
    }
    return section_ < other.section_;
  }
  bool operator>(const AdapterConfig& rhs) const {
    return (rhs < *this);
+96 −0
Original line number Diff line number Diff line
@@ -61,3 +61,99 @@ TEST(AdapterConfigTest, equality_test) {
  ASSERT_NE(adapter_config_1, adapter_config_3);
}

TEST(AdapterConfigTest, operator_less_than) {
  ConfigCache config1(10, Device::kLinkKeyProperties);
  ConfigCache config2(10, Device::kLinkKeyProperties);
  ASSERT_NE(&config1, &config2);
  ConfigCache* smaller_config_ptr = &config1;
  ConfigCache* larger_config_ptr = &config2;
  if (&config2 < &config1) {
    smaller_config_ptr = &config2;
    larger_config_ptr = &config1;
  }

  ConfigCache memory_only_config1(10, {});
  ConfigCache memory_only_config2(10, {});
  ASSERT_NE(&memory_only_config1, &memory_only_config2);
  ConfigCache* smaller_memory_only_config_ptr = &memory_only_config1;
  ConfigCache* larger_memory_only_config_ptr = &memory_only_config2;
  if (&memory_only_config2 < &memory_only_config1) {
    smaller_memory_only_config_ptr = &memory_only_config2;
    larger_memory_only_config_ptr = &memory_only_config1;
  }

  bluetooth::hci::Address smaller_address = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
  bluetooth::hci::Address larger_address = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x07}};

  {
    AdapterConfig adapter_config1(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    AdapterConfig adapter_config2(larger_config_ptr, larger_memory_only_config_ptr, larger_address.ToString());
    ASSERT_TRUE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(larger_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    AdapterConfig adapter_config2(smaller_config_ptr, larger_memory_only_config_ptr, larger_address.ToString());
    ASSERT_FALSE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(smaller_config_ptr, larger_memory_only_config_ptr, smaller_address.ToString());
    AdapterConfig adapter_config2(larger_config_ptr, smaller_memory_only_config_ptr, larger_address.ToString());
    ASSERT_TRUE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(smaller_config_ptr, smaller_memory_only_config_ptr, larger_address.ToString());
    AdapterConfig adapter_config2(larger_config_ptr, larger_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_TRUE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(larger_config_ptr, larger_memory_only_config_ptr, smaller_address.ToString());
    AdapterConfig adapter_config2(smaller_config_ptr, smaller_memory_only_config_ptr, larger_address.ToString());
    ASSERT_FALSE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(larger_config_ptr, larger_memory_only_config_ptr, larger_address.ToString());
    AdapterConfig adapter_config2(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_FALSE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(smaller_config_ptr, larger_memory_only_config_ptr, larger_address.ToString());
    AdapterConfig adapter_config2(larger_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_TRUE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(larger_config_ptr, smaller_memory_only_config_ptr, larger_address.ToString());
    AdapterConfig adapter_config2(smaller_config_ptr, larger_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_FALSE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    AdapterConfig adapter_config2(smaller_config_ptr, larger_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_TRUE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    AdapterConfig adapter_config2(smaller_config_ptr, smaller_memory_only_config_ptr, larger_address.ToString());
    ASSERT_TRUE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    AdapterConfig adapter_config2(larger_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_TRUE(adapter_config1 < adapter_config2);
  }

  {
    AdapterConfig adapter_config1(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    AdapterConfig adapter_config2(smaller_config_ptr, larger_memory_only_config_ptr, larger_address.ToString());
    ASSERT_TRUE(adapter_config1 < adapter_config2);
  }
}
+7 −1
Original line number Diff line number Diff line
@@ -49,7 +49,13 @@ class ClassicDevice {
    return !(*this == other);
  }
  bool operator<(const ClassicDevice& other) const {
    return config_ < other.config_ && memory_only_config_ < other.memory_only_config_ && section_ < other.section_;
    if (config_ != other.config_) {
      return config_ < other.config_;
    }
    if (memory_only_config_ != other.memory_only_config_) {
      return memory_only_config_ < other.memory_only_config_;
    }
    return section_ < other.section_;
  }
  bool operator>(const ClassicDevice& rhs) const {
    return (rhs < *this);
+96 −0
Original line number Diff line number Diff line
@@ -65,3 +65,99 @@ TEST(ClassicDeviceTest, equality_test) {
  ASSERT_NE(device1, device3);
}

TEST(ClassicDeviceTest, operator_less_than) {
  ConfigCache config1(10, Device::kLinkKeyProperties);
  ConfigCache config2(10, Device::kLinkKeyProperties);
  ASSERT_NE(&config1, &config2);
  ConfigCache* smaller_config_ptr = &config1;
  ConfigCache* larger_config_ptr = &config2;
  if (&config2 < &config1) {
    smaller_config_ptr = &config2;
    larger_config_ptr = &config1;
  }

  ConfigCache memory_only_config1(10, {});
  ConfigCache memory_only_config2(10, {});
  ASSERT_NE(&memory_only_config1, &memory_only_config2);
  ConfigCache* smaller_memory_only_config_ptr = &memory_only_config1;
  ConfigCache* larger_memory_only_config_ptr = &memory_only_config2;
  if (&memory_only_config2 < &memory_only_config1) {
    smaller_memory_only_config_ptr = &memory_only_config2;
    larger_memory_only_config_ptr = &memory_only_config1;
  }

  bluetooth::hci::Address smaller_address = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
  bluetooth::hci::Address larger_address = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x07}};

  {
    ClassicDevice device1(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ClassicDevice device2(larger_config_ptr, larger_memory_only_config_ptr, larger_address.ToString());
    ASSERT_TRUE(device1 < device2);
  }

  {
    ClassicDevice device1(larger_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ClassicDevice device2(smaller_config_ptr, larger_memory_only_config_ptr, larger_address.ToString());
    ASSERT_FALSE(device1 < device2);
  }

  {
    ClassicDevice device1(smaller_config_ptr, larger_memory_only_config_ptr, smaller_address.ToString());
    ClassicDevice device2(larger_config_ptr, smaller_memory_only_config_ptr, larger_address.ToString());
    ASSERT_TRUE(device1 < device2);
  }

  {
    ClassicDevice device1(smaller_config_ptr, smaller_memory_only_config_ptr, larger_address.ToString());
    ClassicDevice device2(larger_config_ptr, larger_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_TRUE(device1 < device2);
  }

  {
    ClassicDevice device1(larger_config_ptr, larger_memory_only_config_ptr, smaller_address.ToString());
    ClassicDevice device2(smaller_config_ptr, smaller_memory_only_config_ptr, larger_address.ToString());
    ASSERT_FALSE(device1 < device2);
  }

  {
    ClassicDevice device1(larger_config_ptr, larger_memory_only_config_ptr, larger_address.ToString());
    ClassicDevice device2(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_FALSE(device1 < device2);
  }

  {
    ClassicDevice device1(smaller_config_ptr, larger_memory_only_config_ptr, larger_address.ToString());
    ClassicDevice device2(larger_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_TRUE(device1 < device2);
  }

  {
    ClassicDevice device1(larger_config_ptr, smaller_memory_only_config_ptr, larger_address.ToString());
    ClassicDevice device2(smaller_config_ptr, larger_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_FALSE(device1 < device2);
  }

  {
    ClassicDevice device1(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ClassicDevice device2(smaller_config_ptr, larger_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_TRUE(device1 < device2);
  }

  {
    ClassicDevice device1(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ClassicDevice device2(smaller_config_ptr, smaller_memory_only_config_ptr, larger_address.ToString());
    ASSERT_TRUE(device1 < device2);
  }

  {
    ClassicDevice device1(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ClassicDevice device2(larger_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ASSERT_TRUE(device1 < device2);
  }

  {
    ClassicDevice device1(smaller_config_ptr, smaller_memory_only_config_ptr, smaller_address.ToString());
    ClassicDevice device2(smaller_config_ptr, larger_memory_only_config_ptr, larger_address.ToString());
    ASSERT_TRUE(device1 < device2);
  }
}
+7 −1
Original line number Diff line number Diff line
@@ -132,7 +132,13 @@ class Device {
    return !(*this == other);
  }
  bool operator<(const Device& other) const {
    return config_ < other.config_ && memory_only_config_ < other.memory_only_config_ && section_ < other.section_;
    if (config_ != other.config_) {
      return config_ < other.config_;
    }
    if (memory_only_config_ != other.memory_only_config_) {
      return memory_only_config_ < other.memory_only_config_;
    }
    return section_ < other.section_;
  }
  bool operator>(const Device& rhs) const {
    return (rhs < *this);
Loading