-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handling the ENODEV errors for Linux (closes #28)
- Loading branch information
Showing
12 changed files
with
112 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::fs; | ||
|
||
use super::super::SysFsDevice; | ||
|
||
// https://github.com/svartalf/rust-battery/issues/28 | ||
// | ||
// This test is not actually covers the `ENODEV` case, | ||
// but it would be nice to have some test cases, | ||
// especially when people are so gracious to provide | ||
// the test data. | ||
#[test] | ||
fn test_issue_28() { | ||
let root = sysfs_test_suite!( | ||
"charge_full_design" => 3600000, | ||
"serial_number" => "41167", | ||
"technology" => "Li-ion", | ||
"charge_now" => 725000, | ||
"present" => 1, | ||
"manufacturer" => "Hewlett-Packard", | ||
"type" => "Battery", | ||
"charge_full" => 3424000, | ||
"capacity" => 21, | ||
"cycle_count" => 0, | ||
"voltage_now" => 10663000, | ||
"status" => "Discharging", | ||
"alarm" => 340000, | ||
"model_name" => "PABAS0241231", | ||
"voltage_min_design" => 11400000, | ||
"capacity_level" => "Normal" | ||
); | ||
|
||
let path = root.into_path(); | ||
let device = SysFsDevice::try_from(path.clone()); | ||
|
||
assert!(device.is_ok()); | ||
|
||
fs::remove_dir_all(path).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/// This macro generates the bunch of files representing the | ||
/// `/sys/class/power_supply/{name}/*` directory contents. | ||
macro_rules! sysfs_test_suite { | ||
( $( $name:expr => $value:expr ),* ) => {{ | ||
use ::std::io::Write as _; | ||
|
||
let root = tempfile::tempdir().unwrap(); | ||
|
||
$( | ||
let mut file = ::std::fs::OpenOptions::new() | ||
.write(true) | ||
.create_new(true) | ||
.open(root.path().join($name)) | ||
.unwrap(); | ||
file.write_fmt(format_args!("{}\n", $value)).unwrap(); | ||
)* | ||
|
||
root | ||
}}; | ||
} | ||
|
||
mod issue_28; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters