use super::OfdPageGraphicsConfiguration;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GraphicsDeviceType {
Screen,
Printer,
Image,
}
#[derive(Debug, Clone)]
pub struct OfdPageGraphicsDevice {
pub device_type: GraphicsDeviceType,
pub name: Option<String>,
pub configuration: OfdPageGraphicsConfiguration,
}
impl OfdPageGraphicsDevice {
#[must_use]
pub fn new() -> Self {
Self {
device_type: GraphicsDeviceType::Image,
name: None,
configuration: OfdPageGraphicsConfiguration::new(),
}
}
#[must_use]
pub fn with_type(device_type: GraphicsDeviceType) -> Self {
Self {
device_type,
name: None,
configuration: OfdPageGraphicsConfiguration::new(),
}
}
#[must_use]
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
#[must_use]
pub fn configuration(mut self, config: OfdPageGraphicsConfiguration) -> Self {
self.configuration = config;
self
}
#[must_use]
pub fn device_type(&self) -> GraphicsDeviceType {
self.device_type
}
}
impl Default for OfdPageGraphicsDevice {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_default() {
let d = OfdPageGraphicsDevice::new();
assert_eq!(d.device_type(), GraphicsDeviceType::Image);
assert!(d.name.is_none());
}
#[test]
fn test_with_type() {
let d = OfdPageGraphicsDevice::with_type(GraphicsDeviceType::Screen);
assert_eq!(d.device_type(), GraphicsDeviceType::Screen);
}
#[test]
fn test_builder() {
let config = OfdPageGraphicsConfiguration::new().dpi(300);
let d = OfdPageGraphicsDevice::new()
.name("Printer1")
.configuration(config);
assert_eq!(d.name.as_deref(), Some("Printer1"));
assert_eq!(d.configuration.dpi_x, 300);
}
#[test]
fn test_device_type_variants() {
assert_ne!(GraphicsDeviceType::Screen, GraphicsDeviceType::Printer);
assert_ne!(GraphicsDeviceType::Printer, GraphicsDeviceType::Image);
}
#[test]
fn test_default() {
let d = OfdPageGraphicsDevice::default();
assert_eq!(d.device_type(), GraphicsDeviceType::Image);
}
}