shdrlib 0.1.5

A three-tiered Vulkan shader compilation and rendering framework built in pure Rust
Documentation
//! Unit tests for EZ tier
//!
//! These tests verify the EZ tier's high-level APIs and error handling.
//! Most EZ functionality requires a Vulkan context, so these tests focus on
//! configuration, error paths, and API surface validation.

use crate::ez::*;

#[test]
fn test_ez_config_defaults() {
    let config = EzConfig::default();

    // Verify sensible defaults
    assert_eq!(config.app_name, "EZ Renderer");
    assert_eq!(config.in_flight_frames, 2);

    // Validation should be enabled in debug builds
    #[cfg(debug_assertions)]
    assert!(config.enable_validation);

    #[cfg(not(debug_assertions))]
    assert!(!config.enable_validation);
}

#[test]
fn test_ez_config_custom_values() {
    let config = EzConfig {
        app_name: "Custom App".to_string(),
        enable_validation: true,
        in_flight_frames: 3,
    };

    assert_eq!(config.app_name, "Custom App");
    assert!(config.enable_validation);
    assert_eq!(config.in_flight_frames, 3);
}

#[test]
fn test_ez_config_clone() {
    let config1 = EzConfig {
        app_name: "Test App".to_string(),
        enable_validation: false,
        in_flight_frames: 4,
    };

    let config2 = config1.clone();

    assert_eq!(config1.app_name, config2.app_name);
    assert_eq!(config1.enable_validation, config2.enable_validation);
    assert_eq!(config1.in_flight_frames, config2.in_flight_frames);
}

#[test]
fn test_ez_error_display() {
    // Test that error types can be displayed (for debugging)
    let error = EzError::RuntimeError("test error".to_string());
    let display = format!("{}", error);
    assert!(display.contains("test error"));
}

#[test]
fn test_ez_error_from_shader_manager_error() {
    use crate::ex::ShaderManagerError;

    let shader_error = ShaderManagerError::InvalidShaderId(crate::ex::ShaderId(999));
    let ez_error: EzError = shader_error.into();

    // Verify error conversion works
    match ez_error {
        EzError::RuntimeError(_) => {}
        _ => panic!("Expected RuntimeError variant"),
    }
}

#[test]
fn test_ez_error_from_runtime_error() {
    use crate::ex::RuntimeError;

    let runtime_error = RuntimeError::NoGraphicsQueue;
    let ez_error: EzError = runtime_error.into();

    // Verify error conversion works
    match ez_error {
        EzError::InitializationFailed { .. } => {}
        _ => panic!("Expected InitializationFailed variant"),
    }
}

#[test]
fn test_ez_config_validation_disabled_in_release() {
    // In release builds, validation should default to false for performance
    #[cfg(not(debug_assertions))]
    {
        let config = EzConfig::default();
        assert!(
            !config.enable_validation,
            "Validation should be disabled in release builds"
        );
    }
}

#[test]
fn test_ez_config_validation_enabled_in_debug() {
    // In debug builds, validation should default to true for safety
    #[cfg(debug_assertions)]
    {
        let config = EzConfig::default();
        assert!(
            config.enable_validation,
            "Validation should be enabled in debug builds"
        );
    }
}

#[test]
fn test_ez_config_reasonable_frame_count() {
    let config = EzConfig::default();

    // Frame count should be reasonable (typically 2-3)
    assert!(
        config.in_flight_frames >= 1,
        "Need at least one in-flight frame"
    );
    assert!(
        config.in_flight_frames <= 5,
        "Too many in-flight frames is wasteful"
    );
}

#[test]
fn test_ez_config_app_name_not_empty() {
    let config = EzConfig::default();
    assert!(
        !config.app_name.is_empty(),
        "Default app name should not be empty"
    );
}

#[test]
fn test_ez_error_is_send_and_sync() {
    // Verify error type can be used across threads
    fn assert_send<T: Send>() {}
    fn assert_sync<T: Sync>() {}

    assert_send::<EzError>();
    assert_sync::<EzError>();
}

#[test]
fn test_ez_config_is_clone() {
    // Verify config implements Clone properly
    fn assert_clone<T: Clone>() {}
    assert_clone::<EzConfig>();
}

// Integration test helpers (these would require Vulkan context in real tests)

#[test]
#[ignore] // Requires Vulkan context
fn test_ez_renderer_creation() {
    // This test would verify EzRenderer::new() works
    // Ignored because it requires Vulkan to be available
    // See demos/ez/ for working examples
}

#[test]
#[ignore] // Requires Vulkan context
fn test_ez_renderer_with_custom_config() {
    // This test would verify EzRenderer::with_config() works
    // Ignored because it requires Vulkan to be available
}

#[test]
#[ignore] // Requires Vulkan context
fn test_quick_pipeline_compilation() {
    // This test would verify quick_pipeline() compiles shaders
    // Ignored because it requires Vulkan to be available
}

#[test]
#[ignore] // Requires Vulkan context
fn test_quick_compute_compilation() {
    // This test would verify quick_compute() compiles compute shaders
    // Ignored because it requires Vulkan to be available
}

#[test]
#[ignore] // Requires Vulkan context
fn test_buffer_creation() {
    // This test would verify buffer creation APIs work
    // Ignored because it requires Vulkan to be available
}

#[test]
#[ignore] // Requires Vulkan context
fn test_image_creation() {
    // This test would verify image creation APIs work
    // Ignored because it requires Vulkan to be available
}

#[test]
#[ignore] // Requires Vulkan context
fn test_render_frame_callback() {
    // This test would verify render_frame() closure API works
    // Ignored because it requires Vulkan to be available
}

/// Documentation tests verify that the examples in docs compile and work correctly.
/// These are extracted from doc comments and run by `cargo test --doc`.
///
/// The doc tests in ez/mod.rs and ez/renderer.rs provide integration test coverage
/// for the EZ tier APIs. Run them with:
///
/// ```bash
/// cargo test --doc ez
/// ```
#[test]
fn test_documentation_tests_exist() {
    // This is a meta-test to remind maintainers that doc tests are the primary
    // integration tests for EZ tier. The doc tests in:
    // - src/ez/mod.rs (module-level examples)
    // - src/ez/renderer.rs (API examples)
    //
    // provide real working examples that also serve as tests.

    // This test validates that we have documentation coverage.
    // The actual integration tests run as doc tests.
}