//! Integration tests for CP2K-RS
//!
//! These tests check the basic functionality of the CP2K Rust bindings.

use cp2k_rs::{finalize, get_version, init};

#[test]
fn test_cp2k_version() {
    // This test checks if we can get the CP2K version
    // It doesn't require initialization
    match get_version() {
        Ok(version) => {
            println!("CP2K version: {}", version);
            assert!(!version.is_empty());
            assert!(version.contains("CP2K"));
        }
        Err(e) => {
            println!("Warning: Could not get CP2K version: {}", e);
            // This might fail if CP2K is not properly linked, but we shouldn't panic the test
        }
    }
}

#[test]
fn test_cp2k_init_finalize() {
    // Test basic initialization and finalization
    match init() {
        Ok(_) => {
            println!("CP2K initialized successfully");

            // Try to get version after initialization
            match get_version() {
                Ok(version) => println!("CP2K version after init: {}", version),
                Err(e) => println!("Could not get version after init: {}", e),
            }

            // Finalize
            match finalize() {
                Ok(_) => println!("CP2K finalized successfully"),
                Err(e) => println!("CP2K finalization failed: {}", e),
            }
        }
        Err(e) => {
            println!("CP2K initialization failed: {}", e);
            // This might fail if MPI is not properly set up, but we don't want to fail the test
        }
    }
}

#[cfg(feature = "mpi")]
#[test]
fn test_mpi_functionality() {
    use cp2k_rs::{finalize, init};

    // This test is only run when MPI feature is enabled
    match init() {
        Ok(_) => {
            println!("CP2K with MPI initialized successfully");

            match finalize() {
                Ok(_) => println!("CP2K with MPI finalized successfully"),
                Err(e) => println!("CP2K MPI finalization failed: {}", e),
            }
        }
        Err(e) => {
            println!("CP2K MPI initialization failed: {}", e);
        }
    }
}
