peripheral_battery_tests.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Copyright 2020 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. #ifndef ASH_SYSTEM_POWER_PERIPHERAL_BATTERY_TESTS_H_
  5. #define ASH_SYSTEM_POWER_PERIPHERAL_BATTERY_TESTS_H_
  6. #include "ash/system/power/peripheral_battery_listener.h"
  7. #include "chromeos/dbus/power/power_manager_client.h"
  8. #include "third_party/abseil-cpp/absl/types/optional.h"
  9. // Constants common to peripheral battery listener and notifier tests.
  10. // HID device.
  11. inline constexpr char kTestBatteryPath[] =
  12. "/sys/class/power_supply/hid-AA:BB:CC:DD:EE:FF-battery";
  13. inline constexpr char kTestBatteryAddress[] = "aa:bb:cc:dd:ee:ff";
  14. inline constexpr char kTestDeviceName[] = "test device";
  15. inline constexpr char16_t kTestDeviceName16[] = u"test device";
  16. const inline auto kTestBatteryStatusIn = power_manager::
  17. PeripheralBatteryStatus_ChargeStatus_CHARGE_STATUS_DISCHARGING;
  18. const inline auto kTestBatteryStatusOut =
  19. ash::PeripheralBatteryListener::BatteryInfo::ChargeStatus::kDischarging;
  20. inline constexpr char kTestBatteryId[] = "battery_bluetooth-aa:bb:cc:dd:ee:ff";
  21. inline constexpr char kTestBatteryNotificationId[] =
  22. "battery_notification-battery_bluetooth-aa:bb:cc:dd:ee:ff";
  23. // Charging device
  24. inline constexpr char kTestChargerPath[] =
  25. "/sys/class/power_supply/peripheral0";
  26. inline constexpr char kTestChargerName[] = "";
  27. inline constexpr char kTestChargerId[] = "peripheral0";
  28. inline constexpr char kTestOtherChargerPath[] =
  29. "/sys/class/power_supply/peripheral1";
  30. inline constexpr char kTestOtherChargerName[] = "";
  31. inline constexpr char kTestOtherChargerId[] = "peripheral1";
  32. // TODO(b/215381232): Temporarily support both 'PCHG' name and 'peripheral' name
  33. // till upstream kernel driver is merged. Remove variable when upstream kernel
  34. // driver is merged.
  35. inline constexpr char kTestPCHGChargerPath[] = "/sys/class/power_supply/PCHG0";
  36. // Bluetooth devices.
  37. inline constexpr char kBluetoothDeviceAddress1[] = "aa:bb:cc:dd:ee:ff";
  38. inline constexpr char kBluetoothDeviceAddress2[] = "11:22:33:44:55:66";
  39. inline constexpr char kBluetoothDeviceName1[] = "device_name_1";
  40. inline constexpr char16_t kBluetoothDeviceName116[] = u"device_name_1";
  41. inline constexpr char kBluetoothDeviceName2[] = "device_name_2";
  42. inline constexpr char16_t kBluetoothDeviceName216[] = u"device_name_2";
  43. inline constexpr char kBluetoothDeviceId1[] =
  44. "battery_bluetooth-aa:bb:cc:dd:ee:ff";
  45. inline constexpr char kBluetoothDeviceNotificationId1[] =
  46. "battery_notification-battery_bluetooth-aa:bb:cc:dd:ee:ff";
  47. inline constexpr char kBluetoothDeviceId2[] =
  48. "battery_bluetooth-11:22:33:44:55:66";
  49. inline constexpr char kBluetoothDeviceNotificationId2[] =
  50. "battery_notification-battery_bluetooth-11:22:33:44:55:66";
  51. // Stylus devices.
  52. const inline char kTestStylusBatteryPath[] =
  53. "/sys/class/power_supply/hid-AAAA:BBBB:CCCC.DDDD-battery";
  54. const inline char kTestStylusName[] = "test_stylus";
  55. const inline auto kTestStylusBatteryStatusDischargingIn = power_manager::
  56. PeripheralBatteryStatus_ChargeStatus_CHARGE_STATUS_DISCHARGING;
  57. const inline auto kTestStylusBatteryStatusDischargingOut =
  58. ash::PeripheralBatteryListener::BatteryInfo::ChargeStatus::kDischarging;
  59. const inline char kStylusEligibleSerialNumbers[][18] = {
  60. "FABCDE01BCA23633", "019F02212D4F446E", "154006440FE368C",
  61. "0190AB234FFE368", "0154006440FE368C9", "0204009540fE368C9",
  62. "0347we-$%^$#^#*"};
  63. const inline char kStylusIneligibleSerialNumbers[][17] = {
  64. "0190AB234FFE368C", "0190AB234fFe368C", "0154006440FE368C",
  65. "0204009540FE368C", "2011003140FE368C", ""};
  66. // A period of time less than full garage charge, in seconds
  67. const inline int kPartialGarageChargeTime = 3;
  68. // A period of time greater than full garage charge, in seconds
  69. const inline int kFullGarageChargeTime = 30;
  70. inline constexpr char kStylusChargerDeviceName[] = "garaged-stylus-charger";
  71. // Provide pretty-printers in aid of EXPECT_CALL() diagnostics.
  72. namespace absl {
  73. inline void PrintTo(const absl::optional<uint8_t>& optional, std::ostream* os) {
  74. if (!optional.has_value()) {
  75. *os << "absl::nullopt";
  76. } else {
  77. *os << (int)*optional;
  78. }
  79. }
  80. } // namespace absl
  81. namespace ash {
  82. inline void PrintTo(
  83. const ash::PeripheralBatteryListener::BatteryInfo::ChargeStatus& status,
  84. std::ostream* os) {
  85. switch (status) {
  86. case ash::PeripheralBatteryListener::BatteryInfo::ChargeStatus::kUnknown:
  87. *os << "Unknown";
  88. break;
  89. case ash::PeripheralBatteryListener::BatteryInfo::ChargeStatus::
  90. kDischarging:
  91. *os << "Discharging";
  92. break;
  93. case ash::PeripheralBatteryListener::BatteryInfo::ChargeStatus::kCharging:
  94. *os << "Charging";
  95. break;
  96. case ash::PeripheralBatteryListener::BatteryInfo::ChargeStatus::kFull:
  97. *os << "Full";
  98. break;
  99. case ash::PeripheralBatteryListener::BatteryInfo::ChargeStatus::
  100. kNotCharging:
  101. *os << "NotCharging";
  102. break;
  103. case ash::PeripheralBatteryListener::BatteryInfo::ChargeStatus::kError:
  104. *os << "Error";
  105. break;
  106. default:
  107. *os << "unknown-enum-value";
  108. }
  109. *os << "(" << (int)status << ")";
  110. }
  111. inline void PrintTo(
  112. const ash::PeripheralBatteryListener::BatteryInfo::PeripheralType& type,
  113. std::ostream* os) {
  114. switch (type) {
  115. case ash::PeripheralBatteryListener::BatteryInfo::PeripheralType::kOther:
  116. *os << "Other";
  117. break;
  118. case ash::PeripheralBatteryListener::BatteryInfo::PeripheralType::
  119. kStylusViaScreen:
  120. *os << "StylusViaScreen";
  121. break;
  122. case ash::PeripheralBatteryListener::BatteryInfo::PeripheralType::
  123. kStylusViaCharger:
  124. *os << "StylusViaCharger";
  125. break;
  126. default:
  127. *os << "unknown-enum-value";
  128. }
  129. *os << "(" << (int)type << ")";
  130. }
  131. } // namespace ash
  132. #endif // ASH_SYSTEM_POWER_PERIPHERAL_BATTERY_TESTS_H_