hid_battery_util_unittest.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/power/hid_battery_util.h"
  5. #include <string>
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace ash {
  8. using HidBatteryUtilTest = testing::Test;
  9. TEST_F(HidBatteryUtilTest, IsHIDBattery) {
  10. EXPECT_FALSE(IsHIDBattery(std::string()));
  11. EXPECT_FALSE(IsHIDBattery("invalid-path"));
  12. EXPECT_FALSE(IsHIDBattery("/sys/class/power_supply/hid-"));
  13. EXPECT_FALSE(IsHIDBattery("-battery"));
  14. EXPECT_FALSE(IsHIDBattery("/sys/class/power_supply/hid--battery"));
  15. EXPECT_TRUE(
  16. IsHIDBattery("/sys/class/power_supply/hid-A0:b1:C2:d3:E4:f5-battery"));
  17. }
  18. TEST_F(HidBatteryUtilTest, ExtractHIDIdentifier) {
  19. EXPECT_EQ(std::string(), ExtractHIDBatteryIdentifier("invalid-path"));
  20. EXPECT_EQ("A0:b1:C2:d3:E4:f5",
  21. ExtractHIDBatteryIdentifier(
  22. "/sys/class/power_supply/hid-A0:b1:C2:d3:E4:f5-battery"));
  23. }
  24. TEST_F(HidBatteryUtilTest, ExtractBluetoothAddressFromHIDBatteryPath) {
  25. EXPECT_EQ(std::string(),
  26. ExtractBluetoothAddressFromHIDBatteryPath("invalid-path"));
  27. // 3 characters at the end of the address, "f55".
  28. EXPECT_EQ(std::string(),
  29. ExtractBluetoothAddressFromHIDBatteryPath(
  30. "/sys/class/power_supply/hid-A0:b1:C2:d3:E4:f55-battery"));
  31. // 3 characters at the start of the address, "A00".
  32. EXPECT_EQ(std::string(),
  33. ExtractBluetoothAddressFromHIDBatteryPath(
  34. "/sys/class/power_supply/hid-A00:b1:C2:d3:E4:f5-battery"));
  35. EXPECT_EQ("a0:b1:c2:d3:e4:f5",
  36. ExtractBluetoothAddressFromHIDBatteryPath(
  37. "/sys/class/power_supply/hid-A0:b1:C2:d3:E4:f5-battery"));
  38. }
  39. } // namespace ash