i3status/testcases
johcgt d5c69a9d60 Treat zero battery capacity as "not available" (#259)
`print_battery_info` computes `batt_info.percentage_remaining` by
dividing batt_info.remaining by `full`. If `full` is `0` then the
battery remaining will be reported as "inf".

Before this, it tries to set `full` to either the design capacity or to
the last known good charge. It determines if these values are available
by checking whether their fields in `batt_info` are non-negative. As it
initialized `batt_info` with values of `-1`, a non-negative value
implies that something has provided a value.

`slurp_all_batteries` and `add_battery_info` however initialize these
fields to zero, so if these functions are called then
`batt_info.full_design` will always be used.

This means that on systems that don't provide a value for design
capacity the percentage remaining will be reported as "inf", unless the
user has set `last_full_capacity` to `true` in their `i3status.conf`.

This patch changes `print_battery_info` to expect values for the battery
capacity to be strictly greater than zero. This seems reasonable as a
battery with a capacity of zero isn't useful.

An alternative solution would be to change `slurp_all_batteries` and
`add_battery_info` to initialize `batt_info` with `-1`, as
`print_battery_info` does. This is less appealing as `add_battery_info`
is accumulating the values, so using `-1` would introduce off-by-one
errors without additional code to avoid them.
2018-01-28 15:37:51 +01:00
..
001-battery
002-cpu-temp
003-path-exists
004-run-watch Added test case for run_watch 2016-11-14 21:33:09 +00:00
005-cpu-temp-max-threshold-format Add unit tests for threshold format 2016-11-15 13:34:06 +02:00
006-cpu-usage-max-threshold-format Add unit tests for threshold format 2016-11-15 13:34:06 +02:00
007-cpu-usage-degraded-threshold-format Add unit tests for threshold format 2016-11-15 13:34:06 +02:00
008-load-max-threshold-format Add unit tests for threshold format 2016-11-15 13:34:06 +02:00
009-disk-low-threshold-format Adding documentation for PR #179 (#182) 2016-11-19 06:02:10 -08:00
010-cpu-usage Fix CPU unit tests (#239) 2017-08-29 19:01:30 +02:00
011-cpu-usage Fix CPU unit tests (#239) 2017-08-29 19:01:30 +02:00
012-cpu-usage-error Fix CPU unit tests (#239) 2017-08-29 19:01:30 +02:00
013-cpu-usage-error Multiple CPU support for cpu_usage (#209) 2017-03-26 06:54:07 -04:00
014-battery-capacity Fix CPU unit tests (#239) 2017-08-29 19:01:30 +02:00
015-battery-capacity Add battery capacity parsing (#216) 2017-04-13 21:46:21 +02:00
016-ethernet-down Add network test cases (#246) 2017-11-20 19:51:48 +01:00
017-wireless-down Add network test cases (#246) 2017-11-20 19:51:48 +01:00
018-battery-capacity Treat zero battery capacity as "not available" (#259) 2018-01-28 15:37:51 +01:00
019-battery-capacity Treat zero battery capacity as "not available" (#259) 2018-01-28 15:37:51 +01:00