diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/battery-tests.el | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/lisp/battery-tests.el b/test/lisp/battery-tests.el index 92ab013f040..8d7cc7fccf3 100644 --- a/test/lisp/battery-tests.el +++ b/test/lisp/battery-tests.el | |||
| @@ -81,6 +81,69 @@ | |||
| 81 | (should (equal (match-string 2 str) "mWh"))) | 81 | (should (equal (match-string 2 str) "mWh"))) |
| 82 | (should-not (string-match (rx battery--acpi-capacity eos) "45 mW"))) | 82 | (should-not (string-match (rx battery--acpi-capacity eos) "45 mW"))) |
| 83 | 83 | ||
| 84 | (ert-deftest battery-upower-state () | ||
| 85 | "Test `battery--upower-state'." | ||
| 86 | ;; Charging. | ||
| 87 | (dolist (total '(nil charging discharging empty fully-charged | ||
| 88 | pending-charge pending-discharge)) | ||
| 89 | (should (eq (battery--upower-state '(("State" . 1)) total) 'charging))) | ||
| 90 | (dolist (state '(nil 0 1 2 3 4 5 6)) | ||
| 91 | (should (eq (battery--upower-state `(("State" . ,state)) 'charging) | ||
| 92 | 'charging))) | ||
| 93 | ;; Discharging. | ||
| 94 | (dolist (total '(nil discharging empty fully-charged | ||
| 95 | pending-charge pending-discharge)) | ||
| 96 | (should (eq (battery--upower-state '(("State" . 2)) total) 'discharging))) | ||
| 97 | (dolist (state '(nil 0 2 3 4 5 6)) | ||
| 98 | (should (eq (battery--upower-state `(("State" . ,state)) 'discharging) | ||
| 99 | 'discharging))) | ||
| 100 | ;; Pending charge. | ||
| 101 | (dolist (total '(nil empty fully-charged pending-charge pending-discharge)) | ||
| 102 | (should (eq (battery--upower-state '(("State" . 5)) total) | ||
| 103 | 'pending-charge))) | ||
| 104 | (dolist (state '(nil 0 3 4 5 6)) | ||
| 105 | (should (eq (battery--upower-state `(("State" . ,state)) 'pending-charge) | ||
| 106 | 'pending-charge))) | ||
| 107 | ;; Pending discharge. | ||
| 108 | (dolist (total '(nil empty fully-charged pending-discharge)) | ||
| 109 | (should (eq (battery--upower-state '(("State" . 6)) total) | ||
| 110 | 'pending-discharge))) | ||
| 111 | (dolist (state '(nil 0 3 4 6)) | ||
| 112 | (should (eq (battery--upower-state `(("State" . ,state)) 'pending-discharge) | ||
| 113 | 'pending-discharge))) | ||
| 114 | ;; Empty. | ||
| 115 | (dolist (total '(nil empty)) | ||
| 116 | (should (eq (battery--upower-state '(("State" . 3)) total) 'empty))) | ||
| 117 | (dolist (state '(nil 0 3)) | ||
| 118 | (should (eq (battery--upower-state `(("State" . ,state)) 'empty) 'empty))) | ||
| 119 | ;; Fully charged. | ||
| 120 | (dolist (total '(nil fully-charged)) | ||
| 121 | (should (eq (battery--upower-state '(("State" . 4)) total) 'fully-charged))) | ||
| 122 | (dolist (state '(nil 0 4)) | ||
| 123 | (should (eq (battery--upower-state `(("State" . ,state)) 'fully-charged) | ||
| 124 | 'fully-charged)))) | ||
| 125 | |||
| 126 | (ert-deftest battery-upower-state-unknown () | ||
| 127 | "Test `battery--upower-state' with unknown states." | ||
| 128 | ;; Unknown running total retains new state. | ||
| 129 | (should-not (battery--upower-state () nil)) | ||
| 130 | (should-not (battery--upower-state '(("State" . state)) nil)) | ||
| 131 | (should-not (battery--upower-state '(("State" . 0)) nil)) | ||
| 132 | (should (eq (battery--upower-state '(("State" . 1)) nil) 'charging)) | ||
| 133 | (should (eq (battery--upower-state '(("State" . 2)) nil) 'discharging)) | ||
| 134 | (should (eq (battery--upower-state '(("State" . 3)) nil) 'empty)) | ||
| 135 | (should (eq (battery--upower-state '(("State" . 4)) nil) 'fully-charged)) | ||
| 136 | (should (eq (battery--upower-state '(("State" . 5)) nil) 'pending-charge)) | ||
| 137 | (should (eq (battery--upower-state '(("State" . 6)) nil) 'pending-discharge)) | ||
| 138 | ;; Unknown new state retains running total. | ||
| 139 | (dolist (props '(() (("State" . state)) (("State" . 0)))) | ||
| 140 | (dolist (total '(nil charging discharging empty fully-charged | ||
| 141 | pending-charge pending-discharge)) | ||
| 142 | (should (eq (battery--upower-state props total) total)))) | ||
| 143 | ;; Conflicting empty and fully-charged. | ||
| 144 | (should-not (battery--upower-state '(("State" . 3)) 'fully-charged)) | ||
| 145 | (should-not (battery--upower-state '(("State" . 4)) 'empty))) | ||
| 146 | |||
| 84 | (ert-deftest battery-format () | 147 | (ert-deftest battery-format () |
| 85 | "Test `battery-format'." | 148 | "Test `battery-format'." |
| 86 | (should (equal (battery-format "" ()) "")) | 149 | (should (equal (battery-format "" ()) "")) |