Skip to content

Commit

Permalink
Add incomplete deserialization tests
Browse files Browse the repository at this point in the history
Verifies a few fields of ScannerCapabilities and ScannerStatus that are
interesting to me atm.
  • Loading branch information
tanuva committed Dec 4, 2023
1 parent aeca3c3 commit 35f2c3c
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 0 deletions.
56 changes: 56 additions & 0 deletions escl-scan/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,59 @@ pub struct ScanSettings {
#[serde(rename = "scan:YResolution")]
pub y_resolution: i16,
}

#[cfg(test)]
mod tests {
use crate::structs::*;
use std::io::Read;

#[test]
fn scanner_capabilities() {
let xml_file_result =
std::fs::File::open("../reference/Brother_MFC-2710DW_Capabilities.xml");
assert!(xml_file_result.is_ok());
let mut xml = String::new();
assert!(xml_file_result
.ok()
.unwrap()
.read_to_string(&mut xml)
.is_ok());

let result = serde_xml_rs::from_str::<ScannerCapabilities>(&xml);
if let Err(err) = result {
println!("{err}");
assert!(false);
return;
}

assert!(result.is_ok());
let caps = result.ok().unwrap();
let setting_profiles = caps.platen.platen_input_caps.setting_profiles.entries;
assert!(setting_profiles.len() == 1);
let platen_profile = setting_profiles.first().unwrap();
let color_modes = &platen_profile.color_modes.entries;
assert!(color_modes.len() == 3);
assert!(color_modes[0].mode_name == "BlackAndWhite1");
assert!(color_modes[1].mode_name == "Grayscale8");
assert!(color_modes[2].mode_name == "RGB24");
}

#[test]
fn scanner_status() {
let xml_file_result =
std::fs::File::open("../reference/Brother_MFC-2710DW_ScannerStatus.xml");
assert!(xml_file_result.is_ok());
let mut xml = String::new();
assert!(xml_file_result
.ok()
.unwrap()
.read_to_string(&mut xml)
.is_ok());

let result = serde_xml_rs::from_str::<ScannerStatus>(&xml);
assert!(result.is_ok());
let status = result.ok().unwrap();
assert!(status.state == ScannerState::Idle);
// TODO adf_state
}
}
170 changes: 170 additions & 0 deletions reference/Brother_MFC-2710DW_Capabilities.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="UTF-8"?>
<scan:ScannerCapabilities xmlns:scan="http://schemas.hp.com/imaging/escl/2011/05/03"
xmlns:pwg="http://www.pwg.org/schemas/2010/12/sm"
xmlns:dest="http://schemas.hp.com/imaging/destination/2011/06/06"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.hp.com/imaging/escl/2011/05/03 ../../schemas/eSCL-1_92.xsd">
<pwg:Version>2.63</pwg:Version>
<pwg:MakeAndModel>Brother MFC-L2710DW series</pwg:MakeAndModel>
<pwg:SerialNumber>E78295A8N498138</pwg:SerialNumber>
<scan:UUID>e3248000-80ce-11db-8000-3c2af4493199</scan:UUID>
<scan:AdminURI>http://brw2c6fc93127d1.local./net/net/airprint.html</scan:AdminURI>
<scan:IconURI>http://brw2c6fc93127d1.local./icons/device-icons-128.png</scan:IconURI>
<scan:Platen>
<scan:PlatenInputCaps>
<scan:MinWidth>16</scan:MinWidth>
<scan:MaxWidth>2550</scan:MaxWidth>
<scan:MinHeight>16</scan:MinHeight>
<scan:MaxHeight>3507</scan:MaxHeight>
<scan:MaxScanRegions>1</scan:MaxScanRegions>
<scan:SettingProfiles>
<scan:SettingProfile>
<scan:ColorModes>
<scan:ColorMode>BlackAndWhite1</scan:ColorMode>
<scan:ColorMode>Grayscale8</scan:ColorMode>
<scan:ColorMode>RGB24</scan:ColorMode>
</scan:ColorModes>
<scan:DocumentFormats>
<pwg:DocumentFormat>application/pdf</pwg:DocumentFormat>
<pwg:DocumentFormat>image/jpeg</pwg:DocumentFormat>
<scan:DocumentFormatExt>application/pdf</scan:DocumentFormatExt>
<scan:DocumentFormatExt>image/jpeg</scan:DocumentFormatExt>
</scan:DocumentFormats>
<scan:SupportedResolutions>
<scan:DiscreteResolutions>
<scan:DiscreteResolution>
<scan:XResolution>100</scan:XResolution>
<scan:YResolution>100</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>200</scan:XResolution>
<scan:YResolution>200</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>300</scan:XResolution>
<scan:YResolution>300</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>600</scan:XResolution>
<scan:YResolution>600</scan:YResolution>
</scan:DiscreteResolution>
</scan:DiscreteResolutions>
</scan:SupportedResolutions>
<scan:ColorSpaces>
<scan:ColorSpace>CMYK</scan:ColorSpace>
<scan:ColorSpace>YCC</scan:ColorSpace>
<scan:ColorSpace>sRGB</scan:ColorSpace>
</scan:ColorSpaces>
<scan:CcdChannels>
<scan:CcdChannel>Red</scan:CcdChannel>
<scan:CcdChannel>Green</scan:CcdChannel>
<scan:CcdChannel>Blue</scan:CcdChannel>
<scan:CcdChannel>NTSC</scan:CcdChannel>
<scan:CcdChannel>GrayCcd</scan:CcdChannel>
<scan:CcdChannel>GrayCcdEmulated</scan:CcdChannel>
</scan:CcdChannels>
<scan:BinaryRenderings>
<scan:BinaryRendering>Halftone</scan:BinaryRendering>
<scan:BinaryRendering>Threshold</scan:BinaryRendering>
</scan:BinaryRenderings>
</scan:SettingProfile>
</scan:SettingProfiles>
<scan:SupportedIntents>
<scan:Intent>Document</scan:Intent>
<scan:Intent>TextAndGraphic</scan:Intent>
<scan:Intent>Photo</scan:Intent>
<scan:Intent>Preview</scan:Intent>
</scan:SupportedIntents>
<scan:MaxOpticalXResolution>2400</scan:MaxOpticalXResolution>
<scan:MaxOpticalYResolution>2400</scan:MaxOpticalYResolution>
<scan:RiskyLeftMargin>0</scan:RiskyLeftMargin>
<scan:RiskyRightMargin>0</scan:RiskyRightMargin>
<scan:RiskyTopMargin>0</scan:RiskyTopMargin>
<scan:RiskyBottomMargin>0</scan:RiskyBottomMargin>
<scan:MaxPhysicalWidth>0</scan:MaxPhysicalWidth>
<scan:MaxPhysicalHeight>0</scan:MaxPhysicalHeight>
</scan:PlatenInputCaps>
</scan:Platen>
<scan:Adf>
<scan:AdfSimplexInputCaps>
<scan:MinWidth>16</scan:MinWidth>
<scan:MaxWidth>2550</scan:MaxWidth>
<scan:MinHeight>16</scan:MinHeight>
<scan:MaxHeight>4200</scan:MaxHeight>
<scan:MaxScanRegions>1</scan:MaxScanRegions>
<scan:SettingProfiles>
<scan:SettingProfile>
<scan:ColorModes>
<scan:ColorMode>BlackAndWhite1</scan:ColorMode>
<scan:ColorMode>Grayscale8</scan:ColorMode>
<scan:ColorMode>RGB24</scan:ColorMode>
</scan:ColorModes>
<scan:DocumentFormats>
<pwg:DocumentFormat>application/pdf</pwg:DocumentFormat>
<pwg:DocumentFormat>image/jpeg</pwg:DocumentFormat>
<scan:DocumentFormatExt>application/pdf</scan:DocumentFormatExt>
<scan:DocumentFormatExt>image/jpeg</scan:DocumentFormatExt>
</scan:DocumentFormats>
<scan:SupportedResolutions>
<scan:DiscreteResolutions>
<scan:DiscreteResolution>
<scan:XResolution>100</scan:XResolution>
<scan:YResolution>100</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>200</scan:XResolution>
<scan:YResolution>200</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>300</scan:XResolution>
<scan:YResolution>300</scan:YResolution>
</scan:DiscreteResolution>
<scan:DiscreteResolution>
<scan:XResolution>600</scan:XResolution>
<scan:YResolution>600</scan:YResolution>
</scan:DiscreteResolution>
</scan:DiscreteResolutions>
</scan:SupportedResolutions>
<scan:ColorSpaces>
<scan:ColorSpace>CMYK</scan:ColorSpace>
<scan:ColorSpace>YCC</scan:ColorSpace>
<scan:ColorSpace>sRGB</scan:ColorSpace>
</scan:ColorSpaces>
<scan:CcdChannels>
<scan:CcdChannel>Red</scan:CcdChannel>
<scan:CcdChannel>Green</scan:CcdChannel>
<scan:CcdChannel>Blue</scan:CcdChannel>
<scan:CcdChannel>NTSC</scan:CcdChannel>
<scan:CcdChannel>GrayCcd</scan:CcdChannel>
<scan:CcdChannel>GrayCcdEmulated</scan:CcdChannel>
</scan:CcdChannels>
<scan:BinaryRenderings>
<scan:BinaryRendering>Halftone</scan:BinaryRendering>
<scan:BinaryRendering>Threshold</scan:BinaryRendering>
</scan:BinaryRenderings>
</scan:SettingProfile>
</scan:SettingProfiles>
<scan:SupportedIntents>
<scan:Intent>Document</scan:Intent>
<scan:Intent>TextAndGraphic</scan:Intent>
<scan:Intent>Photo</scan:Intent>
<scan:Intent>Preview</scan:Intent>
</scan:SupportedIntents>
<scan:MaxOpticalXResolution>2400</scan:MaxOpticalXResolution>
<scan:MaxOpticalYResolution>2400</scan:MaxOpticalYResolution>
<scan:RiskyLeftMargin>0</scan:RiskyLeftMargin>
<scan:RiskyRightMargin>0</scan:RiskyRightMargin>
<scan:RiskyTopMargin>0</scan:RiskyTopMargin>
<scan:RiskyBottomMargin>0</scan:RiskyBottomMargin>
<scan:MaxPhysicalWidth>0</scan:MaxPhysicalWidth>
<scan:MaxPhysicalHeight>0</scan:MaxPhysicalHeight>
</scan:AdfSimplexInputCaps>
<scan:FeederCapacity>20</scan:FeederCapacity>
<scan:AdfOptions>
<scan:AdfOption>DetectPaperLoaded</scan:AdfOption>
</scan:AdfOptions>
</scan:Adf>
<scan:StoredJobRequestSupport>
<scan:MaxStoredjobRequests>0</scan:MaxStoredjobRequests>
<scan:TimeoutInSeconds>0</scan:TimeoutInSeconds>
</scan:StoredJobRequestSupport>
</scan:ScannerCapabilities>
49 changes: 49 additions & 0 deletions reference/Brother_MFC-2710DW_ScannerStatus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<scan:ScannerStatus xmlns:pwg="http://www.pwg.org/schemas/2010/12/sm"
xmlns:scan="http://schemas.hp.com/imaging/escl/2011/05/03"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.hp.com/imaging/escl/2011/05/03 ../../schemas/eSCL-1_92.xsd">
<pwg:Version>2.63</pwg:Version>
<pwg:State>Idle</pwg:State>
<scan:AdfState>ScannerAdfEmpty</scan:AdfState>
<scan:Jobs>
<scan:JobInfo>
<pwg:JobUri>
/eSCL/ScanJobs/71af3a90-8d5b-11ee-80cb-3c2af4493199
</pwg:JobUri>
<pwg:JobUuid>urn:uuid:71af3a90-8d5b-11ee-80cb-3c2af4493199</pwg:JobUuid>
<scan:Age>289564</scan:Age>
<pwg:ImagesCompleted>1</pwg:ImagesCompleted>
<pwg:ImagesToTransfer>1</pwg:ImagesToTransfer>
<pwg:JobState>Completed</pwg:JobState>
<pwg:JobStateReasons>
<pwg:JobStateReason>JobCompletedSuccessfully</pwg:JobStateReason>
</pwg:JobStateReasons>
</scan:JobInfo>
<scan:JobInfo>
<pwg:JobUri>
/eSCL/ScanJobs/0381d914-8e8d-11ee-8108-3c2af4493199
</pwg:JobUri>
<pwg:JobUuid>urn:uuid:0381d914-8e8d-11ee-8108-3c2af4493199</pwg:JobUuid>
<scan:Age>285373</scan:Age>
<pwg:ImagesCompleted>1</pwg:ImagesCompleted>
<pwg:ImagesToTransfer>1</pwg:ImagesToTransfer>
<pwg:JobState>Completed</pwg:JobState>
<pwg:JobStateReasons>
<pwg:JobStateReason>JobCompletedSuccessfully</pwg:JobStateReason>
</pwg:JobStateReasons>
</scan:JobInfo>
<scan:JobInfo>
<pwg:JobUri>
/eSCL/ScanJobs/253b25c7-8e8d-11ee-8109-3c2af4493199
</pwg:JobUri>
<pwg:JobUuid>urn:uuid:253b25c7-8e8d-11ee-8109-3c2af4493199</pwg:JobUuid>
<scan:Age>285324</scan:Age>
<pwg:ImagesCompleted>1</pwg:ImagesCompleted>
<pwg:ImagesToTransfer>1</pwg:ImagesToTransfer>
<pwg:JobState>Completed</pwg:JobState>
<pwg:JobStateReasons>
<pwg:JobStateReason>JobCompletedSuccessfully</pwg:JobStateReason>
</pwg:JobStateReasons>
</scan:JobInfo>
</scan:Jobs>
</scan:ScannerStatus>

0 comments on commit 35f2c3c

Please sign in to comment.